Page 1 of 1
changing the GDT and LDT entries
Posted: Sat Jan 08, 2011 4:25 pm
by yaami
Hi all,
Assuming that the operating system is running in the protected mode, is it possible for the user applications to change the values of the entries in the GDT and LDT. or they just read only for user applications. If we want to change them from the user-land (say), can we use any system call (linux or windows) to change.
Does the operating system put value 3 in the CPL and RPL entries in the segment selectors by default, so that the programs run in the ring 3. And is it possible to change these values.
Thanks.
Re: changing the GDT and LDT entries
Posted: Sat Jan 08, 2011 4:33 pm
by Tosi
This topic is in the wrong forum (it should be OS development or general programming) but I will give an answer.
The short answer: What do you think? Do you think designers of these operating systems, both of which were created by large teams of experienced programmers, would seriously overlook such a grave mistake?
The long answer:
I have tried writing the GDT and IDT under Windows XP (x32). The program crashed with a GPF. No room for argument. When reading the GDT, I found out that one of the data segment regs (it was fs or gs) was different than the ds, es, and fs.
On Linux, if you are root, I think you can request the kernel to give you access to those kind of things. I know you can do it with ports, I wrote a program which messed with timers and DMA once. I ended up crashing the entire PC.
So if you're looking to be a 1337 h4x0r and rewrite system registers, look again. You can't do it.
Re: changing the GDT and LDT entries
Posted: Sat Jan 08, 2011 5:23 pm
by yaami
Sorry for posting this in the wrong forum. How do I move it to a different forum.
So in-short we cannot change these stuff from user-land. And regarding my other question does the OS put the user programs in ring-3 by using the value 3 in the RPL/CPL entries of the segment selectors. Is this how it puts the user programs in "user mode".
Thanks.
Re: changing the GDT and LDT entries
Posted: Sat Jan 08, 2011 5:55 pm
by Combuster
I wonder what the reason is why you are asking us those questions that are answered by both the official processor manuals and the wiki? You don't need us for the answer.
Re: changing the GDT and LDT entries
Posted: Sat Jan 08, 2011 9:09 pm
by yaami
Combuster wrote:I wonder what the reason is why you are asking us those questions that are answered by both the official processor manuals and the wiki? You don't need us for the answer.
I'm asking because I want to make sure that I understood the thing correctly. And regarding the point
OS put the user programs in ring-3 by using the value 3 in the RPL/CPL entries of the segment selectors
I could not find this thing put in words explicitly in the manual. I know that OS does put the user programs in ring-3 but how it does it was my question which I could not find the answer. Does it put, by default design, the value in the CPL/RPL. I thought I might get this answered in the forums. Though I do not want state this as an excuse for not knowing the answer or not understanding the manual, but still I'm not taking any courses and doing self study. So people out there are my teachers. Of course I do not expect you to teach me operating systems/computer architecture 101 course. But I had this doubt that I wanted to get clarified.
Re: changing the GDT and LDT entries
Posted: Sun Jan 09, 2011 4:45 am
by Combuster
I could not find this thing put in words explicitly in the manual
Intel 3A chapter 5 verse 5 wrote:Current privilege level (CPL) — The CPL is the privilege level of the currently
executing program or task. It is stored in bits 0 and 1 of the CS and SS segment
registers.
Better excuse wanted.
Re: changing the GDT and LDT entries
Posted: Sun Jan 09, 2011 10:09 am
by yaami
Pardon my lord Combustor, grave mistake committed.
I'm fired up now. I'll make a OS competing with MOS, and name it C-MOS, just kidding (no offense intended). But I'll try seriously to write one. I do not know why but this post got me motivated.
Thanks for the answer though. And thanks for your time to post a "verse" from the manual. I read that what I wanted to know was if OS does this. Anyway it is now clear.
Re: changing the GDT and LDT entries
Posted: Mon Jan 10, 2011 1:42 pm
by Owen
Linux has APIs for creating an LDT and setting entries in it. Its used by, for example, WINE. One assumes that FreeBSD and other operating systems capable of running WINE have similar features.