+ * posix_spawn_file_actions_fchdir_np
+ *
+ * Description: Add a fchdir action to the object referenced by 'file_actions'
+ * that will cause the current working directory to attempt to be changed
+ * to that referenced by the descriptor 'filedes' in the spawned process.
+ *
+ * Parameters: file_actions File action object to augment
+ * filedes fd to chdir to
+ *
+ * Returns: 0 Success
+ * EBADF The value specified by either fildes is negative or
+ * greater than or equal to {OPEN_MAX}.
+ * ENOMEM Insufficient memory exists to add to
+ * the spawn file actions object.
+ *
+ * NOTIMP: Allowed failures (checking NOT required):
+ * EINVAL The value specified by file_actions is invalid.
+ */
+int
+posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *file_actions,
+ int filedes)
+{
+ _posix_spawn_file_actions_t *psactsp;
+ _psfa_action_t *psfileact;
+
+ if (file_actions == NULL || *file_actions == NULL) {
+ return EINVAL;
+ }
+
+ psactsp = (_posix_spawn_file_actions_t *)file_actions;
+ /* Range check; in spirit of POSIX */
+ if (filedes < 0 || filedes >= OPEN_MAX) {
+ return EBADF;
+ }
+
+ /* If we do not have enough slots, grow the structure */
+ if ((*psactsp)->psfa_act_count == (*psactsp)->psfa_act_alloc) {
+ /* need to grow file actions structure */
+ if (_posix_spawn_file_actions_grow(psactsp)) {
+ return ENOMEM;
+ }
+ }
+
+ /*
+ * Allocate next available slot and fill it out
+ */
+ psfileact = &(*psactsp)->psfa_act_acts[(*psactsp)->psfa_act_count++];
+
+ psfileact->psfaa_type = PSFA_FCHDIR;
+ psfileact->psfaa_filedes = filedes;
+
+ return 0;
+}
+
+int
+posix_spawnattr_setcpumonitor_default(posix_spawnattr_t * __restrict attr)
+{
+ return posix_spawnattr_setcpumonitor(attr, PROC_POLICY_CPUMON_DEFAULTS, 0);
+}
+
+int
+posix_spawnattr_setcpumonitor(posix_spawnattr_t * __restrict attr,
+ uint64_t percent, uint64_t interval)
+{
+ _posix_spawnattr_t psattr;
+
+ if (attr == NULL || *attr == NULL) {
+ return EINVAL;
+ }
+
+ psattr = *(_posix_spawnattr_t *)attr;
+
+ psattr->psa_cpumonitor_percent = percent;
+ psattr->psa_cpumonitor_interval = interval;
+
+ return 0;
+}
+
+int
+posix_spawnattr_getcpumonitor(posix_spawnattr_t * __restrict attr,
+ uint64_t *percent, uint64_t *interval)
+{
+ _posix_spawnattr_t psattr;
+
+ if (attr == NULL || *attr == NULL) {
+ return EINVAL;
+ }
+
+ psattr = *(_posix_spawnattr_t *)attr;
+
+ *percent = psattr->psa_cpumonitor_percent;
+ *interval = psattr->psa_cpumonitor_interval;
+
+ return 0;
+}
+
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
+/*
+ * posix_spawnattr_setjetsam
+ *
+ * Description: Set jetsam attributes for the spawn attribute object
+ * referred to by 'attr'.
+ *
+ * Parameters: flags The flags value to set
+ * priority Relative jetsam priority
+ * memlimit Value in megabytes; a memory footprint
+ * above this level may result in termination.
+ * Implies both active and inactive limits.
+ *
+ * Returns: 0 Success
+ *
+ * Note: to be deprecated (not available on desktop)
+ *
+ */
+int
+posix_spawnattr_setjetsam(posix_spawnattr_t * __restrict attr,
+ short flags, int priority, int memlimit)
+{
+ short flags_ext = flags;
+
+ if (flags & POSIX_SPAWN_JETSAM_MEMLIMIT_FATAL) {
+ flags_ext |= POSIX_SPAWN_JETSAM_MEMLIMIT_ACTIVE_FATAL;
+ flags_ext |= POSIX_SPAWN_JETSAM_MEMLIMIT_INACTIVE_FATAL;
+ } else {
+ flags_ext &= ~POSIX_SPAWN_JETSAM_MEMLIMIT_ACTIVE_FATAL;
+ flags_ext &= ~POSIX_SPAWN_JETSAM_MEMLIMIT_INACTIVE_FATAL;
+ }
+
+ return posix_spawnattr_setjetsam_ext(attr, flags_ext, priority, memlimit, memlimit);
+}
+#endif /* (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */
+
+/*
+ * posix_spawnattr_setjetsam_ext
+ *
+ * Description: Set jetsam attributes for the spawn attribute object
+ * referred to by 'attr'.
+ *
+ * Parameters: flags The flags value to set
+ * priority Relative jetsam priority
+ * memlimit_active Value in megabytes; memory footprint
+ * above this level while process is
+ * active may result in termination.
+ * memlimit_inactive Value in megabytes; memory footprint
+ * above this level while process is
+ * inactive may result in termination.
+ *
+ * Returns: 0 Success
+ */
+int
+posix_spawnattr_setjetsam_ext(posix_spawnattr_t * __restrict attr,
+ short flags, int priority, int memlimit_active, int memlimit_inactive)
+{
+ _posix_spawnattr_t psattr;
+
+ if (attr == NULL || *attr == NULL) {
+ return EINVAL;
+ }
+
+ psattr = *(_posix_spawnattr_t *)attr;
+
+ psattr->psa_jetsam_flags = flags;
+ psattr->psa_jetsam_flags |= POSIX_SPAWN_JETSAM_SET;
+ psattr->psa_priority = priority;
+ psattr->psa_memlimit_active = memlimit_active;
+ psattr->psa_memlimit_inactive = memlimit_inactive;
+
+ return 0;
+}
+
+int
+posix_spawnattr_set_threadlimit_ext(posix_spawnattr_t * __restrict attr,
+ int thread_limit)
+{
+ _posix_spawnattr_t psattr;
+
+ if (attr == NULL || *attr == NULL) {
+ return EINVAL;
+ }
+
+ psattr = *(_posix_spawnattr_t *)attr;
+
+ psattr->psa_thread_limit = thread_limit;
+
+ return 0;
+}
+
+
+/*
+ * posix_spawnattr_set_importancewatch_port_np
+ *
+ * Description: Mark ports referred to by these rights
+ * to boost the new task instead of their current task
+ * for the spawn attribute object referred to by 'attr'.
+ * Ports must be valid at posix_spawn time. They will NOT be
+ * consumed by the kernel, so they must be deallocated after the spawn returns.
+ * (If you are SETEXEC-ing, they are cleaned up by the exec operation).