- 论坛徽章:
- 0
|
回复 6# gvim
谢谢了 这个内核栈的位置搞清楚了 还有个疑点 sp(内核堆栈指针) - kstack 代表什么?
cpu_fork(p1, p2)
register struct proc *p1, *p2;
{
register struct user *up = p2->p_addr;
int offset;
extern caddr_t getsp();
extern char kstack[];
p2->p_md.md_regs = p1->p_md.md_regs;
p2->p_md.md_flags = (p1->p_md.md_flags & ~(MDP_AST|MDP_HPUXTRACE));
/*
* Copy pcb and stack from proc p1 to p2.
* We do this as cheaply as possible, copying only the active
* part of the stack. The stack and pcb need to agree;
* this is tricky, as the final pcb is constructed by savectx,
* but its frame isn't yet on the stack when the stack is copied.
* switch compensates for this when the child eventually runs.
* This should be done differently, with a single call
* that copies and updates the pcb+stack,
* replacing the bcopy and savectx.
*/
p2->p_addr->u_pcb = p1->p_addr->u_pcb;
offset = getsp() - kstack;
bcopy((caddr_t)kstack + offset, (caddr_t)p2->p_addr + offset,
(unsigned) ctob(UPAGES) - offset);
PMAP_ACTIVATE(&p2->p_vmspace->vm_pmap, &up->u_pcb, 0);
/*
* Arrange for a non-local goto when the new process
* is started, to resume here, returning nonzero from setjmp.
*/
if (savectx(up, 1)) {
/*
* Return 1 in child.
*/
return (1);
}
return (0);
} |
|