Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

327 lines
7.4 KiB

  1. title "Thunks"
  2. ;++
  3. ;
  4. ; Copyright (c) 1989 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; thunk.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements all Win32 thunks. This includes the
  13. ; first level thread starter...
  14. ;
  15. ; Author:
  16. ;
  17. ; Mark Lucovsky (markl) 28-Sep-1990
  18. ;
  19. ; Revision History:
  20. ;
  21. ;--
  22. .386p
  23. .xlist
  24. include ks386.inc
  25. include callconv.inc
  26. .list
  27. _DATA SEGMENT DWORD PUBLIC 'DATA'
  28. _BasepTickCountMultiplier dd 0d1b71759H
  29. _DATA ENDS
  30. _TEXT SEGMENT DWORD PUBLIC 'CODE'
  31. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  32. ;; align 512
  33. page ,132
  34. subttl "BaseThreadStartThunk"
  35. ;++
  36. ;
  37. ; VOID
  38. ; BaseThreadStartThunk(
  39. ; IN PTHREAD_START_ROUTINE StartRoutine,
  40. ; IN PVOID ThreadParameter
  41. ; )
  42. ;
  43. ; Routine Description:
  44. ;
  45. ; This function calls to the portable thread starter after moving
  46. ; its arguments from registers to the stack.
  47. ;
  48. ; Arguments:
  49. ;
  50. ; EAX - StartRoutine
  51. ; EBX - ThreadParameter
  52. ;
  53. ; Return Value:
  54. ;
  55. ; Never Returns
  56. ;
  57. ;--
  58. EXTRNP _BaseThreadStart,2
  59. cPublicProc _BaseThreadStartThunk,2
  60. xor ebp,ebp
  61. push ebx
  62. push eax
  63. push 0
  64. jmp _BaseThreadStart@8
  65. stdENDP _BaseThreadStartThunk
  66. ;++
  67. ;
  68. ; VOID
  69. ; BaseProcessStartThunk(
  70. ; IN LPVOID lpProcessStartAddress,
  71. ; IN LPVOID lpParameter
  72. ; );
  73. ;
  74. ; Routine Description:
  75. ;
  76. ; This function calls the process starter after moving
  77. ; its arguments from registers to the stack.
  78. ;
  79. ; Arguments:
  80. ;
  81. ; EAX - StartRoutine
  82. ; EBX - ProcessParameter
  83. ;
  84. ; Return Value:
  85. ;
  86. ; Never Returns
  87. ;
  88. ;--
  89. EXTRNP _BaseProcessStart,1
  90. cPublicProc _BaseProcessStartThunk,2
  91. xor ebp,ebp
  92. push eax
  93. push 0
  94. jmp _BaseProcessStart@4
  95. stdENDP _BaseProcessStartThunk
  96. ;++
  97. ;
  98. ; VOID
  99. ; SwitchToFiber(
  100. ; PFIBER NewFiber
  101. ; )
  102. ;
  103. ; Routine Description:
  104. ;
  105. ; This function saves the state of the current fiber and switches
  106. ; to the new fiber.
  107. ;
  108. ; Arguments:
  109. ;
  110. ; NewFiber (TOS+4) - Supplies the address of the new fiber.
  111. ;
  112. ; Return Value:
  113. ;
  114. ; None
  115. ;
  116. ;--
  117. cPublicProc _SwitchToFiber,1
  118. mov edx,fs:[PcTeb] ; edx is flat TEB
  119. mov eax,[edx]+TbFiberData ; eax points to current fiber
  120. ;
  121. ; Setup and save nonvolitile state
  122. ;
  123. mov ecx,esp
  124. mov [eax]+FbFiberContext+CsEbx,ebx
  125. mov [eax]+FbFiberContext+CsEdi,edi
  126. mov [eax]+FbFiberContext+CsEsi,esi
  127. mov [eax]+FbFiberContext+CsEbp,ebp
  128. mov ebx,[esp] ; get return address
  129. add ecx,8 ; adjust esp to account for args + ra
  130. mov [eax]+FbFiberContext+CsEsp,ecx
  131. mov [eax]+FbFiberContext+CsEip,ebx
  132. ;
  133. ; Save exception list, stack base, stack limit
  134. ;
  135. mov ecx,[edx]+PcExceptionList
  136. mov ebx,[edx]+PcStackLimit
  137. mov [eax]+FbExceptionList,ecx
  138. mov [eax]+FbStackLimit,ebx
  139. ;
  140. ; Now restore the new fiber
  141. ;
  142. mov eax,[esp]+4 ; eax is new fiber
  143. ;
  144. ; now restore new fiber TEB state
  145. ;
  146. mov ecx,[eax]+FbExceptionList
  147. mov ebx,[eax]+FbStackBase
  148. mov esi,[eax]+FbStackLimit
  149. mov edi,[eax]+FbDeallocationStack
  150. mov [edx]+PcExceptionList,ecx
  151. mov [edx]+PcInitialStack,ebx
  152. mov [edx]+PcStackLimit,esi
  153. mov [edx]+TbDeallocationStack,edi
  154. ;
  155. ; Restore FiberData
  156. ;
  157. mov [edx]+TbFiberData,eax
  158. ;
  159. ; Restore new fiber nonvolitile state
  160. ;
  161. mov edi,[eax]+FbFiberContext+CsEdi
  162. mov esi,[eax]+FbFiberContext+CsEsi
  163. mov ebp,[eax]+FbFiberContext+CsEbp
  164. mov ebx,[eax]+FbFiberContext+CsEbx
  165. mov ecx,[eax]+FbFiberContext+CsEip
  166. mov esp,[eax]+FbFiberContext+CsEsp
  167. jmp ecx
  168. stdENDP _SwitchToFiber
  169. ;++
  170. ;
  171. ; VOID
  172. ; LdrpCallInitRoutine(
  173. ; IN PDLL_INIT_ROUTINE InitRoutine,
  174. ; IN PVOID DllHandle,
  175. ; IN ULONG Reason,
  176. ; IN PCONTEXT Context OPTIONAL
  177. ; )
  178. ;
  179. ; Routine Description:
  180. ;
  181. ; This function calls an x86 DLL init routine. It is robust
  182. ; against DLLs that don't preserve EBX or fail to clean up
  183. ; enough stack.
  184. ;
  185. ; The only register that the DLL init routine cannot trash is ESI.
  186. ;
  187. ; Arguments:
  188. ;
  189. ; InitRoutine - Address of init routine to call
  190. ;
  191. ; DllHandle - Handle of DLL to call
  192. ;
  193. ; Reason - one of the DLL_PROCESS_... or DLL_THREAD... values
  194. ;
  195. ; Context - context pointer or NULL
  196. ;
  197. ; Return Value:
  198. ;
  199. ; FALSE if the init routine fails, TRUE for success.
  200. ;
  201. ;--
  202. cPublicProc __ResourceCallEnumLangRoutine , 6
  203. EnumRoutine equ [ebp + 8]
  204. ModuleHandle equ [ebp + 12]
  205. LpType equ [ebp + 16]
  206. LpName equ [ebp + 20]
  207. WLanguage equ [ebp + 24]
  208. LParam equ [ebp + 28]
  209. stdENDP __ResourceCallEnumLangRoutine
  210. push ebp
  211. mov ebp, esp
  212. push esi ; save esi across the call
  213. push edi ; save edi across the call
  214. push ebx ; save ebx on the stack across the call
  215. mov esi,esp ; save the stack pointer in esi across the call
  216. push LParam
  217. push WLanguage
  218. push LpName
  219. push LpType
  220. push ModuleHandle
  221. call EnumRoutine
  222. mov esp,esi ; restore the stack pointer in case callee forgot to clean up
  223. pop ebx ; restore ebx
  224. pop edi ; restore edi
  225. pop esi ; restore esi
  226. pop ebp
  227. stdRET __ResourceCallEnumLangRoutine
  228. cPublicProc __ResourceCallEnumNameRoutine , 5
  229. EnumRoutine equ [ebp + 8]
  230. ModuleHandle equ [ebp + 12]
  231. LpType equ [ebp + 16]
  232. LpName equ [ebp + 20]
  233. LParam equ [ebp + 24]
  234. stdENDP __ResourceCallEnumNameRoutine
  235. push ebp
  236. mov ebp, esp
  237. push esi ; save esi across the call
  238. push edi ; save edi across the call
  239. push ebx ; save ebx on the stack across the call
  240. mov esi,esp ; save the stack pointer in esi across the call
  241. push LParam
  242. push LpName
  243. push LpType
  244. push ModuleHandle
  245. call EnumRoutine
  246. mov esp,esi ; restore the stack pointer in case callee forgot to clean up
  247. pop ebx ; restore ebx
  248. pop edi ; restore edi
  249. pop esi ; restore esi
  250. pop ebp
  251. stdRET __ResourceCallEnumNameRoutine
  252. cPublicProc __ResourceCallEnumTypeRoutine , 4
  253. EnumRoutine equ [ebp + 8]
  254. ModuleHandle equ [ebp + 12]
  255. LpType equ [ebp + 16]
  256. LParam equ [ebp + 20]
  257. stdENDP __ResourceCallEnumTypeRoutine
  258. push ebp
  259. mov ebp, esp
  260. push esi ; save esi across the call
  261. push edi ; save edi across the call
  262. push ebx ; save ebx on the stack across the call
  263. mov esi,esp ; save the stack pointer in esi across the call
  264. push LParam
  265. push LpType
  266. push ModuleHandle
  267. call EnumRoutine
  268. mov esp,esi ; restore the stack pointer in case callee forgot to clean up
  269. pop ebx ; restore ebx
  270. pop edi ; restore edi
  271. pop esi ; restore esi
  272. pop ebp
  273. stdRET __ResourceCallEnumTypeRoutine
  274. _TEXT ends
  275. end