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.

203 lines
5.4 KiB

  1. ;; W32func.inc
  2. ;
  3. ; Definitions for 32-bit system functions available to 16-bit system
  4. ; code.
  5. ;
  6. ; CALL32
  7. ;
  8. ; Macro to call a 32-bit function from 16-bit code.
  9. ;
  10. ; Usage: CALL32 ProtoOrdinal, arg1, arg2, ..., argN
  11. ;
  12. ; ProtoOrdinal is a textequ of the format: "type, ordinal",
  13. ; where type is a typedef of the function prototype.
  14. ;
  15. ; Example:
  16. ;
  17. ; BlockThreadFun typedef proto far stdcall TimeOut:dword
  18. ; BlockThreadOrd equ 7
  19. ;
  20. ; ThkBlockThread textequ <BlockThreadFun, BlockThreadOrd>
  21. ;
  22. ; CALL32 ThkBlockThread, -1
  23. ;
  24. ;
  25. ; The stack is dword aligned, parameters are pushed, and a common
  26. ; routine is called to setup flat selectors and translate the 16-bit
  27. ; segmented stack pointer to flat.
  28. ;
  29. ; Note that parameters are NOT thunked, ie. it is the caller's
  30. ; responsibility to ensure parameters are suitable for the target
  31. ; function.
  32. ;
  33. ; Also note that registers EBX, ESI, and EDI are destroyed. The
  34. ; return value from the 32-bit function (in eax) is passed through
  35. ; unchanged.
  36. ;
  37. CALL32 macro ProtoOrdinal:req, arg:vararg
  38. local comma, ord, fun
  39. ;
  40. ; Parse ProtoOrdinal into its two components.
  41. ;
  42. comma instr ProtoOrdinal, <,> ; find the delimiter
  43. fun substr ProtoOrdinal, 1, &comma - 1 ; function prototype
  44. ord substr ProtoOrdinal, &comma + 1 ; ordinal
  45. push fs:[TIBSTRUCT.tib_ss16] ; save fs:[ss16]
  46. mov fs:[TIBSTRUCT.tib_ss16], ss ; set new fs:[ss16]
  47. mov bx, sp ; save the current sp value
  48. and sp, 0fffcH ; dword align sp
  49. push ebx ; save the old, unaligned, sp value
  50. mov bx, ord
  51. ifnb <arg>
  52. invoke fun ptr SystemThunk32, arg
  53. else
  54. invoke fun ptr SystemThunk32
  55. endif
  56. assume ds:nothing, es:nothing, fs:nothing, gs:nothing
  57. pop sp ; restore unaligned sp
  58. pop fs:[TIBSTRUCT.tib_ss16] ; restore fs:[ss16]
  59. endm
  60. ALIGNSTACK macro
  61. mov ax,sp ; save current sp value
  62. and sp,0fffch ; dword align sp
  63. push eax ; save unaligned sp value
  64. endm
  65. UNALIGNSTACK macro
  66. pop sp ; restore unaligned sp value
  67. endm
  68. CCALL32 macro ordinal, arg
  69. mov bx,ordinal
  70. cCall SystemThunk32, <arg>, C
  71. assume ds:nothing, es:nothing, fs:nothing, gs:nothing
  72. endm
  73. ;
  74. ; The Kernel32 export table is located at the beginning of the first object
  75. ; in the dll. Note that we don't have a way to enforce the specific location,
  76. ; we're just relying on the linker being consistent.
  77. ;
  78. KrnExportTableOffs equ 1000H
  79. ifndef WOW
  80. KrnExportTable equ Kernel32Base + KrnExportTableOffs
  81. endif
  82. KrnExportSignature equ 05058454BH ; "KEXP"
  83. ;
  84. ; The procedure for adding an export to the private kernel32 export table:
  85. ;
  86. ; 1. If you're doing this to add a 16->32 internal thunk, please reconsider.
  87. ; These thunks are slow and it's usually much easier to
  88. ; add a compiled thunk to krnthksl.thk. Ask AtsushiK how to
  89. ; do this if you don't know how.
  90. ; 2. Pick an available ordinal in the following list of ordinals.
  91. ; 3. Create a prototype typedef for the function in the list below
  92. ; (not necessary for data exports).
  93. ; 4. It's really better to use the thunk compiler. Are you sure you want
  94. ; to do this?
  95. ; 5. Create a ProtoOrdinal in the list below (not necessary for data exports).
  96. ; 6. Add the address of the function/data being exported to the kernel32
  97. ; export table defined in win32\kernel\krninit.asm.
  98. ;
  99. ; Ordinals of private 32-bit system entry points.
  100. ;
  101. KrnSignature equ 0 ; first slot is the signature
  102. KrnThunk16EntryTable equ 1 ; ptr to ptr to 16->32 thunk table
  103. KrnpptdbCur equ 2 ; ptr to ptr to current thread
  104. KrnInitialize equ 3 ; start up initialization
  105. KrnUninit equ 5 ; Called at Windows exit time
  106. KrnInitCrst equ 18 ; initialize critical section
  107. KrnDestroyCrst equ 19 ; destroy critical section
  108. KrnFT_RT_Win32Lock equ 24
  109. KrnQT_RT_Win32Lock equ 25
  110. KrnFT_RT_Win16Lock equ 26
  111. KrnQT_RT_Win16Lock equ 27
  112. KrnQT_RT_Win32NoLock equ 28
  113. ;
  114. ; Prototypes of 16->32 thunks
  115. ;
  116. fnInitialize typedef proto far stdcall :dword
  117. fnUninit typedef proto far stdcall
  118. fnInitCrst typedef proto far stdcall :dword
  119. fnDestroyCrst typedef proto far stdcall :dword
  120. ;
  121. ; ProtoOrdinals for use with the CALL32 macro
  122. ;
  123. ThkInitialize textequ <fnInitialize, KrnInitialize>
  124. ThkUninit textequ <fnUninit, KrnUninit>
  125. ThkInitCrst textequ <fnInitCrst, KrnInitCrst>
  126. ThkDestroyCrst textequ <fnDestroyCrst, KrnDestroyCrst>
  127. ;; CALL16
  128. ;
  129. ; Macro to call a 16-bit function from 32-bit code.
  130. ;
  131. ; Usage: CALL16 ordinal
  132. ;
  133. ; The stack pointer is switched to 16:16, and all registers are
  134. ; unmodified on both to/from 16-bit code.
  135. ;
  136. ; Note that Thunk16EntryTable points to the KERNEL16 (krnl386)
  137. ; entry table, which is below 1M. This memory is addressible by
  138. ; CS, but NOT DS.
  139. ;
  140. CALL16 macro ordinal
  141. local a
  142. push cs
  143. push offset a ; save our return address
  144. push eax
  145. mov eax, Thunk16EntryTable
  146. mov eax, cs:[eax][ordinal*4]
  147. xchg eax, [esp]
  148. db 066H, 0cbH ; far 16:16 ret
  149. a:
  150. endm
  151. ;
  152. ; Private 16-bit system entry points used by KERNEL32
  153. ;
  154. Krn16Int41 equ 0 ; wdeb386 interface
  155. Krn16Int21 equ 1 ; DOS interface
  156. ;;;Krn16Int31 equ 2 ; DPMI interface
  157. Krn16WOW equ 3 ; for WOW
  158. Krn16BopUnsimulate equ 4 ; for WOW
  159. Krn16FreeAll equ 9 ; gfreeall
  160. Krn16AllocSelArray equ 10 ; Allocs selectors
  161. Krn16FreeSel equ 11 ; FreeSelector()
  162. Krn16ThreadStartup equ 12 ; 16-bit entry point for CreateThread
  163. nKrn16Entries equ 16 ; the actual number of entries
  164. ;
  165. ; Wait termination status codes. BUGBUG--defined in multiple places.
  166. ;
  167. idWaitOK equ 0000h
  168. idWaitExit equ 0f01h
  169. idWaitIdle equ 0f02h