how to get pointer to user memory address space in Os/161 in execv
I am writing execv(char *program, char **args)
call in Os/161.
So, I get a copy of data user provided in program and in args in kernel space. Then I create brand new address space to which program with args is loaded.
The question is how to find appropriate pointer to user space virtual memory in order to copyout data from kernel space to user space before doing switching into user spa开发者_运维百科ce?
use the stack, but ensure that the memory is aligned
I'm working on OS161 too. Here is how I do it.
Before you destroy current address space, copy all the arguments into a kernel buffer. Then after you create and activate a new address space, get the stack pointer via as_define_stack and copy these arguments into the stack. You need to pack them very carefully otherwise you new stack will be corrupted. Also, as James said, all the pointers (start of each argument string) must be aligned at 4 bytes as well as the stackptr. After this, you need to adjust the stackptr accordingly to make space for these arguments.
Here is a doc offered by Harvard, you can check the details on page 9.
[EDIT]
I composed a blog about os161's execv system call. Hope I've make the question clear there.
[/EDIT]
精彩评论