我试图使用除默认代码和数据用户和内核段之外的不同段进行一些实验.我希望通过使用本地描述符表和modify_ldt系统调用来实现这一点.通过系统调用,我在LDT中创建了一个新条目,它是一个段描述符,其基地址是我要"隔离"的全局变量,限制为4个字节.
我尝试通过C程序中的内联汇编将数据段寄存器与我的自定义LDT条目的段选择器一起加载,但是当我尝试访问变量时,我收到了分段错误.
我的怀疑是我的全局变量的偏移存在问题,并且当计算地址时,它超出了我的自定义段的限制,因此导致seg错误.
有谁知道这种情况的工作?
哦,顺便说一句,这是在Linux的x86架构上.这是我第一次在论坛上提出这样的问题,所以如果有任何其他信息可以证明是有用的,请告诉我.
先感谢您.
编辑:我意识到我可能应该包含源代码:)
struct user_desc* table_entry_ptr = NULL;
/* Allocates memory for a user_desc struct */
table_entry_ptr = (struct user_desc*)malloc(sizeof(struct user_desc));
/* Fills the user_desc struct which represents the segment for mx */
table_entry_ptr->entry_number = 0;
table_entry_ptr->base_addr = ((unsigned long)&mx);
table_entry_ptr->limit = 0x4;
table_entry_ptr->seg_32bit = 0x1;
table_entry_ptr->contents = 0x0;
table_entry_ptr->read_exec_only = 0x0;
table_entry_ptr->limit_in_pages = 0x0;
table_entry_ptr->seg_not_present = 0x0;
table_entry_ptr->useable = 0x1;
/* Writes a user_desc struct to the ldt */
num_bytes = syscall( __NR_modify_ldt,
LDT_WRITE, // …Run Code Online (Sandbox Code Playgroud)