Page 1 of 1
Multitasking not working in JamesM tutorial
Posted: Mon Apr 23, 2012 4:45 am
by vjain20
Hi,
I am trying to the run the code downloaded from JamesM tutorial from the
multitasking section but I am getting a page fault.
Page fault! (present) at 0x106d7815 - EIP: 0x106d7815
PANIC(Page fault) at paging.c: 230.
I haven't made any change to the code.
I have seen another post reporting the same problem. If anyone has fixed this issue please
help me.
Re: Multitasking not working in JamesM tutorial
Posted: Mon Apr 23, 2012 4:49 am
by gravaera
Yo:
What is at paging.c, line 230?
--Peace out
gravaera
Re: Multitasking not working in JamesM tutorial
Posted: Mon Apr 23, 2012 8:25 am
by serviper
It's better to set up kernel stack and (perhaps a few pages) user stack when initializing paging. Just allocate pages for them and load the base address into esp and ebp, and call another function using the new stack frame - or you may crash because of invalid memory access.
Re: Multitasking not working in JamesM tutorial
Posted: Mon Apr 23, 2012 10:28 am
by JamesM
berkus wrote:It's not supposed to work, because that stack copying implementation is fragile and mostly invalid.
Indeed, it is shite.
Whoever wrote it deserves a slap.
Re: Multitasking not working in JamesM tutorial
Posted: Mon Apr 23, 2012 5:42 pm
by vjain20
It's better to set up kernel stack and (perhaps a few pages) user stack when initializing paging. Just allocate pages for them and load the base address into esp and ebp,
What about the data that is already there in the old stack and is being used ?
and call another function using the new stack frame - or you may crash because of invalid memory access.
Could you please explain this ? I am not getting how will it result in invalid memory access and how calling a function would avoid it ?
Re: Multitasking not working in JamesM tutorial
Posted: Tue Apr 24, 2012 9:19 am
by serviper
vjain20 wrote:
What about the data that is already there in the old stack and is being used ?
main() uses the old stack. Once we switch to a new stack and call another function, we'll never return to main(). The old stack is abandoned.
vjain20 wrote:
and call another function using the new stack frame - or you may crash because of invalid memory access.
Could you please explain this ? I am not getting how will it result in invalid memory access and how calling a function would avoid it ?
Local auto variables are accessed using ebp (and also esp sometimes). Switching to a new stack means
Code: Select all
asm volatile ("mov %0, %%ebp" :: "r" (new_stack_bottom));
asm volatile ("mov %0, %%esp" :: "r" (new_stack_bottom));
Note that the new stack frame is empty - no locals, no return address and no stack base address of the caller. Any access to the locals may get a garbage value, which may cause unexpected result (e.g, a page fault if you read a garbage pointer value).
Calling another function avoid invalid memory access by allocate space for local autos on the new stack frame, usually by moving esp first or use [ebp+offset] directly.