Page 1 of 1

Help, sysret causes #PF

Posted: Fri Sep 11, 2009 8:08 am
by torshie
Hi,
I am trying to implement process. The first problem is how to start a process. After building the page map, loading elf64 file into memory, I tried to use sysret to jump to the entry point of the executable, but a #PF happened. The page fault address was the entry point of the executable.

The sysret was used like this:
A static method System::sysret(entry) was used to start the user process. Here parameter entry was the entry point of the executable. System::sysret() was implemented like this:

Code: Select all

void System::sysret(Address address) {
	asm volatile("mov %0, %%rcx\n"
			"sysretq\n" : : "m"(address));
}
But if the process was started like the following, everything would be fine.

Code: Select all

asm volatile("jmp *%0" : : "r"(entry));
What could be possible reasons of the #PF?

Thanks in advance
torshie

Re: Help, sysret causes #PF

Posted: Fri Sep 11, 2009 8:17 am
by AJ
Hi,

My guess it that the User/Supervisor bit on your page table entry is zero. This needs to be set to indicate a user-level page. Your JMP does not change privilege level, byt SYSRET does.

Failing this, could you print the error code and double-check that the faulting address is really the EIP address?

Cheers,
Adam

Re: Help, sysret causes #PF

Posted: Fri Sep 11, 2009 8:46 am
by torshie
Thanks for replying

The problem was that I thought, in 64bit mode, wrmsr & rdmsr would write 64bit rax into msr and read msr into 64bit rax :oops:
I should have kept a copy manual on my desktop, though it is very ...

Thanks again
torshie