Oh weird. Could you please check the value of your page entry after the exception? If it is really not present then maybe someone has changed it to get you into trouble.iansjack wrote:The page is marked as user mode but not present (so says the page fault error code).
Page becomes not present when switching to ring 3
- iocoder
- Member
- Posts: 208
- Joined: Sun Oct 18, 2009 5:47 pm
- Libera.chat IRC: iocoder
- Location: Alexandria, Egypt | Ottawa, Canada
- Contact:
Re: Page becomes not present when switching to ring 3
- 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: Page becomes not present when switching to ring 3
GCC is perfectly allowed to use eax (r) and esp-based references (m) in this construction. Both get clobbered before getting used.SlayterDev wrote:Changed to this (I think thats what you meant):Now I get a general protection fault.Code: Select all
asm volatile(" \ mov $0x23, %%ax; \ mov %%ax, %%ds; \ mov %%ax, %%es; \ mov %%ax, %%fs; \ mov %%ax, %%gs; \ push %0; \ pushl $0x200; \ pushl $0x1B; \ push %1; \ pushl $0x23; \ iret; \ ":: "r" (mainThread->frame.esp), "m" (mainThread->frame.eip));
I also don't trust the iret frame order - your probable eflags (0x200) are where I'd expect either SS or ESP.
-
- Member
- Posts: 25
- Joined: Wed Aug 13, 2014 4:22 pm
Re: Page becomes not present when switching to ring 3
Changing to this:
Produces the same page fault. However, in the page fault handler, I checked the page from the faulting address and it comes up as present. I have no idea what the deal is here.
Code: Select all
asm volatile(" \
pushl $0x23; \
push %0; \
pushl $0x200; \
pushl $0x1B; \
push %1; \
mov $0x23, %%ax; \
mov %%ax, %%ds; \
mov %%ax, %%es; \
mov %%ax, %%fs; \
mov %%ax, %%gs; \
iret; \
":: "r" (mainThread->frame.esp), "m" (mainThread->frame.eip));
-
- Member
- Posts: 25
- Joined: Wed Aug 13, 2014 4:22 pm
Re: Page becomes not present when switching to ring 3
Well I linked the executable higher up at 0x02000000. Now, if the program is just "jmp $" it runs. But if it is anything else, I get a read-only page fault on a page between where I mapped the program and the stack. I make adjustments to ensure that page is mapped and set as writable (present and user-mode of course) but then we get a "page not present" page fault again. Even stranger, the address loaded from cr2 is 0x2 (where the range we should be in is 0x02000000-0x2002000). I'm going to dig around some more in the morning and see if I can figure anything else out. Any ideas?