#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);
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, ®info, 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;
}
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)
}
}
-#if TARGET_OS_EMBEDDED
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
int
proc_setcpu_deadline(pid_t pid, int action, uint64_t deadline)
{
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 */
{
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;
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)
}
}
-#if !TARGET_IPHONE_SIMULATOR
+#if !TARGET_OS_SIMULATOR
int
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;
+}