When I switch to usermode I get a pagefault instantly. Obviously I don't want that, but I can't see what's wrong with my code.
The code that I want to run is simply a while loop in a function, starting at $1006D0.
Page table entry before and after the problem happens: $100023 (means: $100000 -> $101000 is read-write-accessed-usermode)
Error code: $5 (means:: read from usermode)
es, gs, fs, es: $23 (my user data segment selectors, kernel is $10)
cs: $1B (my user code segment selector, kernel is $8)
CR2: $1006D0 (that's where the code is)
Why do I get read errors when the memory is readable?
[solved] Pagefault when I switch to usermode
-
- Member
- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
[solved] Pagefault when I switch to usermode
Last edited by Craze Frog on Wed Oct 08, 2008 7:27 am, edited 1 time in total.
Re: Pagefault when I switch to usermode
can you post some code in order trying to help you
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
but it does make you part of a larger picture.
-
- Member
- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
Re: Pagefault when I switch to usermode
I don't know what part of the code would be relevant.
The code I try to run in usermode (it works fine when I call it from kernel mode):
The code where I go to user-mode:
The code I try to run in usermode (it works fine when I call it from kernel mode):
Code: Select all
procedure myThread();
var
i: integer;
begin
while true do begin
end;
end;
Code: Select all
procedure Run(Thread: TTID);
var
regs: IrqRegs;
entry: pcardinal; { just for debugging }
begin
{ The next line sets up the regs structure with the correct register values, and
switches to the correct page directory (note that even before this "switch" I still used the same page directory.)
RunThread(PThread(Thread), @regs);
{ This code prints the page table entry for debugging }
entry := PageEntryGet($100000);
writestr('changed? ');
writehexln(entry^);
{ Here I go to user-mode }
asm
lea esp, regs
pop gs
pop fs
pop es
pop ds
popa
add esp, 8
iret
end;
end;
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Pagefault when I switch to usermode
is both the page directory entry and the page table entry marked as at least Present+RW+User
Re: Pagefault when I switch to usermode
$100007?Craze Frog wrote:$100023
If you have seen bad English in my words, tell me what's wrong, please.
-
- Member
- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
Re: Pagefault when I switch to usermode
Thank you, it seems like the page directory entry was marked as supervisor. Which is a bit strange since I don't pass that flag when I'm allocating memory for it, but I guess it's added somewhere down the road...Combuster wrote:is both the page directory entry and the page table entry marked as at least Present+RW+User
egos, $100007 is supervisor mode and would definetely not work.
Re: Pagefault when I switch to usermode
Of course, a page is "supervisor" by default - it's more a case of not passing the user flag.Craze Frog wrote:Thank you, it seems like the page directory entry was marked as supervisor. Which is a bit strange since I don't pass that flag...
Cheers,
Adam
-
- Member
- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
Re: Pagefault when I switch to usermode
Thanks guys, everything works perfectly now. I got a bit confused about all the bits.