xml*_*lmx 3 linux kernel conventions api linux-kernel
Linux内核有两个函数:
get_ds() 和 get_fs()
根据这篇文章,我知道ds是data segment.
但是,我猜不出“fs”是什么意思。
有什么解释吗?
FS 来自386 架构上名为 FS 的附加段寄存器(第二段结尾)。
我的猜测是,在数据段的 DS 和额外段的 ES 之后,英特尔只是选择了字母表中的下一个字符(FS、GS)。您可以在wiki 页面的右侧图形上看到 386 寄存器。
来自我的 Linux Mint 系统 ( arch/x86/include/asm/uaccess.h)上的 linux 内核源代码:
/*
* 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))
Run Code Online (Sandbox Code Playgroud)