osbasep.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. osbasep.h
  5. Abstract:
  6. This header contains internal definitions for the Operating System Base
  7. library.
  8. Author:
  9. Evan Green 25-Feb-2013
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. #define OS_API __DLLPROTECTED
  15. #define RTL_API __DLLPROTECTED
  16. #include <minoca/lib/minocaos.h>
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. //
  21. // TODO: Implement syscall system call mechanism on x64, in addition to keeping
  22. // the old int mechanism for full save/restore.
  23. //
  24. #if defined(__amd64)
  25. #define OsSystemCall OspSystemCallFull
  26. #endif
  27. //
  28. // ------------------------------------------------------ Data Type Definitions
  29. //
  30. typedef
  31. INTN
  32. (*POS_SYSTEM_CALL) (
  33. ULONG SystemCallNumber,
  34. PVOID SystemCallParameter
  35. );
  36. /*++
  37. Routine Description:
  38. This routine executes a system call.
  39. Arguments:
  40. SystemCallNumber - Supplies the system call number.
  41. SystemCallParameter - Supplies the system call parameter.
  42. Return Value:
  43. STATUS_SUCCESS or positive integer on success.
  44. Error status code on failure.
  45. --*/
  46. //
  47. // -------------------------------------------------------------------- Globals
  48. //
  49. //
  50. // Store a pointer to the environment.
  51. //
  52. extern PPROCESS_ENVIRONMENT OsEnvironment;
  53. //
  54. // On x86, the system call is a function pointer depending on which processor
  55. // features are supported.
  56. //
  57. #if defined(__i386)
  58. extern POS_SYSTEM_CALL OsSystemCall;
  59. #endif
  60. //
  61. // Store a pointer to the list head of all loaded images.
  62. //
  63. extern LIST_ENTRY OsLoadedImagesHead;
  64. //
  65. // Store the module generation number, which increments whenever a module is
  66. // loaded or unloaded. It is protected under the image list lock.
  67. //
  68. extern UINTN OsImModuleGeneration;
  69. //
  70. // Store the page shift and mask for easy use during image section mappings.
  71. //
  72. extern UINTN OsPageShift;
  73. extern UINTN OsPageSize;
  74. //
  75. // -------------------------------------------------------- Function Prototypes
  76. //
  77. INTN
  78. OspSystemCallFull (
  79. ULONG SystemCallNumber,
  80. PVOID SystemCallParameter
  81. );
  82. /*++
  83. Routine Description:
  84. This routine executes a system call using the traditional method that looks
  85. a lot like an interrupt. On some architectures, this method is highly
  86. compatible, but slow. On other architectures, this is the only system call
  87. mechanism.
  88. Arguments:
  89. SystemCallNumber - Supplies the system call number.
  90. SystemCallParameter - Supplies the system call parameter.
  91. Return Value:
  92. STATUS_SUCCESS or positive integer on success.
  93. Error status code on failure.
  94. --*/
  95. #if defined (__arm__)
  96. INTN
  97. OsSystemCall (
  98. ULONG SystemCallNumber,
  99. PVOID SystemCallParameter
  100. );
  101. /*++
  102. Routine Description:
  103. This routine executes a system call.
  104. Arguments:
  105. SystemCallNumber - Supplies the system call number.
  106. SystemCallParameter - Supplies the system call parameter.
  107. Return Value:
  108. STATUS_SUCCESS or positive integer on success.
  109. Error status code on failure.
  110. --*/
  111. #endif
  112. VOID
  113. OspSetUpSystemCalls (
  114. VOID
  115. );
  116. /*++
  117. Routine Description:
  118. This routine sets up the system call handler.
  119. Arguments:
  120. None.
  121. Return Value:
  122. None.
  123. --*/
  124. VOID
  125. OspSignalHandler (
  126. PSIGNAL_PARAMETERS Parameters,
  127. PSIGNAL_CONTEXT Context
  128. );
  129. /*++
  130. Routine Description:
  131. This routine is called directly by the kernel when a signal occurs. It
  132. marshals the parameters and calls the C routine for handling the signal.
  133. The parameters are stored on the stack with the signal parameters followed
  134. by the signal context.
  135. Arguments:
  136. Parameters - Supplies a pointer to the signal parameters.
  137. Context - Supplies a pointer to the signal context from the kernel.
  138. Return Value:
  139. None.
  140. --*/
  141. VOID
  142. OspInitializeMemory (
  143. VOID
  144. );
  145. /*++
  146. Routine Description:
  147. This routine initializes the memory heap portion of the OS base library.
  148. Arguments:
  149. None.
  150. Return Value:
  151. None.
  152. --*/
  153. VOID
  154. OspInitializeImageSupport (
  155. VOID
  156. );
  157. /*++
  158. Routine Description:
  159. This routine initializes the image library for use in the image creation
  160. tool.
  161. Arguments:
  162. None.
  163. Return Value:
  164. None.
  165. --*/
  166. VOID
  167. OspAcquireImageLock (
  168. BOOL Exclusive
  169. );
  170. /*++
  171. Routine Description:
  172. This routine acquires the global image lock.
  173. Arguments:
  174. Exclusive - Supplies a boolean indicating whether the lock should be
  175. held shared (FALSE) or exclusive (TRUE).
  176. Return Value:
  177. None.
  178. --*/
  179. VOID
  180. OspReleaseImageLock (
  181. VOID
  182. );
  183. /*++
  184. Routine Description:
  185. This routine releases the global image lock.
  186. Arguments:
  187. None.
  188. Return Value:
  189. None.
  190. --*/
  191. PUSER_SHARED_DATA
  192. OspGetUserSharedData (
  193. VOID
  194. );
  195. /*++
  196. Routine Description:
  197. This routine returns a pointer to the user shared data.
  198. Arguments:
  199. None.
  200. Return Value:
  201. Returns a pointer to the user shared data area.
  202. --*/
  203. //
  204. // Thread-Local storage functions
  205. //
  206. VOID
  207. OspInitializeThreadSupport (
  208. VOID
  209. );
  210. /*++
  211. Routine Description:
  212. This routine initializes thread and TLS support in the OS library.
  213. Arguments:
  214. None.
  215. Return Value:
  216. None.
  217. --*/
  218. KSTATUS
  219. OspTlsAllocate (
  220. PLIST_ENTRY ImageList,
  221. PVOID *ThreadData
  222. );
  223. /*++
  224. Routine Description:
  225. This routine creates the OS library data necessary to manage a new thread.
  226. This function is usually called by the C library.
  227. Arguments:
  228. ImageList - Supplies a pointer to the head of the list of loaded images.
  229. Elements on this list have type LOADED_IMAGE.
  230. ThreadData - Supplies a pointer where a pointer to the thread data will be
  231. returned on success. It is the callers responsibility to destroy this
  232. thread data.
  233. Return Value:
  234. Status code.
  235. --*/
  236. VOID
  237. OspTlsDestroy (
  238. PVOID ThreadData
  239. );
  240. /*++
  241. Routine Description:
  242. This routine destroys a previously created thread data structure. Callers
  243. may not use OS library assisted TLS after this routine completes. Signals
  244. should also probably be masked.
  245. Arguments:
  246. ThreadData - Supplies a pointer to the thread data to destroy.
  247. Return Value:
  248. None.
  249. --*/
  250. VOID
  251. OspTlsTearDownModule (
  252. PLOADED_IMAGE Image
  253. );
  254. /*++
  255. Routine Description:
  256. This routine is called when a module is unloaded. It goes through and
  257. frees all the TLS images for the module.
  258. Arguments:
  259. Image - Supplies a pointer to the image being unloaded.
  260. Return Value:
  261. None.
  262. --*/