7e67b7bdaac3d4b37358c1630f6b991737cbb0cd
19 descempty(struct linux_user_desc
*info
)
21 return info
->base_addr
==0 && info
->limit
==0 &&
22 info
->contents
==0 && info
->read_exec_only
==1 &&
23 info
->seg_32bit
==0 && info
->limit_in_pages
==0 &&
24 info
->seg_not_present
==1 && info
->useable
==0;
27 int sys_set_thread_area(void *pinfo
)
29 struct linux_user_desc
*info
= pinfo
;
31 char *p
, *e
, *f
[Nfields
];
34 trace("sys_set_thread_area(%p)", pinfo
);
37 if((fd
= open("/dev/gdt", ORDWR
)) < 0)
40 idx
= info
->entry_number
;
43 if((n
= read(fd
, buf
, sizeof(buf
)-1)) <= 0)
47 while(e
= strchr(p
, '\n')){
49 if(getfields(p
, f
, nelem(f
), 1, " ") != nelem(f
))
51 idx
= strtoul(f
[Index
], nil
, 16);
52 if(idx
>= 8*sizeof(current
->tlsmask
))
54 if((current
->tlsmask
& (1<<idx
)) == 0)
63 if(idx
< 0 || idx
>= 8*sizeof(current
->tlsmask
))
67 if(!info
->seg_not_present
)
69 if(info
->limit_in_pages
)
73 if(info
->contents
& 2){
75 if(info
->contents
& 1)
79 if(!info
->read_exec_only
)
84 if(fprint(fd
, "%x code %s 3 %lux %lux\n",
85 idx
, buf
, (ulong
)info
->base_addr
, (ulong
)info
->limit
) < 0)
89 if(info
->contents
& 1)
93 if(!info
->read_exec_only
)
98 if(fprint(fd
, "%x data %s 3 %lux %lux\n",
99 idx
, buf
, (ulong
)info
->base_addr
, (ulong
)info
->limit
) < 0)
104 info
->entry_number
= idx
;
105 if(!descempty(info
)){
106 current
->tlsmask
|= 1<<idx
;
108 current
->tlsmask
&= ~(1<<idx
);
117 int sys_get_thread_area(void *pinfo
)
119 struct linux_user_desc
*info
= pinfo
;
122 char *p
, *e
, *f
[Nfields
];
124 trace("sys_get_thread_area(%p)", pinfo
);
127 if((fd
= open("/dev/gdt", OREAD
)) < 0)
131 if((n
= read(fd
, buf
, sizeof(buf
)-1)) <= 0)
135 while(e
= strchr(p
, '\n')){
137 if(getfields(p
, f
, nelem(f
), 1, " ") != nelem(f
))
139 idx
= strtoul(f
[Index
], nil
, 16);
140 if(idx
>= 8*sizeof(current
->tlsmask
))
142 if(idx
== info
->entry_number
)
150 if(strcmp(f
[Type
], "code") == 0)
152 info
->seg_not_present
= 1;
153 info
->limit_in_pages
= 0;
155 info
->read_exec_only
= 1;
157 for(p
= f
[Flags
]; *p
; p
++){
160 info
->seg_not_present
= 0;
163 info
->limit_in_pages
= 1;
171 info
->read_exec_only
= 0;
183 info
->base_addr
= strtoul(f
[Base
], nil
, 16);
184 info
->limit
= strtoul(f
[Limit
], nil
, 16);
195 cleardesc(struct linux_user_desc
*info
)
200 info
->read_exec_only
=1;
202 info
->limit_in_pages
=0;
203 info
->seg_not_present
=1;
209 struct linux_user_desc info
;
212 for(i
=0; i
<8*sizeof(current
->tlsmask
); i
++){
213 if((current
->tlsmask
& (1 << i
)) == 0)
216 info
.entry_number
= i
;
217 sys_set_thread_area(&info
);
219 current
->tlsmask
= 0;
222 void clonetls(Uproc
*new)
224 new->tlsmask
= current
->tlsmask
;
227 int sys_modify_ldt(int func
, void *data
, int count
)
229 trace("sys_modify_ldt(%d, %p, %x)", func
, data
, count
);