[NSWI004] Stuck on syscall return

Vojtech Horky horky at d3s.mff.cuni.cz
Sun Feb 16 16:02:38 CET 2020


Hello.

Dne 16. 02. 20 v 15:25 Patrik Smelik napsal(a):
> Hi,
> 
> Since yesterday, we are stuck on this problem. Userspace process is 

It would be extremely useful to send commit hash where the bug is 
reproducible, your master is four weeks old, I do not see implementation 
of print in branch as6...


> created fine, syscall handling also works, e.g. for print it prints out 
> what it needs to, but when returning from syscall, i.e. jumping back to 
> userspace, the application suddenly terminates. I fed the 
> cpu_jump_to_userspace function context->sp and context->epc as 
> arguments.The problem is that the context->sp is set to 0 for some 
> reason, which i believe isn't the correct input for the jump. I traced 
> the change to the memcpy method, so to when the binary image is being 
> copied, but i'm currently stuck here.

Not sure I got it right, but when the syscall is handled, the thread 
returns to userspace normally as with any other exception. That is, you 
need to call cpu_jump_to_userspace only once per process.

And you only use context->epc to advance to next instruction as 
otherwise the syscall would be restarted after being handled.

Also note that this function would typically receive two constants: 
address of the top of stack (so something like 0x3f00) and entry point 
as specified in the linker script (0x4000).

As a side note: in one of your commits I see that you panic when the 
syscall id is invalid. That is definitely a bad behavior because any 
application would be easily able to terminate your kernel.

Hope this helps,
- VH


More information about the NSWI004 mailing list