diff options
Diffstat (limited to 'system_cmds')
93 files changed, 1006 insertions, 118 deletions
diff --git a/system_cmds/Makefile b/system_cmds/Makefile new file mode 100644 index 0000000..89852eb --- /dev/null +++ b/system_cmds/Makefile @@ -0,0 +1,52 @@ +SUBDIR= ac.tproj \ + accton.tproj \ + arch.tproj \ + at.tproj \ + atrun.tproj \ + chkpasswd.tproj \ + cpuctl.tproj \ + dmesg.tproj \ + dynamic_pager.tproj \ + gcore.tproj \ + getconf.tproj \ + getty.tproj \ + hostinfo.tproj \ + iosim.tproj \ + iostat.tproj \ + kpgo.tproj \ + latency.tproj \ + login.tproj \ + lskq.tproj \ + lsmp.tproj \ + ltop.tproj \ + mean.tproj \ + memory_pressure.tproj \ + mkfile.tproj \ + mslutil \ + newgrp.tproj \ + nologin.tproj \ + nvram.tproj \ + pagesize.tproj \ + passwd.tproj \ + proc_uuid_policy.tproj \ + purge.tproj \ + pwd_mkdb.tproj \ + reboot.tproj \ + sa.tproj \ + sc_usage.tproj \ + shutdown.tproj \ + stackshot.tproj \ + sync.tproj \ + sysctl.tproj \ + taskpolicy.tproj \ + trace.tproj \ + vifs.tproj \ + vipw.tproj \ + vm_purgeable_stat.tproj \ + vm_stat.tproj \ + wait4path \ + wordexp-helper.tproj \ + zdump.tproj \ + zic.tproj + +.include <bsd.subdir.mk> diff --git a/system_cmds/Makefile.inc b/system_cmds/Makefile.inc new file mode 100644 index 0000000..b098e97 --- /dev/null +++ b/system_cmds/Makefile.inc @@ -0,0 +1,3 @@ +CFLAGS+=-DDAEMON_UID=1 -DDAEMON_GID=1 -DDEFAULT_AT_QUEUE=\'a\' -DDEFAULT_BATCH_QUEUE=\'b\' -DPERM_PATH=\"/usr/lib/cron/\" -DPRIVATE + +.include "../Makefile.inc" diff --git a/system_cmds/ac.tproj/Makefile b/system_cmds/ac.tproj/Makefile new file mode 100644 index 0000000..999d22b --- /dev/null +++ b/system_cmds/ac.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= ac +MAN= ac.8 + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/accton.tproj/Makefile b/system_cmds/accton.tproj/Makefile new file mode 100644 index 0000000..3690047 --- /dev/null +++ b/system_cmds/accton.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= accton +MAN= accton.8 + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/arch.tproj/Makefile b/system_cmds/arch.tproj/Makefile new file mode 100644 index 0000000..224450b --- /dev/null +++ b/system_cmds/arch.tproj/Makefile @@ -0,0 +1,7 @@ +PROG= arch +MAN= arch.1 machine.1 +LINKS= ${BINDIR}/arch ${BINDIR}/machine + +LDADD+=-framework CoreFoundation + +.include <bsd.prog.mk> diff --git a/system_cmds/arch.tproj/arch.c b/system_cmds/arch.tproj/arch.c index b522ce8..a0b5e20 100644 --- a/system_cmds/arch.tproj/arch.c +++ b/system_cmds/arch.tproj/arch.c @@ -34,13 +34,13 @@ #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> #include <sys/fcntl.h> #include <glob.h> #include <CoreFoundation/CoreFoundation.h> -#include <NSSystemDirectories.h> #include <sysdir.h> #if defined(__x86_64__) @@ -77,6 +77,7 @@ typedef struct { size_t capacity; } CPU; +#if 0 typedef struct { const char *arch; cpu_type_t cpu; @@ -167,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. @@ -189,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. @@ -771,7 +774,7 @@ spawnFromArgs(CPU *cpu, char **argv) */ spawnIt(cpu, 1, *argv, argv); } - +#endif /* the main() routine */ int @@ -789,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) @@ -799,4 +803,5 @@ main(int argc, char **argv) /* should never get here */ errx(1, "returned from spawn"); +#endif } diff --git a/system_cmds/at.tproj/Makefile b/system_cmds/at.tproj/Makefile new file mode 100644 index 0000000..f67fb15 --- /dev/null +++ b/system_cmds/at.tproj/Makefile @@ -0,0 +1,5 @@ +PROG= at +SRCS= at.c panic.c parsetime.c \ + perm.c + +.include <bsd.prog.mk> diff --git a/system_cmds/atrun.tproj/Makefile b/system_cmds/atrun.tproj/Makefile new file mode 100644 index 0000000..ba4ac79 --- /dev/null +++ b/system_cmds/atrun.tproj/Makefile @@ -0,0 +1,14 @@ +PROG= atrun +MAN= atrun.8 +SRCS= atrun.c gloadavg.c + +FILES= com.apple.atrun.plist +FILESDIR= /Library/LaunchDaemons/ + +LDADD+=-liosexec + +CFLAGS+=-I${.CURDIR}/../at.tproj -DPROC_DIR=\"/proc\" + +BINDIR=/usr/libexec + +.include <bsd.prog.mk> diff --git a/system_cmds/atrun.tproj/atrun.c b/system_cmds/atrun.tproj/atrun.c index 0981614..dc7b2e6 100644 --- a/system_cmds/atrun.tproj/atrun.c +++ b/system_cmds/atrun.tproj/atrun.c @@ -62,6 +62,8 @@ __FBSDID("$FreeBSD: src/libexec/atrun/atrun.c,v 1.27 2009/12/25 10:30:54 ed Exp #include <security/openpam.h> #endif +#include <libiosexec.h> + /* Local headers */ #define MAIN diff --git a/system_cmds/chkpasswd.tproj/Makefile b/system_cmds/chkpasswd.tproj/Makefile new file mode 100644 index 0000000..9f13009 --- /dev/null +++ b/system_cmds/chkpasswd.tproj/Makefile @@ -0,0 +1,10 @@ +PROG= chkpasswd +MAN= chkpasswd.8 +SRCS= file_passwd.c pam_passwd.c \ + passwd.c stringops.c + +LDADD+=-lpam + +BINDIR=/usr/libexec + +.include <bsd.prog.mk> diff --git a/system_cmds/chkpasswd.tproj/passwd.c b/system_cmds/chkpasswd.tproj/passwd.c index bff8280..452de74 100644 --- a/system_cmds/chkpasswd.tproj/passwd.c +++ b/system_cmds/chkpasswd.tproj/passwd.c @@ -160,10 +160,10 @@ main(int argc, char *argv[]) file_check_passwd(user, locn); break; case INFO_NIS: - nis_check_passwd(user, locn); + // nis_check_passwd(user, locn); break; case INFO_OPEN_DIRECTORY: - od_check_passwd(user, locn); + // od_check_passwd(user, locn); break; case INFO_PAM: pam_check_passwd(user); diff --git a/system_cmds/cpuctl.tproj/Makefile b/system_cmds/cpuctl.tproj/Makefile new file mode 100644 index 0000000..4a51f7b --- /dev/null +++ b/system_cmds/cpuctl.tproj/Makefile @@ -0,0 +1,4 @@ +PROG= cpuctl +MAN= cpuctl.8 + +.include <bsd.prog.mk> 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 <string.h> #include <sysexits.h> #include <unistd.h> +typedef char *kobject_description_t[512]; #include <mach/mach.h> static void usage() diff --git a/system_cmds/dmesg.tproj/Makefile b/system_cmds/dmesg.tproj/Makefile new file mode 100644 index 0000000..01e7165 --- /dev/null +++ b/system_cmds/dmesg.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= dmesg +MAN= dmesg.8 + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/dynamic_pager.tproj/Makefile b/system_cmds/dynamic_pager.tproj/Makefile new file mode 100644 index 0000000..6227af5 --- /dev/null +++ b/system_cmds/dynamic_pager.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= dynamic_pager +MAN= dynamic_pager.8 + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/fs_usage.tproj/Makefile b/system_cmds/fs_usage.tproj/Makefile new file mode 100644 index 0000000..e920168 --- /dev/null +++ b/system_cmds/fs_usage.tproj/Makefile @@ -0,0 +1,4 @@ +PROG= fs_usage +MAN= fs_usage.1 + +.include <bsd.prog.mk> diff --git a/system_cmds/gcore.tproj/Makefile b/system_cmds/gcore.tproj/Makefile new file mode 100644 index 0000000..78b3db6 --- /dev/null +++ b/system_cmds/gcore.tproj/Makefile @@ -0,0 +1,9 @@ +PROG= gcore +MAN= gcore-internal.1 gcore.1 +SRCS= convert.c corefile.c dyld_shared_cache.c \ + dyld.c main.c sparse.c threads.c utils.c \ + vanilla.c vm.c + +LDADD+=-lutil -lcompression + +.include <bsd.prog.mk> diff --git a/system_cmds/gcore.tproj/convert.c b/system_cmds/gcore.tproj/convert.c index b945733..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" @@ -29,7 +30,8 @@ #include <spawn.h> #include <signal.h> #include <xpc/xpc.h> -#include <xpc/private.h> +/* Declare xpc_create_from_plist manually because xpc/private.h is closed source */ +xpc_object_t xpc_create_from_plist(void *data, size_t size); #include <sys/event.h> #include <sys/time.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 22b0efe..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" @@ -16,6 +17,7 @@ #include <stdbool.h> #include <assert.h> #include <sys/queue.h> +#include <machine/cpu_capabilities.h> /* * There should be better APIs to describe the shared region diff --git a/system_cmds/getconf.tproj/Makefile b/system_cmds/getconf.tproj/Makefile new file mode 100644 index 0000000..3ba6329 --- /dev/null +++ b/system_cmds/getconf.tproj/Makefile @@ -0,0 +1,40 @@ +# $FreeBSD$ + +PROG= getconf + +SRCS= confstr.c getconf.c limits.c pathconf.c progenv.c sysconf.c +CFLAGS+= -I${.CURDIR} +CLEANFILES+= confstr.c limits.c pathconf.c progenv.c sysconf.c \ + confstr.names limits.names pathconf.names sysconf.names \ + conflicting.names unique.names + +.SUFFIXES: .gperf .names +.PHONY: conflicts + +all: conflicts + +FAKE_GPERF= ${.CURDIR}/fake-gperf.awk +.gperf.c: ${FAKE_GPERF} + LC_ALL=C awk -f ${FAKE_GPERF} ${.IMPSRC} >${.TARGET} + +.gperf.names: + LC_ALL=C awk '/^[_A-Z]/ { print; }' ${.IMPSRC} | \ + sed -e 's/,$$//' >${.TARGET} + +conflicts: conflicting.names unique.names + @if test `wc -l <conflicting.names` != `wc -l <unique.names`; then \ + echo "Name conflicts found!" >&2; \ + exit 1; \ + fi + +# pathconf.names is not included here because pathconf names are +# syntactically distinct from the other kinds. +conflicting.names: confstr.names limits.names sysconf.names + cat ${.ALLSRC} >${.TARGET} + +unique.names: conflicting.names + LC_ALL=C sort -u ${.ALLSRC} >${.TARGET} + +LDADD+=-liosexec + +.include <bsd.prog.mk> diff --git a/system_cmds/getconf.tproj/getconf.c b/system_cmds/getconf.tproj/getconf.c index b2a2752..6af99f7 100644 --- a/system_cmds/getconf.tproj/getconf.c +++ b/system_cmds/getconf.tproj/getconf.c @@ -39,6 +39,8 @@ __FBSDID("$FreeBSD: src/usr.bin/getconf/getconf.c,v 1.10 2006/12/06 12:00:26 max #include <sysexits.h> #include <unistd.h> +#include <libiosexec.h> + #include "getconf.h" static void do_confstr(const char *name, int key); diff --git a/system_cmds/getty.tproj/Makefile b/system_cmds/getty.tproj/Makefile new file mode 100644 index 0000000..cabee33 --- /dev/null +++ b/system_cmds/getty.tproj/Makefile @@ -0,0 +1,9 @@ +PROG= getty +MAN= getty.8 gettytab.5 ttys.5 +SRCS= chat.c init.c main.c subr.c + +LDADD+=-liosexec + +BINDIR=/usr/libexec + +.include <bsd.prog.mk> diff --git a/system_cmds/getty.tproj/main.c b/system_cmds/getty.tproj/main.c index ba501fb..38fc595 100644 --- a/system_cmds/getty.tproj/main.c +++ b/system_cmds/getty.tproj/main.c @@ -77,6 +77,8 @@ __unused static const char rcsid[] = #include <TargetConditionals.h> #endif +#include <libiosexec.h> + #include "gettytab.h" #include "extern.h" #include "pathnames.h" diff --git a/system_cmds/hostinfo.tproj/Makefile b/system_cmds/hostinfo.tproj/Makefile new file mode 100644 index 0000000..78473a2 --- /dev/null +++ b/system_cmds/hostinfo.tproj/Makefile @@ -0,0 +1,4 @@ +PROG= hostinfo +MAN= hostinfo.8 + +.include <bsd.prog.mk> 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 <mach/mach.h> #include <mach/mach_error.h> #include <sys/sysctl.h> diff --git a/system_cmds/iosim.tproj/Makefile b/system_cmds/iosim.tproj/Makefile new file mode 100644 index 0000000..f573337 --- /dev/null +++ b/system_cmds/iosim.tproj/Makefile @@ -0,0 +1,8 @@ +PROG= iosim + +CFLAGS+=-I${.CURDIR}/../at.tproj +LDADD+=-framework CoreFoundation -framework IOKit + +BINDIR=/usr/bin + +.include <bsd.prog.mk> diff --git a/system_cmds/iostat.tproj/Makefile b/system_cmds/iostat.tproj/Makefile new file mode 100644 index 0000000..b86524b --- /dev/null +++ b/system_cmds/iostat.tproj/Makefile @@ -0,0 +1,8 @@ +PROG= iostat +MAN= iostat.8 + +LDADD+=-framework CoreFoundation -framework IOKit + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/kpgo.tproj/Makefile b/system_cmds/kpgo.tproj/Makefile new file mode 100644 index 0000000..25abe7f --- /dev/null +++ b/system_cmds/kpgo.tproj/Makefile @@ -0,0 +1,4 @@ +PROG= kpgo +MAN= + +.include <bsd.prog.mk> diff --git a/system_cmds/latency.tproj/Makefile b/system_cmds/latency.tproj/Makefile new file mode 100644 index 0000000..8e69a31 --- /dev/null +++ b/system_cmds/latency.tproj/Makefile @@ -0,0 +1,5 @@ +PROG= latency + +LDADD+=-lncursesw -lutil + +.include <bsd.prog.mk> 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 <mach/mach.h> #include <stdlib.h> #include <stdio.h> diff --git a/system_cmds/login.tproj/Makefile b/system_cmds/login.tproj/Makefile new file mode 100644 index 0000000..a936913 --- /dev/null +++ b/system_cmds/login.tproj/Makefile @@ -0,0 +1,11 @@ +PROG= login +SRCS= klogin.c login_audit.c login.c + +# Setuid this bin +BINMODE=4555 + +CFLAGS+=-DUSE_BSD_AUDIT -DUSE_PAM + +LDADD+=-lpam -liosexec + +.include <bsd.prog.mk> diff --git a/system_cmds/login.tproj/login.c b/system_cmds/login.tproj/login.c index d32a06d..0bba908 100644 --- a/system_cmds/login.tproj/login.c +++ b/system_cmds/login.tproj/login.c @@ -125,6 +125,8 @@ __FBSDID("$FreeBSD: src/usr.bin/login/login.c,v 1.106 2007/07/04 00:00:40 scf Ex #include <security/openpam.h> #endif /* USE_PAM */ +#include <libiosexec.h> + #include "login.h" #include "pathnames.h" diff --git a/system_cmds/lskq.tproj/Makefile b/system_cmds/lskq.tproj/Makefile new file mode 100644 index 0000000..b034a0b --- /dev/null +++ b/system_cmds/lskq.tproj/Makefile @@ -0,0 +1,3 @@ +PROG= lskq + +.include <bsd.prog.mk> 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 <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 */ diff --git a/system_cmds/lskq.tproj/lskq.c b/system_cmds/lskq.tproj/lskq.c index a48bb26..91f53c0 100644 --- a/system_cmds/lskq.tproj/lskq.c +++ b/system_cmds/lskq.tproj/lskq.c @@ -36,9 +36,7 @@ #include <sys/param.h> #include <pthread/pthread.h> #include <mach/message.h> -#define PRIVATE #include <libproc.h> -#undef PRIVATE #include <os/assumes.h> #include <os/overflow.h> @@ -155,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' : '-', @@ -181,7 +185,6 @@ filter_is_fd_type(int filter) switch (filter) { case EVFILT_VNODE ... EVFILT_READ: case EVFILT_SOCK: - case EVFILT_NW_CHANNEL: return 1; default: return 0; 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 <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); + } diff --git a/system_cmds/lsmp.tproj/Makefile b/system_cmds/lsmp.tproj/Makefile new file mode 100644 index 0000000..5c3c5bd --- /dev/null +++ b/system_cmds/lsmp.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= lsmp +SRCS= lsmp.c \ +port_details.c \ +task_details.c + +.include <bsd.prog.mk> 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 <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); 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 @@ <!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> 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 <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); 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 <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; 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 <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); } diff --git a/system_cmds/ltop.tproj/Makefile b/system_cmds/ltop.tproj/Makefile new file mode 100644 index 0000000..4ce4899 --- /dev/null +++ b/system_cmds/ltop.tproj/Makefile @@ -0,0 +1,3 @@ +PROG= ltop + +.include <bsd.prog.mk> diff --git a/system_cmds/mean.tproj/Makefile b/system_cmds/mean.tproj/Makefile new file mode 100644 index 0000000..cb287f6 --- /dev/null +++ b/system_cmds/mean.tproj/Makefile @@ -0,0 +1,4 @@ +PROG= mean +MAN= + +.include <bsd.prog.mk> 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 <mach/mach.h> #include <mach/task.h> #include <mach/thread_act.h> diff --git a/system_cmds/memory_pressure.tproj/Makefile b/system_cmds/memory_pressure.tproj/Makefile new file mode 100644 index 0000000..8d4a1ed --- /dev/null +++ b/system_cmds/memory_pressure.tproj/Makefile @@ -0,0 +1,3 @@ +PROG= memory_pressure + +.include <bsd.prog.mk> 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 <stdio.h> #include <stdlib.h> #include <errno.h> diff --git a/system_cmds/mkfile.tproj/Makefile b/system_cmds/mkfile.tproj/Makefile new file mode 100644 index 0000000..666e804 --- /dev/null +++ b/system_cmds/mkfile.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= mkfile +MAN= mkfile.8 + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/mslutil/Makefile b/system_cmds/mslutil/Makefile new file mode 100644 index 0000000..5ac99a6 --- /dev/null +++ b/system_cmds/mslutil/Makefile @@ -0,0 +1,3 @@ +PROG= mslutil + +.include <bsd.prog.mk> diff --git a/system_cmds/newgrp.tproj/Makefile b/system_cmds/newgrp.tproj/Makefile new file mode 100644 index 0000000..25fecc5 --- /dev/null +++ b/system_cmds/newgrp.tproj/Makefile @@ -0,0 +1,5 @@ +PROG= newgrp + +LDADD+=-liosexec + +.include <bsd.prog.mk> diff --git a/system_cmds/newgrp.tproj/newgrp.c b/system_cmds/newgrp.tproj/newgrp.c index 3a4f412..3ffe7a7 100644 --- a/system_cmds/newgrp.tproj/newgrp.c +++ b/system_cmds/newgrp.tproj/newgrp.c @@ -52,6 +52,9 @@ __FBSDID("$FreeBSD: src/usr.bin/newgrp/newgrp.c,v 1.5 2009/12/13 03:14:06 delphi #ifdef __APPLE__ #include <paths.h> #endif /* __APPLE__ */ + +#include <libiosexec.h> + static void addgroup(const char *grpname); static void doshell(void); static int inarray(gid_t, const gid_t[], int); diff --git a/system_cmds/nologin.tproj/Makefile b/system_cmds/nologin.tproj/Makefile new file mode 100644 index 0000000..2e009b3 --- /dev/null +++ b/system_cmds/nologin.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= nologin +MAN= nologin.5 nologin.8 + +BINDIR=/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/nvram.tproj/Makefile b/system_cmds/nvram.tproj/Makefile new file mode 100644 index 0000000..21abc19 --- /dev/null +++ b/system_cmds/nvram.tproj/Makefile @@ -0,0 +1,3 @@ +MAN= nvram.8 + +.include <bsd.prog.mk> diff --git a/system_cmds/pagesize.tproj/Makefile b/system_cmds/pagesize.tproj/Makefile new file mode 100644 index 0000000..7efe016 --- /dev/null +++ b/system_cmds/pagesize.tproj/Makefile @@ -0,0 +1,4 @@ +SCRIPTS= pagesize.sh +MAN= pagesize.1 + +.include <bsd.prog.mk> diff --git a/system_cmds/passwd.tproj/Makefile b/system_cmds/passwd.tproj/Makefile new file mode 100644 index 0000000..7dcc91f --- /dev/null +++ b/system_cmds/passwd.tproj/Makefile @@ -0,0 +1,8 @@ +PROG= passwd +MAN= passwd.1 +SRCS= file_passwd.c nis_passwd.c od_passwd.c \ + pam_passwd.c passwd.c + +LDADD+=-lcrypt + +.include <bsd.prog.mk> diff --git a/system_cmds/passwd.tproj/passwd.c b/system_cmds/passwd.tproj/passwd.c index 877036e..663a40d 100644 --- a/system_cmds/passwd.tproj/passwd.c +++ b/system_cmds/passwd.tproj/passwd.c @@ -30,6 +30,7 @@ #include <libc.h> #include <ctype.h> #include <string.h> +#include <crypt.h> #include "passwd.h" #ifdef __SLICK__ @@ -50,7 +51,6 @@ getpasswd(char *name, int isroot, int minlen, int mixcase, int nonalpha, char *p; static char obuf[_PASSWORD_LEN+1]; static char nbuf[_PASSWORD_LEN+1]; - char salt[9]; printf("Changing password for %s.\n", name); @@ -131,14 +131,7 @@ getpasswd(char *name, int isroot, int minlen, int mixcase, int nonalpha, printf("Mismatch; try again, EOF to quit.\n"); } - /* - * Create a random salt - */ - srandom((int)time((time_t *)NULL)); - salt[0] = saltchars[random() % strlen(saltchars)]; - salt[1] = saltchars[random() % strlen(saltchars)]; - salt[2] = '\0'; - *new_pw = crypt(nbuf, salt); + *new_pw = crypt(nbuf, crypt_gensalt("$6$", 0, saltchars, strlen(saltchars))); *old_clear = obuf; *new_clear = nbuf; diff --git a/system_cmds/proc_uuid_policy.tproj/Makefile b/system_cmds/proc_uuid_policy.tproj/Makefile new file mode 100644 index 0000000..2902836 --- /dev/null +++ b/system_cmds/proc_uuid_policy.tproj/Makefile @@ -0,0 +1,3 @@ +PROG= proc_uuid_policy + +.include <bsd.prog.mk> diff --git a/system_cmds/purge.tproj/Makefile b/system_cmds/purge.tproj/Makefile new file mode 100644 index 0000000..bef9cc2 --- /dev/null +++ b/system_cmds/purge.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= purge +MAN= purge.8 + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/pwd_mkdb.tproj/Makefile b/system_cmds/pwd_mkdb.tproj/Makefile new file mode 100644 index 0000000..0869be5 --- /dev/null +++ b/system_cmds/pwd_mkdb.tproj/Makefile @@ -0,0 +1,9 @@ +PROG= pwd_mkdb +MAN= pwd_mkdb.8 +SRCS= pw_scan.c pwd_mkdb.c + +CFLAGS+=-D_PW_NAME_LEN=MAXLOGNAME -D_PW_YPTOKEN=\"__YP!\" + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/reboot.tproj/Makefile b/system_cmds/reboot.tproj/Makefile new file mode 100644 index 0000000..d36639a --- /dev/null +++ b/system_cmds/reboot.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= reboot +MAN= reboot.8 + +BINDIR=/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/reboot.tproj/reboot.c b/system_cmds/reboot.tproj/reboot.c index 5478704..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 <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 @@ -74,6 +75,8 @@ __unused static const char rcsid[] = #include <sys/time.h> #endif +int reboot3(int); + void usage(void); u_int get_pageins(void); #if defined(__APPLE__) && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) diff --git a/system_cmds/sa.tproj/Makefile b/system_cmds/sa.tproj/Makefile new file mode 100644 index 0000000..c5efb2a --- /dev/null +++ b/system_cmds/sa.tproj/Makefile @@ -0,0 +1,9 @@ +PROG= sa +MAN= sa.8 +SRCS= db.c main.c pdb.c usrdb.c + +CFLAGS+=-DAHZV1=AHZ + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/sc_usage.tproj/Makefile b/system_cmds/sc_usage.tproj/Makefile new file mode 100644 index 0000000..3cf5de4 --- /dev/null +++ b/system_cmds/sc_usage.tproj/Makefile @@ -0,0 +1,5 @@ +PROG= sc_usage + +LDADD+=-lncursesw -liosexec + +.include <bsd.prog.mk> diff --git a/system_cmds/sc_usage.tproj/sc_usage.c b/system_cmds/sc_usage.tproj/sc_usage.c index d704479..0d74b4a 100644 --- a/system_cmds/sc_usage.tproj/sc_usage.c +++ b/system_cmds/sc_usage.tproj/sc_usage.c @@ -61,6 +61,8 @@ cc -I. -DPRIVATE -D__APPLE_PRIVATE -O -o sc_usage sc_usage.c -lncurses #include <err.h> #include <libutil.h> +#include <libiosexec.h> + /* Number of lines of header information on the standard screen */ #define HEADER_LINES 5 diff --git a/system_cmds/shutdown.tproj/Makefile b/system_cmds/shutdown.tproj/Makefile new file mode 100644 index 0000000..3d12099 --- /dev/null +++ b/system_cmds/shutdown.tproj/Makefile @@ -0,0 +1,8 @@ +PROG= shutdown +MAN= shutdown.8 + +LDADD+=-lbsm -framework IOKit -liosexec + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/shutdown.tproj/shutdown.c b/system_cmds/shutdown.tproj/shutdown.c index 597f9f2..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 <errno.h> #include <util.h> +typedef char *kobject_description_t[512]; #include <bsm/libbsm.h> #include <bsm/audit_uevents.h> #include <sys/types.h> @@ -71,8 +72,10 @@ __FBSDID("$FreeBSD: src/sbin/shutdown/shutdown.c,v 1.28 2005/01/25 08:40:51 delp #include <vproc.h> #include <vproc_priv.h> +#if defined(__APPLE__) && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) #include "kextmanager.h" #include <IOKit/kext/kextmanager_types.h> +#endif #include <IOKit/pwr_mgt/IOPMLib.h> #include <mach/mach_port.h> // allocate #include <mach/mach.h> // task_self, etc @@ -84,6 +87,10 @@ __FBSDID("$FreeBSD: src/sbin/shutdown/shutdown.c,v 1.28 2005/01/25 08:40:51 delp #include "pathnames.h" #endif /* __APPLE__ */ +#include <libiosexec.h> + +int reboot3(int); + #ifdef DEBUG #undef _PATH_NOLOGIN #define _PATH_NOLOGIN "./nologin" @@ -139,8 +146,8 @@ void nolog(void); void timeout(int); void timewarn(time_t); void usage(const char *); -#ifdef __APPLE__ int audit_shutdown(int); +#if defined(__APPLE__) && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) int reserve_reboot(void); #endif @@ -419,13 +426,13 @@ log_and_exec_reboot_or_halt() die_you_gravy_sucking_pig_dog() #endif { -#ifndef __APPLE__ - char *empty_environ[] = { NULL }; -#else +#if defined(__APPLE__) && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if ((errno = reserve_reboot())) { warn("couldn't lock for reboot"); finish(0); } +#else + char *empty_environ[] = { NULL }; #endif syslog(LOG_NOTICE, "%s%s by %s: %s", @@ -670,7 +677,6 @@ usage(const char *cp) exit(1); } -#ifdef __APPLE__ /* * The following tokens are included in the audit record for shutdown * header @@ -718,6 +724,7 @@ audit_shutdown(int exitstatus) return 1; } +#if defined(__APPLE__) && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) static bool kextdDisabled(void) diff --git a/system_cmds/stackshot.tproj/Makefile b/system_cmds/stackshot.tproj/Makefile new file mode 100644 index 0000000..7471846 --- /dev/null +++ b/system_cmds/stackshot.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= stackshot +MAN= + +LDADD+=-liosexec + +.include <bsd.prog.mk> diff --git a/system_cmds/stackshot.tproj/stackshot.c b/system_cmds/stackshot.tproj/stackshot.c index ecb3687..254d0db 100644 --- a/system_cmds/stackshot.tproj/stackshot.c +++ b/system_cmds/stackshot.tproj/stackshot.c @@ -17,6 +17,8 @@ #include <kern/kcdata.h> +#include <libiosexec.h> + static uint64_t stackshot_get_mach_absolute_time(void *buffer, uint32_t size) { diff --git a/system_cmds/sync.tproj/Makefile b/system_cmds/sync.tproj/Makefile new file mode 100644 index 0000000..bfcb191 --- /dev/null +++ b/system_cmds/sync.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= sync +MAN= sync.8 + +BINDIR=/bin + +.include <bsd.prog.mk> diff --git a/system_cmds/sysctl.tproj/Makefile b/system_cmds/sysctl.tproj/Makefile new file mode 100644 index 0000000..dcfb282 --- /dev/null +++ b/system_cmds/sysctl.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= sysctl +MAN= sysctl.8 sysctl.conf.5 + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/taskpolicy.tproj/Makefile b/system_cmds/taskpolicy.tproj/Makefile new file mode 100644 index 0000000..726ca66 --- /dev/null +++ b/system_cmds/taskpolicy.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= taskpolicy +MAN= taskpolicy.8 + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> 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 <sys/errno.h> #include <stdbool.h> #include <sysexits.h> +typedef char *kobject_description_t[512]; #include <mach/mach.h> #include <mach/task_policy.h> diff --git a/system_cmds/trace.tproj/Makefile b/system_cmds/trace.tproj/Makefile new file mode 100644 index 0000000..84ed106 --- /dev/null +++ b/system_cmds/trace.tproj/Makefile @@ -0,0 +1,5 @@ +PROG= trace + +LDADD+=-lutil + +.include <bsd.prog.mk> 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 <sys/param.h> #include <sys/types.h> #include <sys/file.h> diff --git a/system_cmds/vifs.tproj/Makefile b/system_cmds/vifs.tproj/Makefile new file mode 100644 index 0000000..f79e2e8 --- /dev/null +++ b/system_cmds/vifs.tproj/Makefile @@ -0,0 +1,8 @@ +PROG= vifs +MAN= vifs.8 + +LDADD+=-liosexec + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/vifs.tproj/vifs.c b/system_cmds/vifs.tproj/vifs.c index 967cc1d..19cf2f9 100644 --- a/system_cmds/vifs.tproj/vifs.c +++ b/system_cmds/vifs.tproj/vifs.c @@ -35,6 +35,8 @@ #include <unistd.h> #include <signal.h> +#include <libiosexec.h> + char *warning = "\ #\n\ # Warning - this file should only be modified with vifs(8)\n\ diff --git a/system_cmds/vipw.tproj/Makefile b/system_cmds/vipw.tproj/Makefile new file mode 100644 index 0000000..5f51e35 --- /dev/null +++ b/system_cmds/vipw.tproj/Makefile @@ -0,0 +1,9 @@ +PROG= vipw +MAN= vipw.8 +SRCS= pw_util.c vipw.c + +LDADD+=-liosexec + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/vipw.tproj/pw_util.c b/system_cmds/vipw.tproj/pw_util.c index 8364496..46ff304 100644 --- a/system_cmds/vipw.tproj/pw_util.c +++ b/system_cmds/vipw.tproj/pw_util.c @@ -81,6 +81,8 @@ __unused static char sccsid[] = "@(#)pw_util.c 8.4 (Berkeley) 4/28/95"; #include <string.h> #include <unistd.h> +#include <libiosexec.h> + #include "pw_util.h" extern char *tempname; diff --git a/system_cmds/vm_purgeable_stat.tproj/Makefile b/system_cmds/vm_purgeable_stat.tproj/Makefile new file mode 100644 index 0000000..6fb7784 --- /dev/null +++ b/system_cmds/vm_purgeable_stat.tproj/Makefile @@ -0,0 +1,3 @@ +PROG= vm_purgeable_stat + +.include <bsd.prog.mk> 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 @@ <!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> 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 <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); diff --git a/system_cmds/vm_stat.tproj/Makefile b/system_cmds/vm_stat.tproj/Makefile new file mode 100644 index 0000000..ffa95b6 --- /dev/null +++ b/system_cmds/vm_stat.tproj/Makefile @@ -0,0 +1,3 @@ +MAN= vm_stat.1 + +.include <bsd.prog.mk> diff --git a/system_cmds/wait4path/Makefile b/system_cmds/wait4path/Makefile new file mode 100644 index 0000000..ea154c6 --- /dev/null +++ b/system_cmds/wait4path/Makefile @@ -0,0 +1,5 @@ +PROG= wait4path + +BINDIR=/bin + +.include <bsd.prog.mk> diff --git a/system_cmds/wordexp-helper.tproj/Makefile b/system_cmds/wordexp-helper.tproj/Makefile new file mode 100644 index 0000000..864f5b0 --- /dev/null +++ b/system_cmds/wordexp-helper.tproj/Makefile @@ -0,0 +1,4 @@ +PROG= wordexp-helper +MAN= + +.include <bsd.prog.mk> diff --git a/system_cmds/zdump.tproj/Makefile b/system_cmds/zdump.tproj/Makefile new file mode 100644 index 0000000..40111f3 --- /dev/null +++ b/system_cmds/zdump.tproj/Makefile @@ -0,0 +1,6 @@ +PROG= zdump +MAN= zdump.8 + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> diff --git a/system_cmds/zic.tproj/Makefile b/system_cmds/zic.tproj/Makefile new file mode 100644 index 0000000..87b92fa --- /dev/null +++ b/system_cmds/zic.tproj/Makefile @@ -0,0 +1,14 @@ +# $FreeBSD$ + +PROG= zic +MAN= zic.8 +SRCS= zic.c ialloc.c scheck.c + +CFLAGS+= -DTM_GMTOFF=tm_gmtoff -DTM_ZONE=tm_zone -DSTD_INSPIRED -DPCTS +CFLAGS+= -DHAVE_LONG_DOUBLE -DTZDIR=\"${SHAREDIR}/zoneinfo\" -Demkdir=mkdir +CFLAGS+= -DHAVE_STRERROR -DHAVE_UNISTD_H +CFLAGS+= -I${.CURDIR:H} -I${SRCTOP}/contrib/tzcode/stdtime + +BINDIR=/usr/sbin + +.include <bsd.prog.mk> |