]> git.saurik.com Git - apple/xnu.git/blobdiff - libsyscall/wrappers/libproc/libproc.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / libsyscall / wrappers / libproc / libproc.c
index 8cf27b6ac87931e00fbd4ed0787326da0362b651..c3ef51b838e2e916afcf60ddb10ad545f6cd6000 100644 (file)
@@ -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;
+}