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.

385 lines
10 KiB

  1. TITLE LDAPPL - AppLoader Interface
  2. IFNDEF NO_APPLOADER ;* entire file for AppLoader
  3. .xlist
  4. include kernel.inc
  5. include newexe.inc
  6. include tdb.inc
  7. include appl.inc
  8. include protect.inc
  9. .list
  10. DataBegin
  11. externW pGlobalHeap
  12. DataEnd
  13. sBegin CODE
  14. externNP SetOwner
  15. externFP set_discarded_sel_owner
  16. sEnd CODE
  17. externFP MyOpenFile
  18. externFP FarLoadSegment
  19. externFP FarMyAlloc
  20. externNP Int21Handler
  21. IF KDEBUG ;See comment below where this function is used
  22. externFP AppLoaderEntProcAddress
  23. ELSE
  24. externFP FarEntProcAddress
  25. ENDIF
  26. externFP GlobalHandle
  27. externFP Far_get_temp_sel
  28. externFP Far_free_temp_sel
  29. sBegin NRESCODE
  30. assumes CS,NRESCODE
  31. assumes DS,NOTHING
  32. assumes ES,NOTHING
  33. externNP MapDSToDATA
  34. ;-----------------------------------------------------------------------;
  35. ; BootAppl ;
  36. ; ;
  37. ; Boots (i.e. starts) an AppLoader application ;
  38. ; Loads (and relocates) first segment (must be CODE/FIXED/PRELOAD) ;
  39. ; Validates the APPL magic word ;
  40. ; Calls APPL boot procedure ;
  41. ; ;
  42. ; Arguments: ;
  43. ; parmW hexe (handle to exe header) ;
  44. ; parmW fh (file handle) ;
  45. ; ;
  46. ; Returns: ;
  47. ; AX != 0 => ok ;
  48. ; ;
  49. ; Error Returns: ;
  50. ; AX == 0 => error ;
  51. ; ;
  52. ; Registers Preserved: ;
  53. ; ;
  54. ; Registers Destroyed: ;
  55. ; ;
  56. ; Calls: ;
  57. ; various ;
  58. ; ;
  59. ; History: ;
  60. ; ;
  61. ; Thu Oct 01, 1987 11:10:06a -by- David N. Weise [davidw] ;
  62. ; Changed the return values to NOT return ZF. ;
  63. ; ;
  64. ; Thu Jul 30, 1987 11:56:34a -by- Scott A. Randell [scottra] ;
  65. ; Created it. ;
  66. ;-----------------------------------------------------------------------;
  67. cProc BootAppl,<NEAR,PUBLIC>,<si>
  68. parmW hexe
  69. parmW fh
  70. cBegin BootAppl
  71. mov es,hexe
  72. mov si,es:[ne_segtab] ;* es:si => segtab
  73. mov ax,es:[si].ns_flags ;* first segment
  74. test ax,NSMOVE
  75. jnz @f ;* PMode loader will set the
  76. jmp bal_error ;* moveable flag for us
  77. @@:
  78. test ax,NSPRELOAD
  79. jz bal_error ;* must be preload
  80. ;* * load in first segment (turn off Alloced/Loaded, and DS requirement)
  81. and ax,not NSALLOCED+NSLOADED+NSUSESDATA
  82. mov es:[si].ns_flags,ax ;* update flags
  83. mov ax,1 ;* first segment
  84. cCall FarLoadSegment,<es,ax,fh,fh>
  85. jcxz bal_fail ;* not enough memory
  86. ;* * now validate APPL header
  87. mov es,ax
  88. push es
  89. cCall Far_get_temp_sel
  90. xor bx,bx ;* es:bx => first segment
  91. cmp es:[bx].magicAppl,magicApplCur ;* current version ?
  92. ;* (no backward compatibility)
  93. jne bal_error_popes
  94. ;* * fill in global information
  95. mov word ptr es:[bx].lppsMob,dataOffset pGlobalHeap
  96. mov ax,codeBase ;* segment address of FIXED KERNEL
  97. push ds
  98. call MapDStoData
  99. mov word ptr es:[bx].lppsMob+2,ds ;* segment address of krnl data
  100. pop ds
  101. mov word ptr es:[bx].pfnKernelAlloc,codeOffset FarMyAlloc
  102. mov word ptr es:[bx].pfnKernelAlloc+2,ax
  103. ; In DEBUG, we really want RIPs to be able to happen when we don't
  104. ; find ordinals. This saves an enormous amount of debugging
  105. ; time!! The entry point AppLoaderEntProcAddress only exists
  106. ; in debug and allows RIPs to happen (unlike FarEntProcAddress
  107. ; which is the same entry point used for GetProcAddress which
  108. ; should not RIP).
  109. IF KDEBUG
  110. mov word ptr es:[bx].pfnEntProcAddress,codeOffset AppLoaderEntProcAddress
  111. ELSE
  112. mov word ptr es:[bx].pfnEntProcAddress,codeOffset FarEntProcAddress
  113. ENDIF
  114. mov word ptr es:[bx].pfnEntProcAddress+2,ax
  115. ;* * extra entry for Protect Mode only
  116. mov word ptr es:[bx].pfnSetOwner,codeOffset MySetOwner
  117. mov word ptr es:[bx].pfnSetOwner+2,ax
  118. mov ax,es
  119. pop es
  120. cCall Far_free_temp_sel,<ax>
  121. ;* * call the start procedure
  122. cCall es:[pfnBootAppl], <hexe, fh> ;* returns BOOL
  123. bal_end: ;* ax
  124. cEnd BootAppl
  125. bal_error_popes: ;* an error occured (pop es if in PMODE)
  126. mov ax,es
  127. pop es
  128. cCall Far_free_temp_sel,<ax>
  129. bal_error: ;* an error occured
  130. if KDEBUG
  131. int 3
  132. endif
  133. bal_fail: ;* Boot failed (not enough memory)
  134. xor ax,ax
  135. jmps bal_end
  136. ;-----------------------------------------------------------------------;
  137. ; ExitAppl ;
  138. ; ;
  139. ; Exit last instance of an APPLOADER application ;
  140. ; ;
  141. ; Arguments: ;
  142. ; parmW hexe (handle to exe header) ;
  143. ; ;
  144. ; Returns: ;
  145. ; N/A ;
  146. ; ;
  147. ; History: ;
  148. ; ;
  149. ; Sat Sep 19, 1987 15:55:19 -by- Scott A. Randell [scottra] ;
  150. ; Created it ;
  151. ;-----------------------------------------------------------------------;
  152. cProc ExitAppl,<NEAR,PUBLIC>
  153. parmW hexe
  154. cBegin ExitAppl
  155. ; The apps with loaders don't do anything in their exit code except try
  156. ; to close a bogus file handle, so we just will not make this call
  157. ; anymore. This call runs on the kernel PSP, so if the app picked a valid
  158. ; kernel file handle, that file got closed. 0 seems to be a popular
  159. ; handle to inadvertently close. Newer apps do/will not have their own
  160. ; loaders.
  161. ifdef DEAD_CODE ;--------------------------------------------------------
  162. mov es,hexe
  163. mov bx,es:[ne_segtab] ;* es:si => segtab
  164. ;* * first segment is the AppLoader
  165. mov ax,es:[bx].ns_handle ;* handle
  166. or ax, ax ; Out of memory, couldn't load segment?
  167. jz exa_error
  168. HtoS ax ;* back to ring 1
  169. push bx
  170. lar bx, ax
  171. test bh, DSC_PRESENT ; Fix a WinWord bug
  172. pop bx
  173. jz exa_error
  174. mov es,ax
  175. ;* * test to make sure that an APPL is there
  176. cmp es:[magicAppl],magicApplCur
  177. jne exa_error
  178. ; The following hack sets up SS to have a 64k limit before calling the
  179. ; app's exit procedure. Added 12/18/90 to work around a bug in the
  180. ; Excel & WinWord app loader that references a bogus offset from SS. In
  181. ; the past the stack segment at this point already had a large limit, but
  182. ; when the data segment was moved out of the kernel's code segment and
  183. ; the limit decreased to the actual DS size, the Excel/WinWord offset
  184. ; is now beyond the segment limit.
  185. push ss ;save current SS
  186. push es ;seg 1 handle
  187. smov es,ss ;get temp selector takes
  188. cCall far_get_temp_sel ; and returns selector in ES
  189. smov ss,es ;SS now has max limit
  190. pop es ;seg 1 handle
  191. cCall es:[pfnExitAppl], <hexe>
  192. mov ax,ss ;return to original SS and
  193. pop ss ; free temp selector
  194. cCall far_free_temp_sel,<ax>
  195. exa_error:
  196. endif ;DEAD_CODE -------------------------------------------------
  197. cEnd ExitAppl
  198. sEnd NRESCODE
  199. sBegin CODE
  200. assumes CS,CODE
  201. ;-----------------------------------------------------------------------;
  202. ; LoadApplSegment ;
  203. ; ;
  204. ; Load an APPL segment ;
  205. ; open file if not already open ;
  206. ; tests to make sure 1st segment is an APPL loader ;
  207. ; call the Apploader requesting segment be loaded ;
  208. ; NOTE : never call for first segment ;
  209. ; ;
  210. ; Arguments: ;
  211. ; parmW hexe (handle to exe header) ;
  212. ; parmW fh (file handle (may be -1)) ;
  213. ; parmW segno (segment #) ;
  214. ; ;
  215. ; Returns: ;
  216. ; NZ, AX != 0 => ok, AX = segment where loaded, DX = handle of seg;
  217. ; ;
  218. ; Error Returns: ;
  219. ; Z, AX == 0 => error ;
  220. ; ;
  221. ; Registers Preserved: ;
  222. ; ;
  223. ; Registers Destroyed: ;
  224. ; ;
  225. ; Calls: ;
  226. ; various ;
  227. ; ;
  228. ; History: ;
  229. ; ;
  230. ; Thu Jul 30, 1987 11:56:34a -by- Scott A. Randell [scottra] ;
  231. ; Created it ;
  232. ;-----------------------------------------------------------------------;
  233. cProc LoadApplSegment,<NEAR,PUBLIC>,<si>
  234. parmW hexe
  235. parmW fh
  236. parmW segno
  237. localW myfh ;* private file handle
  238. ;* (if one shot open/close)
  239. cBegin LoadApplSegment
  240. mov es,hexe
  241. mov myfh,-1 ;* try with what is open first
  242. mov ax,fh
  243. las_retry: ;* ax = file handle
  244. mov si,es:[ne_segtab] ;* es:si => segtab
  245. ;* * first segment is the AppLoader
  246. mov si,es:[si].ns_handle ;* handle
  247. HtoS si ;* back to ring 1
  248. mov es,si
  249. ;* * test to make sure that an APPL is there
  250. cmp es:[magicAppl],magicApplCur ;* current version ?
  251. ;* (no backward compatibility)
  252. jne las_error
  253. ;* * Try to reload with the handle Windows has (may be -1)
  254. cCall es:[pfnReloadAppl], <hexe, ax, segno>
  255. ;* returns AX = segment
  256. or ax,ax
  257. jnz las_end ;* return AX != 0
  258. ;* * if the file handle was -1, open the file and try again
  259. cmp myfh,-1
  260. jne las_error ;* could not load with a file
  261. ;* * file is not open, open up temporary file (put handle in myfh)
  262. mov es,hexe
  263. mov dx,es:[ne_pfileinfo]
  264. regptr esdx,es,dx
  265. if SHARE_AWARE
  266. mov bx,OF_REOPEN or OF_PROMPT or OF_CANCEL or OF_VERIFY + OF_SHARE_DENY_WRITE
  267. else
  268. mov bx,OF_REOPEN or OF_PROMPT or OF_CANCEL or OF_VERIFY
  269. endif
  270. push dx
  271. Save <es>
  272. cCall MyOpenFile,<esdx,esdx,bx>
  273. pop dx
  274. mov myfh,ax
  275. cmp ax,-1
  276. jne las_retry
  277. las_error: ;* an error occured
  278. ;* * close file (if myfh != -1), then return error
  279. debug_out "LoadApplSegment failed - better find out why!"
  280. xor ax,ax
  281. las_end: ;* ax = return value
  282. mov bx,myfh
  283. inc bx
  284. jz las_no_temp_file
  285. dec bx
  286. push ax
  287. mov ah,3Eh ;* close file handle
  288. DOSCALL
  289. pop ax
  290. las_no_temp_file: ;* ax = return code
  291. or ax,ax
  292. cEnd LoadApplSegment
  293. ;-----------------------------------------------------------------------;
  294. ;-----------------------------------------------------------------------;
  295. ; MySetOwner ;
  296. ; ;
  297. ; Private version of SetOwner for present/non-present selectors ;
  298. ; ;
  299. ; Arguments: ;
  300. ; selector = selector (present or non-present) ;
  301. ; owner = new owner field ;
  302. ; ;
  303. ; History: ;
  304. ; ;
  305. ; Mon 04-Dec-1989 10:03:25 -by- David N. Weise [davidw] ;
  306. ; Made it call set_discarded_sel_owner instead of set_sel_limit. ;
  307. ; ;
  308. ; Mon Jul 03 20:37:22 1989 created -by- Scott A. Randell [scottra] ;
  309. ;-----------------------------------------------------------------------;
  310. cProc MySetOwner,<PUBLIC,FAR>, <SI, DI>
  311. parmW selector
  312. parmW owner
  313. cBegin
  314. cCall GlobalHandle,<selector>
  315. or dx,dx ;* 0 => not present
  316. jz set_owner_NP
  317. ;* * set owner for present selectors
  318. cCall SetOwner,<selector, owner>
  319. jmp short end_set_owner
  320. set_owner_NP:
  321. ;* NP selectors store the owner in the segment limit
  322. mov bx,selector
  323. mov es,owner
  324. call set_discarded_sel_owner
  325. end_set_owner:
  326. cEnd
  327. sEnd CODE
  328. endif ;!NO_APPLOADER (entire file)
  329. end