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.

566 lines
13 KiB

  1. .xlist
  2. include kernel.inc
  3. include pdb.inc
  4. include tdb.inc
  5. include newexe.inc
  6. .list
  7. externFP GlobalDOSAlloc
  8. externFP GlobalDOSFree
  9. externFP GetProfileString
  10. DataBegin
  11. externB kernel_flags
  12. externW MyCSAlias
  13. externW curTDB
  14. externW headTDB
  15. if 0 ; EarleH
  16. externW LastCriticalError
  17. endif
  18. externW LastExtendedError
  19. externD FatalExitProc
  20. DataEnd
  21. sBegin CODE
  22. assumes CS,CODE
  23. assumes ds, nothing
  24. assumes es, nothing
  25. externD PrevInt21Proc
  26. externNP SetOwner
  27. ;-----------------------------------------------------------------------;
  28. ; A20Proc ;
  29. ; Enable / Disable the A20 line by calling an XMS driver ;
  30. ; ;
  31. ; Arguments: ;
  32. ; ;
  33. ; Returns: ;
  34. ; ;
  35. ; Error Returns: ;
  36. ; ;
  37. ; Registers Preserved: ;
  38. ; ;
  39. ; Registers Destroyed: ;
  40. ; ;
  41. ; Calls: ;
  42. ; ;
  43. ; History: ;
  44. ; ;
  45. ; Thu Mar 31, 1988 -by- Tony Gosling ;
  46. ; ;
  47. ;-----------------------------------------------------------------------;
  48. assumes ds, nothing
  49. assumes es, nothing
  50. cProc A20Proc,<PUBLIC,FAR>,<si,di>
  51. parmW enable
  52. cBegin
  53. cEnd
  54. ;**
  55. ;
  56. ; NETBIOSCALL -- Issue an INT 5C for caller
  57. ;
  58. ; This call is provided as a Kernel service to applications that
  59. ; wish to issue NETBIOS INT 5Ch calls WITHOUT coding an INT 5Ch, which
  60. ; is incompatible with protected mode.
  61. ;
  62. ; ENTRY:
  63. ; All registers as for INT 5Ch
  64. ;
  65. ; EXIT:
  66. ; All registers as for particular INT 5Ch call
  67. ;
  68. ; USES:
  69. ; As per INT 5Ch call
  70. ;
  71. ;
  72. cProc NETBIOSCALL,<PUBLIC,FAR>
  73. cBegin
  74. int 5Ch
  75. cEnd
  76. ;**
  77. ;
  78. ; SetHandleCount -- Set the handle count in the PDB
  79. ;
  80. ; Sets the per process handle count to a new value
  81. ; and allocates space for these file handles
  82. ;
  83. ; ENTRY:
  84. ; nFiles - new number of file handles required
  85. ;
  86. ; EXIT:
  87. ; returns new number of file handles
  88. ;
  89. ; USES:
  90. ; C call
  91. ;
  92. ;
  93. cProc ISetHandleCount,<PUBLIC,FAR>,<di,si>
  94. parmW nFiles
  95. cBegin
  96. SetKernelDS
  97. mov si, CurTDB
  98. mov ds, si
  99. UnSetKernelDS
  100. mov ds, ds:[TDB_PDB]
  101. ;** We allow no more than 255. Also, if something smaller than what
  102. ;** we have, we just do nothing and respond with the number we
  103. ;** already have.
  104. mov ax, ds:[PDB_JFN_Length] ; How many now
  105. cmp nFiles,255 ;Validate the parameter
  106. jbe SHC_OK ;Parm OK
  107. IF KDEBUG
  108. push ax
  109. kerror ERR_PARAMETER,<SetHandleCount: Too many files requested:>,nFiles,0
  110. pop ax
  111. ENDIF
  112. mov nFiles,255 ;Force it to do no more than 255
  113. SHC_OK: mov bx, nFiles
  114. cmp ax, bx ; Don't want more?
  115. jae no_change
  116. ;** Allocate memory for a new file handle table
  117. add bx, 2
  118. cCall GlobalDOSAlloc, <0, bx>
  119. or ax, ax
  120. jnz ok_we_got_it
  121. mov ax, ds:[PDB_JFN_Length] ; Return original number
  122. jmp SHORT no_change
  123. ok_we_got_it:
  124. ;** Prepare the new table and update the PDB for the new table
  125. cCall SetOwner,<ax,si> ;Hide it from GlobalFreeAll
  126. mov es, ax ;Point to new table with ES
  127. mov WORD PTR ds:[PDB_JFN_Pointer][2], dx ;Save seg address
  128. xor di, di
  129. mov si, word ptr ds:[PDB_JFN_Pointer] ;Offset of old table
  130. mov cx, ds:[PDB_JFN_Length] ;Bytes to copy (one byte per handle)
  131. mov WORD PTR ds:[PDB_JFN_Pointer][0], di ;Save new offset
  132. mov bx, nFiles ;Save new number of files
  133. mov ds:[PDB_JFN_Length], bx
  134. push ds ;Save PDB selector for later
  135. ;** We use the PDB selector to copy if we're copying the original
  136. ;** table which is always in the PDB. Note that we only have a
  137. ;** non-zero offset if the table is in the PDB. We can't save
  138. ;** the selector in the table in this case until AFTER
  139. or si, si ;Table in PDB?
  140. jnz @F ;Yes
  141. mov ds, WORD PTR ds:[PDB_JFN_Table] ;Get old selector to copy from
  142. @@:
  143. ;** Copy the existing table into the new one
  144. cld
  145. rep movsb ;Copy existing files
  146. mov al, -1
  147. mov cx, nFiles
  148. sub cx, di
  149. rep stosb ;Pad new files with -1
  150. mov ax, ds
  151. pop bx ;Retrieve PDB selector
  152. mov ds, bx
  153. mov WORD PTR ds:[PDB_JFN_Table], es ;Save new selector
  154. ;** We only free the old table if it wasn't in the PDB
  155. cmp ax, bx ;Were we using the PDB selector?
  156. je SHC_OldTableInPDB ;Yes. Don't free it
  157. cCall GlobalDOSFree, <ax> ;Free old table
  158. SHC_OldTableInPDB:
  159. mov ax, nFiles
  160. no_change:
  161. cEnd
  162. ;-----------------------------------------------------------------------;
  163. ; GetSetKernelDOSProc ;
  164. ; Set the address kernel calls for DOS ;
  165. ; ;
  166. ; Arguments: ;
  167. ; ;
  168. ; Returns: ;
  169. ; ;
  170. ; Error Returns: ;
  171. ; ;
  172. ; Registers Preserved: ;
  173. ; ;
  174. ; Registers Destroyed: ;
  175. ; ;
  176. ; Calls: ;
  177. ; ;
  178. ; History: ;
  179. ; ;
  180. ; Fri Dec 31, 1990 -by- Tony Gosling ;
  181. ; ;
  182. ;-----------------------------------------------------------------------;
  183. assumes ds, nothing
  184. assumes es, nothing
  185. cProc GetSetKernelDOSProc,<PUBLIC,FAR>
  186. parmD NewProc
  187. cBegin
  188. SetKernelDS
  189. mov ds, MyCSAlias
  190. assumes ds, CODE
  191. mov ax, word ptr NewProc[0]
  192. xchg ax, word ptr PrevInt21Proc[0]
  193. mov dx, word ptr NewProc[2]
  194. xchg dx, word ptr PrevInt21Proc[2]
  195. cEnd
  196. ;-----------------------------------------------------------------------;
  197. ; FatalExitHook ;
  198. ; Hooks FatalExit ;
  199. ; ;
  200. ; Arguments: ;
  201. ; ;
  202. ; Returns: ;
  203. ; ;
  204. ; Error Returns: ;
  205. ; ;
  206. ; Registers Preserved: ;
  207. ; ;
  208. ; Registers Destroyed: ;
  209. ; ;
  210. ; Calls: ;
  211. ; ;
  212. ; History: ;
  213. ; ;
  214. ; Fri Dec 31, 1990 -by- Tony Gosling ;
  215. ; ;
  216. ;-----------------------------------------------------------------------;
  217. assumes ds, nothing
  218. assumes es, nothing
  219. cProc FatalExitHook,<PUBLIC,FAR>
  220. parmD NewProc
  221. cBegin
  222. SetKernelDS
  223. mov ax, word ptr NewProc[0]
  224. xchg ax, word ptr FatalExitProc[0]
  225. mov dx, word ptr NewProc[2]
  226. xchg dx, word ptr FatalExitProc[2]
  227. cEnd
  228. if 0 ; EarleH
  229. ;-----------------------------------------------------------------------;
  230. ; GetLastCriticalError ;
  231. ; Get the last int 24h error and extended error code ;
  232. ; ;
  233. ; Arguments: ;
  234. ; ;
  235. ; Returns: ;
  236. ; ;
  237. ; Error Returns: ;
  238. ; ;
  239. ; Registers Preserved: ;
  240. ; ;
  241. ; Registers Destroyed: ;
  242. ; ;
  243. ; Calls: ;
  244. ; ;
  245. ; History: ;
  246. ; ;
  247. ; Fri Dec 31, 1990 -by- Tony Gosling ;
  248. ; ;
  249. ;-----------------------------------------------------------------------;
  250. assumes ds, nothing
  251. assumes es, nothing
  252. cProc GetLastCriticalError,<PUBLIC,FAR>
  253. cBegin
  254. SetKernelDS
  255. mov ax, -1
  256. mov dx, ax
  257. xchg ax, LastExtendedError
  258. xchg dx, LastCriticalError
  259. cEnd
  260. endif ;0
  261. ;-----------------------------------------------------------------------;
  262. ; DWORD GetAppCompatFlags(HTASK hTask) ;
  263. ; ;
  264. ; Returns win.ini [Compatibility] flags for hTask (or current task ;
  265. ; if hTask is NULL). ;
  266. ; ;
  267. ; Arguments: ;
  268. ; ;
  269. ; Returns: ;
  270. ; ;
  271. ; Error Returns: ;
  272. ; ;
  273. ; Registers Preserved: ;
  274. ; ;
  275. ; All but DX:AX ;
  276. ; ;
  277. ; Registers Destroyed: ;
  278. ; ;
  279. ; DX, AX ;
  280. ; ;
  281. ; Calls: ;
  282. ; ;
  283. ; History: ;
  284. ; ;
  285. ;-----------------------------------------------------------------------;
  286. assumes ds, nothing
  287. assumes es, nothing
  288. cProc GetAppCompatFlags,<PUBLIC,FAR>,<DS>
  289. parmW hTask
  290. cBegin
  291. SetKernelDS
  292. mov ax,hTask
  293. or ax,ax
  294. jnz got_tdb
  295. mov ax,curTDB ; If no current task (e.g., during boot)
  296. cwd ; just return 0L.
  297. or ax,ax
  298. jz gacf_exit
  299. got_tdb:
  300. mov ds,ax
  301. UnSetKernelDS
  302. mov ax,ds:[TDB_CompatFlags]
  303. mov dx,ds:[TDB_CompatFlags2]
  304. gacf_exit:
  305. UnSetKernelDS
  306. cEnd
  307. ; Simpler (faster) NEAR version for Kernel -- only works for current task!
  308. ;
  309. ; Preserves all regs except dx:ax
  310. ;
  311. cProc MyGetAppCompatFlags,<PUBLIC,NEAR>
  312. cBegin nogen
  313. push ds
  314. SetKernelDS
  315. mov ax, curTDB
  316. cwd
  317. or ax, ax ; No current task while booting
  318. jz mygacf_exit
  319. mov ds, ax
  320. UnSetKernelDS
  321. mov ax, ds:[TDB_CompatFlags]
  322. mov dx, ds:[TDB_CompatFlags2]
  323. mygacf_exit:
  324. pop ds
  325. UnSetKernelDS
  326. ret
  327. cEnd nogen
  328. ifdef WOW
  329. cProc MyGetAppWOWCompatFlags,<PUBLIC,NEAR>
  330. cBegin nogen
  331. push ds
  332. SetKernelDS
  333. mov ax, curTDB
  334. cwd
  335. or ax, ax ; No current task while booting
  336. jz wow_mygacf_exit
  337. mov ds, ax
  338. UnSetKernelDS
  339. mov ax, ds:[TDB_WOWCompatFlags]
  340. mov dx, ds:[TDB_WOWCompatFlags2]
  341. wow_mygacf_exit:
  342. pop ds
  343. UnSetKernelDS
  344. ret
  345. cEnd nogen
  346. ;
  347. ; Returns WOW extended compatiblity flags
  348. ;
  349. ; Preserves all regs except dx:ax
  350. ;
  351. cProc MyGetAppWOWCompatFlagsEx,<PUBLIC,FAR>
  352. cBegin nogen
  353. push ds
  354. SetKernelDS
  355. mov ax, curTDB
  356. cwd
  357. or ax, ax ; No current task while booting
  358. jz wow_mygacfex_exit
  359. mov ds, ax
  360. UnSetKernelDS
  361. mov ax, ds:[TDB_WOWCompatFlagsEx]
  362. mov dx, ds:[TDB_WOWCompatFlagsEx2]
  363. wow_mygacfex_exit:
  364. pop ds
  365. UnSetKernelDS
  366. retf
  367. cEnd nogen
  368. ;---------------------------------------------------------------------------
  369. ; This gets called from FreeProcInstance. If the proc being freed is an
  370. ; AbortProc that was set by the app, we reset it to NULL. This way we dont
  371. ; callback to a proc that's garbage.
  372. ;
  373. ; This case happens with Aldus Pagemaker ver 5.0 when one prints to EPS file.
  374. ; The app sets the AbortProc and then later calls freeprocinstance.
  375. ; Subsequently when it make the call Escape(..OPENCHANNEL..) the callback
  376. ; occurs and we die randomly.
  377. ;
  378. ; This solution is a general solution.
  379. ; - Nanduri
  380. ;---------------------------------------------------------------------------
  381. cProc HandleAbortProc, <PUBLIC,FAR>, <ds, ax>
  382. ParmD pproc
  383. cBegin
  384. SetKernelDS
  385. mov ax, curTDB
  386. or ax, ax ; No current task while booting
  387. jz wow_aproc_exit
  388. mov ds, ax
  389. UnSetKernelDS
  390. mov ax, ds:[TDB_vpfnAbortProc+2]
  391. or ax, ax
  392. je wow_aproc_exit ; sel = 0 - no abort proc. done
  393. cmp ax, word ptr [pproc+2]
  394. jnz wow_aproc_exit ; selectors don't match
  395. mov ax, ds:[TDB_vpfnAbortProc]
  396. cmp ax, word ptr [pproc]
  397. jnz wow_aproc_exit ; offsets don't match
  398. mov ds:[TDB_vpfnAbortProc], 0 ; set abort proc to NULL.
  399. mov ds:[TDB_vpfnAbortProc+2], 0
  400. wow_aproc_exit:
  401. UnSetKernelDS
  402. cEnd
  403. endif ; WOW
  404. sEnd CODE
  405. sBegin NRESCODE
  406. assumes CS,NRESCODE
  407. ifndef WOW ; WOW thunks SetAppCompatFlags for special processing
  408. CompatSection DB 'Compatibility'
  409. DefVal DB 0
  410. cProc SetAppCompatFlags, <PUBLIC, NEAR>, <ds, es, si, di>
  411. localV szHex,12 ; read string to here
  412. localV key, <SIZE TDB_Modname + 2> ; ModName of loading app
  413. cBegin
  414. xor ax, ax
  415. cwd
  416. cmp es:[TDB_ExpWinVer], 400h ; Hacks don't apply to 4.0 or above
  417. jae sa_exit
  418. push es ; Copy ModName to zero-terminate it
  419. pop ds
  420. lea si, es:[TDB_ModName]
  421. push ss
  422. pop es
  423. lea di, key
  424. mov cx, SIZE TDB_Modname
  425. cld
  426. rep movsb
  427. stosb
  428. push cs
  429. push NREScodeoffset CompatSection
  430. push ss
  431. lea ax, key
  432. push ax
  433. push cs
  434. push NREScodeoffset DefVal
  435. push ss
  436. lea ax, szHex
  437. push ax
  438. push 12
  439. call GetProfileString
  440. cwd
  441. or ax, ax
  442. jz sa_exit
  443. xor dx,dx ; zero our value in dx:bx
  444. xor bx,bx
  445. push ss
  446. pop ds
  447. lea si, szHex
  448. lodsw ; String starts with '0x'
  449. and ah, not 20h
  450. cmp ax, 'X0'
  451. jnz sa_done
  452. sa_again:
  453. lodsb
  454. sub al, '0'
  455. jc sa_done
  456. cmp al, '9'-'0'
  457. jbe @F
  458. add al, '0'-'A'+10 ; map 'A'..F' to 10..15
  459. ; (lower case guys are 0x20 apart!)
  460. @@:
  461. add bx,bx ; value << 4;
  462. adc dx,dx
  463. add bx,bx
  464. adc dx,dx
  465. add bx,bx
  466. adc dx,dx
  467. add bx,bx
  468. adc dx,dx
  469. and al,0fh ; value |= (al & 0x0f);
  470. or bl,al
  471. jmps sa_again
  472. sa_done: ; DX:BX contains flags
  473. mov ax, bx
  474. cmp es:[TDB_ExpWinVer], 30Ah ; SOME hacks don't apply to 3.1 or above
  475. jb sa_end
  476. and dx, HIW_GACF_31VALIDMASK
  477. and ax, LOW_GACF_31VALIDMASK
  478. sa_end:
  479. sa_exit: ; DX:AX contains flags, or 0x00000000
  480. cEnd
  481. endif ; WOW
  482. cProc ValidateCodeSegments,<PUBLIC,FAR>
  483. cBegin nogen
  484. ret
  485. cEnd nogen
  486. sEnd NRESCODE
  487. end