X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/cb3231590a3c94ab4375e2228bd5e86b0cf1ad7e..refs/heads/master:/libsyscall/wrappers/libproc/libproc.c?ds=sidebyside diff --git a/libsyscall/wrappers/libproc/libproc.c b/libsyscall/wrappers/libproc/libproc.c index 8cf27b6ac..c3ef51b83 100644 --- a/libsyscall/wrappers/libproc/libproc.c +++ b/libsyscall/wrappers/libproc/libproc.c @@ -37,6 +37,7 @@ #include "libproc_internal.h" int __proc_info(int callnum, int pid, int flavor, uint64_t arg, void * buffer, int buffersize); +int __proc_info_extended_id(int32_t callnum, int32_t pid, uint32_t flavor, uint32_t flags, uint64_t ext_id, uint64_t arg, user_addr_t buffer, int32_t buffersize); __private_extern__ int proc_setthreadname(void * buffer, int buffersize); int __process_policy(int scope, int action, int policy, int policy_subtype, proc_policy_attribute_t * attrp, pid_t target_pid, uint64_t target_threadid); int proc_rlimit_control(pid_t pid, int flavor, void *arg); @@ -234,7 +235,7 @@ proc_regionfilename(int pid, uint64_t address, void * buffer, uint32_t buffersiz } retval = proc_pidinfo(pid, PROC_PIDREGIONPATH, (uint64_t)address, &path, sizeof(struct proc_regionpath)); - if (retval != -1) { + if (retval != 0) { return (int)(strlcpy(buffer, path.prpo_path, buffersize)); } return 0; @@ -273,6 +274,31 @@ proc_pidpath(int pid, void * buffer, uint32_t buffersize) return 0; } +int +proc_pidpath_audittoken(audit_token_t *audittoken, void * buffer, uint32_t buffersize) +{ + int retval, len; + + if (buffersize < PROC_PIDPATHINFO_SIZE) { + errno = ENOMEM; + return 0; + } + if (buffersize > PROC_PIDPATHINFO_MAXSIZE) { + errno = EOVERFLOW; + return 0; + } + + int pid = audittoken->val[5]; + int idversion = audittoken->val[7]; + + retval = __proc_info_extended_id(PROC_INFO_CALL_PIDINFO, pid, PROC_PIDPATHINFO, PIF_COMPARE_IDVERSION, (uint64_t)idversion, + (uint64_t)0, buffer, buffersize); + if (retval != -1) { + len = (int)strlen(buffer); + return len; + } + return 0; +} int proc_libversion(int *major, int * minor) @@ -1003,3 +1029,69 @@ proc_suppress(__unused pid_t pid, __unused uint64_t *generation) #endif /* !TARGET_OS_SIMULATOR */ #endif /* !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */ + +int +proc_set_no_smt(void) +{ + if (__process_policy(PROC_POLICY_SCOPE_PROCESS, PROC_POLICY_ACTION_APPLY, PROC_POLICY_NO_SMT, 0, NULL, getpid(), (uint64_t)0) == -1) { + return errno; + } + return 0; +} + +int +proc_setthread_no_smt(void) +{ + extern uint64_t __thread_selfid(void); + if (__process_policy(PROC_POLICY_SCOPE_THREAD, PROC_POLICY_ACTION_APPLY, PROC_POLICY_NO_SMT, 0, NULL, 0, __thread_selfid()) == -1) { + return errno; + } + return 0; +} + +int +proc_set_csm(uint32_t flags) +{ + const uint32_t mask = PROC_CSM_ALL | PROC_CSM_TECS | PROC_CSM_NOSMT; + if ((flags & ~mask) != 0) { + return EINVAL; + } + + if (flags & (PROC_CSM_NOSMT | PROC_CSM_ALL)) { + if (__process_policy(PROC_POLICY_SCOPE_PROCESS, PROC_POLICY_ACTION_APPLY, PROC_POLICY_NO_SMT, 0, NULL, getpid(), (uint64_t)0) == -1) { + return errno; + } + } + + if (flags & (PROC_CSM_TECS | PROC_CSM_ALL)) { + if (__process_policy(PROC_POLICY_SCOPE_PROCESS, PROC_POLICY_ACTION_APPLY, PROC_POLICY_TECS, 0, NULL, getpid(), (uint64_t)0) == -1) { + return errno; + } + } + + return 0; +} + +int +proc_setthread_csm(uint32_t flags) +{ + extern uint64_t __thread_selfid(void); + const uint32_t mask = PROC_CSM_ALL | PROC_CSM_TECS | PROC_CSM_NOSMT; + if ((flags & ~mask) != 0) { + return EINVAL; + } + + if (flags & (PROC_CSM_NOSMT | PROC_CSM_ALL)) { + if (__process_policy(PROC_POLICY_SCOPE_THREAD, PROC_POLICY_ACTION_APPLY, PROC_POLICY_NO_SMT, 0, NULL, 0, __thread_selfid()) == -1) { + return errno; + } + } + + if (flags & (PROC_CSM_TECS | PROC_CSM_ALL)) { + if (__process_policy(PROC_POLICY_SCOPE_THREAD, PROC_POLICY_ACTION_APPLY, PROC_POLICY_TECS, 0, NULL, 0, __thread_selfid()) == -1) { + return errno; + } + } + + return 0; +}