Reputation:
I am currently testing xv6 and implemented a new syscall.
As far as I can see, all syscalls in xv6 return an int. Is this needed and why?
Because I would like to return a C struct.
Is this possible? What would I have to do, to achieve this?
Upvotes: 0
Views: 1389
Reputation: 5265
The return value from the syscalls is stored in the eax
register.
As seen in the source:
proc->tf->eax = syscalls[num]();
This means that the return value will always be a single 32-bit value.
The type of the functions for system call handlers is also defined as returning int
and taking no arguments:
static int (*syscalls[])(void)
The correct way to return a struct in this situation is to pass a user-space pointer to as a syscall argument. After verifying that it's valid, it will store the struct data at that pointer. Note that since the syscall handler itself takes no arguments, you have to use the argument getters like argptr
, which handles validity checking for you.
Upvotes: 1