Skip to contentSkip to conversation

Assignment of GDT entries

DISCUSSION Albert Cahalan 2 participants 2 messages Sep 14, 2006

lore
Share & tools
lore
#0 lore raw
Quoted 5 lines · Linus Torvalds
Quoted 2 lines · Jeremy Fitzhardinge

So does this mean that moving the user-visible cs/ds isn't likely to break stuff, if it has been done before?

Quoted 8 lines

Yes. I _think_ we could do it. It's been done before, and nobody noticed.

That said, it may actually be that programs have since become much more aware of segments, for a rather perverse reason: the TLS stuff. Old programs are all very much coded and compiled for a totally flat model, and as such they really don't know _anything_ about segments. But with more TLS stuff, it's possible that a modern threded program is at least aware of _some_ of it.

We actually have an ABI problem right now because of this. Note that i386 and x86_64 use different GDT slots.

As far as I can tell, users need to hard-code the mapping from TLS slot to segment number. They use 0,1,2 to ask the kernel to set things up (via set_thread_area), but can't just pop that into %fs or %gs.

So a 32-bit app using set_thread_area can work on i386 or x86_64, but not both. I guess glibc gets %gs set up free via clone() with the right flags, and thus does not need to determine the kernel. For anything involving set_thread_area though, it gets nasty.

Typical hacks that result from this:

call uname() and look for "x86_64"
see of the addresses of local variables exceed 0xbfffffff examine /proc/1/maps
check for a /lib64 directory
change SSE register 8 in a signal handler frame and see if it sticks checksum the vdso code
...

Please save us from these foul hacks.

#1 lore raw
Quoted 7 lines · Albert Cahalan

We actually have an ABI problem right now because of this. Note that i386 and x86_64 use different GDT slots.

As far as I can tell, users need to hard-code the mapping from TLS slot to segment number. They use 0,1,2 to ask the kernel to set things up (via set_thread_area), but can't just pop that into %fs or %gs.

That's not true at all. The program I posted earlier in this thread uses set_thread_area() to allocate a GDT slot, and it works on both native 32 bit and 32-under-64. The entry_number field in the struct user_desc is an actual entry number, so you can easily construct a selector from it.

Quoted 11 lines

Typical hacks that result from this:

call uname() and look for "x86_64"
see of the addresses of local variables exceed 0xbfffffff examine /proc/1/maps
check for a /lib64 directory
change SSE register 8 in a signal handler frame and see if it sticks checksum the vdso code
...

Please save us from these foul hacks.

Er, that all looks completely unnecessary.

J