]> git.cameronkatri.com Git - apple_cmds.git/commitdiff
system_cmds: Fix compilation for lower targets, downgrade lsmp
authorCameron Katri <me@cameronkatri.com>
Sun, 23 May 2021 15:51:14 +0000 (11:51 -0400)
committerCameron Katri <me@cameronkatri.com>
Sun, 23 May 2021 15:51:14 +0000 (11:51 -0400)
29 files changed:
system_cmds/arch.tproj/arch.c
system_cmds/cpuctl.tproj/cpuctl.c
system_cmds/gcore.tproj/convert.c
system_cmds/gcore.tproj/corefile.c
system_cmds/gcore.tproj/dyld.c
system_cmds/gcore.tproj/main.c
system_cmds/gcore.tproj/sparse.c
system_cmds/gcore.tproj/threads.c
system_cmds/gcore.tproj/utils.c
system_cmds/gcore.tproj/vanilla.c
system_cmds/gcore.tproj/vm.c
system_cmds/hostinfo.tproj/hostinfo.c
system_cmds/latency.tproj/latency.c
system_cmds/lskq.tproj/common.h
system_cmds/lskq.tproj/lskq.c
system_cmds/lsmp.patch [new file with mode: 0644]
system_cmds/lsmp.tproj/common.h
system_cmds/lsmp.tproj/entitlements.plist
system_cmds/lsmp.tproj/lsmp.c
system_cmds/lsmp.tproj/port_details.c
system_cmds/lsmp.tproj/task_details.c
system_cmds/mean.tproj/mean.c
system_cmds/memory_pressure.tproj/memory_pressure.c
system_cmds/reboot.tproj/reboot.c
system_cmds/shutdown.tproj/shutdown.c
system_cmds/taskpolicy.tproj/taskpolicy.c
system_cmds/trace.tproj/trace.c
system_cmds/vm_purgeable_stat.tproj/entitlements.plist
system_cmds/vm_purgeable_stat.tproj/vm_purgeable_stat.c

index 326b541b1951a4b9f6e59a245ee3007269a7e63c..a0b5e2023d2efc8b8682001a2d066619c5e9f2c8 100644 (file)
@@ -34,6 +34,7 @@
 #include <sys/param.h>
 #include <paths.h>
 #include <err.h>
+typedef char *kobject_description_t[512];
 #include <mach/mach.h>
 #include <mach-o/arch.h>
 #include <limits.h>
@@ -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
 }
index 482187858c29389b6df24a11bd98498c803d0330..22e2f3370797921584972b37dd52f34827178b22 100644 (file)
@@ -14,6 +14,7 @@
 #include <string.h>
 #include <sysexits.h>
 #include <unistd.h>
+typedef char *kobject_description_t[512];
 #include <mach/mach.h>
 
 static void usage()
index a3b41f3b0194a81078f9cd700e4ec665adcf588c..5e38244108a38c654d13eda054396cccb9cb15fb 100644 (file)
@@ -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"
index b1e4421cdd1c6e770d23a0d1264cbc13f17622a0..8e61ca6cc8c1c5f820f757c5a54ae13b99ab2298 100644 (file)
@@ -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"
index 92aeac1fe758dcb2b22f78c760c37f271b7abc8d..5ef98999ecd31bea39f7781237d143051360fa3e 100644 (file)
@@ -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"
index abefa14fbff986162805926b3222a5107fd1aab4..b20e721e63fa5d0e946bff5b91329535eb92c003 100644 (file)
@@ -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"
index c62b9f3f4dfc7deae8f7d569b637eced543b4c37..616eedf17e80620275109dccc54bbfa9fa1fa576 100644 (file)
@@ -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"
index b1b3d6f814ede08150516b99d1365364d922af2b..f47cbfd0c9a723f98944d9f450a9852dbe2b4446 100644 (file)
@@ -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"
index f0edcf842f0d4e0510dcb00104fc01152eb557c4..8706b6e0b184b65cc79bedb5427983f426fcbb5b 100644 (file)
@@ -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"
index 2253bffd9f3c1ef9cd8e5e586198adc3bbf80acc..46b91b5af5f49ca1dd4672a8080358d3e30c1b5a 100644 (file)
@@ -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"
index 3c4e7e6291081b3800f99a9ed5d2494dc4a7cccc..0504f51e8380c8b6c59788a42a5fed866f2006d7 100644 (file)
@@ -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"
index 1828583bc25b732a40746d6f78fab761d50f8c4b..7739975bf95514317ccaf3ba868d4cff410152d1 100644 (file)
@@ -37,6 +37,7 @@
  *     execting on.
  */
 
