Leaked source code of windows server 2003
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.

374 lines
9.9 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. .586p
  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 PARA PUBLIC 'CODE'
  31. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  32. page ,132
  33. subttl "BaseThreadStartThunk"
  34. ;++
  35. ;
  36. ; VOID
  37. ; BaseThreadStartThunk(
  38. ; IN PTHREAD_START_ROUTINE StartRoutine,
  39. ; IN PVOID ThreadParameter
  40. ; )
  41. ;
  42. ; Routine Description:
  43. ;
  44. ; This function calls to the portable thread starter after moving
  45. ; its arguments from registers to the stack.
  46. ;
  47. ; Arguments:
  48. ;
  49. ; EAX - StartRoutine
  50. ; EBX - ThreadParameter
  51. ;
  52. ; Return Value:
  53. ;
  54. ; Never Returns
  55. ;
  56. ;--
  57. EXTRNP _BaseThreadStart,2
  58. cPublicProc _BaseThreadStartThunk,2
  59. xor ebp,ebp
  60. push ebx
  61. push eax
  62. push 0
  63. jmp _BaseThreadStart@8
  64. stdENDP _BaseThreadStartThunk
  65. ;++
  66. ;
  67. ; VOID
  68. ; BaseProcessStartThunk(
  69. ; IN LPVOID lpProcessStartAddress,
  70. ; IN LPVOID lpParameter
  71. ; );
  72. ;
  73. ; Routine Description:
  74. ;
  75. ; This function calls the process starter after moving
  76. ; its arguments from registers to the stack.
  77. ;
  78. ; Arguments:
  79. ;
  80. ; EAX - StartRoutine
  81. ; EBX - ProcessParameter
  82. ;
  83. ; Return Value:
  84. ;
  85. ; Never Returns
  86. ;
  87. ;--
  88. EXTRNP _BaseProcessStart,1
  89. cPublicProc _BaseProcessStartThunk,2
  90. xor ebp,ebp
  91. push eax
  92. push 0
  93. jmp _BaseProcessStart@4
  94. stdENDP _BaseProcessStartThunk
  95. ;++
  96. ;
  97. ; VOID
  98. ; SwitchToFiber(
  99. ; PFIBER NewFiber
  100. ; )
  101. ;
  102. ; Routine Description:
  103. ;
  104. ; This function saves the state of the current fiber and switches
  105. ; to the new fiber.
  106. ;
  107. ; Arguments:
  108. ;
  109. ; NewFiber (TOS+4) - Supplies the address of the new fiber.
  110. ;
  111. ; Return Value:
  112. ;
  113. ; None
  114. ;
  115. ;--
  116. LDMXCSR macro
  117. db 0Fh, 0AEh, 051h, 028h ; ldmxcsr FbFiberContext+CsDr6[eax]
  118. endm
  119. STMXCSR macro
  120. db 0Fh, 0AEh, 058h, 028h ; stmxcsr FbFiberContext+CsDr6[eax]
  121. endm
  122. FLOAT_SAVE equ FbFiberContext + CsFloatSave
  123. SAVE_FLOATING equ CONTEXT_FULL or CONTEXT_FLOATING_POINT
  124. XMMI_AVAILABLE equ UsProcessorFeatures + PF_XMMI_INSTRUCTIONS_AVAILABLE
  125. cPublicProc _SwitchToFiber,1
  126. ;
  127. ; Save current fiber context.
  128. ;
  129. mov edx, fs:[PcTeb] ; get TEB address
  130. mov eax, [edx]+TeFiberData ; get current fiber address
  131. ;
  132. ; Save nonvolatile integer registers.
  133. ;
  134. mov [eax]+FbFiberContext+CsEbx, ebx ;
  135. mov [eax]+FbFiberContext+CsEdi, edi ;
  136. mov [eax]+FbFiberContext+CsEsi, esi ;
  137. mov [eax]+FbFiberContext+CsEbp, ebp ;
  138. ;
  139. ; Save floating state if specified.
  140. ;
  141. cmp dword ptr [eax]+FbFiberContext+CsContextFlags, SAVE_FLOATING ; check for save
  142. jne short STF10 ; if ne, no floating environment switched
  143. fstsw [eax]+FLOAT_SAVE+FpStatusWord ; save status word
  144. fnstcw [eax]+FLOAT_SAVE+FpControlWord ; save control word
  145. cmp byte ptr ds:[MM_SHARED_USER_DATA_VA+XMMI_AVAILABLE], 1 ; check for XMMI support
  146. jne short STF10 ; if ne, XMMI not supported
  147. STMXCSR ; stmxcsr [eax]+FbFiberContext+CsDr6
  148. ;
  149. ; Save stack pointer and fiber local storage data structure address.
  150. ;
  151. STF10: mov [eax]+FbFiberContext+CsEsp, esp ; save stack pointer
  152. mov ecx, [edx]+TeFlsData ;
  153. mov [eax]+FbFlsData, ecx ;
  154. ;
  155. ; Save exception list and stack limit.
  156. ;
  157. mov ecx, [edx]+TeExceptionList ;
  158. mov ebx, [edx]+TeStackLimit ;
  159. mov [eax]+FbExceptionList, ecx ;
  160. mov [eax]+FbStackLimit, ebx ;
  161. ;
  162. ; Restore new fiber context.
  163. ;
  164. mov ecx, [esp]+4 ; get new fiber address
  165. mov [edx]+TeFiberData, ecx ; set fiber address
  166. ;
  167. ; Restore exception list, stack base, stack limit, and deallocation stack.
  168. ;
  169. mov esi, [ecx]+FbExceptionList ;
  170. mov ebx, [ecx]+FbStackBase ;
  171. mov [edx]+TeExceptionList, esi ;
  172. mov [edx]+TeStackBase, ebx ;
  173. mov esi, [ecx]+FbStackLimit ;
  174. mov ebx, [ecx]+FbDeallocationStack ;
  175. mov [edx]+TeStackLimit, esi ;
  176. mov [edx]+TeDeallocationStack, ebx ;
  177. ;
  178. ; Restore floating state if specified.
  179. ;
  180. cmp dword ptr [ecx]+FbFiberContext+CsContextFlags, SAVE_FLOATING ; check for save
  181. jne short STF40 ; if ne, no floating environment switched
  182. ;
  183. ; If the old floating control and status words are equal to the new control
  184. ; and status words, then there is no need to load any legacy floating state.
  185. ;
  186. mov ebx, [eax]+FLOAT_SAVE+FpStatusWord ; get previous status word
  187. cmp bx, [ecx]+FLOAT_SAVE+FpStatusWord ; check if status words equal
  188. jne short STF20 ; if ne, status words not equal
  189. mov ebx, [eax]+FLOAT_SAVE+FpControlWord ; get previous control word
  190. cmp bx, [ecx]+FLOAT_SAVE+FpControlWord ; check if control words equal
  191. je short STF30 ; if e, control words equal
  192. STF20: mov word ptr [ecx]+FLOAT_SAVE+FpTagWord, 0ffffh ; set tag word
  193. fldenv [ecx]+FLOAT_SAVE ; restore floating environment
  194. STF30: cmp byte ptr ds:[MM_SHARED_USER_DATA_VA+XMMI_AVAILABLE], 1 ; check for XMMI support
  195. jne short STF40 ; if ne, XMMI not supported
  196. LDMXCSR ; ldmxcsr [eax]+FbFiberContext+CsDr6
  197. ;
  198. ; Restore nonvolitile integer registers.
  199. ;
  200. STF40: mov edi, [ecx]+FbFiberContext+CsEdi ;
  201. mov esi, [ecx]+FbFiberContext+CsEsi ;
  202. mov ebp, [ecx]+FbFiberContext+CsEbp ;
  203. mov ebx, [ecx]+FbFiberContext+CsEbx ;
  204. ;
  205. ; Restore stack address and fiber local storage data structure address.
  206. ;
  207. mov eax, [ecx]+FbFlsData ;
  208. mov [edx]+TeFlsData, eax ;
  209. mov esp, [ecx]+FbFiberContext+CsEsp ;
  210. stdRET _SwitchToFiber
  211. stdENDP _SwitchToFiber
  212. ;++
  213. ;
  214. ; VOID
  215. ; LdrpCallInitRoutine(
  216. ; IN PDLL_INIT_ROUTINE InitRoutine,
  217. ; IN PVOID DllHandle,
  218. ; IN ULONG Reason,
  219. ; IN PCONTEXT Context OPTIONAL
  220. ; )
  221. ;
  222. ; Routine Description:
  223. ;
  224. ; This function calls an x86 DLL init routine. It is robust
  225. ; against DLLs that don't preserve EBX or fail to clean up
  226. ; enough stack.
  227. ;
  228. ; The only register that the DLL init routine cannot trash is ESI.
  229. ;
  230. ; Arguments:
  231. ;
  232. ; InitRoutine - Address of init routine to call
  233. ;
  234. ; DllHandle - Handle of DLL to call
  235. ;
  236. ; Reason - one of the DLL_PROCESS_... or DLL_THREAD... values
  237. ;
  238. ; Context - context pointer or NULL
  239. ;
  240. ; Return Value:
  241. ;
  242. ; FALSE if the init routine fails, TRUE for success.
  243. ;
  244. ;--
  245. cPublicProc __ResourceCallEnumLangRoutine , 6
  246. EnumRoutine equ [ebp + 8]
  247. ModuleHandle equ [ebp + 12]
  248. LpType equ [ebp + 16]
  249. LpName equ [ebp + 20]
  250. WLanguage equ [ebp + 24]
  251. LParam equ [ebp + 28]
  252. stdENDP __ResourceCallEnumLangRoutine
  253. push ebp
  254. mov ebp, esp
  255. push esi ; save esi across the call
  256. push edi ; save edi across the call
  257. push ebx ; save ebx on the stack across the call
  258. mov esi,esp ; save the stack pointer in esi across the call
  259. push LParam
  260. push WLanguage
  261. push LpName
  262. push LpType
  263. push ModuleHandle
  264. call EnumRoutine
  265. mov esp,esi ; restore the stack pointer in case callee forgot to clean up
  266. pop ebx ; restore ebx
  267. pop edi ; restore edi
  268. pop esi ; restore esi
  269. pop ebp
  270. stdRET __ResourceCallEnumLangRoutine
  271. cPublicProc __ResourceCallEnumNameRoutine , 5
  272. EnumRoutine equ [ebp + 8]
  273. ModuleHandle equ [ebp + 12]
  274. LpType equ [ebp + 16]
  275. LpName equ [ebp + 20]
  276. LParam equ [ebp + 24]
  277. stdENDP __ResourceCallEnumNameRoutine
  278. push ebp
  279. mov ebp, esp
  280. push esi ; save esi across the call
  281. push edi ; save edi across the call
  282. push ebx ; save ebx on the stack across the call
  283. mov esi,esp ; save the stack pointer in esi across the call
  284. push LParam
  285. push LpName
  286. push LpType
  287. push ModuleHandle
  288. call EnumRoutine
  289. mov esp,esi ; restore the stack pointer in case callee forgot to clean up
  290. pop ebx ; restore ebx
  291. pop edi ; restore edi
  292. pop esi ; restore esi
  293. pop ebp
  294. stdRET __ResourceCallEnumNameRoutine
  295. cPublicProc __ResourceCallEnumTypeRoutine , 4
  296. EnumRoutine equ [ebp + 8]
  297. ModuleHandle equ [ebp + 12]
  298. LpType equ [ebp + 16]
  299. LParam equ [ebp + 20]
  300. stdENDP __ResourceCallEnumTypeRoutine
  301. push ebp
  302. mov ebp, esp
  303. push esi ; save esi across the call
  304. push edi ; save edi across the call
  305. push ebx ; save ebx on the stack across the call
  306. mov esi,esp ; save the stack pointer in esi across the call
  307. push LParam
  308. push LpType
  309. push ModuleHandle
  310. call EnumRoutine
  311. mov esp,esi ; restore the stack pointer in case callee forgot to clean up
  312. pop ebx ; restore ebx
  313. pop edi ; restore edi
  314. pop esi ; restore esi
  315. pop ebp
  316. stdRET __ResourceCallEnumTypeRoutine
  317. _TEXT ends
  318. end