userspace.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /****************************************************************************
  2. * include/nuttx/userspace.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 __INCLUDE_NUTTX_USERSPACE_H
  36. #define __INCLUDE_NUTTX_USERSPACE_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <sys/types.h>
  42. #include <stdint.h>
  43. #include <signal.h>
  44. #include <pthread.h>
  45. #include <nuttx/arch.h>
  46. #ifdef CONFIG_BUILD_PROTECTED
  47. /****************************************************************************
  48. * Pre-processor Definitions
  49. ****************************************************************************/
  50. /* Configuration ************************************************************/
  51. /* If CONFIG_BUILD_PROTECTED, then CONFIG_NUTTX_USERSPACE must be defined to
  52. * provide the address where the user-space header can be found in memory.
  53. */
  54. #ifndef CONFIG_NUTTX_USERSPACE
  55. # error "CONFIG_NUTTX_USERSPACE is not defined"
  56. #endif
  57. /* Let's insist on 4-byte alignment. This alignment may not be required
  58. * technically for all platforms. However, neither is it an unreasonable
  59. * requirement for any platform.
  60. */
  61. #if (CONFIG_NUTTX_USERSPACE & 3) != 0
  62. # warning "CONFIG_NUTTX_USERSPACE is not aligned to a 4-byte boundary"
  63. #endif
  64. /* Helper Macros ************************************************************/
  65. /* This macro is used to access the struct userpace_s header that can be
  66. * found at the beginning of the user-space blob.
  67. */
  68. #define USERSPACE ((FAR struct userspace_s *)CONFIG_NUTTX_USERSPACE)
  69. /* In user space, these functions are directly callable. In kernel space,
  70. * they can be called through the userspace structure.
  71. */
  72. /****************************************************************************
  73. * Public Type Definitions
  74. ****************************************************************************/
  75. struct mm_heaps_s; /* Forward reference */
  76. /* Every user-space blob starts with a header that provides information about
  77. * the blob. The form of that header is provided by struct userspace_s. An
  78. * instance of this is expected to reside at CONFIG_NUTTX_USERSPACE.
  79. */
  80. struct userspace_s
  81. {
  82. /* General memory map */
  83. main_t us_entrypoint;
  84. uintptr_t us_textstart;
  85. uintptr_t us_textend;
  86. uintptr_t us_datasource;
  87. uintptr_t us_datastart;
  88. uintptr_t us_dataend;
  89. uintptr_t us_bssstart;
  90. uintptr_t us_bssend;
  91. uintptr_t us_heapend;
  92. /* Memory manager heap structure */
  93. FAR struct mm_heap_s *us_heap;
  94. /* Task/thread startup routines */
  95. CODE void (*task_startup)(main_t entrypt, int argc, FAR char *argv[]);
  96. #ifndef CONFIG_DISABLE_PTHREAD
  97. CODE void (*pthread_startup)(pthread_startroutine_t entrypt,
  98. pthread_addr_t arg);
  99. #endif
  100. /* Signal handler trampoline */
  101. CODE void (*signal_handler)(_sa_sigaction_t sighand, int signo,
  102. FAR siginfo_t *info, FAR void *ucontext);
  103. /* User-space work queue support */
  104. #ifdef CONFIG_LIB_USRWORK
  105. CODE int (*work_usrstart)(void);
  106. #endif
  107. };
  108. /****************************************************************************
  109. * Public Data
  110. ****************************************************************************/
  111. #ifdef __cplusplus
  112. #define EXTERN extern "C"
  113. extern "C"
  114. {
  115. #else
  116. #define EXTERN extern
  117. #endif
  118. /****************************************************************************
  119. * Public Function Prototypes
  120. ****************************************************************************/
  121. /****************************************************************************
  122. * Name: pthread_startup
  123. *
  124. * Description:
  125. * This function is the user-space, pthread startup function. It is called
  126. * from up_pthread_start() in user-mode.
  127. *
  128. * Input Parameters:
  129. * entrypt - The user-space address of the pthread entry point
  130. * arg - Standard argument for the pthread entry point
  131. *
  132. * Returned Value:
  133. * None. This function does not return.
  134. *
  135. ****************************************************************************/
  136. #if !defined(__KERNEL__) && !defined(CONFIG_DISABLE_PTHREAD)
  137. void pthread_startup(pthread_startroutine_t entrypt, pthread_addr_t arg);
  138. #endif
  139. #undef EXTERN
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif /* CONFIG_BUILD_PROTECTED */
  144. #endif /* __INCLUDE_NUTTX_USERSPACE_H */