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.

575 lines
13 KiB

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