What is "fs" short for in kernel function "get_fs()"?

8,519

Solution 1

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 USER_DS         MAKE_MM_SEG(TASK_SIZE_MAX)

#define get_ds()        (KERNEL_DS)
#define get_fs()        (current_thread_info()->addr_limit)
#define set_fs(x)       (current_thread_info()->addr_limit = (x))

Solution 2

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.

Solution 3

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

Share:
8,519

Related videos on Youtube

xmllmx
Author by

xmllmx

Updated on September 18, 2022

Comments

  • xmllmx
    xmllmx over 1 year

    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?

  • wurtel
    wurtel over 9 years
    But what is that segment register used for in Linux...
  • Anthon
    Anthon over 9 years
    @wurfel argument validity checking or not (see updated answer).
  • dr_
    dr_ over 8 years
    Do you have any source for that?