There are two Linux kernel functions:

get_ds() and get_fs()

According to this article, I know ds is short for data segment.

However, I cannot guess what "fs" is short for.

Any explanations?


The FS comes from the additional segment register named FS on the 386 architecture (end of second paragraph).

My guess is that after DS for Data Segment and ES for Extra Segment Intel just went for the next characters in the alphabet (FS, GS). You can see the 386 register on the wiki page, on the graphic on the right side.

From the linux kernel source on my Linux Mint system (arch/x86/include/asm/uaccess.h):

 * The fs value determines whether argument validity checking should be
 * performed or not.  If get_fs() == USER_DS, checking is performed, with
 * get_fs() == KERNEL_DS, checking is bypassed.
 * For historical reasons, these macros are grossly misnamed.

#define MAKE_MM_SEG(s)  ((mm_segment_t) { (s) })

#define KERNEL_DS       MAKE_MM_SEG(-1UL)

#define get_ds()        (KERNEL_DS)
#define get_fs()        (current_thread_info()->addr_limit)
#define set_fs(x)       (current_thread_info()->addr_limit = (x))
|improve this answer|||||
  • But what is that segment register used for in Linux... – wurtel Feb 3 '15 at 12:15
  • @wurfel argument validity checking or not (see updated answer). – Anthon Feb 3 '15 at 12:38

A recent article, A farewell to set_fs, posted by Jonathan Corbet explains the historical reason for using fs in get_fs/set_fs.

The original role of set_fs() was to set the x86 processor's FS segment register which, in the early days, was used to control the range of virtual addresses that could be accessed by unprivileged code. The kernel has, of course, long since stopped using x86 segments this way.

|improve this answer|||||

As explained by Anthon above, it's just subsequent letters in alphabet that denotes they are additional data-segments.

This is more clearer from Intel's Vol-3A Sys.Prg.Guide, as shown below, where it says ES/ FS/ GS are 'three additional data-segment registers'

from Intel's (Vol3A) Sys.Prg.Guide

To know more about a bit of history on extra segment registers (FS/GS) got introduced from 286 to 386 refer the answer by "Mellowcandle" here

|improve this answer|||||

In get_fs(), fs is for free segment.

|improve this answer|||||
  • 2
    Do you have any source for that? – dr_ Aug 27 '15 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.