spawn.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /****************************************************************************
  2. * include/spawn.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __INCLUDE_SPAWN_H
  21. #define __INCLUDE_SPAWN_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <sys/types.h>
  27. #include <sched.h>
  28. #include <signal.h>
  29. /****************************************************************************
  30. * Pre-processor Definitions
  31. ****************************************************************************/
  32. /* Configuration ************************************************************/
  33. #ifndef CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE
  34. # define CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE 2048
  35. #endif
  36. /* "The spawn.h header shall define the flags that may be set in a
  37. * posix_spawnattr_t object using the posix_spawnattr_setflags() function:"
  38. */
  39. #define POSIX_SPAWN_RESETIDS (1 << 0) /* 1: Reset effective user ID */
  40. #define POSIX_SPAWN_SETPGROUP (1 << 1) /* 1: Set process group */
  41. #define POSIX_SPAWN_SETSCHEDPARAM (1 << 2) /* 1: Set task's priority */
  42. #define POSIX_SPAWN_SETSCHEDULER (1 << 3) /* 1: Set task's scheduler policy */
  43. #define POSIX_SPAWN_SETSIGDEF (1 << 4) /* 1: Set default signal actions */
  44. #define POSIX_SPAWN_SETSIGMASK (1 << 5) /* 1: Set sigmask */
  45. #define POSIX_SPAWN_SETSID (1 << 7) /* 1: Create the new session(glibc specific) */
  46. /****************************************************************************
  47. * Type Definitions
  48. ****************************************************************************/
  49. /* "The spawn.h header shall define the posix_spawnattr_t and
  50. * posix_spawn_file_actions_t types used in performing spawn operations.
  51. *
  52. * The internal structure underlying the posix_spawnattr_t is exposed here
  53. * because the user will be required to allocate this memory.
  54. */
  55. struct timespec;
  56. struct posix_spawnattr_s
  57. {
  58. /* Used by posix_spawn, posix_spawnp, and task_spawn */
  59. uint8_t flags; /* See POSIX_SPAWN_ definitions */
  60. uint8_t priority; /* Task scheduling priority */
  61. uint8_t policy; /* Task scheduling policy */
  62. #ifdef CONFIG_SCHED_SPORADIC
  63. uint8_t low_priority; /* Low scheduling priority */
  64. uint8_t max_repl; /* Maximum pending replenishments */
  65. #endif
  66. sigset_t sigmask; /* Signals to be masked */
  67. #ifndef CONFIG_BUILD_KERNEL
  68. /* Used only by task_spawn (non-standard) */
  69. FAR void *stackaddr; /* Task stack address */
  70. size_t stacksize; /* Task stack size */
  71. #endif
  72. #ifdef CONFIG_SCHED_SPORADIC
  73. struct timespec repl_period; /* Replenishment period */
  74. struct timespec budget; /* Initial budget */
  75. #endif
  76. };
  77. typedef struct posix_spawnattr_s posix_spawnattr_t;
  78. /* posix_spawn_file_actions_addclose(), posix_spawn_file_actions_adddup2(),
  79. * and posix_spawn_file_actions_addopen() will allocate memory and append
  80. * a new file action to an instance of posix_spawn_file_actions_t. The
  81. * internal representation of these structures is not exposed to the user.
  82. * The user need only know that the size sizeof(posix_spawn_file_actions_t)
  83. * will hold a pointer to data.
  84. */
  85. typedef FAR void *posix_spawn_file_actions_t;
  86. /****************************************************************************
  87. * Public Function Prototypes
  88. ****************************************************************************/
  89. /* "The following shall be declared as functions and may also be defined as
  90. * macros. Function prototypes shall be provided."
  91. */
  92. #ifdef __cplusplus
  93. extern "C"
  94. {
  95. #endif
  96. /* Spawn interfaces *********************************************************/
  97. /* Standard posix_spawn[p] interfaces. These functions execute files in the
  98. * file system at 'path'
  99. */
  100. #ifdef CONFIG_LIB_ENVPATH
  101. int posix_spawnp(FAR pid_t *pid, FAR const char *path,
  102. FAR const posix_spawn_file_actions_t *file_actions,
  103. FAR const posix_spawnattr_t *attr,
  104. FAR char * const argv[], FAR char * const envp[]);
  105. #define posix_spawn(pid,path,file_actions,attr,argv,envp) \
  106. posix_spawnp(pid,path,file_actions,attr,argv,envp)
  107. #else
  108. int posix_spawn(FAR pid_t *pid, FAR const char *path,
  109. FAR const posix_spawn_file_actions_t *file_actions,
  110. FAR const posix_spawnattr_t *attr,
  111. FAR char * const argv[], FAR char * const envp[]);
  112. #define posix_spawnp(pid,path,file_actions,attr,argv,envp) \
  113. posix_spawn(pid,path,file_actions,attr,argv,envp)
  114. #endif
  115. #ifndef CONFIG_BUILD_KERNEL
  116. /* Non-standard task_spawn interface. This function uses the same
  117. * semantics to execute a file in memory at 'entry', giving it the name
  118. * 'name'.
  119. */
  120. int task_spawn(FAR const char *name, main_t entry,
  121. FAR const posix_spawn_file_actions_t *file_actions,
  122. FAR const posix_spawnattr_t *attr,
  123. FAR char * const argv[], FAR char * const envp[]);
  124. #endif
  125. /* File action interfaces ***************************************************/
  126. /* File action initialization and destruction */
  127. int posix_spawn_file_actions_init(
  128. FAR posix_spawn_file_actions_t *file_actions);
  129. int posix_spawn_file_actions_destroy(
  130. FAR posix_spawn_file_actions_t *file_actions);
  131. /* Add file action interfaces */
  132. int posix_spawn_file_actions_addclose(
  133. FAR posix_spawn_file_actions_t *file_actions,
  134. int fd);
  135. int posix_spawn_file_actions_adddup2(
  136. FAR posix_spawn_file_actions_t *file_actions,
  137. int fd1, int fd2);
  138. int posix_spawn_file_actions_addopen(
  139. FAR posix_spawn_file_actions_t *file_actions,
  140. int fd, FAR const char *path, int oflags, mode_t mode);
  141. /* Spawn attributes interfaces **********************************************/
  142. /* Spawn attributes initialization and destruction */
  143. int posix_spawnattr_init(FAR posix_spawnattr_t *attr);
  144. /* int posix_spawnattr_destroy(FAR posix_spawnattr_t *); */
  145. #define posix_spawnattr_destroy(attr) (0)
  146. /* Get spawn attributes interfaces */
  147. int posix_spawnattr_getflags(FAR const posix_spawnattr_t *attr,
  148. FAR short *flags);
  149. #define posix_spawnattr_getpgroup(attr,group) (ENOSYS)
  150. int posix_spawnattr_getschedparam(FAR const posix_spawnattr_t *attr,
  151. FAR struct sched_param *param);
  152. int posix_spawnattr_getschedpolicy(FAR const posix_spawnattr_t *attr,
  153. FAR int *policy);
  154. #define posix_spawnattr_getsigdefault(attr,sigdefault) (ENOSYS)
  155. int posix_spawnattr_getsigmask(FAR const posix_spawnattr_t *attr,
  156. FAR sigset_t *sigmask);
  157. /* Set spawn attributes interfaces */
  158. int posix_spawnattr_setflags(FAR posix_spawnattr_t *attr, short flags);
  159. #define posix_spawnattr_setpgroup(attr,group) (ENOSYS)
  160. int posix_spawnattr_setschedparam(FAR posix_spawnattr_t *attr,
  161. FAR const struct sched_param *param);
  162. int posix_spawnattr_setschedpolicy(FAR posix_spawnattr_t *attr, int policy);
  163. #define posix_spawnattr_setsigdefault(attr,sigdefault) (ENOSYS)
  164. int posix_spawnattr_setsigmask(FAR posix_spawnattr_t *attr,
  165. FAR const sigset_t *sigmask);
  166. /* Non-standard get/set spawn attributes interfaces for use only with
  167. * task_spawn()
  168. */
  169. int task_spawnattr_getstackaddr(FAR const posix_spawnattr_t *attr,
  170. FAR void **stackaddr);
  171. int task_spawnattr_setstackaddr(FAR posix_spawnattr_t *attr,
  172. FAR void *stackaddr);
  173. int task_spawnattr_getstacksize(FAR const posix_spawnattr_t *attr,
  174. FAR size_t *stacksize);
  175. int task_spawnattr_setstacksize(FAR posix_spawnattr_t *attr,
  176. size_t stacksize);
  177. /* Non standard debug functions */
  178. #ifdef CONFIG_DEBUG_FEATURES
  179. void posix_spawn_file_actions_dump(
  180. FAR posix_spawn_file_actions_t *file_actions);
  181. void posix_spawnattr_dump(FAR posix_spawnattr_t *attr);
  182. #else
  183. # define posix_spawn_file_actions_dump(fa)
  184. # define posix_spawnattr_dump(a)
  185. #endif
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189. #endif /* __INCLUDE_SPAWN_H */