GDT at runtime

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
stanko51
Member
Member
Posts: 32
Joined: Fri Mar 27, 2009 6:58 pm

GDT at runtime

Post by stanko51 »

hello,

no paging enabled.
When loading a task I modify the GDT at run time to add the descriptor for this task and create a sergment of the needed size and then delete it when the task finishes. What do you think of this implementation ? Is there some special precaution to take i would have forgot ?

So far it is not working because the task crashes when it tries to run.

Thank you for your advice.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: GDT at runtime

Post by Tosi »

I think he wants to have memory protection, but without paging.
As for the problem, we will need more than "it doesn't work" to understand what the problem is. Mostly likely, you are not filling in the structure for a GDT entry correctly.
a5498828
Member
Member
Posts: 99
Joined: Thu Aug 12, 2010 7:25 am

Re: GDT at runtime

Post by a5498828 »

never modify gdt at runtime. never.
you set it up in real mode, enter p mode and it satys this way for the rest of os life. if you wana enter long mode, you setup entire gdt in real mode anyway.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: GDT at runtime

Post by Tosi »

There is nothing wrong with modifying the GDT at runtime, as long as it is done correctly. But if he wants to use segmentation for a memory protection scheme, I would recommend he use LDTs too.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: GDT at runtime

Post by AJ »

Hi,
stanko51 wrote:Is there some special precaution to take i would have forgot ?
Have you remembered to reload GDTR with the new GDT limit? Otherwise, as suggested above, look at the bits in your GDT entry and ensure they're all as you would expect.

This is perfectly valid and is how segmentation-based memory protection works. This is now considered legacy and if you ever want to dabble in long mode, you will need paging. Most resources you will find also relate to paging-based memory protection (with flat segmentation).

Cheers,
Adam
User avatar
Karatorian
Posts: 4
Joined: Sat Sep 13, 2008 9:36 am
Location: Rindge NH USA
Contact:

Re: GDT at runtime

Post by Karatorian »

a5498828 wrote:never modify gdt at runtime. never.
There are legitimate reasons for modifying the GDT at run time. One of them being using segmentation for memory protection (which is what the OP is trying to do). Another is booting from GRUB or any other multiboot compliant boot loader. (The processor is in protected mode, but there's no guarantee that the GDT is valid. Even reloading the segment registers with the same values they had before may not work.) Additionally, using segmentation is one of the methods of emulating NX on processors that don't support it.
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: GDT at runtime

Post by Gigasoft »

Windows also changes two GDT entries on each thread switch. One of them is updated to point to the current Thread Environment Block, and another is pointed at the LDT for the current process.
Post Reply