[英]how to have a child process forked through sys_fork() to have its kernel stack contain the trap frame?
I am working on the implementation of system call sys_fork() on the kernel level. 我正在内核级别上实现系统调用sys_fork()的工作。 I did the copying of the parent process to the child process as per requirements.
我按照要求将父流程复制到了子流程。 The problem is how to copy the child's trapframe (copy of the parent trapframe) onto the child's kernel stack to pass the assertion in mips_usermode()?
问题是如何将子级的陷印框(父级陷印框的副本)复制到子级的内核堆栈中,以在mips_usermode()中传递断言?
I figured out my problem. 我发现了我的问题。
But what I am going to say is related to OS161 system. 但是我要说的与OS161系统有关。 So anyone working on this system, this will be helpful.
因此,使用此系统的任何人都将有所帮助。
Ok, there is a function on the kernel side which deals with context switch. 好的,内核方面有一个函数可以处理上下文切换。 This function stores all the data related to context switch frame onto the threads kernel stack.
该函数将所有与上下文切换帧相关的数据存储到线程内核堆栈中。
So all you need to do is follow the same steps and instead of switch frame structure, you need to replace it with trap frame structure. 因此,您所需要做的就是遵循相同的步骤,而不是用开关框架结构代替开关框架结构。
Here is the implementation for it:- 这是它的实现:
vaddr_t stacktop;
struct trapframe *tf;
stacktop = ((vaddr_t)thread->t_stack) + STACK_SIZE; //t_stack is the kernel stack
tf = ((struct trapframe *) stacktop) - 1;
t_stack is just a chunk of memory on the kernel side to store anything related to exceptions or context switch. t_stack只是内核侧的一块内存,用于存储与异常或上下文切换有关的任何内容。
Be sure to first clean out the t_stack before you load it with trapframe as it will contain data related to context switch frame incase of sys_fork implementation. 确保在使用trapframe加载t_stack之前先对其进行清理,因为在sys_fork实现的情况下,它将包含与上下文切换帧相关的数据。
Any corrections or comments on this are welcomed. 欢迎对此进行任何更正或评论。
I'm working on OS161 too. 我也在OS161上工作。 Here is how I tackle the problem.
这是我解决问题的方法。
In sys_fork, I copy parent's trapframe into a kernel heap space allocated via kmalloc: 在sys_fork中,我将双亲的trapframe复制到通过kmalloc分配的内核堆空间中:
struct trapframe* ctf = (struct trapframe*)kmalloc(sizeof(struct trapframe));
*ctf = *tf; // tf points to parent's trapframe;
Then I use thread_fork to create a child thread: 然后,我使用thread_fork创建一个子线程:
// passing address space using the second parameter of
// child_forkentry, quite dirty
thread_fork(curthread->t_name, child_forkentry, ctf, (unsigned long)as, NULL);
In child_forkentry, which is the first function called by the child, I do the following: 在child_forkentry中,这是孩子调用的第一个函数,我执行以下操作:
struct trapframe tf; // tf will be allocated on child's kernel stack
tf = *ctf
misp_usermode(&tf);
This will pass the stack check in mips_usermode. 这将通过mips_usermode中的堆栈检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.