Page 1 of 1
Reflect GDT changes
Posted: Wed Apr 18, 2007 3:20 am
by XCHG
I have coded two functions with below prototypes:
Code: Select all
DWORD __AddGDTDescriptor (void* GDTR, DWORD LowOrderDWORD, DWORD HighOrderDWORD); StdCall;
Boolean __RemoveGDTDescriptor (void* GDTR, DWORD SegmentSelector); StdCall;
The former adds a Segment Descriptor to the GDT and the latter removes one. Let's say I have added a Segment Descriptor to the GDT and I have put its segment selector in the GS. After I remove it from the GDT, I still can use GS. Does anybody have any idea why? When I remove a descriptor from the GDT, I simply put null in all 8 bytes of the descriptor. I can put the code in here if it helps you help me.
Thanks in advance.
Posted: Wed Apr 18, 2007 3:31 am
by pcmattman
Try removing CS or DS. I bet anything that it won't work then.
Posted: Wed Apr 18, 2007 4:06 am
by XCHG
Oh I just figured something out. As long as the Segment Selector is in either DS, ES, FS or GS and you have removed the segment descriptor from the GDT, you will still be able to use it but as soon as you put the previous value of either one of those segment selectors into themselves, as in the means of reloading them with their own values, you will get a general protection fault. This is weird isn't it?
pcmattman,
I tried removing the Data Segment Descriptor from the GDT and I could still use DS. I then did the below after having removed the DS from GDT:
And DS became invalid then. I guess we have to reload the segment selectors in order to validate and/or invalidate them.
Posted: Wed Apr 18, 2007 4:36 am
by Ztane
Quite opposite.. it is well-documented behaviour.
80386 programmer's reference manual, section 5.1.4:
"The 80386 stores information from descriptors in segment registers, thereby avoiding the need to consult a descriptor table every time it accesses memory." (
http://pdos.csail.mit.edu/6.828/2005/re ... s05_01.htm)