+static cpu_type_t
+process_cpu_subtype(proc_t core_proc)
+{
+ cpu_type_t what_we_think;
+#if defined (__i386__) || defined (__x86_64__)
+ if (IS_64BIT_PROCESS(core_proc)) {
+ what_we_think = CPU_SUBTYPE_X86_64_ALL;
+ } else {
+ what_we_think = CPU_SUBTYPE_I386_ALL;
+ }
+#elif defined (__arm__) || defined(__arm64__)
+ if (IS_64BIT_PROCESS(core_proc)) {
+ what_we_think = CPU_SUBTYPE_ARM64_ALL;
+ } else {
+ what_we_think = CPU_SUBTYPE_ARM_ALL;
+ }
+#endif
+ return what_we_think;
+}
+
+static void
+collectth_state(thread_t th_act, void *tirp)
+{
+ vm_offset_t header;
+ size_t hoffset, i;
+ mythread_state_flavor_t *flavors;
+ struct thread_command *tc;
+ tir_t *t = (tir_t *)tirp;
+
+ /*
+ * Fill in thread command structure.
+ */
+ header = t->header;
+ hoffset = t->hoffset;
+ flavors = t->flavors;
+
+ tc = (struct thread_command *) (header + hoffset);
+ tc->cmd = LC_THREAD;
+ tc->cmdsize = (uint32_t)(sizeof(struct thread_command)
+ + t->tstate_size);
+ hoffset += sizeof(struct thread_command);
+ /*
+ * Follow with a struct thread_state_flavor and
+ * the appropriate thread state struct for each
+ * thread state flavor.
+ */
+ for (i = 0; i < t->flavor_count; i++) {
+ *(mythread_state_flavor_t *)(header + hoffset) =
+ flavors[i];
+ hoffset += sizeof(mythread_state_flavor_t);
+ thread_getstatus(th_act, flavors[i].flavor,
+ (thread_state_t)(header + hoffset),
+ &flavors[i].count);
+ hoffset += flavors[i].count * sizeof(int);
+ }
+
+ t->hoffset = hoffset;
+}