Skip to content

Commit

Permalink
Add hostinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
asdfugil committed Aug 12, 2024
1 parent 8510c5a commit 782fb5c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
1. [x] print-cache
1. [x] print-disabled
1. [x] plist
1. [ ] procinfo
1. [ ] hostinfo
1. [x] procinfo
1. [x] hostinfo
1. [ ] resolveport
1. [x] limit
1. [x] runstats
Expand Down
2 changes: 1 addition & 1 deletion launchctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static const struct {
{ "print-disabled", "Prints which services are disabled.", NULL, print_disabled_cmd },
{ "plist", "Prints a property list embedded in a binary (targets the Info.plist by default).", "[segment,section] <path>", plist_cmd },
{ "procinfo", "Prints port information about a process.", "<pid>", procinfo_cmd },
{ "hostinfo", "Prints port information about the host.", NULL, todo_cmd },
{ "hostinfo", "Prints port information about the host.", NULL, hostinfo_cmd },
{ "resolveport", "Resolves a port name from a process to an endpoint in launchd.", "<owner-pid> <port-name>", todo_cmd },
{ "limit", "Reads or modifies launchd's resource limits.", "[<limit-name> [<both-limits> | <soft-limit> <hard-limit>]", limit_cmd },
{ "runstats", "Prints performance statistics for a service.", "<service-target>", runstats_cmd },
Expand Down
1 change: 1 addition & 0 deletions launchctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ cmd_main dumpjpcategory_cmd;

// procinfo.c
cmd_main procinfo_cmd;
cmd_main hostinfo_cmd;

void launchctl_xpc_object_print(xpc_object_t, const char *name, int level);
int launchctl_send_xpc_to_launchd(uint64_t routine, xpc_object_t msg, xpc_object_t *reply);
Expand Down
28 changes: 27 additions & 1 deletion procinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
#include "launchctl.h"

/* #include <mach/port_descriptions.h> */
const char *mach_task_special_port_description(int offset);
const char *mach_host_special_port_description(int port);
const char *mach_task_special_port_description(int port);
/* END <mach/mach/port_descriptions.h> */

#include <sys/proc_info.h>
Expand Down Expand Up @@ -600,3 +601,28 @@ procinfo_launchd_info: {}
printf("\n");
return 0;
}

int
hostinfo_cmd(xpc_object_t *msg, int argc, char **argv, char **envp, char **apple) {
for (int i = 0; i < HOST_MAX_SPECIAL_PORT; i++) {
mach_port_t port;
int retval = host_get_special_port(mach_host_self(), HOST_LOCAL_NODE, i, &port);
if (retval || !MACH_PORT_VALID(port)) continue;
char* type = get_port_type(port);
printf("host-%s port = 0x%x %s\n", mach_host_special_port_description(i), port, type);
free(type);
}

exception_mask_t masks[EXC_TYPES_COUNT];
mach_msg_type_number_t masksCnt;
exception_handler_t old_handlers[EXC_TYPES_COUNT];
exception_behavior_t old_behaviors[EXC_TYPES_COUNT];
thread_state_flavor_t old_flavors[EXC_TYPES_COUNT];
kern_return_t kr = host_get_exception_ports(mach_host_self(), 0x3ffe, masks, &masksCnt, old_handlers, old_behaviors, old_flavors);
if (kr) {
fprintf(stderr, "host_get_exception_ports(): 0x%x\n", kr);
} else {
print_exception_port_info(0, masks, masksCnt, old_handlers);
}
return 0;
}

0 comments on commit 782fb5c

Please sign in to comment.