// Per-process state structproc { structspinlocklock;
// p->lock must be held when using these: enumprocstatestate;// Process state structproc *parent;// Parent process void *chan; // If non-zero, sleeping on chan int killed; // If non-zero, have been killed int xstate; // Exit status to be returned to parent's wait int pid; // Process ID // these are private to the process, so p->lock need not be held. int intv; // alarm interval int ticks; // ticks after last time handler is called int handler_ret; // whether a handler has returned uint64 sigret_pc; // pc after returning from sigreturn uint64 kstack; // Virtual address of kernel stack uint64 sz; // Size of process memory (bytes) pagetable_t pagetable; // User page table structtrapframe *trapframe;// data page for trampoline.S structsigframe *sigframe;// data saved for sigalarm and sigreturn structcontextcontext;// swtch() here to run process structfile *ofile[NOFILE];// Open files structinode *cwd;// Current directory void (*handler)(); // handler function char name[16]; // Process name (debugging) };
然后是trap.c中完整版的时钟中断处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
if(which_dev == 2) { if(p->intv) { p->ticks++; if(p->ticks == p->intv && p->handler_ret) { // p->trapframe->epc stores the pc when trap occurred // we will recover it when sigreturn is called savesigreg();// copy regs, it is easy so the definition isn't shown here~ p->sigret_pc = p->trapframe->epc; p->trapframe->epc = (uint64)(p->handler); p->handler_ret = 0; p->ticks = 0; } else yield(); } else yield(); }
最后是sys_sigreturn函数
1 2 3 4 5 6 7 8 9
uint64 sys_sigreturn(void) { structproc *p = myproc(); ... // what should we be do here? :) p->trapframe->epc = p->sigret_pc; p->handler_ret = 1; return0; }