+typedef char *kobject_description_t[512];
 #include <mach/mach.h>
 #include <mach/mach_error.h>
 #include <sys/sysctl.h>
index afd67cc5951c3397fb76b7c932237a6ce255c715..3183eb010ce940593ced2bbe08f8806d6f1d005f 100644 (file)
@@ -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 <mach/mach.h>
 #include <stdlib.h>
 #include <stdio.h>
index 959ac66e2dbbf2bd3ecf518197bd0c95a3f72746..c01cff47804ceddd0391dcecf2736bd96192c83a 100644 (file)
 
 #include <stdint.h>
 
+#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
  */
index d19f72271e22a30e4e40f0a32da8dc28315c1b73..91f53c0f2c8d1ee441190beff6610fa6b732b93e 100644 (file)
@@ -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 (file)
index 0000000..6b1e129
--- /dev/null
@@ -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 <mach/mach.h>
++#include <mach_debug/ipc_info.h>
+ #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 @@
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+ <plist version="1.0">
+ <dict>
+-      <key>task_for_pid-allow</key>
+-      <true/>
+-      <key>com.apple.system-task-ports</key>
++      <key>com.apple.system-task-ports.read</key>
+       <true/>
+ </dict>
+ </plist>
+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 <System/sys/proc.h>
+ #include <unistd.h>
+ #include <mach/mach.h>
+ #include <mach/mach_error.h>
+@@ -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 <behaviors>           mask   \n");
++                printf("    exc_port_object    receiver_task    flavor  <behaviors>           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 <behaviors>           mask   -> name    owner\n");
++                            printf("\n    exc_port_object    exc_port_receiver    flavor <behaviors>           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);
+ }
index a059eb555cfd8b7a5fc3c8f8cf81ef3320eb479f..9a47012d07212998517aa0fa1125bc4a724397dd 100644 (file)
@@ -25,7 +25,6 @@
 #define system_cmds_common_h
 
 #include <mach/mach.h>
-#include <mach_debug/ipc_info.h>
 #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);
index cdf0e9eaa532973fa2dd28ccd1061aacb9fe8c30..b7b4e6c614e0ae0e9e32b513409cb53b2da1ebd5 100644 (file)
@@ -2,7 +2,9 @@
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
-       <key>com.apple.system-task-ports.read</key>
+       <key>task_for_pid-allow</key>
+       <true/>
+       <key>com.apple.system-task-ports</key>
        <true/>
 </dict>
 </plist>
index 114c5b6e17b2de2edf8086e6f914941ca31d276a..e1a89d92cded5ddf545ae0cb0fb26183d3c67cc2 100644 (file)
@@ -19,7 +19,7 @@
  *
  * @APPLE_LICENSE_HEADER_END@
  */
-#include <System/sys/proc.h>
+typedef char *kobject_description_t[512];
 #include <unistd.h>
 #include <mach/mach.h>
 #include <mach/mach_error.h>
@@ -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);
index 69fc9beaf20b972759150fdf96a10b7b51f6f4a8..f6222cd1cc8c81ff83f141a5a484ceabee8743a7 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <libproc.h>
 #include <assert.h>
+typedef char *kobject_description_t[512];
 #include <mach/mach.h>
 //#include <mach/mach_port.h.h>
 #include <mach/mach_voucher.h>
