]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/corpses/corpse.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / corpses / corpse.c
index d440c79bd3418b4bd750083256def0124224324b..fcb67e2020192de9e051385b029d33a422060c1e 100644 (file)
 #include <kern/kern_cdata.h>
 #include <mach/mach_vm.h>
 #include <kern/exc_guard.h>
+#include <os/log.h>
 
 #if CONFIG_MACF
 #include <security/mac_mach_internal.h>
@@ -218,6 +219,9 @@ total_corpses_count(void)
        return gate.corpses;
 }
 
+extern char *proc_best_name(struct proc *);
+extern int proc_pid(struct proc *);
+
 /*
  * Routine: task_crashinfo_get_ref()
  *          Grab a slot at creating a corpse.
@@ -227,6 +231,7 @@ static kern_return_t
 task_crashinfo_get_ref(corpse_flags_t kcd_u_flags)
 {
        union corpse_creation_gate oldgate, newgate;
+       struct proc *p = (void *)current_proc();
 
        assert(kcd_u_flags & CORPSE_CRASHINFO_HAS_REF);
 
@@ -235,10 +240,14 @@ task_crashinfo_get_ref(corpse_flags_t kcd_u_flags)
                newgate = oldgate;
                if (kcd_u_flags & CORPSE_CRASHINFO_USER_FAULT) {
                        if (newgate.user_faults++ >= TOTAL_USER_FAULTS_ALLOWED) {
+                               os_log(OS_LOG_DEFAULT, "%s[%d] Corpse failure, too many faults %d\n",
+                                   proc_best_name(p), proc_pid(p), newgate.user_faults);
                                return KERN_RESOURCE_SHORTAGE;
                        }
                }
                if (newgate.corpses++ >= TOTAL_CORPSES_ALLOWED) {
+                       os_log(OS_LOG_DEFAULT, "%s[%d] Corpse failure, too many %d\n",
+                           proc_best_name(p), proc_pid(p), newgate.corpses);
                        return KERN_RESOURCE_SHORTAGE;
                }
 
@@ -246,6 +255,8 @@ task_crashinfo_get_ref(corpse_flags_t kcd_u_flags)
                if (atomic_compare_exchange_strong_explicit(&inflight_corpses,
                    &oldgate.value, newgate.value, memory_order_relaxed,
                    memory_order_relaxed)) {
+                       os_log(OS_LOG_DEFAULT, "%s[%d] Corpse allowed %d of %d\n",
+                           proc_best_name(p), proc_pid(p), newgate.corpses, TOTAL_CORPSES_ALLOWED);
                        return KERN_SUCCESS;
                }
        }
@@ -277,6 +288,7 @@ task_crashinfo_release_ref(corpse_flags_t kcd_u_flags)
                if (atomic_compare_exchange_strong_explicit(&inflight_corpses,
                    &oldgate.value, newgate.value, memory_order_relaxed,
                    memory_order_relaxed)) {
+                       os_log(OS_LOG_DEFAULT, "Corpse released, count at %d\n", newgate.corpses);
                        return KERN_SUCCESS;
                }
        }
@@ -653,7 +665,7 @@ error_task_generate_corpse:
                        /* Terminate all the other threads in the task. */
                        queue_iterate(&new_task->threads, thread_next, thread_t, task_threads)
                        {
-                               thread_terminate_internal(thread_next);
+                               thread_terminate_internal(thread_next, TH_TERMINATE_OPTION_NONE);
                        }
                        /* wait for all the threads in the task to terminate */
                        task_wait_till_threads_terminate_locked(new_task);