From af3b128436e874c2c42b6f154405af8ecf27168c Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Sun, 23 May 2021 11:51:14 -0400 Subject: system_cmds: Fix compilation for lower targets, downgrade lsmp --- system_cmds/arch.tproj/arch.c | 10 +- system_cmds/cpuctl.tproj/cpuctl.c | 1 + system_cmds/gcore.tproj/convert.c | 1 + system_cmds/gcore.tproj/corefile.c | 1 + system_cmds/gcore.tproj/dyld.c | 1 + system_cmds/gcore.tproj/main.c | 1 + system_cmds/gcore.tproj/sparse.c | 1 + system_cmds/gcore.tproj/threads.c | 1 + system_cmds/gcore.tproj/utils.c | 1 + system_cmds/gcore.tproj/vanilla.c | 1 + system_cmds/gcore.tproj/vm.c | 1 + system_cmds/hostinfo.tproj/hostinfo.c | 1 + system_cmds/latency.tproj/latency.c | 1 + system_cmds/lskq.tproj/common.h | 25 ++ system_cmds/lskq.tproj/lskq.c | 6 + system_cmds/lsmp.patch | 406 +++++++++++++++++++++ system_cmds/lsmp.tproj/common.h | 15 +- system_cmds/lsmp.tproj/entitlements.plist | 4 +- system_cmds/lsmp.tproj/lsmp.c | 19 +- system_cmds/lsmp.tproj/port_details.c | 37 +- system_cmds/lsmp.tproj/task_details.c | 112 +++--- system_cmds/mean.tproj/mean.c | 1 + .../memory_pressure.tproj/memory_pressure.c | 1 + system_cmds/reboot.tproj/reboot.c | 1 + system_cmds/shutdown.tproj/shutdown.c | 1 + system_cmds/taskpolicy.tproj/taskpolicy.c | 1 + system_cmds/trace.tproj/trace.c | 1 + .../vm_purgeable_stat.tproj/entitlements.plist | 2 +- .../vm_purgeable_stat.tproj/vm_purgeable_stat.c | 8 +- 29 files changed, 565 insertions(+), 97 deletions(-) create mode 100644 system_cmds/lsmp.patch diff --git a/system_cmds/arch.tproj/arch.c b/system_cmds/arch.tproj/arch.c index 326b541..a0b5e20 100644 --- a/system_cmds/arch.tproj/arch.c +++ b/system_cmds/arch.tproj/arch.c @@ -34,6 +34,7 @@ #include #include #include +typedef char *kobject_description_t[512]; #include #include #include @@ -76,6 +77,7 @@ typedef struct { size_t capacity; } CPU; +#if 0 typedef struct { const char *arch; cpu_type_t cpu; @@ -166,6 +168,7 @@ isSupportedCPU(cpu_type_t cpu) bool unrecognizednative32seen = false; bool unrecognizednative64seen = false; +#endif /* * arch - perform the original behavior of the arch and machine commands. @@ -188,6 +191,7 @@ arch(int archcmd) exit(0); } +#if 0 /* * spawnIt - run the posix_spawn command. cpu is the auto-sizing CPU structure. * pflag is non-zero to call posix_spawnp; zero means to call posix_spawn. @@ -770,7 +774,7 @@ spawnFromArgs(CPU *cpu, char **argv) */ spawnIt(cpu, 1, *argv, argv); } - +#endif /* the main() routine */ int @@ -788,7 +792,8 @@ main(int argc, char **argv) if(argc == 1) arch(1); /* the "arch" command with no arguments was called */ } - + return(0); +#if 0 initCPU(&cpu); if(my_name_is_arch) @@ -798,4 +803,5 @@ main(int argc, char **argv) /* should never get here */ errx(1, "returned from spawn"); +#endif } diff --git a/system_cmds/cpuctl.tproj/cpuctl.c b/system_cmds/cpuctl.tproj/cpuctl.c index 4821878..22e2f33 100644 --- a/system_cmds/cpuctl.tproj/cpuctl.c +++ b/system_cmds/cpuctl.tproj/cpuctl.c @@ -14,6 +14,7 @@ #include #include #include +typedef char *kobject_description_t[512]; #include static void usage() diff --git a/system_cmds/gcore.tproj/convert.c b/system_cmds/gcore.tproj/convert.c index a3b41f3..5e38244 100644 --- a/system_cmds/gcore.tproj/convert.c +++ b/system_cmds/gcore.tproj/convert.c @@ -2,6 +2,7 @@ * Copyright (c) 2016 Apple Inc. All rights reserved. */ +typedef char *kobject_description_t[512]; #include "convert.h" #include "corefile.h" #include "vanilla.h" diff --git a/system_cmds/gcore.tproj/corefile.c b/system_cmds/gcore.tproj/corefile.c index b1e4421..8e61ca6 100644 --- a/system_cmds/gcore.tproj/corefile.c +++ b/system_cmds/gcore.tproj/corefile.c @@ -2,6 +2,7 @@ * Copyright (c) 2016-2018 Apple Inc. All rights reserved. */ +typedef char *kobject_description_t[512]; #include "options.h" #include "corefile.h" #include "sparse.h" diff --git a/system_cmds/gcore.tproj/dyld.c b/system_cmds/gcore.tproj/dyld.c index 92aeac1..5ef9899 100644 --- a/system_cmds/gcore.tproj/dyld.c +++ b/system_cmds/gcore.tproj/dyld.c @@ -2,6 +2,7 @@ * Copyright (c) 2016 Apple Inc. All rights reserved. */ +typedef char *kobject_description_t[512]; #include "options.h" #include "dyld.h" #include "utils.h" diff --git a/system_cmds/gcore.tproj/main.c b/system_cmds/gcore.tproj/main.c index abefa14..b20e721 100644 --- a/system_cmds/gcore.tproj/main.c +++ b/system_cmds/gcore.tproj/main.c @@ -2,6 +2,7 @@ * Copyright (c) 2016 Apple Inc. All rights reserved. */ +typedef char *kobject_description_t[512]; #include "options.h" #include "utils.h" #include "corefile.h" diff --git a/system_cmds/gcore.tproj/sparse.c b/system_cmds/gcore.tproj/sparse.c index c62b9f3..616eedf 100644 --- a/system_cmds/gcore.tproj/sparse.c +++ b/system_cmds/gcore.tproj/sparse.c @@ -2,6 +2,7 @@ * Copyright (c) 2016 Apple Inc. All rights reserved. */ +typedef char *kobject_description_t[512]; #include "options.h" #include "vm.h" #include "region.h" diff --git a/system_cmds/gcore.tproj/threads.c b/system_cmds/gcore.tproj/threads.c index b1b3d6f..f47cbfd 100644 --- a/system_cmds/gcore.tproj/threads.c +++ b/system_cmds/gcore.tproj/threads.c @@ -2,6 +2,7 @@ * Copyright (c) 2015 Apple Inc. All rights reserved. */ +typedef char *kobject_description_t[512]; #include "options.h" #include "utils.h" #include "threads.h" diff --git a/system_cmds/gcore.tproj/utils.c b/system_cmds/gcore.tproj/utils.c index f0edcf8..8706b6e 100644 --- a/system_cmds/gcore.tproj/utils.c +++ b/system_cmds/gcore.tproj/utils.c @@ -2,6 +2,7 @@ * Copyright (c) 2016 Apple Inc. All rights reserved. */ +typedef char *kobject_description_t[512]; #include "options.h" #include "utils.h" #include "region.h" diff --git a/system_cmds/gcore.tproj/vanilla.c b/system_cmds/gcore.tproj/vanilla.c index 2253bff..46b91b5 100644 --- a/system_cmds/gcore.tproj/vanilla.c +++ b/system_cmds/gcore.tproj/vanilla.c @@ -2,6 +2,7 @@ * Copyright (c) 2016 Apple Inc. All rights reserved. */ +typedef char *kobject_description_t[512]; #include "options.h" #include "vm.h" #include "region.h" diff --git a/system_cmds/gcore.tproj/vm.c b/system_cmds/gcore.tproj/vm.c index 3c4e7e6..0504f51 100644 --- a/system_cmds/gcore.tproj/vm.c +++ b/system_cmds/gcore.tproj/vm.c @@ -2,6 +2,7 @@ * Copyright (c) 2016 Apple Inc. All rights reserved. */ +typedef char *kobject_description_t[512]; #include "options.h" #include "vm.h" #include "utils.h" diff --git a/system_cmds/hostinfo.tproj/hostinfo.c b/system_cmds/hostinfo.tproj/hostinfo.c index 1828583..7739975 100644 --- a/system_cmds/hostinfo.tproj/hostinfo.c +++ b/system_cmds/hostinfo.tproj/hostinfo.c @@ -37,6 +37,7 @@ * execting on. */ +typedef char *kobject_description_t[512]; #include #include #include diff --git a/system_cmds/latency.tproj/latency.c b/system_cmds/latency.tproj/latency.c index afd67cc..3183eb0 100644 --- a/system_cmds/latency.tproj/latency.c +++ b/system_cmds/latency.tproj/latency.c @@ -25,6 +25,7 @@ cc -I/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders -DPRIVATE -D__APPLE_PRIVATE -arch x86_64 -arch i386 -O -o latency latency.c -lncurses -lutil */ +typedef char *kobject_description_t[512]; #include #include #include diff --git a/system_cmds/lskq.tproj/common.h b/system_cmds/lskq.tproj/common.h index 959ac66..c01cff4 100644 --- a/system_cmds/lskq.tproj/common.h +++ b/system_cmds/lskq.tproj/common.h @@ -26,6 +26,31 @@ #include +#ifndef __enum_open +#if __has_attribute(enum_extensibility) +#define __enum_open __attribute__((__enum_extensibility__(open))) +#define __enum_closed __attribute__((__enum_extensibility__(closed))) +#else +#define __enum_open +#define __enum_closed +#endif // __has_attribute(enum_extensibility) +#endif + +#ifndef __enum_options +#if __has_attribute(flag_enum) +#define __enum_options __attribute__((__flag_enum__)) +#else +#define __enum_options +#endif +#endif + +#ifndef __enum_decl +#define __enum_decl(_name, _type, ...) \ + typedef _type _name; enum __VA_ARGS__ __enum_open +#define __options_decl(_name, _type, ...) \ + typedef _type _name; enum __VA_ARGS__ __enum_open __enum_options +#endif + /* * This file must be kept in sync with xnu headers */ diff --git a/system_cmds/lskq.tproj/lskq.c b/system_cmds/lskq.tproj/lskq.c index d19f722..91f53c0 100644 --- a/system_cmds/lskq.tproj/lskq.c +++ b/system_cmds/lskq.tproj/lskq.c @@ -153,10 +153,16 @@ fflags_build(struct kevent_extinfo *info, char *str, int len) break; case EVFILT_WORKLOOP: +#ifdef NOTE_WL_SYNC_IPC snprintf(str, len, "%c%c%c%c%c ", +#else + snprintf(str, len, "%c%c%c%c ", +#endif (ff & NOTE_WL_THREAD_REQUEST) ? 't' : (ff & NOTE_WL_SYNC_WAIT) ? 'w' : +#ifdef NOTE_WL_SYNC_IPC (ff & NOTE_WL_SYNC_IPC) ? 'i' : '-', +#endif (ff & NOTE_WL_SYNC_WAKE) ? 'W' : '-', (ff & NOTE_WL_UPDATE_QOS) ? 'q' : '-', (ff & NOTE_WL_DISCOVER_OWNER) ? 'o' : '-', diff --git a/system_cmds/lsmp.patch b/system_cmds/lsmp.patch new file mode 100644 index 0000000..6b1e129 --- /dev/null +++ b/system_cmds/lsmp.patch @@ -0,0 +1,406 @@ +diff -urN system_cmds-880.60.2/lsmp.tproj/common.h system_cmds-880.100.5/lsmp.tproj/common.h +--- system_cmds-880.60.2/lsmp.tproj/common.h 2020-05-26 14:16:58.000000000 -0400 ++++ system_cmds-880.100.5/lsmp.tproj/common.h 2021-01-15 00:52:22.000000000 -0500 +@@ -25,6 +25,7 @@ + #define system_cmds_common_h + + #include ++#include + #include "json.h" + + #define PROC_NAME_LEN 100 +@@ -46,7 +47,7 @@ + /* exception port information */ + struct exc_port_info { + mach_msg_type_number_t count; +- mach_port_t ports[EXC_TYPES_COUNT]; ++ ipc_info_port_t ports_info[EXC_TYPES_COUNT]; + exception_mask_t masks[EXC_TYPES_COUNT]; + exception_behavior_t behaviors[EXC_TYPES_COUNT]; + thread_state_flavor_t flavors[EXC_TYPES_COUNT]; +@@ -74,7 +75,7 @@ + + /* private structure to wrap up per-task info */ + typedef struct my_per_task_info { +- task_t task; ++ task_read_t task; + pid_t pid; + vm_address_t task_kobject; + ipc_info_space_t info; +@@ -181,12 +182,12 @@ + + /* mach port related functions */ + const char * kobject_name(natural_t kotype); +-void get_receive_port_context(task_t taskp, mach_port_name_t portname, mach_port_context_t *context); +-int get_recieve_port_status(task_t taskp, mach_port_name_t portname, mach_port_info_ext_t *info); ++void get_receive_port_context(task_read_t taskp, mach_port_name_t portname, mach_port_context_t *context); ++int get_recieve_port_status(task_read_t taskp, mach_port_name_t portname, mach_port_info_ext_t *info); + void show_task_mach_ports(my_per_task_info_t *taskinfo, uint32_t taskCount, my_per_task_info_t *allTaskInfos, JSON_t json); + + /* task and thread related helper functions */ +-kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_t target_task); ++kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_read_t target_task); + my_per_task_info_t * allocate_taskinfo_memory(uint32_t taskCount); + void deallocate_taskinfo_memory(my_per_task_info_t *data); + kern_return_t print_task_exception_info(my_per_task_info_t *taskinfo, JSON_t json); +@@ -195,8 +196,8 @@ + + void get_exc_behavior_string(exception_behavior_t b, char *out_string, size_t len); + void get_exc_mask_string(exception_mask_t m, char *out_string, size_t len); +-kern_return_t get_taskinfo_of_receiver_by_send_right(ipc_info_name_t *sendright, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info); +-kern_return_t get_ipc_info_from_lsmp_spaceinfo(mach_port_t port_name, ipc_info_name_t *out_sendright); ++kern_return_t get_taskinfo_of_receiver_by_send_right(ipc_info_name_t sendright, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info); ++kern_return_t get_taskinfo_of_receiver_by_send_right_info(ipc_info_port_t sendright_info, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info); + + /* basic util functions */ + uint32_t print_hex_data(char *outstr, uint32_t maxlen, char *prefix, char *desc, void *addr, int len); +diff -urN system_cmds-880.60.2/lsmp.tproj/entitlements.plist system_cmds-880.100.5/lsmp.tproj/entitlements.plist +--- system_cmds-880.60.2/lsmp.tproj/entitlements.plist 2015-07-21 20:13:05.000000000 -0400 ++++ system_cmds-880.100.5/lsmp.tproj/entitlements.plist 2021-01-15 00:52:22.000000000 -0500 +@@ -2,9 +2,7 @@ + + + +- task_for_pid-allow +- +- com.apple.system-task-ports ++ com.apple.system-task-ports.read + + + +diff -urN system_cmds-880.60.2/lsmp.tproj/lsmp.c system_cmds-880.100.5/lsmp.tproj/lsmp.c +--- system_cmds-880.60.2/lsmp.tproj/lsmp.c 2019-04-09 18:58:12.000000000 -0400 ++++ system_cmds-880.100.5/lsmp.tproj/lsmp.c 2021-01-15 00:52:22.000000000 -0500 +@@ -19,6 +19,7 @@ + * + * @APPLE_LICENSE_HEADER_END@ + */ ++#include + #include + #include + #include +@@ -32,7 +33,7 @@ + #include "json.h" + + #if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) +-#define TASK_FOR_PID_USAGE_MESG "\nPlease check your boot-args to ensure you have access to task_for_pid()." ++#define TASK_FOR_PID_USAGE_MESG "\nPlease check your boot-args to ensure you have access to task_read_for_pid()." + #else + #define TASK_FOR_PID_USAGE_MESG "" + #endif +@@ -72,7 +73,7 @@ + + int main(int argc, char *argv[]) { + kern_return_t ret; +- task_t aTask; ++ task_read_t aTask; + my_per_task_info_t *taskinfo = NULL; + task_array_t tasks; + char *progname = "lsmp"; +@@ -153,10 +154,10 @@ + mach_port_deallocate(mach_task_self(), psets[0]); + vm_deallocate(mach_task_self(), (vm_address_t)psets, (vm_size_t)psetCount * sizeof(mach_port_t)); + +- /* convert the processor-set-priv to a list of tasks for the processor set */ +- ret = processor_set_tasks(pset_priv, &tasks, &taskCount); ++ /* convert the processor-set-priv to a list of task read ports for the processor set */ ++ ret = processor_set_tasks_with_flavor(pset_priv, TASK_FLAVOR_READ, &tasks, &taskCount); + if (ret != KERN_SUCCESS) { +- fprintf(stderr, "processor_set_tasks() failed: %s\n", mach_error_string(ret)); ++ fprintf(stderr, "processor_set_tasks_with_flavor() failed: %s\n", mach_error_string(ret)); + exit(1); + } + mach_port_deallocate(mach_task_self(), pset_priv); +@@ -164,7 +165,7 @@ + /* swap my current instances port to be last to collect all threads and exception port info */ + int myTaskPosition = -1; + for (int i = 0; i < taskCount; i++) { +- if (tasks[i] == mach_task_self()){ ++ if (mach_task_is_self(tasks[i])){ + myTaskPosition = i; + break; + } +@@ -181,7 +182,7 @@ + { + fprintf(stderr, "warning: should run as root for best output (cross-ref to other tasks' ports).\n"); + /* just the one process */ +- ret = task_for_pid(mach_task_self(), lsmp_config.pid, &aTask); ++ ret = task_read_for_pid(mach_task_self(), lsmp_config.pid, &aTask); + if (ret != KERN_SUCCESS) { + fprintf(stderr, "task_for_pid() failed: %s %s\n", mach_error_string(ret), TASK_FOR_PID_USAGE_MESG); + exit(1); +@@ -200,8 +201,9 @@ + continue; + } + +- if (psettaskinfo[i].pid == lsmp_config.pid) ++ if (psettaskinfo[i].pid == lsmp_config.pid) { + taskinfo = &psettaskinfo[i]; ++ } + } + + JSON_OBJECT_BEGIN(lsmp_config.json_output); +diff -urN system_cmds-880.60.2/lsmp.tproj/port_details.c system_cmds-880.100.5/lsmp.tproj/port_details.c +--- system_cmds-880.60.2/lsmp.tproj/port_details.c 2020-05-26 14:16:58.000000000 -0400 ++++ system_cmds-880.100.5/lsmp.tproj/port_details.c 2021-01-15 00:52:22.000000000 -0500 +@@ -232,7 +232,7 @@ + return voucher_outstr; + } + +-void get_receive_port_context(task_t taskp, mach_port_name_t portname, mach_port_context_t *context) { ++void get_receive_port_context(task_read_t taskp, mach_port_name_t portname, mach_port_context_t *context) { + if (context == NULL) { + return; + } +@@ -248,7 +248,7 @@ + return; + } + +-int get_recieve_port_status(task_t taskp, mach_port_name_t portname, mach_port_info_ext_t *info){ ++int get_recieve_port_status(task_read_t taskp, mach_port_name_t portname, mach_port_info_ext_t *info){ + if (info == NULL) { + return -1; + } +@@ -625,13 +625,19 @@ + if (ret == KERN_SUCCESS && kotype != 0) { + JSON_OBJECT_SET(json, identifier, "0x%08x", (natural_t)kobject); + JSON_OBJECT_SET(json, type, "%s", kobject_name(kotype)); +- if (desc[0]) { +- JSON_OBJECT_SET(json, description, "%s", desc); +- printf(" 0x%08x %s %s", (natural_t)kobject, kobject_name(kotype), desc); +- } else { +- printf(" 0x%08x %s", (natural_t)kobject, kobject_name(kotype)); +- } +- if ((kotype == IKOT_TASK_RESUME) || (kotype == IKOT_TASK_CONTROL) || (kotype == IKOT_TASK_NAME)) { ++ ++ if (desc[0]) { ++ JSON_OBJECT_SET(json, description, "%s", desc); ++ printf(" 0x%08x %s %s", (natural_t)kobject, kobject_name(kotype), desc); ++ } else { ++ printf(" 0x%08x %s", (natural_t)kobject, kobject_name(kotype)); ++ } ++ ++ if ((kotype == IKOT_TASK_RESUME) || ++ (kotype == IKOT_TASK_CONTROL) || ++ (kotype == IKOT_TASK_READ) || ++ (kotype == IKOT_TASK_INSPECT) || ++ (kotype == IKOT_TASK_NAME)) { + if (taskinfo->task_kobject == kobject) { + /* neat little optimization since in most cases tasks have themselves in their ipc space */ + JSON_OBJECT_SET(json, pid, %d, taskinfo->pid); +@@ -645,7 +651,9 @@ + } + } + +- if (kotype == IKOT_THREAD_CONTROL) { ++ if ((kotype == IKOT_THREAD_CONTROL) || ++ (kotype == IKOT_THREAD_READ) || ++ (kotype == IKOT_THREAD_INSPECT)) { + for (int i = 0; i < taskinfo->threadCount; i++) { + if (taskinfo->threadInfos[i].th_kobject == kobject) { + printf(" (%#llx)", taskinfo->threadInfos[i].th_id); +@@ -673,7 +681,7 @@ + /* not kobject - find the receive right holder */ + my_per_task_info_t *recv_holder_taskinfo; + mach_port_name_t recv_name = MACH_PORT_NULL; +- if (KERN_SUCCESS == get_taskinfo_of_receiver_by_send_right(entry, &recv_holder_taskinfo, &recv_name)) { ++ if (KERN_SUCCESS == get_taskinfo_of_receiver_by_send_right(*entry, &recv_holder_taskinfo, &recv_name)) { + mach_port_status_t port_status; + mach_port_info_ext_t info; + mach_port_context_t port_context = (mach_port_context_t)0; +diff -urN system_cmds-880.60.2/lsmp.tproj/task_details.c system_cmds-880.100.5/lsmp.tproj/task_details.c +--- system_cmds-880.60.2/lsmp.tproj/task_details.c 2020-05-26 14:16:58.000000000 -0400 ++++ system_cmds-880.100.5/lsmp.tproj/task_details.c 2021-01-15 00:52:22.000000000 -0500 +@@ -139,7 +139,7 @@ + } + } + +-kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_t target_task) ++kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_read_t target_task) + { + int i; + kern_return_t ret = KERN_SUCCESS; +@@ -149,10 +149,10 @@ + taskinfo->task = target_task; + pid_for_task(target_task, &taskinfo->pid); + +- ret = task_get_exception_ports(taskinfo->task, EXC_MASK_ALL, taskinfo->exceptionInfo.masks, &taskinfo->exceptionInfo.count, taskinfo->exceptionInfo.ports, taskinfo->exceptionInfo.behaviors, taskinfo->exceptionInfo.flavors); ++ ret = task_get_exception_ports_info(taskinfo->task, EXC_MASK_ALL, taskinfo->exceptionInfo.masks, &taskinfo->exceptionInfo.count, taskinfo->exceptionInfo.ports_info, taskinfo->exceptionInfo.behaviors, taskinfo->exceptionInfo.flavors); + + if (ret != KERN_SUCCESS) { +- fprintf(stderr, "task_get_exception_ports() failed: pid:%d error: %s\n",taskinfo->pid, mach_error_string(ret)); ++ fprintf(stderr, "task_get_exception_ports_info() failed: pid:%d error: %s\n",taskinfo->pid, mach_error_string(ret)); + taskinfo->pid = 0; + } + +@@ -180,9 +180,9 @@ + mach_msg_type_number_t th_info_count = THREAD_IDENTIFIER_INFO_COUNT; + struct exc_port_info *excinfo = &(taskinfo->threadExceptionInfos[i]); + +- ret = thread_get_exception_ports(threadPorts[i], EXC_MASK_ALL, excinfo->masks, &excinfo->count, excinfo->ports, excinfo->behaviors, excinfo->flavors); ++ ret = thread_get_exception_ports_info(threadPorts[i], EXC_MASK_ALL, excinfo->masks, &excinfo->count, excinfo->ports_info, excinfo->behaviors, excinfo->flavors); + if (ret != KERN_SUCCESS){ +- fprintf(stderr, "thread_get_exception_ports() failed: pid: %d thread: %d error %s\n", taskinfo->pid, threadPorts[i], mach_error_string(ret)); ++ fprintf(stderr, "thread_get_exception_ports_info() failed: pid: %d thread: %d error %s\n", taskinfo->pid, threadPorts[i], mach_error_string(ret)); + } + + if (excinfo->count != 0) { +@@ -236,8 +236,9 @@ + proc_pid_to_name(taskinfo->pid, taskinfo->processName); + + ret = mach_port_kernel_object(mach_task_self(), taskinfo->task, &kotype, (unsigned *)&kobject); +- +- if (ret == KERN_SUCCESS && kotype == IKOT_TASK_CONTROL) { ++ ++ /* Now that we are using read ports, kotype should be checked against IKOT_TASK_READ */ ++ if (ret == KERN_SUCCESS && kotype == IKOT_TASK_READ) { + taskinfo->task_kobject = kobject; + taskinfo->valid = TRUE; + } +@@ -307,23 +308,32 @@ + + boolean_t header_required = TRUE; + for (int i = 0; i < taskinfo->exceptionInfo.count; i++) { +- if (taskinfo->exceptionInfo.ports[i] != MACH_PORT_NULL) { ++ if (taskinfo->exceptionInfo.ports_info[i].iip_port_object != 0) { ++ my_per_task_info_t * _found_task; ++ + if (header_required) { + +- printf(" exc_port flavor mask \n"); ++ printf(" exc_port_object receiver_task flavor mask \n"); + header_required = FALSE; + } + get_exc_behavior_string(taskinfo->exceptionInfo.behaviors[i], behavior_string, sizeof(behavior_string)); + get_exc_mask_string(taskinfo->exceptionInfo.masks[i], mask_string, sizeof(mask_string)); + + JSON_OBJECT_BEGIN(json); +- JSON_OBJECT_SET(json, port, "0x%08x", taskinfo->exceptionInfo.ports[i]); ++ JSON_OBJECT_SET(json, port_object, "0x%08x", taskinfo->exceptionInfo.ports_info[i].iip_port_object); ++ JSON_OBJECT_SET(json, receiver_object, "0x%08x", taskinfo->exceptionInfo.ports_info[i].iip_receiver_object); + JSON_OBJECT_SET(json, flavor, "0x%03x", taskinfo->exceptionInfo.flavors[i]); + JSON_OBJECT_SET(json, behavior, "%s", behavior_string); + JSON_OBJECT_SET(json, mask, "%s", mask_string); + JSON_OBJECT_END(json); // exception port +- +- printf(" 0x%08x 0x%03x <%s> %s \n" , taskinfo->exceptionInfo.ports[i], taskinfo->exceptionInfo.flavors[i], behavior_string, mask_string); ++ ++ _found_task = get_taskinfo_by_kobject((natural_t)taskinfo->exceptionInfo.ports_info[i].iip_receiver_object); ++ ++ printf(" 0x%08x (%d) %s 0x%03x <%s> %s \n", ++ taskinfo->exceptionInfo.ports_info[i].iip_port_object, ++ _found_task->pid, ++ _found_task->processName, ++ taskinfo->exceptionInfo.flavors[i], behavior_string, mask_string); + } + + } +@@ -389,39 +399,35 @@ + for (int i = 0; i < excinfo->count; i++) { + JSON_OBJECT_BEGIN(json); + +- if (excinfo->ports[i] != MACH_PORT_NULL) { ++ if (excinfo->ports_info[i].iip_port_object != 0) { + if (header_required) { +- printf("\n exc_port flavor mask -> name owner\n"); ++ printf("\n exc_port_object exc_port_receiver flavor mask -> name owner\n"); + header_required = FALSE; + } + get_exc_behavior_string(excinfo->behaviors[i], behavior_string, sizeof(behavior_string)); + get_exc_mask_string(excinfo->masks[i], mask_string, sizeof(mask_string)); + +- JSON_OBJECT_SET(json, port, "0x%08x", excinfo->ports[i]); ++ JSON_OBJECT_SET(json, port_object, "0x%08x", excinfo->ports_info[i].iip_port_object); ++ JSON_OBJECT_SET(json, receiver_object, "0x%08x", excinfo->ports_info[i].iip_receiver_object); + JSON_OBJECT_SET(json, flavor, "0x%03x", excinfo->flavors[i]); + JSON_OBJECT_SET(json, behavior, "%s", behavior_string); + JSON_OBJECT_SET(json, mask, "%s", mask_string); + +- printf(" 0x%08x 0x%03x <%s> %s " , excinfo->ports[i], excinfo->flavors[i], behavior_string, mask_string); ++ printf(" 0x%08x 0x%08x 0x%03x <%s> %s " , excinfo->ports_info[i].iip_port_object, excinfo->ports_info[i].iip_receiver_object, excinfo->flavors[i], behavior_string, mask_string); + +- ipc_info_name_t actual_sendinfo; +- if (KERN_SUCCESS == get_ipc_info_from_lsmp_spaceinfo(excinfo->ports[i], &actual_sendinfo)) { +- my_per_task_info_t *recv_holder_taskinfo; +- mach_port_name_t recv_name = MACH_PORT_NULL; +- if (KERN_SUCCESS == get_taskinfo_of_receiver_by_send_right(&actual_sendinfo, &recv_holder_taskinfo, &recv_name)) { ++ my_per_task_info_t *recv_holder_taskinfo; ++ mach_port_name_t recv_name = MACH_PORT_NULL; ++ if (KERN_SUCCESS == get_taskinfo_of_receiver_by_send_right_info(excinfo->ports_info[i], &recv_holder_taskinfo, &recv_name)) { ++ JSON_OBJECT_SET(json, name, "0x%08x", recv_name); ++ JSON_OBJECT_SET(json, ipc-object, "0x%08x", excinfo->ports_info[i].iip_port_object); ++ JSON_OBJECT_SET(json, pid, %d, recv_holder_taskinfo->pid); ++ JSON_OBJECT_SET(json, process, "%s", recv_holder_taskinfo->processName); + +- JSON_OBJECT_SET(json, name, "0x%08x", recv_name); +- JSON_OBJECT_SET(json, ipc-object, "0x%08x", actual_sendinfo.iin_object); +- JSON_OBJECT_SET(json, pid, %d, recv_holder_taskinfo->pid); +- JSON_OBJECT_SET(json, process, "%s", recv_holder_taskinfo->processName); +- +- printf(" -> 0x%08x 0x%08x (%d) %s\n", +- recv_name, +- actual_sendinfo.iin_object, +- recv_holder_taskinfo->pid, +- recv_holder_taskinfo->processName); +- } +- ++ printf(" -> 0x%08x 0x%08x (%d) %s\n", ++ recv_name, ++ excinfo->ports_info[i].iip_port_object, ++ recv_holder_taskinfo->pid, ++ recv_holder_taskinfo->processName); + } else { + fprintf(stderr, "failed to find"); + } +@@ -463,14 +469,14 @@ + return retval; + } + +-kern_return_t get_taskinfo_of_receiver_by_send_right(ipc_info_name_t *sendright, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info) ++static kern_return_t _get_taskinfo_of_receiver_by_send_right(natural_t kobject, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info) + { + *out_taskinfo = &NOT_FOUND_TASK_INFO; + struct k2n_table_node *k2nnode; + +- for (int j = 0; j < global_taskcount; j++) { +- if ((k2nnode = k2n_table_lookup(global_taskinfo[j].k2ntable, sendright->iin_object))) { +- assert(k2nnode->info_name->iin_object == sendright->iin_object); ++ for (unsigned int j = 0; j < global_taskcount; j++) { ++ if ((k2nnode = k2n_table_lookup(global_taskinfo[j].k2ntable, kobject))) { ++ assert(k2nnode->info_name->iin_object == kobject); + + if (k2nnode->info_name->iin_type & MACH_PORT_TYPE_RECEIVE) { + *out_taskinfo = &global_taskinfo[j]; +@@ -483,25 +489,12 @@ + return KERN_FAILURE; + } + +-kern_return_t get_ipc_info_from_lsmp_spaceinfo(mach_port_t port_name, ipc_info_name_t *out_sendright){ +- kern_return_t retval = KERN_FAILURE; +- bzero(out_sendright, sizeof(ipc_info_name_t)); +- my_per_task_info_t *mytaskinfo = NULL; +- for (int i = global_taskcount - 1; i >= 0; i--){ +- if (global_taskinfo[i].task == mach_task_self()){ +- mytaskinfo = &global_taskinfo[i]; +- break; +- } +- } +- if (mytaskinfo) { +- for (int k = 0; k < mytaskinfo->tableCount; k++) { +- if (port_name == mytaskinfo->table[k].iin_name){ +- bcopy(&mytaskinfo->table[k], out_sendright, sizeof(ipc_info_name_t)); +- retval = KERN_SUCCESS; +- break; +- } +- } +- } +- return retval; ++kern_return_t get_taskinfo_of_receiver_by_send_right(ipc_info_name_t sendright, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info) ++{ ++ return _get_taskinfo_of_receiver_by_send_right(sendright.iin_object, out_taskinfo, out_recv_info); ++} + ++kern_return_t get_taskinfo_of_receiver_by_send_right_info(ipc_info_port_t sendright_info, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info) ++{ ++ return _get_taskinfo_of_receiver_by_send_right(sendright_info.iip_port_object, out_taskinfo, out_recv_info); + } diff --git a/system_cmds/lsmp.tproj/common.h b/system_cmds/lsmp.tproj/common.h index a059eb5..9a47012 100644 --- a/system_cmds/lsmp.tproj/common.h +++ b/system_cmds/lsmp.tproj/common.h @@ -25,7 +25,6 @@ #define system_cmds_common_h #include -#include #include "json.h" #define PROC_NAME_LEN 100 @@ -47,7 +46,7 @@ extern struct prog_configs lsmp_config; /* exception port information */ struct exc_port_info { mach_msg_type_number_t count; - ipc_info_port_t ports_info[EXC_TYPES_COUNT]; + mach_port_t ports[EXC_TYPES_COUNT]; exception_mask_t masks[EXC_TYPES_COUNT]; exception_behavior_t behaviors[EXC_TYPES_COUNT]; thread_state_flavor_t flavors[EXC_TYPES_COUNT]; @@ -75,7 +74,7 @@ struct k2n_table_node *k2n_table_lookup(struct k2n_table_node **table, natural_t /* private structure to wrap up per-task info */ typedef struct my_per_task_info { - task_read_t task; + task_t task; pid_t pid; vm_address_t task_kobject; ipc_info_space_t info; @@ -182,12 +181,12 @@ char *copy_voucher_detail(mach_port_t task, mach_port_name_t voucher, JSON_t jso /* mach port related functions */ const char * kobject_name(natural_t kotype); -void get_receive_port_context(task_read_t taskp, mach_port_name_t portname, mach_port_context_t *context); -int get_recieve_port_status(task_read_t taskp, mach_port_name_t portname, mach_port_info_ext_t *info); +void get_receive_port_context(task_t taskp, mach_port_name_t portname, mach_port_context_t *context); +int get_recieve_port_status(task_t taskp, mach_port_name_t portname, mach_port_info_ext_t *info); void show_task_mach_ports(my_per_task_info_t *taskinfo, uint32_t taskCount, my_per_task_info_t *allTaskInfos, JSON_t json); /* task and thread related helper functions */ -kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_read_t target_task); +kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_t target_task); my_per_task_info_t * allocate_taskinfo_memory(uint32_t taskCount); void deallocate_taskinfo_memory(my_per_task_info_t *data); kern_return_t print_task_exception_info(my_per_task_info_t *taskinfo, JSON_t json); @@ -196,8 +195,8 @@ my_per_task_info_t * get_taskinfo_by_kobject(natural_t kobj); void get_exc_behavior_string(exception_behavior_t b, char *out_string, size_t len); void get_exc_mask_string(exception_mask_t m, char *out_string, size_t len); -kern_return_t get_taskinfo_of_receiver_by_send_right(ipc_info_name_t sendright, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info); -kern_return_t get_taskinfo_of_receiver_by_send_right_info(ipc_info_port_t sendright_info, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info); +kern_return_t get_taskinfo_of_receiver_by_send_right(ipc_info_name_t *sendright, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info); +kern_return_t get_ipc_info_from_lsmp_spaceinfo(mach_port_t port_name, ipc_info_name_t *out_sendright); /* basic util functions */ uint32_t print_hex_data(char *outstr, uint32_t maxlen, char *prefix, char *desc, void *addr, int len); diff --git a/system_cmds/lsmp.tproj/entitlements.plist b/system_cmds/lsmp.tproj/entitlements.plist index cdf0e9e..b7b4e6c 100644 --- a/system_cmds/lsmp.tproj/entitlements.plist +++ b/system_cmds/lsmp.tproj/entitlements.plist @@ -2,7 +2,9 @@ - com.apple.system-task-ports.read + task_for_pid-allow + + com.apple.system-task-ports diff --git a/system_cmds/lsmp.tproj/lsmp.c b/system_cmds/lsmp.tproj/lsmp.c index 114c5b6..e1a89d9 100644 --- a/system_cmds/lsmp.tproj/lsmp.c +++ b/system_cmds/lsmp.tproj/lsmp.c @@ -19,7 +19,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include +typedef char *kobject_description_t[512]; #include #include #include @@ -33,7 +33,7 @@ #include "json.h" #if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) -#define TASK_FOR_PID_USAGE_MESG "\nPlease check your boot-args to ensure you have access to task_read_for_pid()." +#define TASK_FOR_PID_USAGE_MESG "\nPlease check your boot-args to ensure you have access to task_for_pid()." #else #define TASK_FOR_PID_USAGE_MESG "" #endif @@ -73,7 +73,7 @@ static void print_task_info(my_per_task_info_t *taskinfo, mach_msg_type_number_t int main(int argc, char *argv[]) { kern_return_t ret; - task_read_t aTask; + task_t aTask; my_per_task_info_t *taskinfo = NULL; task_array_t tasks; char *progname = "lsmp"; @@ -154,10 +154,10 @@ int main(int argc, char *argv[]) { mach_port_deallocate(mach_task_self(), psets[0]); vm_deallocate(mach_task_self(), (vm_address_t)psets, (vm_size_t)psetCount * sizeof(mach_port_t)); - /* convert the processor-set-priv to a list of task read ports for the processor set */ - ret = processor_set_tasks_with_flavor(pset_priv, TASK_FLAVOR_READ, &tasks, &taskCount); + /* convert the processor-set-priv to a list of tasks for the processor set */ + ret = processor_set_tasks(pset_priv, &tasks, &taskCount); if (ret != KERN_SUCCESS) { - fprintf(stderr, "processor_set_tasks_with_flavor() failed: %s\n", mach_error_string(ret)); + fprintf(stderr, "processor_set_tasks() failed: %s\n", mach_error_string(ret)); exit(1); } mach_port_deallocate(mach_task_self(), pset_priv); @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) { /* swap my current instances port to be last to collect all threads and exception port info */ int myTaskPosition = -1; for (int i = 0; i < taskCount; i++) { - if (mach_task_is_self(tasks[i])){ + if (tasks[i] == mach_task_self()){ myTaskPosition = i; break; } @@ -182,7 +182,7 @@ int main(int argc, char *argv[]) { { fprintf(stderr, "warning: should run as root for best output (cross-ref to other tasks' ports).\n"); /* just the one process */ - ret = task_read_for_pid(mach_task_self(), lsmp_config.pid, &aTask); + ret = task_for_pid(mach_task_self(), lsmp_config.pid, &aTask); if (ret != KERN_SUCCESS) { fprintf(stderr, "task_for_pid() failed: %s %s\n", mach_error_string(ret), TASK_FOR_PID_USAGE_MESG); exit(1); @@ -201,9 +201,8 @@ int main(int argc, char *argv[]) { continue; } - if (psettaskinfo[i].pid == lsmp_config.pid) { + if (psettaskinfo[i].pid == lsmp_config.pid) taskinfo = &psettaskinfo[i]; - } } JSON_OBJECT_BEGIN(lsmp_config.json_output); diff --git a/system_cmds/lsmp.tproj/port_details.c b/system_cmds/lsmp.tproj/port_details.c index 69fc9be..f6222cd 100644 --- a/system_cmds/lsmp.tproj/port_details.c +++ b/system_cmds/lsmp.tproj/port_details.c @@ -25,6 +25,7 @@ #include #include #include +typedef char *kobject_description_t[512]; #include //#include #include @@ -232,7 +233,7 @@ char * copy_voucher_detail(mach_port_t task, mach_port_name_t voucher, JSON_t js return voucher_outstr; } -void get_receive_port_context(task_read_t taskp, mach_port_name_t portname, mach_port_context_t *context) { +void get_receive_port_context(task_t taskp, mach_port_name_t portname, mach_port_context_t *context) { if (context == NULL) { return; } @@ -248,7 +249,7 @@ void get_receive_port_context(task_read_t taskp, mach_port_name_t portname, mach return; } -int get_recieve_port_status(task_read_t taskp, mach_port_name_t portname, mach_port_info_ext_t *info){ +int get_recieve_port_status(task_t taskp, mach_port_name_t portname, mach_port_info_ext_t *info){ if (info == NULL) { return -1; } @@ -609,6 +610,7 @@ static void show_task_table_entry(ipc_info_name_t *entry, my_per_task_info_t *ta /* converting to kobjects is not always supported */ +#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130500 desc[0] = '\0'; ret = mach_port_kobject_description(taskinfo->task, entry->iin_name, @@ -621,23 +623,22 @@ static void show_task_table_entry(ipc_info_name_t *entry, my_per_task_info_t *ta entry->iin_name, &kotype, (unsigned *)&kobject); } +#else + ret = mach_port_kernel_object(taskinfo->task, + entry->iin_name, + &kotype, (unsigned *)&kobject); +#endif if (ret == KERN_SUCCESS && kotype != 0) { JSON_OBJECT_SET(json, identifier, "0x%08x", (natural_t)kobject); JSON_OBJECT_SET(json, type, "%s", kobject_name(kotype)); - - if (desc[0]) { - JSON_OBJECT_SET(json, description, "%s", desc); - printf(" 0x%08x %s %s", (natural_t)kobject, kobject_name(kotype), desc); - } else { - printf(" 0x%08x %s", (natural_t)kobject, kobject_name(kotype)); - } - - if ((kotype == IKOT_TASK_RESUME) || - (kotype == IKOT_TASK_CONTROL) || - (kotype == IKOT_TASK_READ) || - (kotype == IKOT_TASK_INSPECT) || - (kotype == IKOT_TASK_NAME)) { + if (desc[0]) { + JSON_OBJECT_SET(json, description, "%s", desc); + printf(" 0x%08x %s %s", (natural_t)kobject, kobject_name(kotype), desc); + } else { + printf(" 0x%08x %s", (natural_t)kobject, kobject_name(kotype)); + } + if ((kotype == IKOT_TASK_RESUME) || (kotype == IKOT_TASK_CONTROL) || (kotype == IKOT_TASK_NAME)) { if (taskinfo->task_kobject == kobject) { /* neat little optimization since in most cases tasks have themselves in their ipc space */ JSON_OBJECT_SET(json, pid, %d, taskinfo->pid); @@ -651,9 +652,7 @@ static void show_task_table_entry(ipc_info_name_t *entry, my_per_task_info_t *ta } } - if ((kotype == IKOT_THREAD_CONTROL) || - (kotype == IKOT_THREAD_READ) || - (kotype == IKOT_THREAD_INSPECT)) { + if (kotype == IKOT_THREAD_CONTROL) { for (int i = 0; i < taskinfo->threadCount; i++) { if (taskinfo->threadInfos[i].th_kobject == kobject) { printf(" (%#llx)", taskinfo->threadInfos[i].th_id); @@ -681,7 +680,7 @@ static void show_task_table_entry(ipc_info_name_t *entry, my_per_task_info_t *ta /* not kobject - find the receive right holder */ my_per_task_info_t *recv_holder_taskinfo; mach_port_name_t recv_name = MACH_PORT_NULL; - if (KERN_SUCCESS == get_taskinfo_of_receiver_by_send_right(*entry, &recv_holder_taskinfo, &recv_name)) { + if (KERN_SUCCESS == get_taskinfo_of_receiver_by_send_right(entry, &recv_holder_taskinfo, &recv_name)) { mach_port_status_t port_status; mach_port_info_ext_t info; mach_port_context_t port_context = (mach_port_context_t)0; diff --git a/system_cmds/lsmp.tproj/task_details.c b/system_cmds/lsmp.tproj/task_details.c index 123f8aa..3111e77 100644 --- a/system_cmds/lsmp.tproj/task_details.c +++ b/system_cmds/lsmp.tproj/task_details.c @@ -21,6 +21,7 @@ */ #include +typedef char *kobject_description_t[512]; #include #include #include @@ -139,7 +140,7 @@ void deallocate_taskinfo_memory(my_per_task_info_t *data){ } } -kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_read_t target_task) +kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_t target_task) { int i; kern_return_t ret = KERN_SUCCESS; @@ -149,10 +150,10 @@ kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_read_t ta taskinfo->task = target_task; pid_for_task(target_task, &taskinfo->pid); - ret = task_get_exception_ports_info(taskinfo->task, EXC_MASK_ALL, taskinfo->exceptionInfo.masks, &taskinfo->exceptionInfo.count, taskinfo->exceptionInfo.ports_info, taskinfo->exceptionInfo.behaviors, taskinfo->exceptionInfo.flavors); + ret = task_get_exception_ports(taskinfo->task, EXC_MASK_ALL, taskinfo->exceptionInfo.masks, &taskinfo->exceptionInfo.count, taskinfo->exceptionInfo.ports, taskinfo->exceptionInfo.behaviors, taskinfo->exceptionInfo.flavors); if (ret != KERN_SUCCESS) { - fprintf(stderr, "task_get_exception_ports_info() failed: pid:%d error: %s\n",taskinfo->pid, mach_error_string(ret)); + fprintf(stderr, "task_get_exception_ports() failed: pid:%d error: %s\n",taskinfo->pid, mach_error_string(ret)); taskinfo->pid = 0; } @@ -180,9 +181,9 @@ kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_read_t ta mach_msg_type_number_t th_info_count = THREAD_IDENTIFIER_INFO_COUNT; struct exc_port_info *excinfo = &(taskinfo->threadExceptionInfos[i]); - ret = thread_get_exception_ports_info(threadPorts[i], EXC_MASK_ALL, excinfo->masks, &excinfo->count, excinfo->ports_info, excinfo->behaviors, excinfo->flavors); + ret = thread_get_exception_ports(threadPorts[i], EXC_MASK_ALL, excinfo->masks, &excinfo->count, excinfo->ports, excinfo->behaviors, excinfo->flavors); if (ret != KERN_SUCCESS){ - fprintf(stderr, "thread_get_exception_ports_info() failed: pid: %d thread: %d error %s\n", taskinfo->pid, threadPorts[i], mach_error_string(ret)); + fprintf(stderr, "thread_get_exception_ports() failed: pid: %d thread: %d error %s\n", taskinfo->pid, threadPorts[i], mach_error_string(ret)); } if (excinfo->count != 0) { @@ -236,9 +237,8 @@ kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_read_t ta proc_pid_to_name(taskinfo->pid, taskinfo->processName); ret = mach_port_kernel_object(mach_task_self(), taskinfo->task, &kotype, (unsigned *)&kobject); - - /* Now that we are using read ports, kotype should be checked against IKOT_TASK_READ */ - if (ret == KERN_SUCCESS && kotype == IKOT_TASK_READ) { + + if (ret == KERN_SUCCESS && kotype == IKOT_TASK_CONTROL) { taskinfo->task_kobject = kobject; taskinfo->valid = TRUE; } @@ -308,32 +308,23 @@ kern_return_t print_task_exception_info(my_per_task_info_t *taskinfo, JSON_t jso boolean_t header_required = TRUE; for (int i = 0; i < taskinfo->exceptionInfo.count; i++) { - if (taskinfo->exceptionInfo.ports_info[i].iip_port_object != 0) { - my_per_task_info_t * _found_task; - + if (taskinfo->exceptionInfo.ports[i] != MACH_PORT_NULL) { if (header_required) { - printf(" exc_port_object receiver_task flavor mask \n"); + printf(" exc_port flavor mask \n"); header_required = FALSE; } get_exc_behavior_string(taskinfo->exceptionInfo.behaviors[i], behavior_string, sizeof(behavior_string)); get_exc_mask_string(taskinfo->exceptionInfo.masks[i], mask_string, sizeof(mask_string)); JSON_OBJECT_BEGIN(json); - JSON_OBJECT_SET(json, port_object, "0x%08x", taskinfo->exceptionInfo.ports_info[i].iip_port_object); - JSON_OBJECT_SET(json, receiver_object, "0x%08x", taskinfo->exceptionInfo.ports_info[i].iip_receiver_object); + JSON_OBJECT_SET(json, port, "0x%08x", taskinfo->exceptionInfo.ports[i]); JSON_OBJECT_SET(json, flavor, "0x%03x", taskinfo->exceptionInfo.flavors[i]); JSON_OBJECT_SET(json, behavior, "%s", behavior_string); JSON_OBJECT_SET(json, mask, "%s", mask_string); JSON_OBJECT_END(json); // exception port - - _found_task = get_taskinfo_by_kobject((natural_t)taskinfo->exceptionInfo.ports_info[i].iip_receiver_object); - - printf(" 0x%08x (%d) %s 0x%03x <%s> %s \n", - taskinfo->exceptionInfo.ports_info[i].iip_port_object, - _found_task->pid, - _found_task->processName, - taskinfo->exceptionInfo.flavors[i], behavior_string, mask_string); + + printf(" 0x%08x 0x%03x <%s> %s \n" , taskinfo->exceptionInfo.ports[i], taskinfo->exceptionInfo.flavors[i], behavior_string, mask_string); } } @@ -399,35 +390,39 @@ kern_return_t print_task_threads_special_ports(my_per_task_info_t *taskinfo, JSO for (int i = 0; i < excinfo->count; i++) { JSON_OBJECT_BEGIN(json); - if (excinfo->ports_info[i].iip_port_object != 0) { + if (excinfo->ports[i] != MACH_PORT_NULL) { if (header_required) { - printf("\n exc_port_object exc_port_receiver flavor mask -> name owner\n"); + printf("\n exc_port flavor mask -> name owner\n"); header_required = FALSE; } get_exc_behavior_string(excinfo->behaviors[i], behavior_string, sizeof(behavior_string)); get_exc_mask_string(excinfo->masks[i], mask_string, sizeof(mask_string)); - JSON_OBJECT_SET(json, port_object, "0x%08x", excinfo->ports_info[i].iip_port_object); - JSON_OBJECT_SET(json, receiver_object, "0x%08x", excinfo->ports_info[i].iip_receiver_object); + JSON_OBJECT_SET(json, port, "0x%08x", excinfo->ports[i]); JSON_OBJECT_SET(json, flavor, "0x%03x", excinfo->flavors[i]); JSON_OBJECT_SET(json, behavior, "%s", behavior_string); JSON_OBJECT_SET(json, mask, "%s", mask_string); - printf(" 0x%08x 0x%08x 0x%03x <%s> %s " , excinfo->ports_info[i].iip_port_object, excinfo->ports_info[i].iip_receiver_object, excinfo->flavors[i], behavior_string, mask_string); - - my_per_task_info_t *recv_holder_taskinfo; - mach_port_name_t recv_name = MACH_PORT_NULL; - if (KERN_SUCCESS == get_taskinfo_of_receiver_by_send_right_info(excinfo->ports_info[i], &recv_holder_taskinfo, &recv_name)) { - JSON_OBJECT_SET(json, name, "0x%08x", recv_name); - JSON_OBJECT_SET(json, ipc-object, "0x%08x", excinfo->ports_info[i].iip_port_object); - JSON_OBJECT_SET(json, pid, %d, recv_holder_taskinfo->pid); - JSON_OBJECT_SET(json, process, "%s", recv_holder_taskinfo->processName); - - printf(" -> 0x%08x 0x%08x (%d) %s\n", - recv_name, - excinfo->ports_info[i].iip_port_object, - recv_holder_taskinfo->pid, - recv_holder_taskinfo->processName); + printf(" 0x%08x 0x%03x <%s> %s " , excinfo->ports[i], excinfo->flavors[i], behavior_string, mask_string); + + ipc_info_name_t actual_sendinfo; + if (KERN_SUCCESS == get_ipc_info_from_lsmp_spaceinfo(excinfo->ports[i], &actual_sendinfo)) { + my_per_task_info_t *recv_holder_taskinfo; + mach_port_name_t recv_name = MACH_PORT_NULL; + if (KERN_SUCCESS == get_taskinfo_of_receiver_by_send_right(&actual_sendinfo, &recv_holder_taskinfo, &recv_name)) { + + JSON_OBJECT_SET(json, name, "0x%08x", recv_name); + JSON_OBJECT_SET(json, ipc-object, "0x%08x", actual_sendinfo.iin_object); + JSON_OBJECT_SET(json, pid, %d, recv_holder_taskinfo->pid); + JSON_OBJECT_SET(json, process, "%s", recv_holder_taskinfo->processName); + + printf(" -> 0x%08x 0x%08x (%d) %s\n", + recv_name, + actual_sendinfo.iin_object, + recv_holder_taskinfo->pid, + recv_holder_taskinfo->processName); + } + } else { fprintf(stderr, "failed to find"); } @@ -469,14 +464,14 @@ my_per_task_info_t * get_taskinfo_by_kobject(natural_t kobj) { return retval; } -static kern_return_t _get_taskinfo_of_receiver_by_send_right(natural_t kobject, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info) +kern_return_t get_taskinfo_of_receiver_by_send_right(ipc_info_name_t *sendright, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info) { *out_taskinfo = &NOT_FOUND_TASK_INFO; struct k2n_table_node *k2nnode; - for (unsigned int j = 0; j < global_taskcount; j++) { - if ((k2nnode = k2n_table_lookup(global_taskinfo[j].k2ntable, kobject))) { - assert(k2nnode->info_name->iin_object == kobject); + for (int j = 0; j < global_taskcount; j++) { + if ((k2nnode = k2n_table_lookup(global_taskinfo[j].k2ntable, sendright->iin_object))) { + assert(k2nnode->info_name->iin_object == sendright->iin_object); if (k2nnode->info_name->iin_type & MACH_PORT_TYPE_RECEIVE) { *out_taskinfo = &global_taskinfo[j]; @@ -489,12 +484,25 @@ static kern_return_t _get_taskinfo_of_receiver_by_send_right(natural_t kobject, return KERN_FAILURE; } -kern_return_t get_taskinfo_of_receiver_by_send_right(ipc_info_name_t sendright, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info) -{ - return _get_taskinfo_of_receiver_by_send_right(sendright.iin_object, out_taskinfo, out_recv_info); -} +kern_return_t get_ipc_info_from_lsmp_spaceinfo(mach_port_t port_name, ipc_info_name_t *out_sendright){ + kern_return_t retval = KERN_FAILURE; + bzero(out_sendright, sizeof(ipc_info_name_t)); + my_per_task_info_t *mytaskinfo = NULL; + for (int i = global_taskcount - 1; i >= 0; i--){ + if (global_taskinfo[i].task == mach_task_self()){ + mytaskinfo = &global_taskinfo[i]; + break; + } + } + if (mytaskinfo) { + for (int k = 0; k < mytaskinfo->tableCount; k++) { + if (port_name == mytaskinfo->table[k].iin_name){ + bcopy(&mytaskinfo->table[k], out_sendright, sizeof(ipc_info_name_t)); + retval = KERN_SUCCESS; + break; + } + } + } + return retval; -kern_return_t get_taskinfo_of_receiver_by_send_right_info(ipc_info_port_t sendright_info, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info) -{ - return _get_taskinfo_of_receiver_by_send_right(sendright_info.iip_port_object, out_taskinfo, out_recv_info); } diff --git a/system_cmds/mean.tproj/mean.c b/system_cmds/mean.tproj/mean.c index 87ecdc2..0c7268d 100644 --- a/system_cmds/mean.tproj/mean.c +++ b/system_cmds/mean.tproj/mean.c @@ -7,6 +7,7 @@ * */ +typedef char *kobject_description_t[512]; #include #include #include diff --git a/system_cmds/memory_pressure.tproj/memory_pressure.c b/system_cmds/memory_pressure.tproj/memory_pressure.c index 1713fcb..eb417c2 100644 --- a/system_cmds/memory_pressure.tproj/memory_pressure.c +++ b/system_cmds/memory_pressure.tproj/memory_pressure.c @@ -21,6 +21,7 @@ * @APPLE_LICENSE_HEADER_END@ */ +typedef char *kobject_description_t[512]; #include #include #include diff --git a/system_cmds/reboot.tproj/reboot.c b/system_cmds/reboot.tproj/reboot.c index ce9a019..8156d65 100644 --- a/system_cmds/reboot.tproj/reboot.c +++ b/system_cmds/reboot.tproj/reboot.c @@ -65,6 +65,7 @@ __unused static const char rcsid[] = #include "kextmanager.h" #include #endif +typedef char *kobject_description_t[512]; #include // allocate #include // task_self, etc #include // bootstrap diff --git a/system_cmds/shutdown.tproj/shutdown.c b/system_cmds/shutdown.tproj/shutdown.c index 021ce59..0dcc41b 100644 --- a/system_cmds/shutdown.tproj/shutdown.c +++ b/system_cmds/shutdown.tproj/shutdown.c @@ -64,6 +64,7 @@ __FBSDID("$FreeBSD: src/sbin/shutdown/shutdown.c,v 1.28 2005/01/25 08:40:51 delp #ifdef __APPLE__ #include #include +typedef char *kobject_description_t[512]; #include #include #include diff --git a/system_cmds/taskpolicy.tproj/taskpolicy.c b/system_cmds/taskpolicy.tproj/taskpolicy.c index 5bc9684..2c87e7c 100644 --- a/system_cmds/taskpolicy.tproj/taskpolicy.c +++ b/system_cmds/taskpolicy.tproj/taskpolicy.c @@ -32,6 +32,7 @@ #include #include #include +typedef char *kobject_description_t[512]; #include #include diff --git a/system_cmds/trace.tproj/trace.c b/system_cmds/trace.tproj/trace.c index f85b336..6ccf0fc 100644 --- a/system_cmds/trace.tproj/trace.c +++ b/system_cmds/trace.tproj/trace.c @@ -7,6 +7,7 @@ * made here may also need to be made there. */ +typedef char *kobject_description_t[512]; #include #include #include diff --git a/system_cmds/vm_purgeable_stat.tproj/entitlements.plist b/system_cmds/vm_purgeable_stat.tproj/entitlements.plist index 2ee8d1e..b21dbd8 100644 --- a/system_cmds/vm_purgeable_stat.tproj/entitlements.plist +++ b/system_cmds/vm_purgeable_stat.tproj/entitlements.plist @@ -2,7 +2,7 @@ - com.apple.system-task-ports.inspect + task_for_pid-allow diff --git a/system_cmds/vm_purgeable_stat.tproj/vm_purgeable_stat.c b/system_cmds/vm_purgeable_stat.tproj/vm_purgeable_stat.c index 330704d..e0a0011 100644 --- a/system_cmds/vm_purgeable_stat.tproj/vm_purgeable_stat.c +++ b/system_cmds/vm_purgeable_stat.tproj/vm_purgeable_stat.c @@ -22,11 +22,11 @@ * @APPLE_LICENSE_HEADER_END@ */ -#include #include #include #include #include +typedef char *kobject_description_t[512]; #include #include #include @@ -88,7 +88,7 @@ int get_task_from_pid(int pid, task_t *task) fprintf(stderr, "%s\n", PRIV_ERR_MSG); return -1; } - kr = task_inspect_for_pid(mach_task_self(), pid, task); + kr = task_for_pid(mach_task_self(), pid, task); if (kr != KERN_SUCCESS) { fprintf(stderr, "Failed to get task port for pid: %d\n", pid); return -1; @@ -128,9 +128,9 @@ int get_system_tasks(task_array_t *tasks, mach_msg_type_number_t *count) vm_deallocate(mach_task_self(), (vm_address_t)psets, (vm_size_t)psetCount * sizeof(mach_port_t)); /* convert the processor-set-priv to a list of tasks for the processor set */ - ret = processor_set_tasks_with_flavor(pset_priv, TASK_FLAVOR_INSPECT, tasks, count); + ret = processor_set_tasks(pset_priv, tasks, count); if (ret != KERN_SUCCESS) { - fprintf(stderr, "processor_set_tasks_with_flavor() failed: %s\n", mach_error_string(ret)); + fprintf(stderr, "processor_set_tasks() failed: %s\n", mach_error_string(ret)); return -1; } mach_port_deallocate(mach_task_self(), pset_priv); -- cgit v1.2.3-56-ge451