Zbr's days.
February
Sun Mon Tue Wed Thu Fri Sat
       
12
     
2007
Months
Feb

About :: TODO :: Blog :: RSS :: Old blog :: Projects :: GIT :: Gallery :: Notes

Mon, 12 Feb 2007

The magic behind %gs access.


Ok, I've cought bodhi breath and understood, what did that mean.

Each descriptor is actually index shifted to 3 bits left, least significant bits are LDT/GDT selector and permissions bits, so %gs equal to 0x33 is actually descriptor number 6, which is first TLS descriptor in GDT.
As we know, each entry in GDT describes some region of memory, so construction "%%gs:123" is a 123 offset inside the area described by that descriptor, as I understand that, although it still requires to think why similar access to %%ds ends up with segmentation fault (I could understand absence of reading permissions for %%cs, but why data segment is not readable, I still can not understand).

That automagically means, that %%gs (which is priveledged descriptor as all other segment registers) can not be used to store information about userspace threads in M:N model, since it always points to the TLS area for the main process, so to get currently running userspace thread in M:N model stack pointer aligned to stack size can be used, but that requires that all stacks have the same size (which is true right now anyway).
Having ability to access curent thread not through ugly pointer allows to naturally scale on SMP, that is the only reason to invent such mechanism.

/devel/threading :: Link / Comments (0)

Please solve this captcha to be allowed to post (need to reload in a minute): 97 + 18

Comments are closed for this story.