+ /* If a core should be generated, notify crash reporter */
+ if (hassigprop(WTERMSIG(rv), SA_CORE) || ((p->p_csflags & CS_KILLED) != 0)) {
+ /*
+ * Workaround for processes checking up on PT_DENY_ATTACH:
+ * should be backed out post-Leopard (details in 5431025).
+ */
+ if ((SIGSEGV == WTERMSIG(rv)) &&
+ (p->p_pptr->p_lflag & P_LNOATTACH)) {
+ goto skipcheck;
+ }
+
+ /*
+ * Crash Reporter looks for the signal value, original exception
+ * type, and low 20 bits of the original code in code[0]
+ * (8, 4, and 20 bits respectively). code[1] is unmodified.
+ */
+ code = ((WTERMSIG(rv) & 0xff) << 24) |
+ ((ut->uu_exception & 0x0f) << 20) |
+ ((int)ut->uu_code & 0xfffff);
+ subcode = ut->uu_subcode;
+ (void) task_exception_notify(EXC_CRASH, code, subcode);
+ }
+
+skipcheck:
+ /* Notify the perf server? */
+ if (perf_notify) {
+ (void)sys_perf_notify(self, p->p_pid);
+ }
+
+ /*
+ * Before this process becomes a zombie, stash resource usage
+ * stats in the proc for external observers to query
+ * via proc_pid_rusage().
+ *
+ * If the zombie allocation fails, just punt the stats.
+ */
+ 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);
+ rup->ri.ri_phys_footprint = 0;
+ rup->ri.ri_proc_exit_abstime = mach_absolute_time();
+
+ /*
+ * Make the rusage_info visible to external observers
+ * only after it has been completely filled in.
+ */
+ p->p_ru = rup;
+ }