Hello,
Up until now, my exec() hasn't removed kernel code+data mappings from the page mappings. This is something I want to do now. I've created a new directory, mapped in the executable's segments, and set up a small stack space.
The page mappings look like this:
08048000-08049000 1000 -rw
10000000-10001000 1000 -rw
My issue is, in my task switch handler, I load esp, ebp, and cr3 with values from the structure containing info about the process. The routine in question looks like this:
Code:
task_switch_real:
cli
mov ecx, [esp + 4] ; eip
mov eax, [esp + 8] ; physical address of current paging dir
mov ebp, [esp + 12] ; ebp
mov esp, [esp + 16] ; esp
mov cr3, eax ; set paging directory
mov eax, 0xDEADBEEF ; magic value to detect task switch
sti
jmp ecx
This routine, and, thus, the instruction pointer when this routine executes, is in the kernel code. When I switch cr3 to that of the new process, kernel code is no longer mapped in, and I'm unable to execute the last instruction to jump to the new process's entry point as the instruction pointer is invalid, and I get a triple fault.
My initial idea was to turn off paging while I switch cr3, but that has the exact same problem: as soon as I turn paging back on to jump to the process's entry point, eip will be invalid again.
How can I work around this? Thanks!