@@ -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;
index 123f8aac9694c6b596024f86cb41ba2111674d5a..3111e77467e1ed1600771d046800ae9fd8beb83c 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include <unistd.h>
+typedef char *kobject_description_t[512];
 #include <mach/mach.h>
 #include <mach/mach_error.h>
 #include <mach_debug/ipc_info.h>
@@ -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  <behaviors>           mask   \n");
+                printf("    exc_port    flavor <behaviors>           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 <behaviors>           mask   -> name    owner\n");
+                            printf("\n    exc_port    flavor <behaviors>           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);
 }
index 87ecdc25f238edcd2ca531ed795b5baf75ed6e27..0c7268d389f843808d082567f15f601171bb39d7 100644 (file)
@@ -7,6 +7,7 @@
  *
  */
 
+typedef char *kobject_description_t[512];
 #include <mach/mach.h>
 #include <mach/task.h>
 #include <mach/thread_act.h>
index 1713fcb5d1738f206bc6224ee2efc51ec55bec3e..eb417c24aee28dff3ae1cd6412f32872cbb7ec8a 100644 (file)
@@ -21,6 +21,7 @@
  * @APPLE_LICENSE_HEADER_END@
  */
 
+typedef char *kobject_description_t[512];
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
index ce9a019078227c01c8214e4b15346b3a12a6275d..8156d658e96a10608dbc06465cb9463a9a0ec23d 100644 (file)
@@ -65,6 +65,7 @@ __unused static const char rcsid[] =
 #include "kextmanager.h"
 #include <IOKit/kext/kextmanager_types.h>
 #endif
+typedef char *kobject_description_t[512];
 #include <mach/mach_port.h>            // allocate
 #include <mach/mach.h>                 // task_self, etc
 #include <servers/bootstrap.h> // bootstrap
index 021ce59789e0c41afd2aeb861cfa55310646d606..0dcc41b8d17c6a725e8d1d743f10287bc3145a02 100644 (file)
@@ -64,6 +64,7 @@ __FBSDID("$FreeBSD: src/sbin/shutdown/shutdown.c,v 1.28 2005/01/25 08:40:51 delp
 #ifdef __APPLE__
 #include <errno.h>
 #include <util.h>
+typedef char *kobject_description_t[512];
 #include <bsm/libbsm.h>
 #include <bsm/audit_uevents.h>
 #include <sys/types.h>
index 5bc96844ba2ef55e41b0c666b55bbb69e678b4bf..2c87e7c3f74f6b719a6779a29e755cb9364ab40e 100644 (file)
@@ -32,6 +32,7 @@
 #include <sys/errno.h>
 #include <stdbool.h>
 #include <sysexits.h>
+typedef char *kobject_description_t[512];
 #include <mach/mach.h>
 #include <mach/task_policy.h>
 
index f85b336ebf8b473390d584917c81ed5f8e860ef7..6ccf0fcd41c0f6a29cf510823aa6f6540188b84c 100644 (file)
@@ -7,6 +7,7 @@
  * made here may also need to be made there.
  */
 
+typedef char *kobject_description_t[512];
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/file.h>
index 2ee8d1e91cd55b80a7859f6d4380e0c36cae306e..b21dbd852d3f6b01c31c04c546591b0f018198f5 100644 (file)
@@ -2,7 +2,7 @@
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
-       <key>com.apple.system-task-ports.inspect</key>
+       <key>task_for_pid-allow</key>
        <true/>
 </dict>
 </plist>
index 330704d0898551985c3ddfe8ffe5a74fd1f90c93..e0a0011d37b1d7dbe34e8397064c5be197d7c18d 100644 (file)
  * @APPLE_LICENSE_HEADER_END@
  */
 
-#include <System/sys/proc.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <unistd.h>
+typedef char *kobject_description_t[512];
 #include <mach/mach.h>
 #include <mach/mach_types.h>
 #include <mach/task.h>
@@ -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);