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