get_segment_selector(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… get_segment_selector(9) πŸ’…

okay so this is from the Kernel API Manual, bestie, and it’s giving β€œwe need a segment selector” energy ✨

🌸 NAME 🌸

  • get_segment_selector β€” obtain segment selector πŸ’–

✨ SYNOPSIS ✨

short get_segment_selector (struct pt_regs *regs , int seg_reg_idx );

πŸŽ€ ARGUMENTS πŸŽ€

  • regs β€” register values as seen when entering kernel mode 🫢
  • seg_reg_idx β€” segment register index to use πŸ‘€

πŸ’– DESCRIPTION πŸ’–

okay so the whole point is to obtain the segment selector from any of the CS, SS, DS, ES, FS, GS segment registers. literally any of those six, she’s got you πŸ’…

In CONFIG_X86_32, the segment is obtained from either pt_regs or kernel_vm86_regs as applicable. In CONFIG_X86_64, CS and SS are obtained from pt_regs. DS, ES, FS and GS are obtained by reading the actual CPU registers. This is done only for completeness, because in CONFIG_X86_64 segment registers are ignored πŸ‘‘

what you get back:

  • the value of the segment selector, including null when running in long mode 🌈
  • -EINVAL on error πŸ’€

πŸ¦‹ SEE ALSO πŸ¦‹

these all live in the kernel file ./arch/x86/lib/insn-eval.c β€” go be nosy, bestie πŸ‘€

later bestie πŸ’– β€” source/version says ./arch/x86/lib, date says October 2026, and this whole page is get_segment_selector(9) πŸ¦‹βœ¨

πŸ“¦ where this page comes from