Page becomes not present when switching to ring 3

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.
User avatar
iocoder
Member
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

Post by iocoder »

iansjack wrote:The page is marked as user mode but not present (so says the page fault error code).
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.
User avatar
Combuster
Member
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

Post by Combuster »

SlayterDev wrote:Changed to this (I think thats what you meant):

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));
Now I get a general protection fault.
GCC is perfectly allowed to use eax (r) and esp-based references (m) in this construction. Both get clobbered before getting used.

I also don't trust the iret frame order - your probable eflags (0x200) are where I'd expect either SS or ESP.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
SlayterDev
Member
Member
Posts: 25
Joined: Wed Aug 13, 2014 4:22 pm

Re: Page becomes not present when switching to ring 3

Post by SlayterDev »

Changing to this:

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));
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.
SlayterDev
Member
Member
Posts: 25
Joined: Wed Aug 13, 2014 4:22 pm

Re: Page becomes not present when switching to ring 3

Post by SlayterDev »

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?
Post Reply