]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/machine_task.c
xnu-2782.20.48.tar.gz
[apple/xnu.git] / osfmk / i386 / machine_task.c
index c05d69bef9b45903276e27f94e6be3ee1fa49323..342f123f53c2b1fe21e72894139fd152b464822c 100644 (file)
 #include <kern/thread.h>
 #include <i386/misc_protos.h>
 
 #include <kern/thread.h>
 #include <i386/misc_protos.h>
 
+#if HYPERVISOR
+#include <kern/hv_support.h>
+#endif
+
 extern zone_t ids_zone;
 
 kern_return_t
 extern zone_t ids_zone;
 
 kern_return_t
@@ -229,6 +233,38 @@ machine_task_get_state(task_t task,
        }
 }
 
        }
 }
 
+/*
+ * This is called when a task is terminated, and also on exec().
+ * Clear machine-dependent state that is stored on the task.
+ */
+void
+machine_task_terminate(task_t task)
+{
+       if (task) {
+               user_ldt_t user_ldt;
+               void *task_debug;
+
+#if HYPERVISOR
+               if (task->hv_task_target) {
+                       hv_callbacks.task_destroy(task->hv_task_target);
+                       task->hv_task_target = NULL;
+               }
+#endif
+
+               user_ldt = task->i386_ldt;
+               if (user_ldt != 0) {
+                       task->i386_ldt = 0;
+                       user_ldt_free(user_ldt);
+               }
+
+               task_debug = task->task_debug;
+               if (task_debug != NULL) {
+                       task->task_debug = NULL;
+                       zfree(ids_zone, task_debug);
+               }        
+       }
+}
+
 /*
  * Set initial default state on a thread as stored in the MACHINE_TASK data.
  * Note: currently only debug state is supported.
 /*
  * Set initial default state on a thread as stored in the MACHINE_TASK data.
  * Note: currently only debug state is supported.