2 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 * [SPN] Support for _POSIX_SPAWN
33 * This file contains internal data structures which are externally represented
34 * as opaque void pointers to prevent introspection. This permits us to
35 * change the underlying implementation of the code to maintain it or to
36 * support new features, as needed, without the consumer needing to recompile
37 * their code because of structure size changes or data reorganization.
40 #ifndef _SYS_SPAWN_INTERNAL_H_
41 #define _SYS_SPAWN_INTERNAL_H_
43 #include <sys/_types.h> /* __offsetof(), __darwin_size_t */
44 #include <sys/param.h>
45 #include <sys/syslimits.h> /* PATH_MAX */
46 #include <sys/spawn.h>
47 #include <mach/machine.h>
48 #include <mach/port.h>
49 #include <mach/exception_types.h>
50 #include <mach/coalition.h> /* COALITION_NUM_TYPES */
53 * Allowable posix_spawn() port action types
59 PSPA_IMP_WATCHPORTS
= 3,
63 * Internal representation of one port to be set on posix_spawn().
64 * Currently this is limited to setting special and exception ports,
65 * but could be extended to other inheritable port types.
67 typedef struct _ps_port_action
{
69 exception_mask_t mask
;
70 mach_port_name_t new_port
;
71 exception_behavior_t behavior
;
72 thread_state_flavor_t flavor
;
77 * A collection of port actions to take on the newly spawned process.
79 typedef struct _posix_spawn_port_actions
{
82 _ps_port_action_t pspa_actions
[];
83 } *_posix_spawn_port_actions_t
;
86 * Returns size in bytes of a _posix_spawn_port_actions holding x elements.
88 #define PS_PORT_ACTIONS_SIZE(x) \
89 __offsetof(struct _posix_spawn_port_actions, pspa_actions[(x)])
94 * Mapping of opaque data pointer to a MAC policy (specified by name).
96 typedef struct _ps_mac_policy_extension
{
100 void *datap
; /* pointer in kernel memory */
103 } _ps_mac_policy_extension_t
;
106 * A collection of extra data passed to MAC policies for the newly spawned process.
108 typedef struct _posix_spawn_mac_policy_extensions
{
111 _ps_mac_policy_extension_t psmx_extensions
[];
112 } *_posix_spawn_mac_policy_extensions_t
;
115 * Returns size in bytes of a _posix_spawn_mac_policy_extensions holding x elements.
117 #define PS_MAC_EXTENSIONS_SIZE(x) \
118 __offsetof(struct _posix_spawn_mac_policy_extensions, psmx_extensions[(x)])
120 #define PS_MAC_EXTENSIONS_INIT_COUNT 2
123 * Coalition posix spawn attributes
125 struct _posix_spawn_coalition_info
{
129 uint32_t psci_reserved1
;
130 uint64_t psci_reserved2
;
131 } psci_info
[COALITION_NUM_TYPES
];
135 * A posix_spawnattr structure contains all of the attribute elements that
136 * can be set, as well as any metadata whose validity is signalled by the
137 * presence of a bit in the flags field. All fields are initialized to the
138 * appropriate default values by posix_spawnattr_init().
141 typedef struct _posix_spawnattr
{
142 short psa_flags
; /* spawn attribute flags */
143 short flags_padding
; /* get the flags to be int aligned */
144 sigset_t psa_sigdefault
; /* signal set to default */
145 sigset_t psa_sigmask
; /* signal set to mask */
146 pid_t psa_pgroup
; /* pgroup to spawn into */
147 cpu_type_t psa_binprefs
[NBINPREFS
]; /* cpu affinity prefs*/
148 int psa_pcontrol
; /* process control bits on resource starvation */
149 int psa_apptype
; /* app type and process spec behav */
150 uint64_t psa_cpumonitor_percent
; /* CPU usage monitor percentage */
151 uint64_t psa_cpumonitor_interval
; /* CPU usage monitor interval, in seconds */
152 uint64_t psa_reserved
;
154 short psa_jetsam_flags
; /* jetsam flags */
155 short short_padding
; /* Padding for alignment issues */
156 int psa_priority
; /* jetsam relative importance */
157 int psa_memlimit_active
; /* jetsam memory limit (in MB) when process is active */
158 int psa_memlimit_inactive
; /* jetsam memory limit (in MB) when process is inactive */
160 uint64_t psa_qos_clamp
; /* QoS Clamp to set on the new process */
161 uint64_t psa_darwin_role
; /* PRIO_DARWIN_ROLE to set on the new process */
164 * NOTE: Extensions array pointers must stay at the end so that
165 * everything above this point stays the same size on different bitnesses
166 * see <rdar://problem/12858307>
168 _posix_spawn_port_actions_t psa_ports
; /* special/exception ports */
169 _posix_spawn_mac_policy_extensions_t psa_mac_extensions
; /* MAC policy-specific extensions. */
170 struct _posix_spawn_coalition_info
*psa_coalition_info
; /* coalition info */
172 } *_posix_spawnattr_t
;
175 * Jetsam flags eg: psa_jetsam_flags
177 #define POSIX_SPAWN_JETSAM_SET 0x8000
179 #define POSIX_SPAWN_JETSAM_USE_EFFECTIVE_PRIORITY 0x01
180 #define POSIX_SPAWN_JETSAM_HIWATER_BACKGROUND 0x02
181 #define POSIX_SPAWN_JETSAM_MEMLIMIT_FATAL 0x04 /* to be deprecated */
184 * Additional flags available for use with
185 * the posix_spawnattr_setjetsam_ext() call
187 #define POSIX_SPAWN_JETSAM_MEMLIMIT_ACTIVE_FATAL 0x04 /* if set, limit is fatal when the process is active */
188 #define POSIX_SPAWN_JETSAM_MEMLIMIT_INACTIVE_FATAL 0x08 /* if set, limit is fatal when the process is inactive */
191 * Deprecated posix_spawn psa_flags values
193 * POSIX_SPAWN_OSX_TALAPP_START 0x0400
194 * POSIX_SPAWN_IOS_RESV1_APP_START 0x0400
195 * POSIX_SPAWN_IOS_APPLE_DAEMON_START 0x0800
196 * POSIX_SPAWN_IOS_APP_START 0x1000
197 * POSIX_SPAWN_OSX_WIDGET_START 0x0800
198 * POSIX_SPAWN_OSX_DBCLIENT_START 0x0800
199 * POSIX_SPAWN_OSX_RESVAPP_START 0x1000
203 * Deprecated posix_spawn psa_apptype values
205 * POSIX_SPAWN_PROCESS_TYPE_APPLEDAEMON 0x00000001
206 * POSIX_SPAWN_PROCESS_TYPE_UIAPP 0x00000002
207 * POSIX_SPAWN_PROCESS_TYPE_ADAPTIVE 0x00000004
208 * POSIX_SPAWN_PROCESS_TYPE_TAL 0x00000001
209 * POSIX_SPAWN_PROCESS_TYPE_WIDGET 0x00000002
210 * POSIX_SPAWN_PROCESS_TYPE_DELAYIDLESLEEP 0x10000000
212 * POSIX_SPAWN_PROCESS_FLAG_IMPORTANCE_DONOR 0x00000010
213 * POSIX_SPAWN_PROCESS_FLAG_ADAPTIVE 0x00000020
214 * POSIX_SPAWN_PROCESS_FLAG_START_BACKGROUND 0x00000040
215 * POSIX_SPAWN_PROCESS_FLAG_START_LIGHT_THROTTLE 0x00000080
219 * posix_spawn psa_apptype process type settings.
220 * when POSIX_SPAWN_PROC_TYPE is set, old psa_apptype bits are ignored
223 #define POSIX_SPAWN_PROCESS_TYPE_NORMAL 0x00000000
224 #define POSIX_SPAWN_PROCESS_TYPE_DEFAULT POSIX_SPAWN_PROCESS_TYPE_NORMAL
226 #define POSIX_SPAWN_PROC_TYPE_MASK 0x00000F00
228 #define POSIX_SPAWN_PROC_TYPE_APP_DEFAULT 0x00000100
229 #define POSIX_SPAWN_PROC_TYPE_APP_TAL 0x00000200
231 #define POSIX_SPAWN_PROC_TYPE_DAEMON_STANDARD 0x00000300
232 #define POSIX_SPAWN_PROC_TYPE_DAEMON_INTERACTIVE 0x00000400
233 #define POSIX_SPAWN_PROC_TYPE_DAEMON_BACKGROUND 0x00000500
234 #define POSIX_SPAWN_PROC_TYPE_DAEMON_ADAPTIVE 0x00000600
236 #define POSIX_SPAWN_PROC_CLAMP_NONE 0x00000000
237 #define POSIX_SPAWN_PROC_CLAMP_UTILITY 0x00000001
238 #define POSIX_SPAWN_PROC_CLAMP_BACKGROUND 0x00000002
239 #define POSIX_SPAWN_PROC_CLAMP_MAINTENANCE 0x00000003
240 #define POSIX_SPAWN_PROC_CLAMP_LAST 0x00000004
242 /* Setting to indicate no change to darwin role */
243 #define POSIX_SPAWN_DARWIN_ROLE_NONE 0x00000000
244 /* Other possible values are specified by PRIO_DARWIN_ROLE in sys/resource.h */
247 * Allowable posix_spawn() file actions
258 * A posix_spawn() file action record for a single action
260 * Notes: We carry around the full open arguments for both the open
261 * and the close to permit the use of a single array of action
262 * elements to be associated with a file actions object.
264 * A possible future optimization would be to break this into
265 * a variable sized vector list to save space (i.e. a separate
266 * string area, allocation of least amount of path buffer per
267 * open action, etc.).
269 * XXX: Currently overloading psfao_oflag for PSFA_DUP2
271 typedef struct _psfa_action
{
272 psfa_t psfaa_type
; /* file action type */
273 int psfaa_filedes
; /* fd to operate on */
275 int psfao_oflag
; /* open flags to use */
276 mode_t psfao_mode
; /* mode for open */
277 char psfao_path
[PATH_MAX
]; /* path to open */
283 * Internal representation of posix_spawn() file actions structure
285 * Notes: This is implemented as a structure followed by an array of
286 * file action records. The psfa_act_alloc value is the number
287 * of elements allocated in this array, and the psfa_act_count is
288 * the number of elements currently in use (to permit some form
289 * of preallocation, e.g. a power of 2 growth for reallocation,
292 * A possible future optimization would keep a size value and
293 * a structure base reference pointer to permit copyin to the
294 * kernel directly as a single blob, without damaging relative
295 * internal pointer math. It's probably better that this be a
296 * long long rather than a true pointer, to make it invariant
297 * for 32 vs. 64 bt programming SPIs.
299 typedef struct _posix_spawn_file_actions
{
300 int psfa_act_alloc
; /* available actions space */
301 int psfa_act_count
; /* count of defined actions */
302 _psfa_action_t psfa_act_acts
[]; /* actions array (uses c99) */
303 } *_posix_spawn_file_actions_t
;
306 * Calculate the size of a structure, given the number of elements that it is
307 * capable of containing.
309 #define PSF_ACTIONS_SIZE(x) \
310 __offsetof(struct _posix_spawn_file_actions, psfa_act_acts[(x)])
313 * Initial count of actions in a struct _posix_spawn_file_actions after it is
314 * first allocated; this should be non-zero, since we expect that one would not
315 * have been allocated unless there was an intent to use it.
317 #define PSF_ACTIONS_INIT_COUNT 2
320 * Structure defining the true third argument to the posix_spawn() system call
321 * entry point; we wrap it and pass a descriptor so that we can know the
322 * copyin size ahead of time, and deal with copying in variant lists of things
323 * as single monolithic units, instead of many individual elements. This is a
324 * performance optimization.
326 struct _posix_spawn_args_desc
{
327 __darwin_size_t attr_size
; /* size of attributes block */
328 _posix_spawnattr_t attrp
; /* pointer to block */
329 __darwin_size_t file_actions_size
; /* size of file actions block */
330 _posix_spawn_file_actions_t
331 file_actions
; /* pointer to block */
332 __darwin_size_t port_actions_size
; /* size of port actions block */
333 _posix_spawn_port_actions_t
334 port_actions
; /* pointer to port block */
335 __darwin_size_t mac_extensions_size
;
336 _posix_spawn_mac_policy_extensions_t
337 mac_extensions
; /* pointer to policy-specific
339 __darwin_size_t coal_info_size
;
340 struct _posix_spawn_coalition_info
*coal_info
; /* pointer to coalition info */
342 __darwin_size_t reserved_size
;
347 #include <sys/appleapiopts.h>
348 #ifdef __APPLE_API_PRIVATE
350 #if __DARWIN_ALIGN_NATURAL
351 #pragma options align=natural
354 struct user32__posix_spawn_args_desc
{
355 uint32_t attr_size
; /* size of attributes block */
356 uint32_t attrp
; /* pointer to block */
357 uint32_t file_actions_size
; /* size of file actions block */
358 uint32_t file_actions
; /* pointer to block */
359 uint32_t port_actions_size
; /* size of port actions block */
360 uint32_t port_actions
; /* pointer to block */
361 uint32_t mac_extensions_size
;
362 uint32_t mac_extensions
;
363 uint32_t coal_info_size
;
365 uint32_t reserved_size
;
369 struct user__posix_spawn_args_desc
{
370 user_size_t attr_size
; /* size of attributes block */
371 user_addr_t attrp
; /* pointer to block */
372 user_size_t file_actions_size
; /* size of file actions block */
373 user_addr_t file_actions
; /* pointer to block */
374 user_size_t port_actions_size
; /* size of port actions block */
375 user_addr_t port_actions
; /* pointer to block */
376 user_size_t mac_extensions_size
; /* size of MAC-specific attrs. */
377 user_addr_t mac_extensions
; /* pointer to block */
378 user_size_t coal_info_size
;
379 user_addr_t coal_info
;
380 user_size_t reserved_size
;
381 user_addr_t reserved
;
385 #if __DARWIN_ALIGN_NATURAL
386 #pragma options align=reset
389 #endif /* __APPLE_API_PRIVATE */
392 #endif /* _SYS_SPAWN_INTERNAL_H_ */