master
  1/*
  2 * Copyright (c) 2006, 2010 Apple Inc. All rights reserved.
  3 *
  4 * @APPLE_LICENSE_HEADER_START@
  5 *
  6 * This file contains Original Code and/or Modifications of Original Code
  7 * as defined in and that are subject to the Apple Public Source License
  8 * Version 2.0 (the 'License'). You may not use this file except in
  9 * compliance with the License. Please obtain a copy of the License at
 10 * http://www.opensource.apple.com/apsl/ and read it before using this
 11 * file.
 12 *
 13 * The Original Code and all software distributed under the License are
 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
 18 * Please see the License for the specific language governing rights and
 19 * limitations under the License.
 20 *
 21 * @APPLE_LICENSE_HEADER_END@
 22 */
 23
 24
 25#ifndef _SPAWN_H_
 26#define _SPAWN_H_
 27
 28/*
 29 * [SPN] Support for _POSIX_SPAWN
 30 */
 31
 32#include <sys/cdefs.h>
 33#include <_types.h>
 34#include <sys/spawn.h> /* shared types */
 35
 36#include <Availability.h>
 37
 38/*
 39 * [SPN] Inclusion of the <spawn.h> header may make visible symbols defined
 40 * in the <sched.h>, <signal.h>, and <sys/types.h> headers.
 41 */
 42#include <sys/_types/_pid_t.h>
 43#include <sys/_types/_sigset_t.h>
 44#include <sys/_types/_mode_t.h>
 45
 46/*
 47 * Opaque types for use with posix_spawn() family functions.  Internals are
 48 * not defined, and should not be accessed directly.  Types are defined as
 49 * mandated by POSIX.
 50 */
 51typedef  void *posix_spawnattr_t;
 52typedef  void *posix_spawn_file_actions_t;
 53
 54__BEGIN_DECLS
 55/*
 56 * gcc under c99 mode won't compile "[ __restrict]" by itself.  As a workaround,
 57 * a dummy argument name is added.
 58 */
 59
 60int     posix_spawn(pid_t * __restrict, const char * __restrict,
 61    const posix_spawn_file_actions_t *,
 62    const posix_spawnattr_t * __restrict,
 63    char *const __argv[__restrict],
 64    char *const __envp[__restrict]) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
 65
 66int     posix_spawnp(pid_t * __restrict, const char * __restrict,
 67    const posix_spawn_file_actions_t *,
 68    const posix_spawnattr_t * __restrict,
 69    char *const __argv[__restrict],
 70    char *const __envp[__restrict]) __API_AVAILABLE(macos(10.5), ios(2.0));
 71
 72int     posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t *,
 73    const char * __restrict) __API_AVAILABLE(macos(26.0)) __API_UNAVAILABLE(ios, tvos, watchos, visionos);
 74
 75int     posix_spawn_file_actions_addfchdir(posix_spawn_file_actions_t *,
 76    int) __API_AVAILABLE(macos(26.0)) __API_UNAVAILABLE(ios, tvos, watchos, visionos);
 77
 78int     posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
 79
 80int     posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int,
 81    int) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
 82
 83int     posix_spawn_file_actions_addopen(
 84	posix_spawn_file_actions_t * __restrict, int,
 85	const char * __restrict, int, mode_t) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
 86
 87int     posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
 88
 89int     posix_spawn_file_actions_init(posix_spawn_file_actions_t *) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
 90
 91int     posix_spawnattr_destroy(posix_spawnattr_t *) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
 92
 93int     posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict,
 94    sigset_t * __restrict) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
 95
 96int     posix_spawnattr_getflags(const posix_spawnattr_t * __restrict,
 97    short * __restrict) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
 98
 99int     posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict,
