From: Apple Date: Fri, 31 Jan 2020 01:57:06 +0000 (+0000) Subject: system_cmds-854.11.2.tar.gz X-Git-Tag: macos-1015^0 X-Git-Url: https://git.saurik.com/apple/system_cmds.git/commitdiff_plain/d52496fdbb8dd3d53ac142500a42d06f3720ea6c system_cmds-854.11.2.tar.gz --- diff --git a/.upstream_base_commits b/.upstream_base_commits new file mode 100644 index 0000000..886f2e2 --- /dev/null +++ b/.upstream_base_commits @@ -0,0 +1,2 @@ +#freebsd = https://github.com/freebsd/freebsd.git +iostat.tproj/iostat.8 freebsd usr.sbin/iostat/iostat.8 4724d1448f7e7698308a1e05a7bb9b2069d68234 diff --git a/arch.tproj/arch.1 b/arch.tproj/arch.1 index 909bac5..afc984c 100644 --- a/arch.tproj/arch.1 +++ b/arch.tproj/arch.1 @@ -58,7 +58,7 @@ command with no arguments, displays the machine's architecture type. .Pp The other use of the .Nm arch -command it to run a selected architecture of a universal binary. +command is to run a selected architecture of a universal binary. A universal binary contains code that can run on different architectures. By default, the operating system will select the architecture that most closely matches the processor type. diff --git a/base.xcconfig b/base.xcconfig new file mode 100644 index 0000000..5cd52d0 --- /dev/null +++ b/base.xcconfig @@ -0,0 +1,9 @@ +CODE_SIGN_IDENTITY = -; +CURRENT_PROJECT_VERSION = $(RC_ProjectSourceVersion); +DEAD_CODE_STRIPPING = YES; +DEBUG_INFORMATION_FORMAT = dwarf-with-dsym; +PREBINDING = NO; +// Current macOS +SDKROOT = macosx.internal; +VERSION_INFO_PREFIX = __attribute__((visibility("hidden"))) __ +VERSIONING_SYSTEM = apple-generic; diff --git a/chpass.tproj/pw_copy.c b/chpass.tproj/pw_copy.c index a9b9c70..8aa74a6 100644 --- a/chpass.tproj/pw_copy.c +++ b/chpass.tproj/pw_copy.c @@ -63,7 +63,7 @@ #include #include -#include +#include "pw_util.h" #include "pw_copy.h" extern char *tempname; diff --git a/cpuctl.tproj/cpuctl.8 b/cpuctl.tproj/cpuctl.8 new file mode 100644 index 0000000..f52f514 --- /dev/null +++ b/cpuctl.tproj/cpuctl.8 @@ -0,0 +1,67 @@ +.\" Darwin cpuctl man page adapted from NetBSD (credits below): +.\" +.\" $NetBSD: cpuctl.8,v 1.18 2018/01/14 00:45:54 mrg Exp $ +.\" +.\" Copyright (c) 2007, 2008, 2012, 2015 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Andrew Doran. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd March 18, 2019 +.Dt CPUCTL 8 +.Os Darwin +.Sh NAME +.Nm cpuctl +.Nd program to control CPUs +.Sh SYNOPSIS +.Nm cpuctl +.Ar command +.Op Ar arguments +.Sh DESCRIPTION +The +.Nm +command can be used to control and inspect the state of CPUs in the system. +.Pp +The first argument, +.Ar command , +specifies the action to take. +Valid commands are: +.Bl -tag -width offline +.It list +For each CPU in the system, display the current state and time of the last +state change. +.It offline Ar cpu Op Ar cpu ... +Set the specified CPUs off line. +.Pp +At least one CPU in the system must remain on line. +.It online Ar cpu Op Ar cpu ... +Set the specified CPUs on line. +.El +.Sh EXAMPLES +Run +.Dl cpuctl offline 2 +and then +.Dl cpuctl list +The output should reflect the fact that CPU#2 was taken offline. diff --git a/cpuctl.tproj/cpuctl.c b/cpuctl.tproj/cpuctl.c new file mode 100644 index 0000000..4821878 --- /dev/null +++ b/cpuctl.tproj/cpuctl.c @@ -0,0 +1,145 @@ +// +// cpuctl.c +// system_cmds +// +// Copyright (c) 2019 Apple Inc. All rights reserved. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void usage() +{ + printf("usage: cpuctl [ list ]\n"); + printf(" cpuctl { offline | online } [ ... ]\n"); + exit(EX_USAGE); +} + +static void fetch_cpu_info(host_t *priv_port, + processor_port_array_t proc_ports, + mach_msg_type_number_t proc_count, + processor_basic_info_data_t *cpus) +{ + for (int i = 0; i < proc_count; i++) { + mach_msg_type_number_t info_count = PROCESSOR_BASIC_INFO_COUNT; + + if (processor_info(proc_ports[i], PROCESSOR_BASIC_INFO, priv_port, + (processor_info_t)&cpus[i], &info_count) != KERN_SUCCESS) { + errx(EX_OSERR, "processor_info(%d) failed", i); + } + } +} + +static int do_cmd_list(mach_msg_type_number_t proc_count, processor_basic_info_data_t *cpus) +{ + int prev_lowest = -1; + for (int i = 0; i < proc_count; i++) { + int lowest_slot = INT_MAX; + int lowest_idx = -1; + for (int j = 0; j < proc_count; j++) { + int slot = cpus[j].slot_num; + if (slot > prev_lowest && slot < lowest_slot) { + lowest_slot = slot; + lowest_idx = j; + } + } + if (lowest_idx == -1) + errx(EX_OSERR, "slot numbers are out of range"); + + processor_basic_info_data_t *cpu = &cpus[lowest_idx]; + printf("CPU%d: %-7s type=%x,%x master=%d\n", + cpu->slot_num, + cpu->running ? "online" : "offline", + cpu->cpu_type, + cpu->cpu_subtype, + cpu->is_master); + + prev_lowest = lowest_slot; + } + return 0; +} + +static int find_cpu_by_slot(mach_msg_type_number_t proc_count, + processor_basic_info_data_t *cpus, + int slot) +{ + for (int i = 0; i < proc_count; i++) { + if (cpus[i].slot_num == slot) + return i; + } + return -1; +} + +int main(int argc, char **argv) +{ + int opt; + + while ((opt = getopt(argc, argv, "h")) != -1) { + switch (opt) { + case 'h': + usage(); + } + } + + host_t priv_port; + if (host_get_host_priv_port(mach_host_self(), &priv_port) != KERN_SUCCESS) + errx(EX_OSERR, "host_get_host_priv_port() failed"); + + processor_port_array_t proc_ports; + mach_msg_type_number_t proc_count; + if (host_processors(priv_port, &proc_ports, &proc_count) != KERN_SUCCESS) + errx(EX_OSERR, "host_processors() failed"); + + processor_basic_info_data_t *cpus = calloc(proc_count, sizeof(*cpus)); + if (!cpus) + errx(EX_OSERR, "calloc() failed"); + fetch_cpu_info(&priv_port, proc_ports, proc_count, cpus); + + if (optind == argc) + return do_cmd_list(proc_count, cpus); + + const char *cmd = argv[optind]; + optind++; + + if (!strcmp(cmd, "list")) + return do_cmd_list(proc_count, cpus); + + bool up = true; + if (!strncmp(cmd, "off", 3)) + up = false; + else if (strncmp(cmd, "on", 2)) + usage(); + + if (optind == argc) + usage(); + + int ret = 0; + for (; optind < argc; optind++) { + char *endp = NULL; + int slot = (int)strtoul(argv[optind], &endp, 0); + if (*endp != 0) + usage(); + + int cpu = find_cpu_by_slot(proc_count, cpus, slot); + if (cpu == -1) + errx(EX_USAGE, "Invalid CPU ID %d", slot); + + if (up) { + if (processor_start(proc_ports[cpu]) != KERN_SUCCESS) + errx(EX_OSERR, "processor_start(%u) failed", cpu); + } else { + if (processor_exit(proc_ports[cpu]) != KERN_SUCCESS) + errx(EX_OSERR, "processor_exit(%u) failed", cpu); + } + } + + return ret; +} diff --git a/fs_usage.tproj/fs_usage.c b/fs_usage.tproj/fs_usage.c index 8d1e67e..8612ae1 100644 --- a/fs_usage.tproj/fs_usage.c +++ b/fs_usage.tproj/fs_usage.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2016 Apple Inc. All rights reserved. + * Copyright (c) 1999-2019 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -42,7 +42,7 @@ #include #include -#include +#include #include #include @@ -413,6 +413,7 @@ void cache_disk_names(void); #define BSC_msync_extended 0x040e0104 #define BSC_pread_extended 0x040e0264 #define BSC_pwrite_extended 0x040e0268 +#define BSC_guarded_pwrite_extended 0x040e0798 #define BSC_mmap_extended 0x040e0314 #define BSC_mmap_extended2 0x040f0314 @@ -558,7 +559,7 @@ const struct bsd_syscall bsd_syscalls[MAX_BSD_SYSCALL] = { SYSCALL_WITH_NOCANCEL(read, FMT_FD_IO), SYSCALL_WITH_NOCANCEL(write, FMT_FD_IO), SYSCALL(guarded_write_np, FMT_FD_IO), - SYSCALL(guarded_pwrite_np, FMT_FD_IO), + SYSCALL(guarded_pwrite_np, FMT_PREAD), SYSCALL(guarded_writev_np, FMT_FD_IO), SYSCALL(fgetxattr, FMT_FD), SYSCALL(fsetxattr, FMT_FD), @@ -686,7 +687,7 @@ static uint64_t mach_to_nano(uint64_t mach) { uint64_t nanoseconds = 0; - assert(ktrace_convert_timestamp_to_nanoseconds(s, mach, &nanoseconds) == 0); + os_assert(ktrace_convert_timestamp_to_nanoseconds(s, mach, &nanoseconds) == 0); return nanoseconds; } @@ -722,6 +723,15 @@ exit_usage(void) exit(1); } +static void fs_usage_cleanup(const char *message) +{ + if (s){ + ktrace_session_destroy(s); + } + + fprintf(stderr, "Cleaning up tracing state because of %s\n", message); +} + int main(int argc, char *argv[]) { @@ -730,10 +740,12 @@ main(int argc, char *argv[]) bool exclude_pids = false; uint64_t time_limit_ns = 0; + os_set_crash_callback(&fs_usage_cleanup); + get_screenwidth(); s = ktrace_session_create(); - assert(s != NULL); + os_assert(s != NULL); (void)ktrace_ignore_process_filter_for_event(s, P_WrData); (void)ktrace_ignore_process_filter_for_event(s, P_RdData); (void)ktrace_ignore_process_filter_for_event(s, P_WrMeta); @@ -840,9 +852,9 @@ main(int argc, char *argv[]) ktrace_exclude_process(s, "csh"); ktrace_exclude_process(s, "sh"); ktrace_exclude_process(s, "zsh"); -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) ktrace_exclude_process(s, "dropbear"); -#endif /* TARGET_OS_EMBEDDED */ +#endif /* (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */ } } @@ -895,7 +907,7 @@ main(int argc, char *argv[]) fprintf(stderr, "ERROR: cannot both include and exclude simultaneously\n"); exit(1); } else { - assert(!rv); + os_assert(!rv); } argc--; @@ -1281,6 +1293,15 @@ setup_ktrace_callbacks(void) }); } +static void +extend_syscall_rw(th_info_t ti, ktrace_event_t event) +{ + ti->arg1 = event->arg1; /* the fd */ + ti->arg2 = event->arg2; /* nbytes */ + ti->arg3 = event->arg3; /* top half offset */ + ti->arg4 = event->arg4; /* bottom half offset */ +} + /* * Handle system call extended trace data. * pread and pwrite: @@ -1295,8 +1316,9 @@ extend_syscall(uint64_t thread, int type, ktrace_event_t event) switch (type) { case BSC_mmap_extended: - if ((ti = event_find(thread, BSC_mmap)) == NULL) + if ((ti = event_find(thread, BSC_mmap)) == NULL) { return; + } ti->arg8 = ti->arg3; /* save protection */ ti->arg1 = event->arg1; /* the fd */ @@ -1316,8 +1338,9 @@ extend_syscall(uint64_t thread, int type, ktrace_event_t event) case BSC_msync_extended: if ((ti = event_find(thread, BSC_msync)) == NULL) { - if ((ti = event_find(thread, BSC_msync_nocancel)) == NULL) + if ((ti = event_find(thread, BSC_msync_nocancel)) == NULL) { return; + } } ti->arg4 = event->arg1; /* top half address */ @@ -1326,26 +1349,30 @@ extend_syscall(uint64_t thread, int type, ktrace_event_t event) case BSC_pread_extended: if ((ti = event_find(thread, BSC_pread)) == NULL) { - if ((ti = event_find(thread, BSC_pread_nocancel)) == NULL) + if ((ti = event_find(thread, BSC_pread_nocancel)) == NULL) { return; + } } - ti->arg1 = event->arg1; /* the fd */ - ti->arg2 = event->arg2; /* nbytes */ - ti->arg3 = event->arg3; /* top half offset */ - ti->arg4 = event->arg4; /* bottom half offset */ + extend_syscall_rw(ti, event); break; case BSC_pwrite_extended: if ((ti = event_find(thread, BSC_pwrite)) == NULL) { - if ((ti = event_find(thread, BSC_pwrite_nocancel)) == NULL) + if ((ti = event_find(thread, BSC_pwrite_nocancel)) == NULL) { return; + } } - ti->arg1 = event->arg1; /* the fd */ - ti->arg2 = event->arg2; /* nbytes */ - ti->arg3 = event->arg3; /* top half offset */ - ti->arg4 = event->arg4; /* bottom half offset */ + extend_syscall_rw(ti, event); + break; + + case BSC_guarded_pwrite_extended: + if ((ti = event_find(thread, BSC_guarded_pwrite_np)) == NULL) { + return; + } + + extend_syscall_rw(ti, event); break; } } @@ -1577,7 +1604,21 @@ check_filter_mode(pid_t pid, th_info_t ti, uint64_t type, int error, int retval, int print_open(ktrace_event_t event, uint64_t flags) { - char mode[] = "______"; + char mode[] = { + '_', + '_', + (flags & O_CREAT) ? 'C' : '_', + (flags & O_APPEND) ? 'A' : '_', + (flags & O_TRUNC) ? 'T' : '_', + (flags & O_EXCL) ? 'E' : '_', + (flags & O_NONBLOCK) ? 'N' : '_', + (flags & O_SHLOCK) ? 'l' : (flags & O_EXLOCK) ? 'L' : '_', + (flags & O_NOFOLLOW) ? 'F' : '_', + (flags & O_SYMLINK) ? 'S' : '_', + (flags & O_EVTONLY) ? 'V' : '_', + (flags & O_CLOEXEC) ? 'X' : '_', + '\0', + }; if (flags & O_RDWR) { mode[0] = 'R'; @@ -1588,19 +1629,6 @@ print_open(ktrace_event_t event, uint64_t flags) mode[0] = 'R'; } - if (flags & O_CREAT) { - mode[2] = 'C'; - } - if (flags & O_APPEND) { - mode[3] = 'A'; - } - if (flags & O_TRUNC) { - mode[4] = 'T'; - } - if (flags & O_EXCL) { - mode[5] = 'E'; - } - if (event->arg1) { return printf(" [%3d] (%s) ", (int)event->arg1, mode); } else { @@ -1647,12 +1675,12 @@ format_print(th_info_t ti, char *sc_name, ktrace_event_t event, mach_time_of_first_event = now; if (format == FMT_DISKIO || format == FMT_DISKIO_CS) { - assert(dio); + os_assert(dio); } else { - assert(event); + os_assert(event); if (format != FMT_UNMAP_INFO) - assert(ti); + os_assert(ti); } /* Filter out WindowServer/xcpm ioctls in fs_usage */ @@ -1696,7 +1724,7 @@ format_print(th_info_t ti, char *sc_name, ktrace_event_t event, if (!command_name) command_name = ""; - assert(now_walltime.tv_sec || now_walltime.tv_usec); + os_assert(now_walltime.tv_sec || now_walltime.tv_usec); /* try and reuse the timestamp string */ if (last_walltime_secs != now_walltime.tv_sec) { @@ -2022,6 +2050,34 @@ format_print(th_info_t ti, char *sc_name, ktrace_event_t event, p = "SETLKW"; break; + case F_SETLKWTIMEOUT: + p = "SETLKWTIMEOUT"; + break; + + case F_GETLKPID: + p = "GETLKPID"; + break; + + case F_OFD_GETLK: + p = "OFD_GETLK"; + break; + + case F_OFD_SETLK: + p = "OFD_SETLK"; + break; + + case F_OFD_SETLKW: + p = "OFD_SETLKW"; + break; + + case F_OFD_SETLKWTIMEOUT: + p = "OFD_SETLKWTIMEOUT"; + break; + + case F_OFD_GETLKPID: + p = "OFD_GETLKPID"; + break; + case F_PREALLOCATE: p = "PREALLOCATE"; break; @@ -2883,7 +2939,7 @@ event_enter(int type, ktrace_event_t event) found = true; } - assert(found); + os_assert(found); #endif /* DEBUG */ if ((ti = add_event(event, type)) == NULL) @@ -2956,7 +3012,7 @@ pfs_get(pid_t pid) struct pid_fd_set *pfs; int hashid; - assert(pid >= 0); + os_assert(pid >= 0); hashid = pid & HASH_MASK; @@ -3047,7 +3103,7 @@ fd_set_is_network(pid_t pid, uint64_t fd, bool set) newsize = MAX(((size_t)fd + CHAR_BIT) / CHAR_BIT, 2 * pfs->setsize); pfs->set = reallocf(pfs->set, newsize); - assert(pfs->set != NULL); + os_assert(pfs->set != NULL); bzero(pfs->set + pfs->setsize, newsize - pfs->setsize); pfs->setsize = newsize; diff --git a/gcore.tproj/convert.c b/gcore.tproj/convert.c index 33dad94..b945733 100644 --- a/gcore.tproj/convert.c +++ b/gcore.tproj/convert.c @@ -25,6 +25,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include #if defined(CONFIG_GCORE_MAP) || defined(CONFIG_GCORE_CONV) || defined(CONFIG_GCORE_FREF) @@ -389,6 +396,350 @@ convert_fileref_with_file(const char *filename, const native_mach_header_t *inmh return 0; } +/* + * expanduser tries to expand the leading '~' (if there is any) in the given + * path and returns a copy of the expanded path; it returns NULL on failures. + * The caller is responsible for freeing the returned string. + */ +static char * +expanduser(const char *path) +{ + if (path == NULL) { + return NULL; + } + if (path[0] != '~') { + /* + * For consistency, still dup the string so that the caller always + * needs to free the string. + */ + return strdup(path); + } + + char *expanded = NULL; + glob_t globbuf = {}; + if (OPTIONS_DEBUG(opt, 1)) { + printf("Expanding %s\n", path); + } + int rc = glob(path, GLOB_TILDE, NULL, &globbuf); + if (rc == 0) { + if (OPTIONS_DEBUG(opt, 3)) { + printf("expanduser - gl_pathc: %zu\n", globbuf.gl_pathc); + for (size_t i = 0; i < globbuf.gl_pathc; i++) { + printf("expanduser - gl_pathv[%zu]: %s\n", i, globbuf.gl_pathv[i]); + } + } + if (globbuf.gl_pathc == 1) { + expanded = strdup(globbuf.gl_pathv[0]); + if (OPTIONS_DEBUG(opt, 1)) { + printf("Expanded path: %s\n", expanded); + } + } + globfree(&globbuf); + } + + return expanded; +} + +#define RESPONSE_BUFF_SIZE (2048) + +/* + * read_response dynamically allocates buffer for reading bytes from the given + * fd. Upon success, this function sets response to point to the buffer and + * returns bytes being read; otherwise, it returns -1. The caller is + * responsible for freeing the response buffer. + */ +static ssize_t +read_response(int fd, char **response) +{ + if (response == NULL || *response) { + warnx("Invalid response buffer pointer"); + return -1; + } + + ssize_t bytes_read = 0; + size_t buff_size = RESPONSE_BUFF_SIZE; + + if (OPTIONS_DEBUG(opt, 3)) { + printf("Allocating response buffer (%zu)\n", buff_size); + } + char *buff = malloc(buff_size); + if (buff == NULL) { + warn("Failed to allocate response buffer (%zu)", buff_size); + return -1; + } + + size_t total = 0; + bool failed = false; + + do { + bytes_read = read(fd, buff + total, buff_size - total); + if (bytes_read == -1) { + if (errno == EINTR) { + continue; + } + failed = true; + break; + } + + total += (size_t)bytes_read; + if (total == buff_size) { + size_t new_buff_size = buff_size * 2; + if (OPTIONS_DEBUG(opt, 3)) { + printf("Reallocating response buffer (%zu)\n", new_buff_size); + } + char *new_buff = realloc(buff, new_buff_size); + if (new_buff == NULL) { + warn("Failed to reallocate response buffer (%zu)", new_buff_size); + failed = true; + break; + } + buff_size = new_buff_size; + buff = new_buff; + } + } while (bytes_read != 0); + + if (failed) { + if (buff != NULL) { + free(buff); + } + return -1; + } + + assert(total < buff_size); + buff[total] = '\0'; + *response = buff; + + return (ssize_t)total; +} + +#define WAITPID_WTO_SIGALRM (100) /* alternative for SIGALRM for kevent timeout */ +#define WAITPID_WTO_SIGERR (101) /* sig for error when waiting for pid */ + +/* + * waitpid_with_timeout returns true if the process exits successfully within + * timeout; otherwise, it returns false along with setting exitstatus and + * signal_no if the pointers are given. + */ +static bool +waitpid_with_timeout(pid_t pid, int *exitstatus, int *signal_no, int timeout) +{ + int status; + int kq = -1; + + if (timeout > 0) { + kq = kqueue(); + struct kevent64_s event = { + .ident = (uint64_t)pid, + .filter = EVFILT_PROC, + .flags = EV_ADD | EV_ONESHOT, + .fflags = NOTE_EXIT + }; + struct timespec tmout = { + .tv_sec = timeout + }; + int ret = kevent64(kq, &event, 1, &event, 1, 0, &tmout); + int kevent64_errno = errno; + + close(kq); + if (ret == 0) { /* timeout */ + if (exitstatus) { + *exitstatus = 0; + } + if (signal_no) { + *signal_no = WAITPID_WTO_SIGALRM; + } + return false; + } + + if (ret == -1) { + warnx("kevent64(): errno=%d (%s)\n", kevent64_errno, strerror(kevent64_errno)); + goto waitpid_error; + } + + if (event.flags == EV_ERROR && event.data != ESRCH) { + warnx("event.data (%lld) is not ESRCH when event.flags is EV_ERROR\n", event.data); + goto waitpid_error; + } + + if (event.ident != (uint64_t)pid) { + warnx("event.ident is %lld (should be pid %d)\n", event.ident, pid); + goto waitpid_error; + } + + if (event.filter != EVFILT_PROC) { + warnx("event.filter (%d) is not EVFILT_PROC\n", event.filter); + goto waitpid_error; + } + } + + while (waitpid(pid, &status, 0) < 0) { + if (errno == EINTR) { + continue; + } + warnx("waitpid(): errno=%d (%s)\n", errno, strerror(errno)); + goto waitpid_error; + } + if (WIFEXITED(status)) { + if (exitstatus) { + *exitstatus = WEXITSTATUS(status); + } + if (signal_no) { + *signal_no = 0; + } + return WEXITSTATUS(status) == 0; + } + if (WIFSIGNALED(status)) { + if (exitstatus) { + *exitstatus = 0; + } + if (signal_no) { + *signal_no = WTERMSIG(status); + } + return false; + } + +waitpid_error: + if (exitstatus) *exitstatus = 0; + if (signal_no) *signal_no = WAITPID_WTO_SIGERR; + return false; +} + +#define DSYMFORUUID_PATH "/usr/local/bin/dsymForUUID" + +/* + * exec_dsymForUUID spawns dsymForUUID to query dsym UUID info and responds the + * result plist. Upon success, this function sets response point to the buffer + * and returns bytes being read; otherwise, it returns -1. The caller is + * responsible for freeing the response buffer. + */ +static ssize_t +exec_dsymForUUID(uuid_string_t id, char **response) +{ + int pipe_fds[2] = {-1, -1}; + bool file_actions_inited = false; + ssize_t bytes_read = -1; + int rc; + + rc = pipe(pipe_fds); + if (rc == -1) { + goto cleanup; + } + + posix_spawn_file_actions_t file_actions; + rc = posix_spawn_file_actions_init(&file_actions); + if (rc) { + goto cleanup; + } + file_actions_inited = true; + + rc = posix_spawn_file_actions_addclose(&file_actions, pipe_fds[0]); + if (rc) { + goto cleanup; + } + + rc = posix_spawn_file_actions_adddup2(&file_actions, pipe_fds[1], STDOUT_FILENO); + if (rc) { + goto cleanup; + } + + rc = posix_spawn_file_actions_addclose(&file_actions, pipe_fds[1]); + if (rc) { + goto cleanup; + } + + char *command[] = {DSYMFORUUID_PATH, id, NULL}; + pid_t child; + rc = posix_spawn(&child, command[0], &file_actions, NULL, command, NULL); + if (rc) { + goto cleanup; + } + + close(pipe_fds[1]); + pipe_fds[1] = -1; + + bytes_read = read_response(pipe_fds[0], response); + + waitpid_with_timeout(child, NULL, NULL, 3); + +cleanup: + if (pipe_fds[1] != -1) { + close(pipe_fds[1]); + } + if (pipe_fds[0] != -1) { + close(pipe_fds[0]); + } + if (file_actions_inited) { + posix_spawn_file_actions_destroy(&file_actions); + } + + return bytes_read; +} + +/* + * get_symbol_rich_executable_path_via_dsymForUUID spawns dsymForUUID to query + * dsym uuid info for the given uuid and returns the string of + * DBGSymbolRichExecutable; otherwise, it returns NULL on failures. The caller + * is responsible for freeing the returned string. + */ +static char * +get_symbol_rich_executable_path_via_dsymForUUID(const uuid_t uuid) +{ + char *response; + ssize_t size; + uuid_string_t uuid_str; + xpc_object_t plist = NULL; + xpc_object_t uuid_info = NULL; + xpc_object_t exec_path = NULL; + char *expanded_exec_path = NULL; + + uuid_unparse_upper(uuid, uuid_str); + + size = exec_dsymForUUID(uuid_str, &response); + if (size <= 0) { + goto cleanup; + } + + if (OPTIONS_DEBUG(opt, 3)) { + printf("dsymForUUID response:\n%s\n", response); + } + + plist = xpc_create_from_plist(response, (size_t)size); + if (plist == NULL) { + goto cleanup; + } + if (xpc_get_type(plist) != XPC_TYPE_DICTIONARY) { + goto cleanup; + } + + uuid_info = xpc_dictionary_get_value(plist, uuid_str); + if (uuid_info == NULL) { + goto cleanup; + } + if (xpc_get_type(uuid_info) != XPC_TYPE_DICTIONARY) { + goto cleanup; + } + + exec_path = xpc_dictionary_get_value(uuid_info, "DBGSymbolRichExecutable"); + if (exec_path == NULL) { + goto cleanup; + } + if (xpc_get_type(exec_path) != XPC_TYPE_STRING) { + goto cleanup; + } + + expanded_exec_path = expanduser(xpc_string_get_string_ptr(exec_path)); + +cleanup: + if (plist) { + xpc_release(plist); + } + if (response) { + free(response); + } + + return expanded_exec_path; +} + /* * bind the file reference into the output core file. * filename optionally prefixed with names from a ':'-separated PATH variable @@ -427,8 +778,25 @@ convert_fileref(const char *path, bool zf, const native_mach_header_t *inmh, con printf("\n"); } + int ecode = 0; + if (opt->dsymforuuid && (FREF_ID_TYPE(infr->flags) == kFREF_ID_UUID)) { + /* Try to use dsymForUUID to get the symbol-rich executable */ + char *symrich_filepath = get_symbol_rich_executable_path_via_dsymForUUID(infr->id); + if (symrich_filepath) { + if (opt->verbose) { + printf("\tTrying %s from dsymForUUID\n", symrich_filepath); + } + ecode = convert_fileref_with_file(symrich_filepath, inmh, infr, &invr, lc, oi); + free(symrich_filepath); + if (ecode == 0) { + return (ecode); + } + warnx("Failed to convert fileref with dsymForUUID. Fall back to local paths"); + } + } + const size_t pathsize = path ? strlen(path) : 0; - int ecode = EX_DATAERR; + ecode = EX_DATAERR; if (0 == pathsize) ecode = convert_fileref_with_file(nm, inmh, infr, &invr, lc, oi); else { diff --git a/gcore.tproj/gcore-internal.1 b/gcore.tproj/gcore-internal.1 index 665e2f5..923f3e9 100644 --- a/gcore.tproj/gcore-internal.1 +++ b/gcore.tproj/gcore-internal.1 @@ -17,6 +17,7 @@ .Sy conv .Op Fl L Ar searchpath .Op Fl z +.Op Fl s .Op Fl v .Op Fl d .Ar incore outcore @@ -112,7 +113,7 @@ references it contains by copying the content and decompressing any compressed data into the output core file. This conversion usually makes the core file substantially larger. .Pp -Files to be dereferenced must be accessible on the +By default, files to be dereferenced must be accessible on the local filesystem by the same relative paths as they were originally recorded when the dump was taken. Files that are Mach-O objects containing UUIDs are required to match @@ -135,6 +136,11 @@ for each file reference. During conversion, if any mapped file identified by modification time cannot be located, substitute zeroed memory. +.It Fl s +When processing file references, +try looking for the pathname through +.Xr dsymForUUID 1 +before searching locally. .It Fl v Report progress on the conversion as it proceeds. .It Fl d @@ -165,7 +171,7 @@ and since it resides on a read-only root filesystem it should generally be easy to retrieve. However on the desktop, the lifecycle of this cache is managed locally e.g. with -.Xr update_dyld_shared_cache 1. +.Xr update_dyld_shared_cache 1 . When this cache is recreated it is given a new UUID, the directory entry for the old cache is removed, and the same filename is used for the new cache. @@ -191,4 +197,5 @@ could examine extended core files directly i.e. without the conversion step. .Pp .Sh SEE ALSO .Xr dyld 1 , -.Xr update_dyld_shared_cache 1 +.Xr update_dyld_shared_cache 1 , +.Xr dsymForUUID 1 diff --git a/gcore.tproj/main.c b/gcore.tproj/main.c index 4c2c3aa..64be227 100644 --- a/gcore.tproj/main.c +++ b/gcore.tproj/main.c @@ -294,6 +294,7 @@ static struct options options = { .chunksize = 0, .calgorithm = COMPRESSION_LZFSE, .ncthresh = DEFAULT_NC_THRESHOLD, + .dsymforuuid = 0, }; static int @@ -506,12 +507,15 @@ gcore_main(int argc, char *const *argv) task_t task = TASK_NULL; const struct proc_bsdinfo *pbi = NULL; + const int rc = kill(pid, 0); - if (-1 != kill(pid, 0)) { - /* process or corpse that responds to signals */ + if (rc == 0) { + /* process or corpse that may respond to signals */ pbi = get_bsdinfo(pid); - if (NULL == pbi) - errx(EX_OSERR, "cannot get process info for %d", pid); + } + + if (rc == 0 && pbi != NULL) { + /* process or corpse that responds to signals */ /* make our data model match the data model of the target */ if (-1 == reexec_to_match_lp64ness(pbi->pbi_flags & PROC_FLAG_LP64)) @@ -547,6 +551,9 @@ gcore_main(int argc, char *const *argv) change_credentials(pbi->pbi_uid, pbi->pbi_gid); } else { if (MACH_PORT_NULL == corpse) { + if (rc == 0) { + errx(EX_OSERR, "cannot get process info for %d", pid); + } switch (errno) { case ESRCH: errc(EX_DATAERR, errno, "no process with pid %d", pid); @@ -762,7 +769,7 @@ gcore_conv_main(int argc, char *argv[]) err_set_exit_b(^(int eval) { if (EX_USAGE == eval) fprintf(stderr, - "usage:\t%s %s [-v] [-L searchpath] [-z] incore outcore\n", pgm, argv[1]); + "usage:\t%s %s [-v] [-L searchpath] [-z] [-s] incore outcore\n", pgm, argv[1]); }); char *searchpath = NULL; @@ -770,7 +777,7 @@ gcore_conv_main(int argc, char *argv[]) int c; optind = 2; - while ((c = getopt(argc, argv, "dzvL:")) != -1) { + while ((c = getopt(argc, argv, "dzvL:s")) != -1) { switch (c) { /* * likely documented options @@ -784,7 +791,9 @@ gcore_conv_main(int argc, char *argv[]) case 'v': options.verbose++; break; - + case 's': + options.dsymforuuid++; + break; /* * dev and debugging help */ diff --git a/gcore.tproj/options.h b/gcore.tproj/options.h index 57e7768..71481fa 100644 --- a/gcore.tproj/options.h +++ b/gcore.tproj/options.h @@ -41,6 +41,7 @@ struct options { compression_algorithm calgorithm; // algorithm in use size_t ncthresh; // F_NOCACHE enabled *above* this value int allfilerefs; // if set, every mapped file on the root fs is a fileref + int dsymforuuid; // Try dsysForUUID to retrieve symbol-rich executable }; extern const struct options *opt; diff --git a/getty.tproj/main.c b/getty.tproj/main.c index 12c78b6..ba501fb 100644 --- a/getty.tproj/main.c +++ b/getty.tproj/main.c @@ -260,7 +260,7 @@ main(int argc, char *argv[]) */ dogettytab(); -#if defined(__APPLE__) && !TARGET_OS_EMBEDDED +#if defined(__APPLE__) && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (strncmp(ttyn, _PATH_CONSOLE, sizeof(ttyn)) == 0) ttyopenmode |= O_POPUP; #endif diff --git a/iosim.tproj/iosim.c b/iosim.tproj/iosim.c index 71ec671..3fde5d1 100644 --- a/iosim.tproj/iosim.c +++ b/iosim.tproj/iosim.c @@ -14,6 +14,9 @@ #include #include #include +#include +#include "panic.h" +#include #define IO_MODE_SEQ 0 #define IO_MODE_RANDOM 1 @@ -25,15 +28,23 @@ #define MAX_THREADS 1000 #define MAX_FILENAME 64 #define MAX_ITERATIONS 10000 -#define LATENCY_BIN_SIZE 500 -#define LATENCY_BINS 11 +#define LATENCY_BIN_SIZE 1000 +#define LATENCY_BINS 31 #define LOW_LATENCY_BIN_SIZE 50 -#define LOW_LATENCY_BINS 11 +#define LOW_LATENCY_BINS 21 #define THROUGHPUT_INTERVAL 5000 #define DEFAULT_FILE_SIZE (262144) #define BLOCKSIZE 1024 #define MAX_CMD_SIZE 256 #define PG_MASK ~(0xFFF) +#define kIONVMeANS2ControllerString "AppleANS2Controller" +#define kIONVMeControllerString "AppleNVMeController" + +typedef enum { + kDefaultDevice = 0, + kNVMeDevice = 1, + kNVMeDeviceANS2 = 2, +} qos_device_type_t; int burst_count = 10; /* Unit: Number ; Desc.: I/O Burst Count */ int inter_burst_duration = 0; /* Unit: msecs ; Desc.: I/O Inter-Burst Duration (-1: Random value [0,100]) */ @@ -47,24 +58,31 @@ int test_duration = 0; /* Unit: secs ; Desc.: Total Test Dura int io_tier = 0; /* Unit: 0/1/2/3; Desc.: I/O Tier */ int file_size = DEFAULT_FILE_SIZE; /* Unit: pages ; Desc.: File Size in 4096 byte blocks */ int cached_io_flag = 0; /* Unit: 0/1 ; Desc.: I/O Caching behavior (no-cached/cached) */ +int io_qos_timeout_ms = 0; /* Unit: msecs ; Desc.: I/O QOS timeout */ char *user_fname; int user_specified_file = 0; +qos_device_type_t qos_device = 0; -int64_t total_io_count; -int64_t total_io_size; -int64_t total_io_time; -int64_t total_burst_count; +int64_t total_io_count = 0; +int64_t total_io_size = 0; +int64_t total_io_time = 0; +int64_t max_io_time = 0; +int64_t total_burst_count = 0; int64_t latency_histogram[LATENCY_BINS]; int64_t burst_latency_histogram[LATENCY_BINS]; int64_t low_latency_histogram[LOW_LATENCY_BINS]; int64_t throughput_histogram[MAX_ITERATIONS]; int64_t throughput_index; +CFRunLoopTimerRef runLoopTimer = NULL; void print_usage(void); -void print_data_percentage(int percent); +void print_data_percentage(double percent); void print_stats(void); unsigned int find_io_bin(int64_t latency, int latency_bin_size, int latency_bins); void signalHandler(int sig); +void assertASP(CFRunLoopTimerRef timer, void *info ); +void start_qos_timer(void); +void stop_qos_timer(void); void perform_io(int fd, char *buf, int size, int type); void *sync_routine(void *arg); void *calculate_throughput(void *arg); @@ -72,7 +90,8 @@ void *io_routine(void *arg); void validate_option(int value, int min, int max, char *option, char *units); void print_test_setup(int value, char *option, char *units, char *comment); void setup_process_io_policy(int io_tier); -void print_latency_histogram(int64_t *data, int latency_bins, int latency_bin_size); +void setup_qos_device(void); +void print_latency_histogram(int64_t *data, int latency_bins, int latency_bin_size, double io_count); void print_usage(void) @@ -92,9 +111,10 @@ print_usage(void) printf("-z: (number) File Size in pages (1 page = 4096 bytes) \n"); printf("-n: (string) File name used for tests (the tool would create files if this option is not specified)\n"); printf("-a: (0/1 : Non-cached/Cached) I/O Caching behavior\n"); + printf("-q: (msecs) I/O QoS timeout. Time of I/O before drive assert and system panic\n"); } -void print_data_percentage(int percent) +void print_data_percentage(double percent) { int count = (int)(round(percent / 5.0)); int spaces = 20 - count; @@ -106,7 +126,7 @@ void print_data_percentage(int percent) printf("|"); } -void print_latency_histogram(int64_t *data, int latency_bins, int latency_bin_size) +void print_latency_histogram(int64_t *data, int latency_bins, int latency_bin_size, double io_count) { double percentage; char label[MAX_FILENAME]; @@ -118,9 +138,9 @@ void print_latency_histogram(int64_t *data, int latency_bins, int latency_bin_si else snprintf(label, MAX_FILENAME, "%d - %d usecs", i * latency_bin_size, (i+1) * latency_bin_size); printf("%25s ", label); - percentage = ((double)data[i] * 100.0) / (double)total_io_count; - print_data_percentage((int)percentage); - printf(" %.2lf%%\n", percentage); + percentage = ((double)data[i] * 100.000000) / io_count; + print_data_percentage(percentage); + printf(" %.6lf%%\n", percentage); } printf("\n"); } @@ -135,13 +155,14 @@ void print_stats() printf("Total I/Os : %lld\n", total_io_count); printf("Avg. Latency : %.2lf usecs\n", ((double)total_io_time) / ((double)total_io_count)); + printf("Max. Latency : %.2lf usecs\n", ((double)max_io_time)); printf("Low Latency Histogram: \n"); - print_latency_histogram(low_latency_histogram, LOW_LATENCY_BINS, LOW_LATENCY_BIN_SIZE); + print_latency_histogram(low_latency_histogram, LOW_LATENCY_BINS, LOW_LATENCY_BIN_SIZE, (double)total_io_count); printf("Latency Histogram: \n"); - print_latency_histogram(latency_histogram, LATENCY_BINS, LATENCY_BIN_SIZE); + print_latency_histogram(latency_histogram, LATENCY_BINS, LATENCY_BIN_SIZE, (double)total_io_count); printf("Burst Avg. Latency Histogram: \n"); - print_latency_histogram(burst_latency_histogram, LATENCY_BINS, LATENCY_BIN_SIZE); + print_latency_histogram(burst_latency_histogram, LATENCY_BINS, LATENCY_BIN_SIZE, (double)total_burst_count); printf("Throughput Timeline: \n"); @@ -176,6 +197,94 @@ void signalHandler(int sig) exit(0); } +void setup_qos_device(void) +{ + kern_return_t status = kIOReturnError; + io_iterator_t iterator = IO_OBJECT_NULL; + + if(io_qos_timeout_ms <= 0) + return; + + printf ( "*** setup_qos_device *** \n" ); + + status = IOServiceGetMatchingServices ( kIOMasterPortDefault, IOServiceMatching ( kIONVMeANS2ControllerString ), &iterator ); + + if ( status != kIOReturnSuccess ) + return; + + if ( iterator != IO_OBJECT_NULL ) { + printf ( "Found NVMe ANS2 Device \n" ); + qos_device = kNVMeDeviceANS2; + } else { + + status= IOServiceGetMatchingServices ( kIOMasterPortDefault, IOServiceMatching ( kIONVMeControllerString ), &iterator ); + + if ( status != kIOReturnSuccess ) + return; + + if ( iterator != IO_OBJECT_NULL ) { + printf ( "Found NVMe Device \n" ); + qos_device = kNVMeDevice; + } + else { + printf ( "NVMe Device not found, not setting qos timeout\n" ); + qos_device = kDefaultDevice; + } + } +} + +void assertASP(CFRunLoopTimerRef timer, void *info ) +{ + char command [ 1024 ]; + + if(qos_device == kDefaultDevice) + return; + + printf("assertASP. Timeout of IO exceeds = %d msec\n", io_qos_timeout_ms); + + // kNVMe_ANS2_Force_Assert_offset = 0x13EC, // GP59 + // kNVMe_Force_Assert_Offset = 0x550, + + if(qos_device == kNVMeDeviceANS2) + snprintf ( command, sizeof ( command ), "/usr/local/bin/nvmectl-tool.py -a WriteRegister32 $((0x13EC)) 0xFFFF" ); + else if(qos_device == kNVMeDevice) + snprintf ( command, sizeof ( command ), "/usr/local/bin/nvmectl-tool.py -a WriteRegister32 $((0x550)) 0xFFFF" ); + else + return; + + // Assert ASP + printf("Command : %s\n", command); + system(command); + + // Panic the system as well + panic("IO time > QoS timeout"); + + return; +} + +void start_qos_timer(void) +{ + float timeout_sec; + + if(io_qos_timeout_ms <= 0) + return; + + timeout_sec = (float)io_qos_timeout_ms/1000; + + // Schedule a "timeout" delayed task that checks IO's which take > timeout sec to complete + runLoopTimer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent()+timeout_sec, 0, 0, 0, assertASP, NULL); + CFRunLoopAddTimer(CFRunLoopGetMain(), runLoopTimer, kCFRunLoopDefaultMode); +} + +void stop_qos_timer(void) +{ + if(runLoopTimer == NULL) + return; + + CFRunLoopTimerInvalidate(runLoopTimer); + CFRunLoopRemoveTimer(CFRunLoopGetMain(), runLoopTimer, kCFRunLoopDefaultMode); + CFRelease(runLoopTimer); +} void perform_io(int fd, char *buf, int size, int type) { @@ -290,13 +399,22 @@ void *io_routine(void *arg) } } + start_qos_timer(); + gettimeofday(&start_tv, NULL); perform_io(fd, data, io_size, workload_type); gettimeofday(&end_tv, NULL); + stop_qos_timer(); + OSAtomicIncrement64(&total_io_count); OSAtomicAdd64(io_size, &total_io_size); elapsed = ((end_tv.tv_sec - start_tv.tv_sec) * 1000000) + (end_tv.tv_usec - start_tv.tv_usec); + + if (elapsed > max_io_time) { + max_io_time = elapsed; + } + OSAtomicAdd64(elapsed, &total_io_time); OSAtomicIncrement64(&(latency_histogram[find_io_bin(elapsed, LATENCY_BIN_SIZE, LATENCY_BINS)])); OSAtomicIncrement64(&(low_latency_histogram[find_io_bin(elapsed, LOW_LATENCY_BIN_SIZE, LOW_LATENCY_BINS)])); @@ -373,7 +491,7 @@ int main(int argc, char *argv[]) pthread_t throughput_thread; char fname[MAX_FILENAME]; - while((option = getopt(argc, argv,"hc:i:d:t:f:m:j:s:x:l:z:n:a:")) != -1) { + while((option = getopt(argc, argv,"hc:i:d:t:f:m:j:s:x:l:z:n:a:q:")) != -1) { switch(option) { case 'c': burst_count = atoi(optarg); @@ -430,6 +548,10 @@ int main(int argc, char *argv[]) cached_io_flag = atoi(optarg); validate_option(cached_io_flag, 0, 1, "I/Os cached/no-cached", ""); break; + case 'q': + io_qos_timeout_ms = atoi(optarg); + validate_option(io_qos_timeout_ms, 0, INT_MAX, "I/O QoS timeout", "msecs"); + break; default: printf("Unknown option %c\n", option); print_usage(); @@ -450,6 +572,7 @@ int main(int argc, char *argv[]) print_test_setup(test_duration, "Test duration", "secs", "0 indicates tool waits for Ctrl+C"); print_test_setup(io_tier, "I/O Tier", "", 0); print_test_setup(cached_io_flag, "I/O Caching", "", "0 indicates non-cached I/Os"); + print_test_setup(io_qos_timeout_ms, "I/O QoS Threshold Timeout", "msecs", 0); print_test_setup(0, "File read-aheads", "", "0 indicates read-aheads disabled"); printf("**********************************************************\n"); @@ -468,6 +591,8 @@ int main(int argc, char *argv[]) system("purge"); setup_process_io_policy(io_tier); + setup_qos_device(); + printf("**********************************************************\n"); printf("Creating threads and generating workload...\n"); @@ -493,9 +618,14 @@ int main(int argc, char *argv[]) exit(1); } - /* All threads are now initialized */ - if (test_duration) - alarm(test_duration); + if(io_qos_timeout_ms > 0) { + CFRunLoopRunInMode(kCFRunLoopDefaultMode, (CFTimeInterval)test_duration, false); + alarm(1); + } else { + /* All threads are now initialized */ + if (test_duration) + alarm(test_duration); + } for(i=0; i < thread_count; i++) pthread_join(thread_list[i], NULL); diff --git a/iostat.tproj/iostat.8 b/iostat.tproj/iostat.8 index a1487e7..f79c834 100644 --- a/iostat.tproj/iostat.8 +++ b/iostat.tproj/iostat.8 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/usr.sbin/iostat/iostat.8,v 1.20 2001/08/07 13:59:48 ru Exp $ +.\" $FreeBSD$ .\" .\" Copyright (c) 1985, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -38,11 +38,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" @@ -60,7 +56,7 @@ .\" .\" @(#)iostat.8 8.1 (Berkeley) 6/6/93 .\" -.Dd September 27, 2001 +.Dd May 22, 2015 .Dt IOSTAT 8 .Os .Sh NAME @@ -69,15 +65,16 @@ .Tn I/O statistics .Sh SYNOPSIS -.Nm iostat +.Nm .Op Fl CUdKIoT?\& .Op Fl c Ar count .Op Fl n Ar devs .Op Fl w Ar wait .Op Ar drives .Sh DESCRIPTION -.Nm Iostat -displays kernel +The +.Nm +utility displays kernel .Tn I/O statistics on terminal, device and cpu operations. The first statistics that are printed are averaged over the system uptime. @@ -87,16 +84,8 @@ averaged over that time. .Pp The options are as follows: .Bl -tag -width flag -.\" ========== .It Fl ?\& Display a usage statement and exit. -.\" ========== -.It Fl C -Display CPU statistics. -This is on by default, unless -.Fl d -is specified. -.\" ========== .It Fl c Repeat the display .Ar count @@ -104,7 +93,11 @@ times. If no .Ar wait interval is specified, the default is 1 second. -.\" ========== +.It Fl C +Display CPU statistics. +This is on by default, unless +.Fl d +is specified. .It Fl d Display only device statistics. If this flag is turned on, only device statistics will be displayed, unless @@ -113,48 +106,42 @@ or .Fl U or .Fl T -is also specfied to enable the display of CPU, load average or TTY statistics. -.\" ========== +is also specified to enable the display of CPU, load average or TTY statistics. .It Fl I -Display total statstics for a given time period, rather than average +Display total statistics for a given time period, rather than average statistics for each second during that time period. -.\" ========== .It Fl K In the blocks transferred display (-o), display block count in kilobytes rather then the device native block size. -.\" ========== .It Fl n Display up to .Ar devs number of devices. -.Nm iostat -will display fewer devices if there aren't +The +.Nm +utility will display fewer devices if there are not .Ar devs devices present. -.\" ========== .It Fl o Display old-style -.Nm iostat +.Nm device statistics. -Sectors per second, transfers per second, and miliseconds per seek are +Sectors per second, transfers per second, and milliseconds per seek are displayed. If .Fl I is specified, total blocks/sectors, total transfers, and -miliseconds per seek are displayed. -.\" ========== +milliseconds per seek are displayed. .It Fl T Display TTY statistics. This is on by default, unless .Fl d is specified. -.\" ========== .It Fl U Display system load averages. This is on by default, unless .Fl d is specified. -.\" ========== .It Fl w Pause .Ar wait @@ -164,8 +151,9 @@ If no repeat is specified, the default is infinity. .El .Pp -.Nm Iostat -displays its information in the following format: +The +.Nm +utility displays its information in the following format: .Bl -tag -width flag .It tty .Bl -tag -width indent -compact @@ -177,20 +165,24 @@ characters written to terminals .It devices Device operations. The header of the field is the device name and unit number. -.Nm iostat +The +.Nm +utility will display as many devices as will fit in a standard 80 column screen, or the maximum number of devices in the system, whichever is smaller. If .Fl n is specified on the command line, -.Nm iostat +.Nm will display the smaller of the requested number of devices, and the maximum number of devices in the system. To force -.Nm iostat +.Nm to display specific drives, their names may be supplied on the command line. -.Nm iostat +The +.Nm +utility will not display more devices than will fit in an 80 column screen, unless the .Fl n @@ -198,11 +190,11 @@ argument is given on the command line to specify a maximum number of devices to display, or the list of specified devices exceeds 80 columns. If fewer devices are specified on the command line than will fit in an 80 column screen, -.Nm iostat +.Nm will show only the specified devices. .Pp The standard -.Nm iostat +.Nm device display shows the following statistics: .Pp .Bl -tag -width indent -compact @@ -215,7 +207,7 @@ megabytes per second .El .Pp The standard -.Nm iostat +.Nm device display, with the .Fl I flag specified, shows the following statistics: @@ -230,7 +222,7 @@ total number of megabytes transferred .El .Pp The old-style -.Nm iostat +.Nm display (using .Fl o ) shows the following statistics: @@ -245,7 +237,7 @@ average milliseconds per transaction .El .Pp The old-style -.Nm iostat +.Nm display, with the .Fl I flag specified, shows the following statistics: @@ -295,16 +287,16 @@ and .Fl C flags are given, the TTY and CPU displays will be displayed. .Sh SEE ALSO -.Xr fstat 1 , .Xr netstat 1 , .Xr nfsstat 1 , .Xr ps 1 , -.Xr pstat 8 +.Xr top 1 , +.Xr vm_stat 1 .Pp The sections starting with ``Interpreting system activity'' in .%T "Installing and Operating 4.3BSD" . .Sh HISTORY This version of -.Nm iostat +.Nm first appeared in -.Nm FreeBSD 3.0 . +.Fx 3.0 . diff --git a/iostat.tproj/iostat.c b/iostat.tproj/iostat.c index 58f62a2..a9c73cb 100644 --- a/iostat.tproj/iostat.c +++ b/iostat.tproj/iostat.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2016 Apple Inc. All rights reserved. + * Copyright (c) 1999-2019 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -21,7 +21,9 @@ * * @APPLE_LICENSE_HEADER_END@ */ -/* +/*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1997, 1998, 2000, 2001 Kenneth D. Merry * All rights reserved. * @@ -48,7 +50,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/iostat/iostat.c,v 1.22 2001/09/01 07:40:19 kris Exp $ + * $FreeBSD$ */ /* * Parts of this program are derived from the original FreeBSD iostat @@ -66,10 +68,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -176,7 +174,7 @@ static IONotificationPortRef notifyPort; /* local function declarations */ static void usage(void); static void phdr(int signo); -static void do_phdr(); +static void do_phdr(void); static void devstats(int perf_select, long double etime, int havelast); static void cpustats(void); static void loadstats(void); diff --git a/latency.tproj/latency.c b/latency.tproj/latency.c index d8b67e4..afd67cc 100644 --- a/latency.tproj/latency.c +++ b/latency.tproj/latency.c @@ -908,6 +908,12 @@ exit_usage(void) exit(1); } +static void +resetscr(void) +{ + (void)endwin(); +} + int main(int argc, char *argv[]) { @@ -1032,9 +1038,10 @@ main(int argc, char *argv[]) if (!RAW_flag) { if (initscr() == NULL) { - printf("Unrecognized TERM type, try vt100\n"); + fprintf(stderr, "Unrecognized TERM type, try vt100\n"); exit(1); } + atexit(resetscr); clear(); refresh(); diff --git a/login.tproj/login.c b/login.tproj/login.c index e04f404..d32a06d 100644 --- a/login.tproj/login.c +++ b/login.tproj/login.c @@ -671,7 +671,7 @@ main(int argc, char *argv[]) bail(SLEEP_EXIT, 1); } -#if defined(__APPLE__) && TARGET_OS_EMBEDDED +#if defined(__APPLE__) && (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) /* on embedded, allow a shell to live in /private/var/personalized_debug/bin/sh */ #define _PATH_DEBUGSHELL "/private/var/personalized_debug/bin/sh" if (stat(pwd->pw_shell, &st) != 0) { diff --git a/lskq.tproj/common.h b/lskq.tproj/common.h index 872f576..959ac66 100644 --- a/lskq.tproj/common.h +++ b/lskq.tproj/common.h @@ -24,6 +24,8 @@ #ifndef _LSKQ_COMMON_H_ #define _LSKQ_COMMON_H_ +#include + /* * This file must be kept in sync with xnu headers */ @@ -31,33 +33,53 @@ /* * bsd/sys/event.h */ -#define KN_ACTIVE 0x0001 -#define KN_QUEUED 0x0002 -#define KN_DISABLED 0x0004 -#define KN_DROPPING 0x0008 -#define KN_USEWAIT 0x0010 -#define KN_ATTACHING 0x0020 -#define KN_STAYACTIVE 0x0040 -#define KN_DEFERDELETE 0x0080 -#define KN_ATTACHED 0x0100 -#define KN_DISPATCH 0x0200 -#define KN_UDATA_SPECIFIC 0x0400 -#define KN_SUPPRESSED 0x0800 -#define KN_STOLENDROP 0x1000 -#define KN_REQVANISH 0x2000 -#define KN_VANISHED 0x4000 - +__options_decl(kn_status_t, uint16_t /* 12 bits really */, { + KN_ACTIVE = 0x001, /* event has been triggered */ + KN_QUEUED = 0x002, /* event is on queue */ + KN_DISABLED = 0x004, /* event is disabled */ + KN_DROPPING = 0x008, /* knote is being dropped */ + KN_LOCKED = 0x010, /* knote is locked (kq_knlocks) */ + KN_POSTING = 0x020, /* f_event() in flight */ + KN_STAYACTIVE = 0x040, /* force event to stay active */ + KN_DEFERDELETE = 0x080, /* defer delete until re-enabled */ + KN_MERGE_QOS = 0x100, /* f_event() / f_* ran concurrently and overrides must merge */ + KN_REQVANISH = 0x200, /* requested EV_VANISH */ + KN_VANISHED = 0x400, /* has vanished */ + KN_SUPPRESSED = 0x800, /* event is suppressed during delivery */ +}); /* * bsd/sys/eventvar.h */ -#define KQ_SEL 0x01 -#define KQ_SLEEP 0x02 -#define KQ_KEV32 0x08 -#define KQ_KEV64 0x10 -#define KQ_KEV_QOS 0x20 -#define KQ_WORKQ 0x40 -#define KQ_WORKLOOP 0x80 +__options_decl(kq_state_t, uint16_t, { + KQ_SEL = 0x0001, /* select was recorded for kq */ + KQ_SLEEP = 0x0002, /* thread is waiting for events */ + KQ_PROCWAIT = 0x0004, /* thread waiting for processing */ + KQ_KEV32 = 0x0008, /* kq is used with 32-bit events */ + KQ_KEV64 = 0x0010, /* kq is used with 64-bit events */ + KQ_KEV_QOS = 0x0020, /* kq events carry QoS info */ + KQ_WORKQ = 0x0040, /* KQ is bound to process workq */ + KQ_WORKLOOP = 0x0080, /* KQ is part of a workloop */ + KQ_PROCESSING = 0x0100, /* KQ is being processed */ + KQ_DRAIN = 0x0200, /* kq is draining */ + KQ_WAKEUP = 0x0400, /* kq awakened while processing */ + KQ_DYNAMIC = 0x0800, /* kqueue is dynamically managed */ + KQ_R2K_ARMED = 0x1000, /* ast notification armed */ + KQ_HAS_TURNSTILE = 0x2000, /* this kqueue has a turnstile */ +}); + +/* + * bsd/pthread/workqueue_internal.h + */ +__enum_decl(workq_tr_state_t, uint8_t, { + WORKQ_TR_STATE_IDLE = 0, /* request isn't in flight */ + WORKQ_TR_STATE_NEW = 1, /* request is being initiated */ + WORKQ_TR_STATE_QUEUED = 2, /* request is being queued */ + WORKQ_TR_STATE_CANCELED = 3, /* request is canceled */ + WORKQ_TR_STATE_BINDING = 4, /* request is preposted for bind */ + WORKQ_TR_STATE_BOUND = 5, /* request is bound to a thread */ +}); + /* * bsd/sys/signal.h diff --git a/lskq.tproj/lskq.1 b/lskq.tproj/lskq.1 index 13c9b7e..88200e1 100644 --- a/lskq.tproj/lskq.1 +++ b/lskq.tproj/lskq.1 @@ -113,10 +113,10 @@ NOTE_SIGNAL NOTE_REAP .Pp .It EVFILT_TIMER: -.It Sy s u n -NOTE_SECONDS, NOTE_USECONDS, NOTE_NSECONDS -.It Sy a -NOTE_ABSOLUTE +.It Sy s u n m +NOTE_SECONDS, NOTE_USECONDS, NOTE_NSECONDS, NOTE_MACHTIME +.It Sy a A +NOTE_ABSOLUTE, NOTE_MACH_CONTINUOUS_TIME .It Sy c NOTE_CRITICAL .It Sy b @@ -133,14 +133,16 @@ NOTE_FFAND NOTE_FFOR .Pp .It EVFILT_WORKLOOP: -.It Sy t w -NOTE_WL_THREAD_REQUEST, NOTE_WL_SYNC_WAIT -.It Sy ! +.It Sy t w i +NOTE_WL_THREAD_REQUEST, NOTE_WL_SYNC_WAIT, NOTE_WL_SYNC_IPC +.It Sy W NOTE_WL_SYNC_WAKE .It Sy q NOTE_WL_UPDATE_QOS -.It Sy O o -NOTE_WL_UPDATE_OWNER, NOTE_WL_DISCOVER_OWNER +.It Sy o +NOTE_WL_DISCOVER_OWNER +.It Sy e +NOTE_WL_IGNORE_ESTALE .El .It flags kevent generic flags bitmask. @@ -182,28 +184,23 @@ KN_ACTIVE (event has triggered) .It Sy q KN_QUEUED (event has been added to the active list) .It Sy d -KN_DISABLED +KN_DISABLED (knote is disabled) +.It Sy p +KN_SUPPRESSED (event delivery is in flight) .It Sy s -KN_STAYQUEUED (event is marked as always-enqueued on the active list) +KN_STAYACTIVE (event is marked as always-enqueued on the active list) .Pp .It Sy d -KN_DROPPING -.It Sy w -KN_USEWAIT -.It Sy c -KN_ATTACHING -.It Sy a -KN_ATTACHED -.Pp -.It Sy s -KN_DISPATCH -.It Sy u -KN_UDATA_SPECIFIC -.It Sy p -KN_SUPPRESSED -.It Sy t -KN_STOLENDROP +KN_DROPPING (knote is about to be dropped) +.It Sy l +KN_LOCKED (knote is locked) +.It Sy P +KN_POSTING (knote is being posted) +.It Sy m +KN_MERGE_QOS (knote is in override saturating mode) .Pp +.It Sy D +KN_DEFERDELETE (knote is waiting for deferred-delete ack) .It Sy v KN_REQVANISH .It Sy n diff --git a/lskq.tproj/lskq.c b/lskq.tproj/lskq.c index a25b1ef..6eaa3a8 100644 --- a/lskq.tproj/lskq.c +++ b/lskq.tproj/lskq.c @@ -132,13 +132,15 @@ fflags_build(struct kevent_extinfo *info, char *str, int len) case EVFILT_TIMER: { snprintf(str, len, "%c%c%c%c%c ", - (ff & NOTE_SECONDS) ? 's' : - (ff & NOTE_USECONDS) ? 'u' : - (ff & NOTE_NSECONDS) ? 'n' : '?', - (ff & NOTE_ABSOLUTE) ? 'a' : '-', - (ff & NOTE_CRITICAL) ? 'c' : '-', - (ff & NOTE_BACKGROUND) ? 'b' : '-', - (ff & NOTE_LEEWAY) ? 'l' : '-' + (ff & NOTE_SECONDS) ? 's' : + (ff & NOTE_USECONDS) ? 'u' : + (ff & NOTE_NSECONDS) ? 'n' : + (ff & NOTE_MACHTIME) ? 'm' : '?', + (ff & NOTE_ABSOLUTE) ? 'a' : + (ff & NOTE_MACH_CONTINUOUS_TIME) ? 'A' : '-', + (ff & NOTE_CRITICAL) ? 'c' : '-', + (ff & NOTE_BACKGROUND) ? 'b' : '-', + (ff & NOTE_LEEWAY) ? 'l' : '-' ); break; } @@ -152,13 +154,14 @@ fflags_build(struct kevent_extinfo *info, char *str, int len) break; case EVFILT_WORKLOOP: - snprintf(str, len, "%c%c%c%c ", + snprintf(str, len, "%c%c%c%c%c ", (ff & NOTE_WL_THREAD_REQUEST) ? 't' : - (ff & NOTE_WL_SYNC_WAIT) ? 'w' : '-', - (ff & NOTE_WL_SYNC_WAKE) ? '!' : '-', + (ff & NOTE_WL_SYNC_WAIT) ? 'w' : + (ff & NOTE_WL_SYNC_IPC) ? 'i' : '-', + (ff & NOTE_WL_SYNC_WAKE) ? 'W' : '-', (ff & NOTE_WL_UPDATE_QOS) ? 'q' : '-', - (ff & NOTE_WL_UPDATE_OWNER) ? 'O' : - (ff & NOTE_WL_DISCOVER_OWNER) ? 'o' : '-' + (ff & NOTE_WL_DISCOVER_OWNER) ? 'o' : '-', + (ff & NOTE_WL_IGNORE_ESTALE) ? 'e' : '-' ); break; @@ -391,8 +394,16 @@ process_kqueue(int pid, const char *procname, enum kqtype type, uint64_t kqid, if (verbose && ret >= sizeof(struct kqueue_dyninfo)) { print_kq_info(pid, procname, kqid, kqinfo.kqdi_info.kq_state); - printf("%18s ", " "); // ident - printf("%-9s ", " "); // filter + if (kqinfo.kqdi_owner) { + printf("%#18llx ", kqinfo.kqdi_owner); // ident + printf("%-9s ", "WL owned"); // filter + } else if (kqinfo.kqdi_servicer) { + printf("%#18llx ", kqinfo.kqdi_servicer); // ident + printf("%-9s ", "WL"); // filter + } else { + printf("%18s ", "-"); // ident + printf("%-9s ", "WL"); // filter + } dynkq_printed = true; if (raw) { @@ -400,24 +411,47 @@ process_kqueue(int pid, const char *procname, enum kqtype type, uint64_t kqid, printf("%-10s ", " "); // flags printf("%-10s ", " "); // evst } else { - printf("%-8s ", " "); // fdtype + const char *reqstate = "???"; + + switch (kqinfo.kqdi_request_state) { + case WORKQ_TR_STATE_IDLE: + reqstate = ""; + break; + case WORKQ_TR_STATE_NEW: + reqstate = "new"; + break; + case WORKQ_TR_STATE_QUEUED: + reqstate = "queued"; + break; + case WORKQ_TR_STATE_CANCELED: + reqstate = "canceled"; + break; + case WORKQ_TR_STATE_BINDING: + reqstate = "binding"; + break; + case WORKQ_TR_STATE_BOUND: + reqstate = "bound"; + break; + } + + printf("%-8s ", reqstate); // fdtype char policy_type; switch (kqinfo.kqdi_pol) { - case POLICY_RR: - policy_type = 'R'; - break; - case POLICY_FIFO: - policy_type = 'F'; - case POLICY_TIMESHARE: - case 0: - default: - policy_type = '-'; - break; + case POLICY_RR: + policy_type = 'R'; + break; + case POLICY_FIFO: + policy_type = 'F'; + case POLICY_TIMESHARE: + case 0: + default: + policy_type = '-'; + break; } snprintf(tmpstr, 4, "%c%c%c", (kqinfo.kqdi_pri == 0)?'-':'P', policy_type, (kqinfo.kqdi_cpupercent == 0)?'-':'%'); printf("%-7s ", tmpstr); // fflags printf("%-15s ", " "); // flags - printf("%-17s ", " "); // evst + printf("%-15s ", " "); // evst } if (!raw && kqinfo.kqdi_pri != 0) { @@ -427,10 +461,6 @@ process_kqueue(int pid, const char *procname, enum kqtype type, uint64_t kqid, kqinfo.kqdi_sync_waiter_qos); printf("%3s ", thread_qos_name(qos)); //qos } - printf("%-18s ", " "); // data - printf("%-18s ", " "); // udata - printf("%#18llx ", kqinfo.kqdi_servicer); // ext0 - printf("%#18llx ", kqinfo.kqdi_owner); // ext1 printf("\n"); } } @@ -549,24 +579,21 @@ process_kqueue(int pid, const char *procname, enum kqtype type, uint64_t kqid, ); unsigned st = info->kqext_status; - printf("%c%c%c%c %c%c%c%c %c%c%c%c %c%c ", - (st & KN_ACTIVE) ? 'a' : '-', - (st & KN_QUEUED) ? 'q' : '-', - (st & KN_DISABLED) ? 'd' : '-', - (st & KN_STAYACTIVE) ? 's' : '-', - - (st & KN_DROPPING) ? 'd' : '-', - (st & KN_USEWAIT) ? 'w' : '-', - (st & KN_ATTACHING) ? 'c' : '-', - (st & KN_ATTACHED) ? 'a' : '-', - - (st & KN_DISPATCH) ? 's' : '-', - (st & KN_UDATA_SPECIFIC) ? 'u' : '-', - (st & KN_SUPPRESSED) ? 'p' : '-', - (st & KN_STOLENDROP) ? 't' : '-', - - (st & KN_REQVANISH) ? 'v' : '-', - (st & KN_VANISHED) ? 'n' : '-' + printf("%c%c%c%c%c %c%c%c%c %c%c%c ", + (st & KN_ACTIVE) ? 'a' : '-', + (st & KN_QUEUED) ? 'q' : '-', + (st & KN_DISABLED) ? 'd' : '-', + (st & KN_SUPPRESSED) ? 'p' : '-', + (st & KN_STAYACTIVE) ? 's' : '-', + + (st & KN_DROPPING) ? 'd' : '-', + (st & KN_LOCKED) ? 'l' : '-', + (st & KN_POSTING) ? 'P' : '-', + (st & KN_MERGE_QOS) ? 'm' : '-', + + (st & KN_DEFERDELETE) ? 'D' : '-', + (st & KN_REQVANISH) ? 'v' : '-', + (st & KN_VANISHED) ? 'n' : '-' ); } @@ -796,28 +823,33 @@ out: static void cheatsheet(void) { + const char *bold = "\033[1m"; + const char *reset = "\033[0m"; + if (!isatty(STDERR_FILENO)) { + bold = reset = ""; + } + fprintf(stderr, "\nFilter-independent flags:\n\n\ -\033[1m\ -command pid kq kqst knid filter fdtype fflags flags evst qos\033[0m\n\033[1m\ --------------------- ----- ------------------ ---- ------------------ --------- -------- ------- --------------- ----------------- ---\033[0m\n\ +%s\ +command pid kq kqst knid filter fdtype fflags flags evst qos%s\n%s\ +-------------------- ----- ------------------ ---- ------------------ --------- -------- ------- --------------- -------------- ---%s\n\ ┌ EV_UDATA_SPECIFIC\n\ EV_DISPATCH ┐ │┌ EV_FLAG0 (EV_POLL)\n\ EV_CLEAR ┐│ ││┌ EV_FLAG1 (EV_OOBAND)\n\ EV_ONESHOT ┐││ │││┌ EV_EOF\n\ EV_RECEIPT ┐│││ ││││┌ EV_ERROR\n\ - ││││ │││││\n\033[1m\ -launchd 1 4 ks- netbiosd 250 PROC ------- andx r1cs upboe aqds dwca supt vn IN\033[0m \n\ - │ │││ ││││ ││││ ││││ ││││ ││\n\ - kqueue file descriptor/dynamic ID ┘ │││ EV_ADD ┘│││ KN_ACTIVE ┘│││ ││││ ││││ ││\n\ - KQ_SLEEP ┘││ EV_ENABLE ┘││ KN_QUEUED ┘││ ││││ ││││ ││\n\ - KQ_SEL ┘│ EV_DISABLE ┘│ KN_DISABLED ┘│ ││││ ││││ │└ KN_VANISHED\n\ - KQ_WORKQ (q) ┤ EV_DELETE ┘ KN_STAYACTIVE ┘ ││││ ││││ └ KN_REQVANISH\n\ - KQ_WORKLOOP (l) ┘ ││││ ││││\n\ - KN_DROPPING ┘│││ │││└ KN_STOLENDROP\n\ - KN_USEWAIT ┘││ ││└ KN_SUPPRESSED\n\ - KN_ATTACHING ┘│ │└ KN_UDATA_SPECIFIC\n\ - KN_ATTACHED ┘ └ KN_DISPATCH\n\ - \n"); + ││││ │││││\n%s\ +launchd 1 4 ks- netbiosd 250 PROC ------- andx r1cs upboe aqdps dlPm Dvn IN%s\n\ + │ │││ ││││ │││││ ││││ │││\n\ + kqueue file descriptor/dynamic ID ┘ │││ EV_ADD ┘│││ KN_ACTIVE ┘││││ ││││ ││└ KN_VANISHED\n\ + KQ_SLEEP ┘││ EV_ENABLE ┘││ KN_QUEUED ┘│││ ││││ │└ KN_REQVANISH\n\ + KQ_SEL ┘│ EV_DISABLE ┘│ KN_DISABLED ┘││ ││││ └ KN_DEFERDELETE\n\ + KQ_WORKQ (q) ┤ EV_DELETE ┘ KN_SUPPRESSED ┘│ ││││\n\ + KQ_WORKLOOP (l) ┘ KN_STAYACTIVE ┘ ││││\n\ + ││││\n\ + KN_DROPPING ┘││└ KN_MERGE_QOS\n\ + KN_LOCKED ┘└ KN_POSTING\n\ + \n", bold, reset, bold, reset, bold, reset); } static void @@ -830,13 +862,13 @@ static void print_header(void) { if (raw) { - printf(" pid kq kqst knid filter fflags flags evst qos data"); + printf(" pid kq kqst knid filter fflags flags evst qos data"); } else { - printf("command pid kq kqst knid filter fdtype fflags flags evst qos data"); + printf("command pid kq kqst knid filter fdtype fflags flags evst qos data"); } if (verbose) { - printf(" udata servicer / ext0 owner / ext1 ext2 ext3 xflags"); + printf(" udata ext0 ext1 ext2 ext3 xflags"); } printf("\n"); @@ -844,7 +876,7 @@ print_header(void) if (raw) { printf("----- ------------------ ---------- ------------------ --------- ---------- ---------- ---------- --- ------------------"); } else { - printf("-------------------- ----- ------------------ ---- ------------------ --------- -------- ------- --------------- ----------------- --- ------------------"); + printf("-------------------- ----- ------------------ ---- ------------------ --------- -------- ------- --------------- -------------- --- ------------------"); } if (verbose) { diff --git a/lsmp.tproj/lsmp.c b/lsmp.tproj/lsmp.c index 92691d7..71a7c68 100644 --- a/lsmp.tproj/lsmp.c +++ b/lsmp.tproj/lsmp.c @@ -31,7 +31,7 @@ #include "common.h" #include "json.h" -#if TARGET_OS_EMBEDDED +#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()." #else #define TASK_FOR_PID_USAGE_MESG "" diff --git a/nvram.tproj/nvram.c b/nvram.tproj/nvram.c index c0df053..7bdf9c6 100644 --- a/nvram.tproj/nvram.c +++ b/nvram.tproj/nvram.c @@ -174,7 +174,7 @@ int main(int argc, char **argv) break; #if TARGET_OS_BRIDGE case 'm': - // -m option is unadvertised -- used to set nvram variables on the Intel side + // used to set nvram variables on the Intel side // from the ARM side (Bridge -> Mac) fprintf(stdout, "Using Mac NVRAM store.\n"); @@ -221,6 +221,9 @@ static void UsageMessage(char *message) printf("\t-f set firmware variables from a text file\n"); printf("\t-d delete the named variable\n"); printf("\t-c delete all variables\n"); +#if TARGET_OS_BRIDGE + printf("\t-m set nvram variables on macOS from bridgeOS\n"); +#endif printf("\tname=value set named variable\n"); printf("\tname print variable\n"); printf("Note that arguments and options are executed in order.\n"); @@ -762,7 +765,8 @@ static void PrintOFVariable(const void *key, const void *value, void *context) } // Get the OF variable's name. - nameLen = CFStringGetLength(key) + 1; + nameLen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(key), + kCFStringEncodingUTF8) + 1; nameBuffer = malloc(nameLen); if( nameBuffer && CFStringGetCString(key, nameBuffer, nameLen, kCFStringEncodingUTF8) ) nameString = nameBuffer; @@ -784,7 +788,8 @@ static void PrintOFVariable(const void *key, const void *value, void *context) else sprintf(numberBuffer, "0x%x", number); valueString = numberBuffer; } else if (typeID == CFStringGetTypeID()) { - valueLen = CFStringGetLength(value) + 1; + valueLen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(value), + kCFStringEncodingUTF8) + 1; valueBuffer = malloc(valueLen + 1); if ( valueBuffer && CFStringGetCString(value, valueBuffer, valueLen, kCFStringEncodingUTF8) ) valueString = valueBuffer; @@ -904,7 +909,8 @@ static void SetOFVariableFromFile(const void *key, const void *value, void *cont char *nameString; // Get the variable's name. - nameLen = CFStringGetLength(key) + 1; + nameLen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(key), + kCFStringEncodingUTF8) + 1; nameBuffer = malloc(nameLen); if( nameBuffer && CFStringGetCString(key, nameBuffer, nameLen, kCFStringEncodingUTF8) ) nameString = nameBuffer; diff --git a/passwd.tproj/passwd.h b/passwd.tproj/passwd.h index 4e70b62..60109db 100644 --- a/passwd.tproj/passwd.h +++ b/passwd.tproj/passwd.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2016 Apple Inc. All rights reserved. + * Copyright (c) 2011-2019 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -25,14 +25,16 @@ #include #define INFO_FILE 1 -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) #define INFO_NIS 2 #define INFO_OPEN_DIRECTORY 3 #define INFO_PAM 4 #endif extern int file_passwd(char *, char *); +#ifdef INFO_NIS extern int nis_passwd(char *, char *); +#endif #ifdef INFO_OPEN_DIRECTORY extern int od_passwd(char *, char *, char*); #endif diff --git a/reboot.tproj/kextmanager.defs b/reboot.tproj/kextmanager.defs index 35544db..6ae21ce 100644 --- a/reboot.tproj/kextmanager.defs +++ b/reboot.tproj/kextmanager.defs @@ -1,5 +1,5 @@ #include -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) subsystem dummy 0; #else #include diff --git a/reboot.tproj/reboot.c b/reboot.tproj/reboot.c index da9cb6f..372efc7 100644 --- a/reboot.tproj/reboot.c +++ b/reboot.tproj/reboot.c @@ -61,7 +61,7 @@ __unused static const char rcsid[] = #ifdef __APPLE__ #include -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) #include "kextmanager.h" #include #endif @@ -76,7 +76,7 @@ __unused static const char rcsid[] = void usage(void); u_int get_pageins(void); -#if defined(__APPLE__) && !TARGET_OS_EMBEDDED +#if defined(__APPLE__) && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) int reserve_reboot(void); #endif @@ -154,7 +154,7 @@ main(int argc, char *argv[]) err(1, NULL); } -#if defined(__APPLE__) && !TARGET_OS_EMBEDDED +#if defined(__APPLE__) && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (!qflag && !lflag) { // shutdown(8) has already checked w/kextd if ((errno = reserve_reboot())) err(1, "couldn't lock for reboot"); @@ -200,9 +200,6 @@ main(int argc, char *argv[]) utx.ut_type = SHUTDOWN_TIME; gettimeofday(&utx.ut_tv, NULL); pututxline(&utx); - - int newvalue = 1; - sysctlbyname("kern.willshutdown", NULL, NULL, &newvalue, sizeof(newvalue)); } #else logwtmp("~", "shutdown", ""); @@ -304,7 +301,7 @@ get_pageins(void) return pageins; } -#if defined(__APPLE__) && !TARGET_OS_EMBEDDED +#if defined(__APPLE__) && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) // XX this routine is also in shutdown.tproj; it would be nice to share #define WAITFORLOCK 1 diff --git a/sc_usage.tproj/sc_usage.c b/sc_usage.tproj/sc_usage.c index 3dcdf9f..d704479 100644 --- a/sc_usage.tproj/sc_usage.c +++ b/sc_usage.tproj/sc_usage.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2016 Apple Inc. All rights reserved. + * Copyright (c) 1999-2019 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -291,6 +291,12 @@ print_time(char *p, unsigned int useconds, unsigned int seconds) } } +static void +resetscr(void) +{ + (void)endwin(); +} + int main(int argc, char *argv[]) { @@ -414,6 +420,7 @@ main(int argc, char *argv[]) printf("Unrecognized TERM type, try vt100\n"); exit(1); } + atexit(resetscr); cbreak(); timeout(100); noecho(); diff --git a/shutdown.tproj/kextmanager.defs b/shutdown.tproj/kextmanager.defs index 35544db..6ae21ce 100644 --- a/shutdown.tproj/kextmanager.defs +++ b/shutdown.tproj/kextmanager.defs @@ -1,5 +1,5 @@ #include -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) subsystem dummy 0; #else #include diff --git a/shutdown.tproj/shutdown.c b/shutdown.tproj/shutdown.c index d6e60d6..904110c 100644 --- a/shutdown.tproj/shutdown.c +++ b/shutdown.tproj/shutdown.c @@ -78,7 +78,6 @@ __FBSDID("$FreeBSD: src/sbin/shutdown/shutdown.c,v 1.28 2005/01/25 08:40:51 delp #include #include #include -#include #include "pathnames.h" #endif /* __APPLE__ */ @@ -484,9 +483,6 @@ die_you_gravy_sucking_pig_dog() utx.ut_type = SHUTDOWN_TIME; gettimeofday(&utx.ut_tv, NULL); pututxline(&utx); - - int newvalue = 1; - sysctlbyname("kern.willshutdown", NULL, NULL, &newvalue, sizeof(newvalue)); } #else logwtmp("~", "shutdown", ""); diff --git a/system_cmds.xcodeproj/project.pbxproj b/system_cmds.xcodeproj/project.pbxproj index 54ccae8..f52edfb 100644 --- a/system_cmds.xcodeproj/project.pbxproj +++ b/system_cmds.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 1812F1ED1C8F923900F3DC9E /* CopyFiles */, ); dependencies = ( + 358407D62245AD55006A0D8E /* PBXTargetDependency */, 926913A61EC706130079D787 /* PBXTargetDependency */, 1812F18D1C8F923900F3DC9E /* PBXTargetDependency */, 1812F18F1C8F923900F3DC9E /* PBXTargetDependency */, @@ -72,6 +73,7 @@ C9D64CD21B91066B00CFA43B /* CopyFiles */, ); dependencies = ( + 358407D22245AD40006A0D8E /* PBXTargetDependency */, 926913A21EC706010079D787 /* PBXTargetDependency */, 08CE3D361E6E24CC00DF1B78 /* PBXTargetDependency */, C21481471C1A1447003BCA63 /* PBXTargetDependency */, @@ -229,6 +231,7 @@ C9D64CD01B91064700CFA43B /* CopyFiles */, ); dependencies = ( + 358407D42245AD4B006A0D8E /* PBXTargetDependency */, 926913A41EC706080079D787 /* PBXTargetDependency */, 08CE3D381E6E24DF00DF1B78 /* PBXTargetDependency */, C21481491C1A14AD003BCA63 /* PBXTargetDependency */, @@ -316,6 +319,10 @@ 1523FE6C1595056C00661E82 /* ltop.c in Sources */ = {isa = PBXBuildFile; fileRef = 1523FE6B1595056C00661E82 /* ltop.c */; }; 1523FE6D1595058100661E82 /* ltop.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1523FE6A1595056C00661E82 /* ltop.1 */; }; 1812F1EE1C8F923900F3DC9E /* system_cmds.plist in CopyFiles */ = {isa = PBXBuildFile; fileRef = C9D64CCF1B91063200CFA43B /* system_cmds.plist */; }; + 358407CE2245AC09006A0D8E /* cpuctl.c in Sources */ = {isa = PBXBuildFile; fileRef = 358407CD2245AC09006A0D8E /* cpuctl.c */; }; + 358407D02245AC32006A0D8E /* cpuctl.8 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 358407CF2245AC32006A0D8E /* cpuctl.8 */; }; + 5262264121E8295A0053ABA1 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 189337C21CC7CB4800B2A6A4 /* CoreFoundation.framework */; }; + 5262264221ED5A780053ABA1 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9E0691D1C58BDB800C956EB /* IOKit.framework */; }; 550C19E61804D226001DA380 /* libutil.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BA4B7A091373BA4600003422 /* libutil.dylib */; }; 550C19EC1804D281001DA380 /* iosim.c in Sources */ = {isa = PBXBuildFile; fileRef = 550C19E11804C55E001DA380 /* iosim.c */; }; 550C19ED1804D295001DA380 /* iosim.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 550C19E01804C55E001DA380 /* iosim.1 */; }; @@ -895,6 +902,27 @@ remoteGlobalIDString = BACC1D0D1377B481007728F4; remoteInfo = mean; }; + 358407D12245AD40006A0D8E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = BA2DE9181372FA9100D1913C /* Project object */; + proxyType = 1; + remoteGlobalIDString = 3521C84C2245AA92001B3201; + remoteInfo = cpuctl; + }; + 358407D32245AD4B006A0D8E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = BA2DE9181372FA9100D1913C /* Project object */; + proxyType = 1; + remoteGlobalIDString = 3521C84C2245AA92001B3201; + remoteInfo = cpuctl; + }; + 358407D52245AD55006A0D8E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = BA2DE9181372FA9100D1913C /* Project object */; + proxyType = 1; + remoteGlobalIDString = 3521C84C2245AA92001B3201; + remoteInfo = cpuctl; + }; 550C19EE1804D2AD001DA380 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = BA2DE9181372FA9100D1913C /* Project object */; @@ -1729,6 +1757,16 @@ ); runOnlyForDeploymentPostprocessing = 1; }; + 3521C84B2245AA92001B3201 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man8; + dstSubfolderSpec = 0; + files = ( + 358407D02245AC32006A0D8E /* cpuctl.8 in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 1; + }; 550C19E71804D226001DA380 /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; @@ -2328,6 +2366,10 @@ 1523FE6B1595056C00661E82 /* ltop.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ltop.c; sourceTree = ""; }; 189337C21CC7CB4800B2A6A4 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; }; 18EA07101C99C76C006D3005 /* EmbeddedOSSupportHost.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = EmbeddedOSSupportHost.framework; path = System/Library/PrivateFrameworks/EmbeddedOSSupportHost.framework; sourceTree = SDKROOT; }; + 3521C84D2245AA92001B3201 /* cpuctl */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = cpuctl; sourceTree = BUILT_PRODUCTS_DIR; }; + 3521C8562245AB52001B3201 /* cpuctl.tproj */ = {isa = PBXFileReference; lastKnownFileType = folder; path = cpuctl.tproj; sourceTree = ""; }; + 358407CD2245AC09006A0D8E /* cpuctl.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = cpuctl.c; path = cpuctl.tproj/cpuctl.c; sourceTree = ""; }; + 358407CF2245AC32006A0D8E /* cpuctl.8 */ = {isa = PBXFileReference; lastKnownFileType = text; name = cpuctl.8; path = cpuctl.tproj/cpuctl.8; sourceTree = ""; }; 550C19E01804C55E001DA380 /* iosim.1 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.man; path = iosim.1; sourceTree = ""; }; 550C19E11804C55E001DA380 /* iosim.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = iosim.c; sourceTree = ""; }; 550C19EB1804D226001DA380 /* iosim */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = iosim; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -2540,7 +2582,6 @@ BA4FD2E51372FAFA0025925C /* zprint.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = zprint.1; sourceTree = ""; }; BA4FD2E61372FAFA0025925C /* zprint.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = zprint.c; sourceTree = ""; }; BA4FD2EF1372FB3D0025925C /* ac */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ac; sourceTree = BUILT_PRODUCTS_DIR; }; - BA4FD2FB1372FB710025925C /* BSD.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = BSD.xcconfig; path = Makefiles/CoreOS/Xcode/BSD.xcconfig; sourceTree = DEVELOPER_DIR; }; BA4FD30D1372FFD80025925C /* accton */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = accton; sourceTree = BUILT_PRODUCTS_DIR; }; BA4FD323137300EE0025925C /* arch */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = arch; sourceTree = BUILT_PRODUCTS_DIR; }; BA4FD3411373073E0025925C /* at */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = at; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -2601,6 +2642,7 @@ C625B28816D6F27E00168EF7 /* taskpolicy */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = taskpolicy; sourceTree = BUILT_PRODUCTS_DIR; }; C625B28A16D6F27E00168EF7 /* taskpolicy.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = taskpolicy.c; sourceTree = ""; }; C625B28C16D6F27E00168EF7 /* taskpolicy.8 */ = {isa = PBXFileReference; lastKnownFileType = text; path = taskpolicy.8; sourceTree = ""; }; + C913CA2E2228B622000051A0 /* base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = base.xcconfig; sourceTree = ""; }; C96F50AC15BDCBF0008682F7 /* lsmp.1 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.man; name = lsmp.1; path = lsmp.tproj/lsmp.1; sourceTree = SOURCE_ROOT; }; C96F50AD15BDCE8E008682F7 /* lsmp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = lsmp.c; path = lsmp.tproj/lsmp.c; sourceTree = SOURCE_ROOT; }; C96F50B715BDCEC3008682F7 /* lsmp */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = lsmp; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -2648,10 +2690,19 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 3521C84A2245AA92001B3201 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 550C19E51804D226001DA380 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 5262264221ED5A780053ABA1 /* IOKit.framework in Frameworks */, + 5262264121E8295A0053ABA1 /* CoreFoundation.framework in Frameworks */, 550C19E61804D226001DA380 /* libutil.dylib in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -3150,10 +3201,13 @@ BA2DE9161372FA9100D1913C = { isa = PBXGroup; children = ( + 358407CF2245AC32006A0D8E /* cpuctl.8 */, + 358407CD2245AC09006A0D8E /* cpuctl.c */, + 3521C8562245AB52001B3201 /* cpuctl.tproj */, + C913CA2E2228B622000051A0 /* base.xcconfig */, 08CE3D321E6E22DE00DF1B78 /* stackshot.c */, 18EA07101C99C76C006D3005 /* EmbeddedOSSupportHost.framework */, BA4FD1E11372FAFA0025925C /* APPLE_LICENSE */, - BA4FD2FB1372FB710025925C /* BSD.xcconfig */, C9D64CCF1B91063200CFA43B /* system_cmds.plist */, BA4FD1D91372FAFA0025925C /* ac.tproj */, BA4FD1DD1372FAFA0025925C /* accton.tproj */, @@ -3748,6 +3802,7 @@ 08CE3D291E6E22A200DF1B78 /* stackshot */, 0D06BC5E1E8F08CB00C6EC2D /* mslutil */, F2291F5D1FFEBB6A00161936 /* zlog */, + 3521C84D2245AA92001B3201 /* cpuctl */, ); name = Products; sourceTree = ""; @@ -3933,6 +3988,23 @@ productReference = 1523FE631595048900661E82 /* ltop */; productType = "com.apple.product-type.tool"; }; + 3521C84C2245AA92001B3201 /* cpuctl */ = { + isa = PBXNativeTarget; + buildConfigurationList = 3521C8512245AA92001B3201 /* Build configuration list for PBXNativeTarget "cpuctl" */; + buildPhases = ( + 3521C8492245AA92001B3201 /* Sources */, + 3521C84A2245AA92001B3201 /* Frameworks */, + 3521C84B2245AA92001B3201 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = cpuctl; + productName = cpuctl; + productReference = 3521C84D2245AA92001B3201 /* cpuctl */; + productType = "com.apple.product-type.tool"; + }; 550C19E21804D226001DA380 /* iosim */ = { isa = PBXNativeTarget; buildConfigurationList = 550C19E91804D226001DA380 /* Build configuration list for PBXNativeTarget "iosim" */; @@ -4772,6 +4844,7 @@ BA2DE9181372FA9100D1913C /* Project object */ = { isa = PBXProject; attributes = { + DefaultBuildSystemTypeForWorkspace = Original; LastUpgradeCheck = 0600; TargetAttributes = { 08CE3D281E6E22A200DF1B78 = { @@ -4792,6 +4865,10 @@ 1812F18C1C8F923900F3DC9E = { ProvisioningStyle = Manual; }; + 3521C84C2245AA92001B3201 = { + CreatedOnToolsVersion = 11.0; + ProvisioningStyle = Automatic; + }; 550C19E21804D226001DA380 = { ProvisioningStyle = Manual; }; @@ -5046,6 +5123,7 @@ 08CE3D281E6E22A200DF1B78 /* stackshot */, 0D06BC5D1E8F08CB00C6EC2D /* mslutil */, F2291F501FFEBB6A00161936 /* zlog */, + 3521C84C2245AA92001B3201 /* cpuctl */, ); }; /* End PBXProject section */ @@ -5363,6 +5441,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 3521C8492245AA92001B3201 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 358407CE2245AC09006A0D8E /* cpuctl.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 550C19E31804D226001DA380 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -6054,6 +6140,21 @@ target = BACC1D0D1377B481007728F4 /* mean */; targetProxy = 1812F1EC1C8F923900F3DC9E /* PBXContainerItemProxy */; }; + 358407D22245AD40006A0D8E /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 3521C84C2245AA92001B3201 /* cpuctl */; + targetProxy = 358407D12245AD40006A0D8E /* PBXContainerItemProxy */; + }; + 358407D42245AD4B006A0D8E /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 3521C84C2245AA92001B3201 /* cpuctl */; + targetProxy = 358407D32245AD4B006A0D8E /* PBXContainerItemProxy */; + }; + 358407D62245AD55006A0D8E /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 3521C84C2245AA92001B3201 /* cpuctl */; + targetProxy = 358407D52245AD55006A0D8E /* PBXContainerItemProxy */; + }; 550C19EF1804D2AD001DA380 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 550C19E21804D226001DA380 /* iosim */; @@ -6900,8 +7001,9 @@ }; 18732FE218CBD4A700275344 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = BA4FD2FB1372FB710025925C /* BSD.xcconfig */; + baseConfigurationReference = C913CA2E2228B622000051A0 /* base.xcconfig */; buildSettings = { + APPLY_RULES_IN_COPY_FILES = YES; DEBUG_INFORMATION_FORMAT = dwarf; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -6910,6 +7012,7 @@ GCC_WARN_ABOUT_MISSING_NEWLINE = YES; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + PLIST_FILE_OUTPUT_FORMAT = binary; SUPPORTED_PLATFORMS = "macosx watchos iphoneos"; WARNING_CFLAGS = ( "-Wall", @@ -7469,6 +7572,56 @@ }; name = Debug; }; + 3521C8522245AA92001B3201 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INSTALL_PATH = /usr/bin; + PRODUCT_NAME = cpuctl; + }; + name = Release; + }; + 3521C8532245AA92001B3201 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INSTALL_PATH = /usr/bin; + PRODUCT_NAME = cpuctl; + }; + name = Debug; + }; 550C19EA1804D226001DA380 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { @@ -7731,14 +7884,16 @@ }; BA2DE91E1372FA9100D1913C /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = BA4FD2FB1372FB710025925C /* BSD.xcconfig */; + baseConfigurationReference = C913CA2E2228B622000051A0 /* base.xcconfig */; buildSettings = { + APPLY_RULES_IN_COPY_FILES = YES; GCC_DYNAMIC_NO_PIC = NO; GCC_TREAT_WARNINGS_AS_ERRORS = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_MISSING_NEWLINE = YES; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + PLIST_FILE_OUTPUT_FORMAT = binary; SUPPORTED_PLATFORMS = "macosx watchos iphoneos"; WARNING_CFLAGS = ( "-Wall", @@ -8371,6 +8526,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 3521C8512245AA92001B3201 /* Build configuration list for PBXNativeTarget "cpuctl" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3521C8522245AA92001B3201 /* Release */, + 3521C8532245AA92001B3201 /* Debug */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 550C19E91804D226001DA380 /* Build configuration list for PBXNativeTarget "iosim" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/system_cmds.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/system_cmds.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings index 08de0be..a3f43a8 100644 --- a/system_cmds.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +++ b/system_cmds.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -2,6 +2,8 @@ + BuildSystemType + Original IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded diff --git a/tests/system_cmds.plist b/tests/system_cmds.plist index d2fd882..3d562ac 100644 --- a/tests/system_cmds.plist +++ b/tests/system_cmds.plist @@ -192,8 +192,13 @@ alt-dyld /usr/bin/yes - EligibleResource - deviceClass == 'iPhone' + RequiredResources + + + Properties + deviceClass == 'iPhone' + + IgnoreCrashes diff --git a/trace.tproj/trace.c b/trace.tproj/trace.c index b68c53e..f85b336 100644 --- a/trace.tproj/trace.c +++ b/trace.tproj/trace.c @@ -2390,8 +2390,9 @@ parse_codefile(const char *filename) if (stat_buf.st_size != 0) { - if ((file_addr = mmap(0, file_size, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_FILE, fd, 0)) == (char*) -1) + file_addr = mmap(0, file_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_FILE, fd, 0); + if (file_addr == MAP_FAILED) { printf("Error: Can't map file: %s\n", filename); close(fd); @@ -2431,7 +2432,7 @@ parse_codefile(const char *filename) */ count++; - // Grow the size of codesc to store new entries. + /* Grow the size of codesc to store new entries. */ size_t total_count = codesc_idx + count; code_type_t *new_codesc = (code_type_t *)realloc(codesc, (total_count) * sizeof(code_type_t)); @@ -2442,10 +2443,11 @@ parse_codefile(const char *filename) codesc = new_codesc; bzero((char *)(codesc + codesc_idx), count * sizeof(code_type_t)); - for (line = 1, j = 0; j < file_size && codesc_idx < total_count; codesc_idx++) + for (line = 1, j = 0; j < file_size && codesc_idx < total_count; + codesc_idx++) { /* Skip blank lines */ - while (file_addr[j] == '\n') + while (j < file_size && file_addr[j] == '\n') { j++; line++; @@ -2464,7 +2466,7 @@ parse_codefile(const char *filename) /* We didn't find a debugid code - skip this line */ if (verbose_flag) printf("Error: while parsing line %d, skip\n", line); - while (file_addr[j] != '\n' && j < file_size) + while (j < file_size && file_addr[j] != '\n') j++; codesc_idx--; line++; @@ -2472,15 +2474,25 @@ parse_codefile(const char *filename) } /* Skip whitespace */ - while (file_addr[j] == ' ' || file_addr[j] == '\t') + while (j < file_size && (file_addr[j] == ' ' || file_addr[j] == '\t')) + { j++; + } + + if (j >= file_size) + { + break; + } /* Get around old file that had count at the beginning */ if (file_addr[j] == '\n') { /* missing debugid string - skip */ if (verbose_flag) - printf("Error: while parsing line %d, (0x%x) skip\n", line, codesc[codesc_idx].debugid); + { + printf("Error: while parsing line %d, (0x%x) skip\n", line, + codesc[codesc_idx].debugid); + } j++; codesc_idx--; @@ -2488,12 +2500,25 @@ parse_codefile(const char *filename) continue; } + if (j >= file_size) + { + break; + } + /* Next is the debugid string terminated by a newline */ codesc[codesc_idx].debug_string = &file_addr[j]; /* Null out the newline terminator */ - while ((j < file_size) && (file_addr[j] != '\n')) + while (j < file_size && file_addr[j] != '\n') + { j++; + } + + if (j >= file_size) + { + break; + } + file_addr[j] = '\0'; /* File must be read-write */ j++; line++; diff --git a/zic.tproj/build_zichost.sh b/zic.tproj/build_zichost.sh index f2ad134..9247765 100755 --- a/zic.tproj/build_zichost.sh +++ b/zic.tproj/build_zichost.sh @@ -39,7 +39,7 @@ env -i \ TOOLCHAINS="${TOOLCHAINS}" \ xcrun -sdk "${SDKROOT}" xcodebuild install \ -target zic \ - -sdk "macosx" \ + -sdk "macosxinternal" \ SRCROOT="${SRCROOT}" \ OBJROOT="${OBJROOT}" \ SYMROOT="${ZICHOST_SYMROOT}" \