* Handle the return of a child process from fork1(). This function * is called from the MD fork_trampoline() entry point. */
| 1034 | * is called from the MD fork_trampoline() entry point. |
| 1035 | */ |
| 1036 | void |
| 1037 | fork_exit(void (*callout)(void *, struct trapframe *), void *arg, |
| 1038 | struct trapframe *frame) |
| 1039 | { |
| 1040 | struct proc *p; |
| 1041 | struct thread *td; |
| 1042 | struct thread *dtd; |
| 1043 | |
| 1044 | td = curthread; |
| 1045 | p = td->td_proc; |
| 1046 | KASSERT(p->p_state == PRS_NORMAL, ("executing process is still new")); |
| 1047 | |
| 1048 | CTR4(KTR_PROC, "fork_exit: new thread %p (td_sched %p, pid %d, %s)", |
| 1049 | td, td_get_sched(td), p->p_pid, td->td_name); |
| 1050 | |
| 1051 | sched_fork_exit(td); |
| 1052 | /* |
| 1053 | * Processes normally resume in mi_switch() after being |
| 1054 | * cpu_switch()'ed to, but when children start up they arrive here |
| 1055 | * instead, so we must do much the same things as mi_switch() would. |
| 1056 | */ |
| 1057 | if ((dtd = PCPU_GET(deadthread))) { |
| 1058 | PCPU_SET(deadthread, NULL); |
| 1059 | thread_stash(dtd); |
| 1060 | } |
| 1061 | thread_unlock(td); |
| 1062 | |
| 1063 | /* |
| 1064 | * cpu_fork_kthread_handler intercepts this function call to |
| 1065 | * have this call a non-return function to stay in kernel mode. |
| 1066 | * initproc has its own fork handler, but it does return. |
| 1067 | */ |
| 1068 | KASSERT(callout != NULL, ("NULL callout in fork_exit")); |
| 1069 | callout(arg, frame); |
| 1070 | |
| 1071 | /* |
| 1072 | * Check if a kernel thread misbehaved and returned from its main |
| 1073 | * function. |
| 1074 | */ |
| 1075 | if (p->p_flag & P_KPROC) { |
| 1076 | printf("Kernel thread \"%s\" (pid %d) exited prematurely.\n", |
| 1077 | td->td_name, p->p_pid); |
| 1078 | kthread_exit(); |
| 1079 | } |
| 1080 | mtx_assert(&Giant, MA_NOTOWNED); |
| 1081 | |
| 1082 | if (p->p_sysent->sv_schedtail != NULL) |
| 1083 | (p->p_sysent->sv_schedtail)(td); |
| 1084 | td->td_pflags &= ~TDP_FORKING; |
| 1085 | } |
| 1086 | |
| 1087 | /* |
| 1088 | * Simplified back end of syscall(), used when returning from fork() |
nothing calls this directly
no test coverage detected