#include <mach/task.h>
#include <mach/thread_act.h>
+#include <vm/vm_protos.h>
+
#include <sys/sdt.h>
+extern boolean_t init_task_died;
extern char init_task_failure_data[];
void proc_prepareexit(proc_t p, int rv, boolean_t perf_notify);
void vfork_exit(proc_t p, int rv);
/*
* Things which should have prototypes in headers, but don't
*/
-void *get_bsduthreadarg(thread_t);
void proc_exit(proc_t p);
int wait1continue(int result);
int waitidcontinue(int result);
-int *get_bsduthreadrval(thread_t);
kern_return_t sys_perf_notify(thread_t thread, int pid);
kern_return_t task_exception_notify(exception_type_t exception,
mach_exception_data_type_t code, mach_exception_data_type_t subcode);
void delay(int);
-void gather_rusage_info_v2(proc_t p, struct rusage_info_v2 *ru, int flavor);
+void gather_rusage_info(proc_t p, rusage_info_current *ru, int flavor);
/*
* NOTE: Source and target may *NOT* overlap!
{
exit1(p, W_EXITCODE(uap->rval, 0), retval);
- /* drop funnel before we return */
thread_exception_return();
/* NOTREACHED */
while (TRUE)
TASK_POLICY_TERMINATED, TASK_POLICY_ENABLE);
proc_lock(p);
- error = proc_transstart(p, 1);
+ error = proc_transstart(p, 1, ((jetsam_flags & P_JETSAM_VNODE) ? 1 : 0));
if (error == EDEADLK) {
/* Temp: If deadlock error, then it implies multithreaded exec is
* in progress. Instread of letting exit continue and
}
sig_lock_to_exit(p);
}
- if (p == initproc) {
+ if (p == initproc && current_proc() == p) {
proc_unlock(p);
printf("pid 1 exited (signal %d, exit %d)",
WTERMSIG(rv), WEXITSTATUS(rv));
+#if (DEVELOPMENT || DEBUG)
+ int err;
+ /*
+ * For debugging purposes, generate a core file of initproc before
+ * panicking. Leave at least 300 MB free on the root volume, and ignore
+ * the process's corefile ulimit.
+ */
+ if ((err = coredump(p, 300, 1)) != 0) {
+ printf("Failed to generate initproc core file: error %d", err);
+ } else {
+ printf("Generated initproc core file");
+ sync(p, (void *)NULL, (int *)NULL);
+ }
+#endif
+ init_task_died = TRUE;
panic("%s died\nState at Last Exception:\n\n%s",
(p->p_comm[0] != '\0' ?
p->p_comm :
MALLOC_ZONE(rup, struct rusage_superset *,
sizeof (*rup), M_ZOMBIE, M_WAITOK);
if (rup != NULL) {
- gather_rusage_info_v2(p, &rup->ri, RUSAGE_INFO_V2);
+ gather_rusage_info(p, &rup->ri, RUSAGE_INFO_CURRENT);
rup->ri.ri_phys_footprint = 0;
rup->ri.ri_proc_exit_abstime = mach_absolute_time();
int exitval;
int knote_hint;
- uth = (struct uthread *)get_bsdthread_info(current_thread());
+ uth = current_uthread();
proc_lock(p);
- proc_transstart(p, 1);
+ proc_transstart(p, 1, 0);
if( !(p->p_lflag & P_LEXIT)) {
/*
* This can happen if a thread_terminate() occurs
if ((tp != TTY_NULL) && (tp->t_session == sessp)) {
session_unlock(sessp);
+ /*
+ * We're going to SIGHUP the foreground process
+ * group. It can't change from this point on
+ * until the revoke is complete.
+ * The process group changes under both the tty
+ * lock and proc_list_lock but we need only one
+ */
+ tty_lock(tp);
+ ttysetpgrphup(tp);
+ tty_unlock(tp);
+
tty_pgsignal(tp, SIGHUP, 1);
session_lock(sessp);
}
context.vc_thread = proc_thread(p); /* XXX */
context.vc_ucred = kauth_cred_proc_ref(p);
- vnode_rele(ttyvp);
VNOP_REVOKE(ttyvp, REVOKEALL, &context);
if (cttyflag) {
/*
* Release the extra usecount taken in cttyopen.
* usecount should be released after VNOP_REVOKE is called.
+ * This usecount was taken to ensure that
+ * the VNOP_REVOKE results in a close to
+ * the tty since cttyclose is a no-op.
*/
vnode_rele(ttyvp);
}
kauth_cred_unref(&context.vc_ucred);
ttyvp = NULLVP;
}
- if (ttyvp)
- vnode_rele(ttyvp);
- if (tp)
+ if (tp) {
+ /*
+ * This is cleared even if not set. This is also done in
+ * spec_close to ensure that the flag is cleared.
+ */
+ tty_lock(tp);
+ ttyclrpgrphup(tp);
+ tty_unlock(tp);
+
ttyfree(tp);
+ }
}
session_lock(sessp);
sessp->s_leader = NULL;
proc_limitdrop(p, 1);
p->p_limit = NULL;
+ vm_purgeable_disown(p->task);
/*
* Finish up by terminating the task
int
wait1continue(int result)
{
- void *vt;
+ proc_t p;
thread_t thread;
+ uthread_t uth;
+ struct _wait4_data *wait4_data;
+ struct wait4_nocancel_args *uap;
int *retval;
- proc_t p;
if (result)
return(result);
p = current_proc();
thread = current_thread();
- vt = get_bsduthreadarg(thread);
- retval = get_bsduthreadrval(thread);
- return(wait4(p, (struct wait4_args *)vt, retval));
+ uth = (struct uthread *)get_bsdthread_info(thread);
+
+ wait4_data = &uth->uu_kevent.uu_wait4_data;
+ uap = wait4_data->args;
+ retval = wait4_data->retval;
+ return(wait4_nocancel(p, uap, retval));
}
int
int sibling_count;
proc_t p;
int status, error;
+ uthread_t uth;
+ struct _wait4_data *wait4_data;
AUDIT_ARG(pid, uap->pid);
*/
if ( sibling_count == 0 ) {
int mask = sigmask(SIGCHLD);
- uthread_t uth = (struct uthread *)get_bsdthread_info(current_thread());
+ uth = current_uthread();
if ( (uth->uu_sigmask & mask) != 0 ) {
/* we are blocking SIGCHLD signals. clear any pending SIGCHLD.
return (0);
}
+ /* Save arguments for continuation. Backing storage is in uthread->uu_arg, and will not be deallocated */
+ uth = current_uthread();
+ wait4_data = &uth->uu_kevent.uu_wait4_data;
+ wait4_data->args = uap;
+ wait4_data->retval = retval;
+
if ((error = msleep0((caddr_t)q, proc_list_mlock, PWAIT | PCATCH | PDROP, "wait", 0, wait1continue)))
return (error);
int
waitidcontinue(int result)
{
- void *vt;
+ proc_t p;
thread_t thread;
+ uthread_t uth;
+ struct _waitid_data *waitid_data;
+ struct waitid_nocancel_args *uap;
int *retval;
if (result)
return (result);
+ p = current_proc();
thread = current_thread();
- vt = get_bsduthreadarg(thread);
- retval = get_bsduthreadrval(thread);
- return (waitid(current_proc(), (struct waitid_args *)vt, retval));
+ uth = (struct uthread *)get_bsdthread_info(thread);
+
+ waitid_data = &uth->uu_kevent.uu_waitid_data;
+ uap = waitid_data->args;
+ retval = waitid_data->retval;
+ return(waitid_nocancel(p, uap, retval));
}
/*
int nfound;
proc_t p;
int error;
+ uthread_t uth;
+ struct _waitid_data *waitid_data;
if (uap->options == 0 ||
(uap->options & ~(WNOHANG|WNOWAIT|WCONTINUED|WSTOPPED|WEXITED)))
return (0);
}
+ /* Save arguments for continuation. Backing storage is in uthread->uu_arg, and will not be deallocated */
+ uth = current_uthread();
+ waitid_data = &uth->uu_kevent.uu_waitid_data;
+ waitid_data->args = uap;
+ waitid_data->retval = retval;
+
if ((error = msleep0(q, proc_list_mlock,
PWAIT | PCATCH | PDROP, "waitid", 0, waitidcontinue)) != 0)
return (error);
if ((tp != TTY_NULL) && (tp->t_session == sessp)) {
session_unlock(sessp);
+ /*
+ * We're going to SIGHUP the foreground process
+ * group. It can't change from this point on
+ * until the revoke is complete.
+ * The process group changes under both the tty
+ * lock and proc_list_lock but we need only one
+ */
+ tty_lock(tp);
+ ttysetpgrphup(tp);
+ tty_unlock(tp);
+
tty_pgsignal(tp, SIGHUP, 1);
session_lock(sessp);
}
context.vc_thread = proc_thread(p); /* XXX */
context.vc_ucred = kauth_cred_proc_ref(p);
- vnode_rele(ttyvp);
VNOP_REVOKE(ttyvp, REVOKEALL, &context);
if (cttyflag) {
/*
* Release the extra usecount taken in cttyopen.
* usecount should be released after VNOP_REVOKE is called.
+ * This usecount was taken to ensure that
+ * the VNOP_REVOKE results in a close to
+ * the tty since cttyclose is a no-op.
*/
vnode_rele(ttyvp);
}
kauth_cred_unref(&context.vc_ucred);
ttyvp = NULLVP;
}
- if (ttyvp)
- vnode_rele(ttyvp);
- if (tp)
+ if (tp) {
+ /*
+ * This is cleared even if not set. This is also done in
+ * spec_close to ensure that the flag is cleared.
+ */
+ tty_lock(tp);
+ ttyclrpgrphup(tp);
+ tty_unlock(tp);
+
ttyfree(tp);
+ }
}
session_lock(sessp);
sessp->s_leader = NULL;
ruadd(&rup->ru, &p->p_stats->p_cru);
- gather_rusage_info_v2(p, &rup->ri, RUSAGE_INFO_V2);
+ gather_rusage_info(p, &rup->ri, RUSAGE_INFO_CURRENT);
rup->ri.ri_phys_footprint = 0;
rup->ri.ri_proc_exit_abstime = mach_absolute_time();