]> 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 4c6fc235696db3068a3d00beca4b303c516fc203..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);
@@ -226,16 +227,16 @@ int
 proc_regionfilename(int pid, uint64_t address, void * buffer, uint32_t buffersize)
 {
        int retval;
-       struct proc_regionwithpathinfo reginfo;
+       struct proc_regionpath path;
 
        if (buffersize < MAXPATHLEN) {
                errno = ENOMEM;
                return 0;
        }
 
-       retval = proc_pidinfo(pid, PROC_PIDREGIONPATHINFO2, (uint64_t)address, &reginfo, sizeof(struct proc_regionwithpathinfo));
-       if (retval != -1) {
-               return (int)(strlcpy(buffer, reginfo.prp_vip.vip_path, MAXPATHLEN));
+       retval = proc_pidinfo(pid, PROC_PIDREGIONPATH, (uint64_t)address, &path, sizeof(struct proc_regionpath));
+       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)
@@ -622,7 +648,7 @@ proc_clear_cpulimits(pid_t pid)
        }
 }
 
-#if TARGET_OS_EMBEDDED
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
 
 int
 proc_setcpu_deadline(pid_t pid, int action, uint64_t deadline)
@@ -739,7 +765,7 @@ proc_can_use_foreground_hw(int pid, uint32_t *reason)
 {
        return __proc_info(PROC_INFO_CALL_CANUSEFGHW, pid, 0, 0, reason, sizeof(*reason));
 }
-#endif /* TARGET_OS_EMBEDDED */
+#endif /* (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */
 
 
 /* Donate importance to adaptive processes from this process */
@@ -748,19 +774,19 @@ proc_donate_importance_boost()
 {
        int rval;
 
-#if TARGET_OS_EMBEDDED
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
        rval = __process_policy(PROC_POLICY_SCOPE_PROCESS,
            PROC_POLICY_ACTION_ENABLE,
            PROC_POLICY_APPTYPE,
            PROC_POLICY_IOS_DONATEIMP,
            NULL, getpid(), (uint64_t)0);
-#else /* TARGET_OS_EMBEDDED */
+#else /* (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */
        rval = __process_policy(PROC_POLICY_SCOPE_PROCESS,
            PROC_POLICY_ACTION_SET,
            PROC_POLICY_BOOST,
            PROC_POLICY_IMP_DONATION,
            NULL, getpid(), 0);
-#endif /* TARGET_OS_EMBEDDED */
+#endif /* (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */
 
        if (rval == 0) {
                return 0;
@@ -903,7 +929,7 @@ proc_denap_assertion_complete(uint64_t assertion_token)
        return proc_importance_assertion_complete(assertion_token);
 }
 
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
 
 int
 proc_clear_vmpressure(pid_t pid)
@@ -992,7 +1018,7 @@ proc_enable_apptype(pid_t pid, int apptype)
        }
 }
 
-#if !TARGET_IPHONE_SIMULATOR
+#if !TARGET_OS_SIMULATOR
 
 int
 proc_suppress(__unused pid_t pid, __unused uint64_t *generation)
@@ -1000,6 +1026,72 @@ proc_suppress(__unused pid_t pid, __unused uint64_t *generation)
        return 0;
 }
 
-#endif /* !TARGET_IPHONE_SIMULATOR */
+#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;
+       }
 
-#endif /* !TARGET_OS_EMBEDDED */
+       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;
+}