Tizen RT Libs&Environment  v1.0 D5
spawn.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /****************************************************************************
19  * include/spawn.h
20  *
21  * Copyright (C) 2013 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name NuttX nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ****************************************************************************/
60 
63 #ifndef __INCLUDE_SPAWN_H
64 #define __INCLUDE_SPAWN_H
65 
66 /****************************************************************************
67  * Included Files
68  ****************************************************************************/
69 
70 #include <tinyara/config.h>
71 
72 #include <sys/types.h>
73 
74 #include <sched.h>
75 #include <signal.h>
76 #include <errno.h>
77 
78 /****************************************************************************
79  * Pre-processor Definitions
80  ****************************************************************************/
81 /* Configuration ************************************************************/
82 
83 #ifndef CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE
84 #define CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE 2048
85 #endif
86 
87 /* "The spawn.h header shall define the flags that may be set in a
88  * posix_spawnattr_t object using the posix_spawnattr_setflags() function:"
89  */
90 
91 #define POSIX_SPAWN_RESETIDS (1 << 0) /* 1: Reset effective user ID */
92 #define POSIX_SPAWN_SETPGROUP (1 << 1) /* 1: Set process group */
93 #define POSIX_SPAWN_SETSCHEDPARAM (1 << 2) /* 1: Set task's priority */
94 #define POSIX_SPAWN_SETSCHEDULER (1 << 3) /* 1: Set task's scheduler policy */
95 #define POSIX_SPAWN_SETSIGDEF (1 << 4) /* 1: Set default signal actions */
96 #define POSIX_SPAWN_SETSIGMASK (1 << 5) /* 1: Set sigmask */
97 
98 /****************************************************************************
99  * Type Definitions
100  ****************************************************************************/
101 /* "The spawn.h header shall define the posix_spawnattr_t and
102  * posix_spawn_file_actions_t types used in performing spawn operations.
103  *
104  * The internal structure underlying the posix_spawnattr_t is exposed here
105  * because the user will be required to allocate this memory.
106  */
111  /* Used by posix_spawn, posix_spawnp, and task_spawn */
112 
113  uint8_t flags; /* See POSIX_SPAWN_ definitions */
114  uint8_t priority; /* Task scheduling priority */
115  uint8_t policy; /* Task scheduling policy */
116 #ifndef CONFIG_DISABLE_SIGNALS
117  sigset_t sigmask; /* Signals to be masked */
118 #endif
119 
120 #ifndef CONFIG_BUILD_KERNEL
121  /* Used only by task_spawn (non-standard) */
122 
123  size_t stacksize; /* Task stack size */
124 #endif
125 };
126 
128 
129 /* posix_spawn_file_actions_addclose(), posix_spawn_file_actions_adddup2(),
130  * and posix_spawn_file_actions_addopen() will allocate memory and append
131  * a new file action to an instance of posix_spawn_file_actions_t. The
132  * internal representation of these structures is not exposed to the user.
133  * The user need only know that the size sizeof(posix_spawn_file_actions_t)
134  * will hold a pointer to data.
135  */
136 
137 typedef FAR void *posix_spawn_file_actions_t;
138 
139 /****************************************************************************
140  * Public Function Prototypes
141  ****************************************************************************/
142 /* "The following shall be declared as functions and may also be defined as
143  * macros. Function prototypes shall be provided."
144  */
145 
146 #ifdef __cplusplus
147 extern "C" {
148 #endif
149 
150 /* Spawn interfaces *********************************************************/
151 /* Standard posix_spawn[p] interfaces. These functions execute files in the
152  * file system at 'path'
153  */
154 
159 int posix_spawn(FAR pid_t *pid, FAR const char *path, FAR const posix_spawn_file_actions_t *file_actions, FAR const posix_spawnattr_t *attr, FAR char *const argv[], FAR char *const envp[]);
160 #define posix_spawnp(pid, path, file_actions, attr, argv, envp) \
161  posix_spawn(pid, path, file_actions, attr, argv, envp)
162 
165 #ifndef CONFIG_BUILD_KERNEL
166 /* Non-standard task_spawn interface. This function uses the same
167  * semantics to execute a file in memory at 'entry', giving it the name
168  * 'name'.
169  */
174 int task_spawn(FAR pid_t *pid, FAR const char *name, main_t entry, FAR const posix_spawn_file_actions_t *file_actions, FAR const posix_spawnattr_t *attr, FAR char *const argv[], FAR char *const envp[]);
178 #endif
179 
180 /* File action interfaces ***************************************************/
181 /* File action initialization and destruction */
192 
193 /* Add file action interfaces */
203 int posix_spawn_file_actions_adddup2(FAR posix_spawn_file_actions_t *file_actions, int fd1, int fd2);
211 int posix_spawn_file_actions_addopen(FAR posix_spawn_file_actions_t *file_actions, int fd, FAR const char *path, int oflags, mode_t mode);
212 
213 /* Spawn attributes interfaces **********************************************/
214 /* Spawn attributes initialization and destruction */
220 
221 /* int posix_spawnattr_destroy(FAR posix_spawnattr_t *); */
222 #ifdef CONFIG_DEBUG
223 #define posix_spawnattr_destroy(attr) (attr ? 0 : EINVAL)
224 #else
225 #define posix_spawnattr_destroy(attr) (0)
226 #endif
227 
228 /* Get spawn attributes interfaces */
233 int posix_spawnattr_getflags(FAR const posix_spawnattr_t *attr, FAR short *flags);
234 #define posix_spawnattr_getpgroup(attr, group) (ENOSYS)
235 
239 int posix_spawnattr_getschedparam(FAR const posix_spawnattr_t *attr, FAR struct sched_param *param);
244 int posix_spawnattr_getschedpolicy(FAR const posix_spawnattr_t *attr, FAR int *policy);
245 #define posix_spawnattr_getsigdefault(attr, sigdefault) (ENOSYS)
246 #ifndef CONFIG_DISABLE_SIGNALS
247 
252 #else
253 #define posix_spawnattr_getsigmask(attr, sigmask) (ENOSYS)
254 #endif
255 
256 /* Set spawn attributes interfaces */
261 int posix_spawnattr_setflags(FAR posix_spawnattr_t *attr, short flags);
262 #define posix_spawnattr_setpgroup(attr, group) (ENOSYS)
263 
267 int posix_spawnattr_setschedparam(FAR posix_spawnattr_t *attr, FAR const struct sched_param *param);
273 #define posix_spawnattr_setsigdefault(attr, sigdefault) (ENOSYS)
274 #ifndef CONFIG_DISABLE_SIGNALS
275 
280 #else
281 #define posix_spawnattr_setsigmask(attr, sigmask) (ENOSYS)
282 #endif
283 
284 /* Non-standard get/set spawn attributes interfaces for use only with
285  * task_spawn()
286  */
297 int task_spawnattr_getstacksize(FAR const posix_spawnattr_t *attr, size_t *stacksize);
309 
310 /* Non standard debug functions */
311 
312 #ifdef CONFIG_DEBUG
313 
323 #else
324 #define posix_spawn_file_actions_dump(fa)
325 #define posix_spawnattr_dump(a)
326 #endif
327 
328 #ifdef __cplusplus
329 }
330 #endif
331 #endif /* __INCLUDE_SPAWN_H */
332 // end of SPAWN_LIBC
int posix_spawn_file_actions_init(FAR posix_spawn_file_actions_t *file_actions)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
Structure of posix_spawn attributes.
Definition: spawn.h:110
int posix_spawnattr_setschedparam(FAR posix_spawnattr_t *attr, FAR const struct sched_param *param)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
size_t stacksize
Definition: spawn.h:123
int posix_spawnattr_setsigmask(FAR posix_spawnattr_t *attr, FAR const sigset_t *sigmask)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int posix_spawn_file_actions_addopen(FAR posix_spawn_file_actions_t *file_actions, int fd, FAR const char *path, int oflags, mode_t mode)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
Errno APIs.
int posix_spawnattr_getschedpolicy(FAR const posix_spawnattr_t *attr, FAR int *policy)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int posix_spawnattr_init(FAR posix_spawnattr_t *attr)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
void posix_spawn_file_actions_dump(FAR posix_spawn_file_actions_t *file_actions)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int posix_spawnattr_getsigmask(FAR const posix_spawnattr_t *attr, FAR sigset_t *sigmask)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
POSIX-like scheduling parameter structure.
Definition: sched.h:105
int posix_spawn_file_actions_addclose(FAR posix_spawn_file_actions_t *file_actions, int fd)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int posix_spawnattr_getschedparam(FAR const posix_spawnattr_t *attr, FAR struct sched_param *param)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
Signal APIs.
int posix_spawn_file_actions_destroy(FAR posix_spawn_file_actions_t *file_actions)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int task_spawnattr_getstacksize(FAR const posix_spawnattr_t *attr, size_t *stacksize)
The task_spawnattr_getstacksize() function will obtain the value of the spawn-stacksize attribute fro...
int task_spawnattr_setstacksize(FAR posix_spawnattr_t *attr, size_t stacksize)
The task_spawnattr_setstacksize() function shall set the spawn- stacksize attribute in an initialized...
FAR void * posix_spawn_file_actions_t
Definition: spawn.h:137
uint8_t policy
Definition: spawn.h:115
sigset_t sigmask
Definition: spawn.h:117
int posix_spawnattr_setflags(FAR posix_spawnattr_t *attr, short flags)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int posix_spawnattr_setschedpolicy(FAR posix_spawnattr_t *attr, int policy)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
uint8_t flags
Definition: spawn.h:113
uint32_t sigset_t
Definition: signal.h:213
void posix_spawnattr_dump(FAR posix_spawnattr_t *attr)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
uint8_t priority
Definition: spawn.h:114
int posix_spawnattr_getflags(FAR const posix_spawnattr_t *attr, FAR short *flags)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)