Help, sysret causes #PF

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.
Post Reply
torshie
Member
Member
Posts: 89
Joined: Sun Jan 11, 2009 7:41 pm

Help, sysret causes #PF

Post 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
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Help, sysret causes #PF

Post 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
torshie
Member
Member
Posts: 89
Joined: Sun Jan 11, 2009 7:41 pm

Re: Help, sysret causes #PF

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