code:trap1 - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki
- 由 trap 调用
2826
2827 /*
2828 * Call the system-entry routine f (out of the
2829 * sysent table). This is a subroutine for trap, and
2830 * not in-line, because if a signal occurs
2831 * during processing, an (abnormal) return is simulated from
2832 * the last caller to savu(qsav); if this took place
2833 * inside of trap, it wouldn’t have a chance to clean up.
2834 *
2835 * If this occurs, the return takes place without
2836 * clearing u_intflg; if it’s still set, trap
2837 * marks an error which means that a system
2838 * call (like read on a typewrite) got interrupted
2839 * by a signal.
2840 */
2841 trap1(f)
2842 int (*f)();
2843 {
2844
2845 u.u_intflg = 1;
2846 savu(u.u_qsav);
- 置 u.u_intflg(系统调用 出错标志)
- 参看 后面的注释
2847 (*f)();
- 保存R5 R6到 u.u_qsav
2848 u.u_intflg = 0;
- 清 u.u_intflg(系统调用 出错标志)
关于此处的说明2849 }
- 如果 系统调用处理函数 正常,则u.u_intflg=0
- 若 系统调用处理函数 运行中 收到信号
- 检测信号 时 直接从u.u_qsav恢复R5,R6(sleep 2106)
- 函数返回到trap(SP已经恢复)
- 此时,u.u_intflg=1
- 在 trap 2773 抛出错误
2850 /* ------------------------- */