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 intern datastructures 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__INTERNALH_
43 #include <sys/_types.h> /* __offsetof(), __darwin_size_t */
44 #include <sys/syslimits.h> /* PATH_MAX */
45 #include <sys/spawn.h>
46 #include <mach/machine.h>
47 #include <mach/port.h>
48 #include <mach/exception_types.h>
51 * Allowable posix_spawn() port action types
59 * Internal representation of one port to be set on posix_spawn().
60 * Currently this is limited to setting special and exception ports,
61 * but could be extended to other inheritable port types.
63 typedef struct _ps_port_action
{
65 exception_mask_t mask
;
67 exception_behavior_t behavior
;
68 thread_state_flavor_t flavor
;
73 * A collection of port actions to take on the newly spawned process.
75 typedef struct _posix_spawn_port_actions
{
78 _ps_port_action_t pspa_actions
[];
79 } *_posix_spawn_port_actions_t
;
82 * Returns size in bytes of a _posix_spawn_port_actions holding x elements.
84 #define PS_PORT_ACTIONS_SIZE(x) \
85 __offsetof(struct _posix_spawn_port_actions, pspa_actions[(x)])
90 * A posix_spawnattr structure contains all of the attribute elements that
91 * can be set, as well as any metadata whose validity is signalled by the
92 * presence of a bit in the flags field. All fields are initialized to the
93 * appropriate default values by posix_spawnattr_init().
95 typedef struct _posix_spawnattr
{
96 short psa_flags
; /* spawn attribute flags */
97 sigset_t psa_sigdefault
; /* signal set to default */
98 sigset_t psa_sigmask
; /* signal set to mask */
99 pid_t psa_pgroup
; /* pgroup to spawn into */
100 cpu_type_t psa_binprefs
[NBINPREFS
]; /* cpu affinity prefs*/
101 _posix_spawn_port_actions_t psa_ports
; /* special/exception ports */
102 } *_posix_spawnattr_t
;
106 * Allowable posix_spawn() file actions
116 * A posix_spawn() file action record for a single action
118 * Notes: We carry around the full open arguments for both the open
119 * and the close to permit the use of a single array of action
120 * elements to be associated with a file actions object.
122 * A possible future optimization would be to break this into
123 * a variable sized vector list to save space (i.e. a separate
124 * string area, allocation of least amount of path buffer per
125 * open action, etc.).
127 * XXX: Currently overloading psfao_oflag for PSFA_DUP2
129 typedef struct _psfa_action
{
130 psfa_t psfaa_type
; /* file action type */
131 int psfaa_filedes
; /* fd to operate on */
133 int psfao_oflag
; /* open flags to use */
134 mode_t psfao_mode
; /* mode for open */
135 char psfao_path
[PATH_MAX
]; /* path to open */
141 * Internal representation of posix_spawn() file actions structure
143 * Notes: This is implemented as a structure followed by an array of
144 * file action records. The psfa_act_alloc value is the number
145 * of elements allocated in this array, and the psfa_act_count is
146 * the number of elements currently in use (to permit some form
147 * of preallocation, e.g. a power of 2 growth for reallocation,
150 * A possible future optimization would keep a size value and
151 * a structure base reference pointer to permit copyin to the
152 * kernel directly as a single blob, without damaging relative
153 * internal pointer math. It's probably better that this be a
154 * long long rather than a true pointer, to make it invariant
155 * for 32 vs. 64 bt programming SPIs.
157 typedef struct _posix_spawn_file_actions
{
158 int psfa_act_alloc
; /* available actions space */
159 int psfa_act_count
; /* count of defined actions */
160 _psfa_action_t psfa_act_acts
[]; /* actions array (uses c99) */
161 } *_posix_spawn_file_actions_t
;
164 * Calculate the size of a structure, given the number of elements that it is
165 * capable of containing.
167 #define PSF_ACTIONS_SIZE(x) \
168 __offsetof(struct _posix_spawn_file_actions, psfa_act_acts[(x)])
171 * Initial count of actions in a struct _posix_spawn_file_actions after it is
172 * first allocated; this should be non-zero, since we expect that one would not
173 * have been allocated unless there was an intent to use it.
175 #define PSF_ACTIONS_INIT_COUNT 2
178 * Structure defining the true third argument to the posix_spawn() system call
179 * entry point; we wrap it and pass a descriptor so that we can know the
180 * copyin size ahead of time, and deal with copying in variant lists of things
181 * as single monolithic units, instead of many individual elements. This is a
182 * performance optimization.
184 struct _posix_spawn_args_desc
{
185 __darwin_size_t attr_size
; /* size of attributes block */
186 _posix_spawnattr_t attrp
; /* pointer to block */
187 __darwin_size_t file_actions_size
; /* size of file actions block */
188 _posix_spawn_file_actions_t
189 file_actions
; /* pointer to block */
190 __darwin_size_t port_actions_size
; /* size of port actions block */
191 _posix_spawn_port_actions_t
192 port_actions
; /* pointer to port block */
196 #include <sys/appleapiopts.h>
197 #ifdef __APPLE_API_PRIVATE
199 #if __DARWIN_ALIGN_NATURAL
200 #pragma options align=natural
203 struct user__posix_spawn_args_desc
{
204 user_size_t attr_size
; /* size of attributes block */
205 user_addr_t attrp
; /* pointer to block */
206 user_size_t file_actions_size
; /* size of file actions block */
207 user_addr_t file_actions
; /* pointer to block */
208 user_size_t port_actions_size
; /* size of port actions block */
209 user_addr_t port_actions
; /* pointer to block */
213 #if __DARWIN_ALIGN_NATURAL
214 #pragma options align=reset
217 #endif /* __APPLE_API_PRIVATE */
220 #endif /* _SYS_SPAWN_INTERNAL_H_ */