spawn.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /****************************************************************************
  2. * sched/task/spawn.h
  3. *
  4. * Copyright (C) 2013 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __SCHED_TASK_SPAWN_H
  36. #define __SCHED_TASK_SPAWN_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <spawn.h>
  42. /****************************************************************************
  43. * Pre-processor Definitions
  44. ****************************************************************************/
  45. #ifndef CONFIG_POSIX_SPAWN_PROXY_STACKSIZE
  46. # define CONFIG_POSIX_SPAWN_PROXY_STACKSIZE 1024
  47. #endif
  48. /****************************************************************************
  49. * Public Type Definitions
  50. ****************************************************************************/
  51. struct spawn_parms_s
  52. {
  53. /* Common parameters */
  54. int result;
  55. FAR pid_t *pid;
  56. FAR const posix_spawn_file_actions_t *file_actions;
  57. FAR const posix_spawnattr_t *attr;
  58. FAR char * const *argv;
  59. /* Parameters that differ for posix_spawn[p] and task_spawn */
  60. union
  61. {
  62. struct
  63. {
  64. FAR const char *path;
  65. } posix;
  66. struct
  67. {
  68. FAR const char *name;
  69. main_t entry;
  70. } task;
  71. } u;
  72. };
  73. /****************************************************************************
  74. * Public Data
  75. ****************************************************************************/
  76. extern sem_t g_spawn_parmsem;
  77. #ifndef CONFIG_SCHED_WAITPID
  78. extern sem_t g_spawn_execsem;
  79. #endif
  80. extern struct spawn_parms_s g_spawn_parms;
  81. /****************************************************************************
  82. * Public Function Prototypes
  83. ****************************************************************************/
  84. /****************************************************************************
  85. * Name: spawn_semtake and spawn_semgive
  86. *
  87. * Description:
  88. * Give and take semaphores
  89. *
  90. * Input Parameters:
  91. *
  92. * sem - The semaphore to act on.
  93. *
  94. * Returned Value:
  95. * None
  96. *
  97. ****************************************************************************/
  98. void spawn_semtake(FAR sem_t *sem);
  99. #define spawn_semgive(sem) nxsem_post(sem)
  100. /****************************************************************************
  101. * Name: spawn_execattrs
  102. *
  103. * Description:
  104. * Set attributes of the new child task after it has been spawned.
  105. *
  106. * Input Parameters:
  107. *
  108. * pid - The pid of the new task.
  109. * attr - The attributes to use
  110. *
  111. * Returned Value:
  112. * Errors are not reported by this function. This is because errors
  113. * cannot occur, but ratther that the new task has already been started
  114. * so there is no graceful way to handle errors detected in this context
  115. * (unless we delete the new task and recover).
  116. *
  117. * Assumptions:
  118. * That task has been started but has not yet executed because pre-
  119. * emption is disabled.
  120. *
  121. ****************************************************************************/
  122. int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr);
  123. /****************************************************************************
  124. * Name: spawn_proxyattrs
  125. *
  126. * Description:
  127. * Set attributes of the proxy task before it has started the new child
  128. * task.
  129. *
  130. * Input Parameters:
  131. *
  132. * pid - The pid of the new task.
  133. * attr - The attributes to use
  134. * file_actions - The attributes to use
  135. *
  136. * Returned Value:
  137. * 0 (OK) on successed; A negated errno value is returned on failure.
  138. *
  139. ****************************************************************************/
  140. int spawn_proxyattrs(FAR const posix_spawnattr_t *attr,
  141. FAR const posix_spawn_file_actions_t *file_actions);
  142. #endif /* __SCHED_TASK_SPAWN_H */