100    pid_t * __restrict) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
101
102int     posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict,
103    sigset_t * __restrict) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
104
105int     posix_spawnattr_init(posix_spawnattr_t *) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
106
107int     posix_spawnattr_setsigdefault(posix_spawnattr_t * __restrict,
108    const sigset_t * __restrict) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
109
110int     posix_spawnattr_setflags(posix_spawnattr_t *, short) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
111
112int     posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
113
114int     posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict,
115    const sigset_t * __restrict) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
116
117#if 0   /* _POSIX_PRIORITY_SCHEDULING [PS] : not supported */
118int     posix_spawnattr_setschedparam(posix_spawnattr_t * __restrict,
119    const struct sched_param * __restrict);
120int     posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int);
121int     posix_spawnattr_getschedparam(const posix_spawnattr_t * __restrict,
122    struct sched_param * __restrict);
123int     posix_spawnattr_getschedpolicy(const posix_spawnattr_t * __restrict,
124    int * __restrict);
125#endif  /* 0 */
126
127__END_DECLS
128
129#if     !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
130/*
131 * Darwin-specific extensions below
132 */
133#include <mach/exception_types.h>
134#include <mach/machine.h>
135#include <mach/port.h>
136
137#include <sys/_types/_size_t.h>
138
139__BEGIN_DECLS
140
141int     posix_spawnattr_getbinpref_np(const posix_spawnattr_t * __restrict,
142    size_t, cpu_type_t *__restrict, size_t *__restrict) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
143
144int     posix_spawnattr_getarchpref_np(const posix_spawnattr_t * __restrict,
145    size_t, cpu_type_t *__restrict, cpu_subtype_t *__restrict, size_t *__restrict) __API_AVAILABLE(macos(11.0), ios(14.0)) __API_UNAVAILABLE(watchos, tvos);
146
147int     posix_spawnattr_setauditsessionport_np(posix_spawnattr_t * __restrict,
148    mach_port_t) __API_AVAILABLE(macos(10.6), ios(3.2));
149
150int     posix_spawnattr_setbinpref_np(posix_spawnattr_t * __restrict,
151    size_t, cpu_type_t *__restrict, size_t *__restrict) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
152
153int     posix_spawnattr_setarchpref_np(posix_spawnattr_t * __restrict,
154    size_t, cpu_type_t *__restrict, cpu_subtype_t *__restrict, size_t *__restrict) __API_AVAILABLE(macos(11.0), ios(14.0)) __API_UNAVAILABLE(watchos, tvos);
155
156int     posix_spawnattr_setexceptionports_np(posix_spawnattr_t * __restrict,
157    exception_mask_t, mach_port_t,
158    exception_behavior_t, thread_state_flavor_t) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
159
160int     posix_spawnattr_setspecialport_np(posix_spawnattr_t * __restrict,
161    mach_port_t, int) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);
162
163int     posix_spawnattr_setnosmt_np(const posix_spawnattr_t * __restrict attr) __API_AVAILABLE(macos(11.0));
164
165/*
166 * Set CPU Security Mitigation on the spawned process
167 * This attribute affects all threads and is inherited on fork and exec
168 */
169int     posix_spawnattr_set_csm_np(const posix_spawnattr_t * __restrict attr, uint32_t flags) __API_AVAILABLE(macos(11.0));
170/*
171 * flags for CPU Security Mitigation attribute
172 * POSIX_SPAWN_NP_CSM_ALL should be used in most cases,
173 * the individual flags are provided only for performance evaluation etc
174 */
175#define POSIX_SPAWN_NP_CSM_ALL         0x0001
176#define POSIX_SPAWN_NP_CSM_NOSMT       0x0002
177#define POSIX_SPAWN_NP_CSM_TECS        0x0004
178
179int     posix_spawn_file_actions_addinherit_np(posix_spawn_file_actions_t *,
180    int) __API_AVAILABLE(macos(10.7), ios(4.3)) __API_UNAVAILABLE(watchos, tvos);
181
182int     posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *,
183    const char * __restrict) __API_DEPRECATED("posix_spawn_file_actions_addchdir(3) has replaced posix_spawn_file_actions_addchdir_np(3)", macos(10.15, 26.0)) __API_UNAVAILABLE(ios, tvos, watchos, visionos);
184
185int     posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *,
186    int) __API_DEPRECATED("posix_spawn_file_actions_addfchdir(3) has replaced posix_spawn_file_actions_addfchdir_np(3)", macos(10.15, 26.0)) __API_UNAVAILABLE(ios, tvos, watchos, visionos);
187
188__END_DECLS
189
190#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
191#endif  /* _SPAWN_H_ */