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.

451 lines
10 KiB

  1. page ,132
  2. title ACMSTUB.ASM
  3. ;***********************************************************************
  4. ;* *
  5. ;* MODULE : ACMSTUB.ASM *
  6. ;* *
  7. ;* DESCRIPTION : Provide functions to allow run-time linking to *
  8. ;* the ACM. *
  9. ;* *
  10. ;* COPYRIGHT : Copyright 1991, Microsoft Corp. All Rights Reserved.*
  11. ;* *
  12. ;* Author: David Maymudes *
  13. ;* Based on similar code for MMSYSTEM by: *
  14. ;* Todd Laney and Matt Saettler - Multimedia Systems *
  15. ;* *
  16. ;***********************************************************************
  17. ;-----------------------------------------------------------------------
  18. ;
  19. ; Documentation (such as it is)
  20. ;
  21. ;------------------------------------------------------------------------
  22. ;
  23. ; Call function as you normally would. Include MSACM.H normally.
  24. ; However, instead of linking to MSACM.LIB, link to ACMSTUB.OBJ
  25. ;
  26. ; All functions will return error conditions if MSACM.DLL is not present.
  27. ;
  28. ; Because I'm lazy, the calling routine has to load the module into
  29. ; memory before calling any of this.
  30. ;------------------------------------------------------------------------
  31. page
  32. .286
  33. ?PLM=1 ; PASCAL Calling convention is DEFAULT
  34. ?WIN=0 ; Windows calling convention
  35. .xlist
  36. include cmacros.inc
  37. .list
  38. ;*********************************************************************
  39. ; CONSTANT DECLARATIONS
  40. ;*********************************************************************
  41. ifndef FALSE
  42. FALSE equ 0
  43. endif
  44. ifndef NULL
  45. NULL equ 0
  46. endif
  47. ifndef MMSYSERR_ERROR
  48. MMSYSERR_ERROR equ 1
  49. endif
  50. ;*********************************************************************
  51. ; EXTERN DECLARATIONS
  52. ;*********************************************************************
  53. externFP OutputDebugString
  54. externFP _wsprintf
  55. externFP GetProcAddress
  56. externFP GetModuleHandle
  57. ;ifdef DEBUG
  58. ; externFP __dprintf ; in DPRINTF.C
  59. ;endif
  60. ;*********************************************************************
  61. ; STRUCTURE DECLARATIONS
  62. ;*********************************************************************
  63. LONG struc
  64. lo dw ?
  65. hi dw ?
  66. LONG ends
  67. FARPOINTER struc
  68. off dw ?
  69. sel dw ?
  70. FARPOINTER ends
  71. PROCENTRY struc
  72. curproc dd ? ; see parameters to macros, below
  73. ordinal dw ?
  74. numparms dw ?
  75. errret dd ?
  76. ifdef DEBUG
  77. szProc db ?
  78. endif
  79. PROCENTRY ends
  80. MODENTRY struc
  81. hModule dw ?
  82. szModule db ?
  83. MODENTRY ends
  84. ;*********************************************************************
  85. ; DATA SEGMENT DECLARATIONS
  86. ;*********************************************************************
  87. ifndef SEGNAME
  88. SEGNAME equ <_TEXT>
  89. endif
  90. createSeg %SEGNAME, CodeSeg, word, public, CODE
  91. page
  92. ;*********************************************************************
  93. ; MACRO DECLARATIONS
  94. ;*********************************************************************
  95. ;
  96. ;------------------------------------------------------------------------------
  97. ;
  98. ; MACRO DOUT
  99. ;
  100. ; Parms:
  101. ;
  102. ; text Text to output using OutputDebugString when DEBUG is defined
  103. ; Text is automatically appended with CR/LF
  104. ;
  105. DOUT macro text
  106. local string_buffer
  107. ifdef DEBUG ; only do output if DEBUG is defined
  108. _DATA segment
  109. string_buffer label byte
  110. db "&text&",13,10,0
  111. _DATA ends
  112. pusha
  113. push DataBASE
  114. push DataOFFSET string_buffer
  115. call OutputDebugString
  116. popa
  117. endif
  118. endm
  119. ;
  120. ;------------------------------------------------------------------------------
  121. ;
  122. ; MACRO Begin_Module_Table
  123. ;
  124. ; Parms:
  125. ;
  126. ; Module_Name Name of Module to Run-Time-Link
  127. ;
  128. ; defines <Module_Name>_Proc Macro
  129. ;
  130. ; Use End_Module_Table to close
  131. Begin_Module_Table MACRO Module_Name
  132. sBegin DATA
  133. ifdef DEBUG
  134. public Module_Name&_Module_Table
  135. endif
  136. Module_Name&_Module_Table label word
  137. dw -1 ; hModule
  138. db "&Module_Name&",0
  139. sEnd Data
  140. sBegin CodeSeg
  141. assumes cs,CodeSeg
  142. assumes ds,Data
  143. assumes es,nothing
  144. ifdef DEBUG ; make public so debugger is aware of it
  145. public load&Module_Name
  146. endif
  147. ;
  148. ; entry:
  149. ; DS:BX --> ProcEntry for API being called
  150. ;
  151. load&Module_Name& proc far
  152. ; stack frame is not modified or copied
  153. ; vars are still in place
  154. mov ax,DataOFFSET Module_Name&_Module_Table
  155. jmp LoadModuleStub
  156. load&Module_Name& endp
  157. sEnd CodeSeg
  158. page
  159. ;
  160. ;------------------------------------------------------------------------------
  161. ;
  162. ; MACRO <Module_Name>_Proc
  163. ;
  164. ; Parms:
  165. ;
  166. ; Name of procedure Name of procedure to emulate
  167. ; ordinal of exported proc
  168. ; # of stack parms use 0 for CDECL routines
  169. ; error return value default error value for use by FailAPIStub
  170. ; fail proc defaults to FailAPIStub if not specified
  171. ; use custom 'fail' proc to replace functionlity
  172. ; if specified module/proc not found in system
  173. ;
  174. Module_Name&_Proc macro ProcName, Ordinal, sizestack, errret, failproc
  175. sBegin Data
  176. ifdef DEBUG
  177. public Module_Name&&Ordinal&
  178. endif
  179. Module_Name&&Ordinal& label word
  180. ifb <failproc>
  181. dd load&Module_Name
  182. dw &Ordinal
  183. dw &sizestack
  184. dd &errret
  185. else
  186. dd load&Module_Name
  187. dw &Ordinal
  188. dw -1
  189. dd &failproc
  190. endif
  191. ifdef DEBUG
  192. db "&ProcName&",0
  193. endif
  194. sEnd Data
  195. sBegin CodeSeg
  196. assumes cs,CodeSeg
  197. assumes ds,Data
  198. assumes es,nothing
  199. public &ProcName&
  200. &ProcName& proc far
  201. ; stack frame is not modified or copied
  202. ; vars are still in place
  203. mov bx,DataOFFSET Module_Name&&Ordinal&
  204. jmp [bx].curproc ; current proc
  205. &ProcName& endp
  206. sEnd CodeSeg
  207. endm
  208. endm
  209. page
  210. ;------------------------------------------------------------------------------
  211. ;
  212. ; MACRO End_Module_Table
  213. ;
  214. ; Parms
  215. ; Module_Name Must be the same as in Begin_Module_Table
  216. ;
  217. End_Module_Table macro Module_Name
  218. purge Module_Name&_Proc
  219. endm
  220. ;-----------------------------------------------------------------------------
  221. ;
  222. ; Helper routines for SHELL
  223. ;
  224. ;-----------------------------------------------------------------------------
  225. sBegin CodeSeg
  226. assumes cs,CodeSeg
  227. assumes ds,Data
  228. assumes es,nothing
  229. ;-----------------------------------------------------------------------------
  230. ;
  231. ; FailApiStub
  232. ;
  233. ; Default handler if Module or Proc Address is not found.
  234. ;
  235. ; returns default error code
  236. ;
  237. ; entry:
  238. ; DS:BX --> PROCENTRY
  239. ;
  240. FailApiStub proc far
  241. pop dx ; get return addr
  242. pop ax
  243. add sp,[bx].numparms ; remove params from stack
  244. push ax ; restore return addr
  245. push dx
  246. mov ax,[bx].errret.lo ; return fail code
  247. mov dx,[bx].errret.hi
  248. retf
  249. FailApiStub endp
  250. ;-----------------------------------------------------------------------------
  251. ;
  252. ; LoadModuleStub
  253. ;
  254. ; Initial handler for all procs. Attempts to load module (if not already
  255. ; loaded) and then gets proc address. If any errors, sets curproc to
  256. ; failproc for 'unavailable' processing.
  257. ;
  258. ; If successful, then sets curproc to imported function and calls it.
  259. ;
  260. ; entry:
  261. ; DS:BX --> PROCENTRY
  262. ; DS:AX --> MODENTRY
  263. ;
  264. ; NOTE: Assumes module is already loaded
  265. ;
  266. ; To be totally general:
  267. ; if can't GetModuleHandle(),
  268. ; needs to do a OpenFile(OF_EXIST,...) + LoadLibrary()
  269. ; needs to FreeLibrary() all DLLs at end/exit
  270. ;
  271. LoadModuleStub proc far
  272. ifdef DEBUG
  273. pusha
  274. sub sp,128
  275. mov si,sp
  276. mov di,ax ; DS:DI --> MODENTRY
  277. push [bx].ordinal ; %d
  278. lea ax,[bx].szProc ; %ls
  279. push ds
  280. push ax
  281. lea ax,[di].szModule ; %ls
  282. push ds
  283. push ax
  284. lea ax,format_string ; format string
  285. push cs
  286. push ax
  287. push ss ; buffer
  288. push si
  289. call _wsprintf
  290. add sp,9*2 ; clear 9 words
  291. cCall OutputDebugString,<ss,si>
  292. add sp,128
  293. popa
  294. jmp @f
  295. format_string:
  296. db "Linking %ls!%ls@%d",13,10,0
  297. @@:
  298. endif
  299. pusha
  300. mov si,ax ; ds:[si] --> MODENTRY
  301. mov di,bx ; ds:[di] --> PROCENTRY
  302. mov ax,[si].hModule
  303. or ax,ax
  304. jz LoadModuleStubFail ; module does not exist
  305. cmp ax,-1
  306. jne LoadModuleStubGetProc
  307. lea ax,[si].szModule
  308. cCall GetModuleHandle, <ds,ax>
  309. mov [si].hModule,ax
  310. or ax,ax
  311. jz LoadModuleStubLoad
  312. LoadModuleStubGetProc:
  313. cCall GetProcAddress,<ax,0,[di].ordinal>
  314. or dx,dx
  315. jz LoadModuleStubFail
  316. LoadModuleStubDone:
  317. mov [di].curproc.lo,ax
  318. mov [di].curproc.hi,dx
  319. popa
  320. jmp [bx].curproc
  321. LoadModuleStubLoad:
  322. ;; call load library here after verifying with OpenFile()
  323. ;
  324. ; for now, fall through to error
  325. LoadModuleStubFail:
  326. DOUT <*** API not found! ***>
  327. mov ax,CodeSegOFFSET FailApiStub
  328. mov dx,cs
  329. cmp [di].numparms,-1 ; do we have a fail proc?
  330. jne LoadModuleStubDone ; no...use FailApiStub
  331. mov ax,[di].errret.lo ; yes..it is stored in errret
  332. mov dx,[di].errret.hi
  333. jmp short LoadModuleStubDone ; use it
  334. LoadModuleStub endp
  335. sEnd CodeSeg
  336. page
  337. ;*********************************************************************
  338. ; CODE and DATA
  339. ;*********************************************************************
  340. ;
  341. ; Define SHELL Run-Time-Load Table
  342. Begin_Module_Table MSACM
  343. MSACM_Proc acmGetVersion 7, 0, 0
  344. MSACM_Proc acmFormatChoose 40, 4, MMSYSERR_ERROR
  345. MSACM_Proc acmMetrics 8, 8, MMSYSERR_ERROR
  346. ;
  347. ; end the MSACM R-T-L table
  348. End_Module_Table MSACM
  349. ;*********************************************************************
  350. ; STUB ROUTINES
  351. ;*********************************************************************
  352. ; no stub routines for MSACM.
  353. end