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.

710 lines
22 KiB

  1. ;--------------------------------------------------------------------------
  2. ifdef DEBUG
  3. DEBUG_RETAIL equ 1
  4. endif ; ifdef DEBUG
  5. ;--------------------------------------------------------------------------
  6. ?PLM = 1
  7. ?WIN = 0
  8. PMODE = 1
  9. .xlist
  10. include cmacros.inc
  11. include windows.inc
  12. include mmsystem.inc
  13. ; include logerror.inc
  14. include mmddk.inc
  15. .list
  16. ;--------------------------------------------------------------------------
  17. ;/* Error modifier bits */
  18. ERR_WARNING equ 08000h
  19. ERR_PARAM equ 04000h
  20. ;/* Generic parameter values */
  21. ERR_BAD_VALUE equ 06001h
  22. ERR_BAD_FLAGS equ 06002h
  23. ERR_BAD_INDEX equ 06003h
  24. ERR_BAD_DVALUE equ 07004h
  25. ERR_BAD_DFLAGS equ 07005h
  26. ERR_BAD_DINDEX equ 07006h
  27. ERR_BAD_PTR equ 07007h
  28. ERR_BAD_FUNC_PTR equ 07008h
  29. ERR_BAD_SELECTOR equ 06009h
  30. ERR_BAD_STRING_PTR equ 0700ah
  31. ERR_BAD_HANDLE equ 0600bh
  32. ;/* KERNEL parameter errors */
  33. ERR_BAD_HINSTANCE equ 06020h
  34. ERR_BAD_HMODULE equ 06021h
  35. ERR_BAD_GLOBAL_HANDLE equ 06022h
  36. ERR_BAD_LOCAL_HANDLE equ 06023h
  37. ERR_BAD_ATOM equ 06024h
  38. ERR_BAD_HFILE equ 06025h
  39. ;/* USER parameter errors */
  40. ERR_BAD_HWND equ 06040h
  41. ERR_BAD_HMENU equ 06041h
  42. ERR_BAD_HCURSOR equ 06042h
  43. ERR_BAD_HICON equ 06043h
  44. ERR_BAD_HDWP equ 06044h
  45. ERR_BAD_CID equ 06045h
  46. ERR_BAD_HDRVR equ 06046h
  47. DBF_TRACE equ 00000h
  48. DBF_WARNING equ 04000h
  49. DBF_ERROR equ 08000h
  50. DBF_FATAL equ 0c000h
  51. ; [Windows] DebugFilter and flags values
  52. DBF_INTERNAL equ 02000h
  53. DBF_KERNEL equ 01000h
  54. DBF_USER equ 00800h
  55. DBF_GDI equ 00400h
  56. DBF_COMPAT equ 00200h
  57. DBF_LOGERROR equ 00100h
  58. DBF_PARAMERROR equ 00080h
  59. DBF_MMSYSTEM equ 00040h
  60. DBF_PENWIN equ 00020h
  61. ;--------------------------------------------------------------------------
  62. AssertF macro reg
  63. local assert_ok
  64. ifdef DEBUG
  65. or reg,reg
  66. jnz assert_ok
  67. int 3
  68. assert_ok:
  69. endif
  70. endm
  71. AssertT macro reg
  72. local assert_ok
  73. ifdef DEBUG
  74. or reg,reg
  75. jz assert_ok
  76. int 3
  77. assert_ok:
  78. endif
  79. endm
  80. ;--------------------------------------------------------------------------
  81. ;
  82. ; DebugErr() macro
  83. ;
  84. ifdef DEBUG_RETAIL
  85. externFP _DebugOutput
  86. DebugErr macro flags,msg
  87. local a,b
  88. push cs
  89. push offset a
  90. push flags or DBF_MMSYSTEM
  91. call _DebugOutput
  92. add sp,6
  93. jmp short b
  94. a:
  95. db "MMSYSTEM: "
  96. db msg
  97. db 13,10,0
  98. b:
  99. endm
  100. else ; DEBUG
  101. DebugErr macro flags,msg
  102. endm
  103. endif ; DEBUG
  104. ;--------------------------------------------------------------------------
  105. ; Define the return address as a type using the DefD macro in order to
  106. ; be able to pass it as a parameter to the LogParamError function.
  107. ReturnAddr equ (dword ptr [bp+2])
  108. DefD ReturnAddr
  109. ;--------------------------------------------------------------------------
  110. NSTYPE equ 00007h ; Segment type mask
  111. NSCODE equ 00000h ; Code segment
  112. NSDATA equ 00001h ; Data segment
  113. NSITER equ 00008h ; Iterated segment flag
  114. NSMOVE equ 00010h ; Movable segment flag
  115. NSPURE equ 00020h ; Pure segment flag
  116. NSPRELOAD equ 00040h ; Preload segment flag
  117. NSRELOC equ 00100h ; Segment has relocations
  118. NSDEBUG equ 00200h ; Segment has debug info
  119. NSDPL equ 00C00h ; 286 DPL bits
  120. NSDISCARD equ 01000h ; Discard bit for segment
  121. CODEINFO struc
  122. ns_sector dw ? ; File sector of start of segment
  123. ns_cbseg dw ? ; Number of bytes in file
  124. ns_flags dw ? ; Attribute flags
  125. ns_minalloc dw ? ; Minimum allocation in bytes
  126. ns_handle dw ? ; handle to object
  127. ns_align dw ? ; file alignment
  128. CODEINFO ends
  129. DSC_CODE_BIT equ 08h
  130. ;--------------------------------------------------------------------------
  131. ;**************************************************************************;
  132. ; IF YOU CHANGE THESE TYPES YOU MUST ALSO CHANGE THE ONES IN MMSYSI.H
  133. ;**************************************************************************;
  134. TYPE_WAVEOUT equ 1
  135. TYPE_WAVEIN equ 2
  136. TYPE_MIDIOUT equ 3
  137. TYPE_MIDIIN equ 4
  138. TYPE_MMIO equ 5
  139. TYPE_IOPROC equ 6
  140. TYPE_MCI equ 7
  141. TYPE_DRVR equ 8
  142. TYPE_MIXER equ 9
  143. ;**************************************************************************;
  144. ;--------------------------------------------------------------------------
  145. ;**************************************************************************;
  146. ; IF YOU CHANGE THIS STRUCTURE YOU MUST ALSO CHANGE THE ONE IN MMSYSI.H
  147. ;**************************************************************************;
  148. HNDL struc
  149. hndlNext dw ? ; link to next handle
  150. hndlType dw ? ; type of handle wave, midi, mmio, ...
  151. hndlTask dw ? ; task that owns it
  152. HNDL ends
  153. ;**************************************************************************;
  154. ;--------------------------------------------------------------------------
  155. externW _pHandleList
  156. externA __AHINCR
  157. externA __WINFLAGS
  158. externFP LogParamError ;(WORD wError, FARPROC lpfn, DWORD dValue);
  159. externFP LocalAlloc ;(WORD fwFlags, WORD wSize);
  160. externFP LocalFree ;(LOCALHANDLE h);
  161. externFP IsWindow ;(HWND hwnd);
  162. externFP GetCodeInfo ;(FARPROC lpfnProc, LPVOID lpSegInfo);
  163. externFP GetCurrentTask ;(void);
  164. externFP IsTask ;(HANDLE hTask);
  165. ; Windows internal pointer validation tools.
  166. externFP IsBadReadPtr ;(LPVOID lp, WORD cb);
  167. externFP IsBadWritePtr ;(LPVOID lp, WORD cb);
  168. externFP IsBadHugeReadPtr ;(LPVOID lp, DWORD cb);
  169. externFP IsBadHugeWritePtr ;(LPVOID lp, DWORD cb);
  170. externFP IsBadCodePtr ;(FARPROC lp);
  171. externFP IsBadStringPtr ;(LPSTR lpsz, WORD wMaxLen);
  172. externFP IsSharedSelector ;(WORD wSelector);
  173. ;--------------------------------------------------------------------------
  174. sBegin Data
  175. sEnd Data
  176. ;--------------------------------------------------------------------------
  177. createSeg _TEXT, CodeRes, word, public, CODE
  178. createSeg FIX, CodeFix, word, public, CODE
  179. sBegin CodeRes
  180. assumes cs, CodeRes
  181. assumes ds, Data
  182. ;--------------------------------------------------------------------------
  183. ; @doc INTERNAL
  184. ;
  185. ; @func HANDLE | NewHandle | allocate a fixed handle in MMSYSTEM's local heap
  186. ;
  187. ; @parm WORD | wType | unique id describing handle type
  188. ; @parm WORD | wSize | size in bytes to be allocated
  189. ;
  190. ; @rdesc Returns pointer/handle to memory object
  191. ;
  192. ; @comm a standard handle header (HNDL) will be added to the object,
  193. ; and it will be linked into the list of MMSYSTEM handles.
  194. ;
  195. cProc NewHandle, <FAR, PUBLIC, PASCAL> <>
  196. parmW wType
  197. parmW wSize
  198. cBegin
  199. mov ax, wSize ; Attempt to allocate local memory
  200. add ax, SIZE HNDL ; Add header to requested size first
  201. cCall LocalAlloc, <LPTR, ax>
  202. AssertF ax
  203. or ax, ax
  204. jz NewHandle_Exit ; Return NULL
  205. mov bx, ax
  206. mov ax, [_pHandleList] ; Put the head of the list as the
  207. mov [bx].hndlNext, ax ; next pointer
  208. cCall GetCurrentTask, <>
  209. mov [bx].hndlTask, ax ; Set task for new handle
  210. mov ax, wType ; Set type for new handle
  211. mov [bx].hndlType, ax
  212. mov [_pHandleList], bx ; Make new handle head of list
  213. lea ax, [bx + SIZE HNDL] ; Return data portion of handle
  214. NewHandle_Exit:
  215. cEnd
  216. ;--------------------------------------------------------------------------
  217. ; @doc INTERNAL
  218. ;
  219. ; @func HANDLE | FreeHandle | free handle allocated with NewHandle
  220. ;
  221. ; @parm HANDLE | hLocal | handle returned from NewHandle
  222. ;
  223. ; @comm handle will be unlinked from list, and memory will be freed with
  224. ; LocalFree
  225. ;
  226. cProc FreeHandle, <FAR, PUBLIC, PASCAL> <>
  227. parmW hLocal
  228. cBegin
  229. mov ax, hLocal
  230. AssertF ax
  231. or ax, ax
  232. jz FreeHandle_Exit ; NULL handle returns NULL
  233. sub ax, SIZE HNDL ; Get real handle from data portion
  234. lea bx, [_pHandleList] ; Pointer to first pointer
  235. errnz hndlNext ; Assume this is the first element
  236. FreeHandle_Search:
  237. mov dx, [bx].hndlNext ; get pointer to next handle
  238. cmp dx, ax ; If this is the handle
  239. je FreeHandle_Free ; Free it
  240. mov bx, dx ; advance to next handle.
  241. or bx, bx ; Check for end of list
  242. jnz FreeHandle_Search
  243. AssertF bx ; bx == 0 force a fail
  244. jmp FreeHandle_Exit ; Handle not found, so return handle
  245. FreeHandle_Free:
  246. xchg ax, bx ; BX --> handle
  247. xor dx, dx ; Zero out entries for better debugging
  248. mov [bx].hndlType, dx
  249. mov [bx].hndlTask, dx
  250. xchg [bx].hndlNext, dx ; Get next handle in list
  251. xchg ax, bx ; BX --> prev handle
  252. mov [bx].hndlNext, dx ; update link
  253. cCall LocalFree, <ax> ; Free handle found, returning error
  254. AssertT ax
  255. FreeHandle_Exit:
  256. cEnd
  257. ;--------------------------------------------------------------------------
  258. ; @doc INTERNAL WAVE MIDI
  259. ;
  260. ; @func BOOL | ValidateHeader | validates a wave or midi date header
  261. ;
  262. ; @parm LPVOID | lpHeader| pointer to wave/midi header
  263. ; @parm WORD | wSize | size of header passed by app
  264. ; @parm WORD | wType | unique id describing header/handle type
  265. ;
  266. ; @rdesc Returns TRUE if <p> is non NULL and <wSize> is the correct size
  267. ; Returns FALSE otherwise
  268. ;
  269. ; @comm if the header is invalid an error will be generated.
  270. ;
  271. cProc ValidateHeader, <FAR, PUBLIC, PASCAL> <>
  272. parmD lpHeader
  273. parmW wSize
  274. parmW wType
  275. cBegin
  276. cCall IsBadWritePtr, <lpHeader, wSize>
  277. or ax, ax ; If fail,
  278. jnz vValidateHeader_Fail_Header_Ptr
  279. mov ax, wType
  280. mov dx, SIZE WAVEHDR ; assume WAVEHDR
  281. mov cx, not WHDR_VALID
  282. cmp ax, TYPE_WAVEIN ; If wave out
  283. jbe ValidateHeader_Size
  284. errnz TYPE_WAVEOUT-1
  285. errnz TYPE_WAVEIN-2
  286. mov dx, SIZE MIDIHDR ; Set MIDIHDR
  287. mov cx, not MHDR_VALID
  288. ValidateHeader_Size:
  289. cmp dx, wSize ; Compare against given size
  290. jne ValidateHeader_Fail_Size; Fail if wrong size, LogParamError
  291. les bx, lpHeader ; Load lpData pointer
  292. mov ax,es:[bx].dwWaveFlags.lo
  293. test ax,cx
  294. jnz ValidateHeader_Fail_Flags
  295. push es:[bx].lpWaveData.hi ; Validate data pointer
  296. push es:[bx].lpWaveData.lo
  297. push es:[bx].dwWaveBufferLength.hi
  298. push es:[bx].dwWaveBufferLength.lo
  299. cCall IsBadHugeWritePtr, <>
  300. or ax,ax
  301. jnz vValidateHeader_Fail_Buffer_Ptr
  302. errn$ ValidateHeader_Exit
  303. ValidateHeader_Exit:
  304. not ax
  305. cEnd
  306. ValidateHeader_Fail_Exit:
  307. mov ax, -1 ; Return FALSE
  308. jmp short ValidateHeader_Exit
  309. vValidateHeader_Fail_Header_Ptr:
  310. jmp ValidateHeader_Fail_Header_Ptr
  311. vValidateHeader_Fail_Buffer_Ptr:
  312. jmp ValidateHeader_Fail_Buffer_Ptr
  313. ValidateHeader_Fail_Size:
  314. DebugErr DBF_ERROR, "Invalid header size."
  315. cCall LogParamError, <ERR_BAD_VALUE, ReturnAddr, 0, wSize>
  316. jmp short ValidateHeader_Fail_Exit
  317. ValidateHeader_Fail_Flags:
  318. cCall LogParamError, <ERR_BAD_FLAGS, ReturnAddr, 0, ax>
  319. jmp short ValidateHeader_Fail_Exit
  320. ValidateHeader_Fail_Header_Ptr:
  321. DebugErr DBF_ERROR, "Invalid header pointer."
  322. cCall LogParamError, <ERR_BAD_PTR, ReturnAddr, lpHeader>
  323. jmp ValidateHeader_Fail_Exit
  324. ValidateHeader_Fail_Buffer_Ptr:
  325. DebugErr DBF_ERROR, "Invalid buffer pointer."
  326. push ERR_BAD_PTR
  327. push ReturnAddr.hi
  328. push ReturnAddr.lo
  329. les bx,lpHeader
  330. push es:[bx].lpWaveData.hi
  331. push es:[bx].lpWaveData.lo
  332. cCall LogParamError
  333. jmp ValidateHeader_Fail_Exit
  334. ;--------------------------------------------------------------------------
  335. ; @doc INTERNAL
  336. ;
  337. ; @func BOOL | ValidateReadPointer | validates that a pointer is valid to
  338. ; read from.
  339. ;
  340. ; @parm LPVOID | lpPoint| pointer to validate
  341. ; @parm DWORD | dLen | supposed length of said pointer
  342. ;
  343. ; @rdesc Returns TRUE if <p> is a valid pointer
  344. ; Returns FALSE if <p> is not a valid pointer
  345. ;
  346. ; @comm will generate error if the pointer is invalid
  347. ;
  348. cProc ValidateReadPointer, <FAR, PUBLIC, PASCAL> <>
  349. parmD lpPoint
  350. parmD dLen
  351. cBegin
  352. cCall IsBadHugeReadPtr, <lpPoint, dLen>
  353. or ax,ax
  354. jz ValidateReadPointer_Exit ; Return TRUE
  355. cCall LogParamError, <ERR_BAD_PTR, ReturnAddr, lpPoint>
  356. mov ax,-1 ; Return FALSE
  357. ValidateReadPointer_Exit:
  358. not ax
  359. cEnd
  360. ;--------------------------------------------------------------------------
  361. ; @doc INTERNAL
  362. ;
  363. ; @func BOOL | ValidateWritePointer | validates that a pointer is valid to
  364. ; write to.
  365. ;
  366. ; @parm LPVOID | lpPoint| pointer to validate
  367. ; @parm DWORD | dLen | supposed length of said pointer
  368. ;
  369. ; @rdesc Returns TRUE if <p> is a valid pointer
  370. ; Returns FALSE if <p> is not a valid pointer
  371. ;
  372. ; @comm will generate error if the pointer is invalid
  373. ;
  374. cProc ValidateWritePointer, <FAR, PUBLIC, PASCAL> <>
  375. parmD lpPoint
  376. parmD dLen
  377. cBegin
  378. cCall IsBadHugeWritePtr, <lpPoint, dLen>
  379. or ax,ax ; If not fail,
  380. jz ValidateWritePointer_Exit ; Return TRUE
  381. cCall LogParamError, <ERR_BAD_PTR, ReturnAddr, lpPoint>
  382. mov ax,-1 ; Return FALSE
  383. ValidateWritePointer_Exit:
  384. not ax
  385. cEnd
  386. ;--------------------------------------------------------------------------
  387. ; @doc INTERNAL
  388. ;
  389. ; @func WORD | ValidDriverCallback |
  390. ;
  391. ; validates that a driver callback is valid, to be valid a driver
  392. ; callback must be a valid window, task, or a function in a FIXED DLL
  393. ; code segment.
  394. ;
  395. ; @parm DWORD | dwCallback | callback to validate
  396. ; @parm WORD | wFlags | driver callback flags
  397. ;
  398. ; @rdesc Returns 0 if <dwCallback> is a valid callback
  399. ; Returns error condition if <dwCallback> is not a valid callback
  400. ;
  401. cProc ValidDriverCallback, <NEAR, PASCAL> <>
  402. parmD dCallback
  403. parmW wFlags
  404. localV ci, %(SIZE CODEINFO)
  405. cBegin
  406. mov ax, wFlags ; switch on callback type
  407. and ax, DCB_TYPEMASK
  408. errnz <DCB_NULL>
  409. jnz ValidDriverCallback_Window ; case DCB_NULL
  410. jmp ValidDriverCallback_Exit ; return zero for success
  411. ValidDriverCallback_Window:
  412. dec ax
  413. errnz <DCB_WINDOW - 1>
  414. jnz ValidDriverCallback_Task ; case DCB_WINDOW
  415. cmp dCallback.hi, 0 ; HIWORD must be NULL
  416. jnz ValidDriverCallback_BadWindow ; Set error
  417. push dCallback.lo ; Check for valid HWND
  418. cCall IsWindow, <>
  419. or ax, ax ; If HWND,
  420. jnz ValidDriverCallback_Success ; Set successful return
  421. ValidDriverCallback_BadWindow: ; Else set error return
  422. mov ax, ERR_BAD_HWND
  423. jmp ValidDriverCallback_Exit ; Return error
  424. ValidDriverCallback_Task:
  425. dec ax
  426. errnz <DCB_TASK - 2>
  427. jnz ValidDriverCallback_Function ; case DCB_TASK
  428. cmp dCallback.hi, 0 ; HIWORD must be NULL
  429. jnz ValidDriverCallback_BadTask ; Set error
  430. push dCallback.lo ; Check for valid Task
  431. cCall IsTask, <>
  432. or ax, ax ; If Task,
  433. jnz ValidDriverCallback_Success ; Set successful return
  434. ValidDriverCallback_BadTask: ; Else set error return
  435. mov ax, ERR_BAD_HANDLE
  436. jmp ValidDriverCallback_Exit ; Return error
  437. ValidDriverCallback_Function:
  438. dec ax
  439. errnz <DCB_FUNCTION - 3> ; case DCB_FUNCTION
  440. jnz ValidDriverCallback_Default
  441. lea ax, ci
  442. cCall GetCodeInfo, <dCallback, ss, ax>
  443. or ax, ax
  444. jz ValidDriverCallback_BadFunction ; Set error return
  445. mov ax, ci.ns_flags ; Check for valid flags
  446. and ax, NSDATA or NSMOVE or NSDISCARD
  447. jz ValidDriverCallback_Exit ; Return zero for success
  448. jnz ValidDriverCallback_BadFunction
  449. ValidDriverCallback_Default:
  450. mov ax, ERR_BAD_FLAGS ; default to error condition
  451. jmp ValidDriverCallback_Exit
  452. ValidDriverCallback_Success:
  453. xor ax, ax
  454. ValidDriverCallback_Exit:
  455. cEnd
  456. ValidDriverCallback_BadFunction: ; Else set error return
  457. DebugErr DBF_ERROR, "Driver callbacks MUST be in a FIXED segment of a DLL."
  458. mov ax, ERR_BAD_FUNC_PTR
  459. jmp ValidDriverCallback_Exit ; Return error
  460. ;--------------------------------------------------------------------------
  461. ; @doc INTERNAL
  462. ;
  463. ; @func BOOL | ValidateDriverCallback |
  464. ;
  465. ; validates that a driver callback is valid, to be valid a driver
  466. ; callback must be a valid window, task, or a function in a FIXED DLL
  467. ; code segment.
  468. ;
  469. ; @parm DWORD | dwCallback | callback to validate
  470. ; @parm WORD | wFlags | driver callback flags
  471. ;
  472. ; @rdesc Returns TRUE if <dwCallback> is a valid callback
  473. ; Returns FALSE if <dwCallback> is not a valid callback
  474. ;
  475. ; @comm will generate error if the callback is invalid
  476. ;
  477. cProc ValidateDriverCallback, <FAR, PUBLIC, PASCAL> <>
  478. parmD dCallback
  479. parmW wFlags
  480. cBegin
  481. cCall ValidDriverCallback, <dCallback, wFlags>
  482. or ax, ax ; If no error return
  483. jz ValidateDriverCallback_Exit ; Return TRUE
  484. cCall LogParamError, <ax, ReturnAddr, dCallback>
  485. mov ax, -1 ; Return FALSE
  486. ValidateDriverCallback_Exit:
  487. not ax
  488. cEnd
  489. ;--------------------------------------------------------------------------
  490. ; @doc INTERNAL
  491. ;
  492. ; @func BOOL | ValidateCallback |
  493. ;
  494. ; validates that a callback is valid.
  495. ;
  496. ; @parm FARPROC | dCallback | callback to validate
  497. ;
  498. ; @rdesc Returns TRUE if <lpfnCallback> is a valid callback
  499. ; Returns FALSE if <lpfnCallback> is not a valid callback
  500. ;
  501. ; @comm will generate error if the callback is invalid
  502. ;
  503. cProc ValidateCallback, <FAR, PUBLIC, PASCAL> <>
  504. parmD dCallback
  505. cBegin
  506. cCall IsBadCodePtr, <dCallback>
  507. or ax,ax ; If not fail,
  508. jz ValidateCallback_Exit ; Return TRUE
  509. cCall LogParamError, <ERR_BAD_FUNC_PTR, ReturnAddr, dCallback>
  510. mov ax, -1 ; Return FALSE
  511. ValidateCallback_Exit:
  512. not ax
  513. cEnd
  514. ;--------------------------------------------------------------------------
  515. ; @doc INTERNAL
  516. ;
  517. ; @func BOOL | ValidateString |
  518. ;
  519. cProc ValidateString, <FAR, PUBLIC, PASCAL> <>
  520. parmD lsz
  521. parmW max_len
  522. cBegin
  523. cCall IsBadStringPtr, <lsz, max_len> ; Maximum length
  524. or ax,ax ; If not fail,
  525. jz ValidateString_Exit ; Return TRUE
  526. cCall LogParamError, <ERR_BAD_STRING_PTR, ReturnAddr, lsz>
  527. mov ax, -1 ; Return FALSE
  528. ValidateString_Exit:
  529. not ax
  530. cEnd
  531. sEnd
  532. ;--------------------------------------------------------------------------
  533. sBegin CodeFix
  534. assumes cs, CodeFix
  535. assumes ds, nothing
  536. ;--------------------------------------------------------------------------
  537. ; @doc INTERNAL
  538. ;
  539. ; @func BOOL | ValidateHandle | validates a handle created with NewHandle
  540. ;
  541. ; @parm HANDLE | hLocal | handle returned from NewHandle
  542. ; @parm WORD | wType | unique id describing handle type
  543. ;
  544. ; @rdesc Returns TRUE if <h> is a valid handle of type <wType>
  545. ; Returns FALSE if <h> is not a valid handle
  546. ;
  547. ; @comm if the handle is invalid an error will be generated.
  548. ;
  549. ;--------------------------------------------------------------------------
  550. assumes ds, Data
  551. assumes es, nothing
  552. cProc ValidateHandle, <FAR, PUBLIC, PASCAL> <>
  553. parmW hLocal
  554. parmW wType
  555. cBegin
  556. mov bx, hLocal
  557. sub bx, SIZE HNDL ; Get actual handle
  558. jc ValidateHandle_Bad
  559. mov ax, ds
  560. lsl ax, ax ; Get DS limit
  561. cmp bx, ax ; Check for out of limit
  562. jae ValidateHandle_Bad
  563. mov ax,[bx].hndlType
  564. cmp ax, wType ; Compare handle type
  565. je ValidateHandle_Exit ; Types are the same, return TRUE
  566. ValidateHandle_Bad:
  567. add bx, SIZE HNDL
  568. cCall LogParamError, <ERR_BAD_HANDLE, ReturnAddr, 0, bx>
  569. xor ax, ax ; Return FALSE
  570. ValidateHandle_Exit:
  571. cEnd
  572. ;--------------------------------------------------------------------------
  573. ; @doc INTERNAL
  574. ;
  575. ; @func BOOL | ValidateTimerCallback |
  576. ;
  577. ; validates that a timer callback is valid, to be valid a driver
  578. ; callback must be a valid function in a FIXED DLL code segment.
  579. ;
  580. ; @parm LPTIMECALLBACK | lpfn | callback to validate
  581. ;
  582. ; @rdesc Returns TRUE if <lpfn> is a valid callback
  583. ; Returns FALSE if <lpfn> is not a valid callback
  584. ;
  585. ; @comm will generate error if the callback is invalid
  586. ;
  587. ;--------------------------------------------------------------------------
  588. assumes ds, nothing
  589. assumes es, nothing
  590. cProc ValidateTimerCallback, <FAR, PUBLIC, PASCAL> <>
  591. parmD lpfn
  592. cBegin
  593. mov ax, lpfn.hi
  594. lar bx, ax
  595. jnz ValidateTimerCallback_Fail ; Invalid segment
  596. test bh, DSC_CODE_BIT
  597. jz ValidateTimerCallback_Fail ; Not executable segment
  598. lsl cx, ax ; Get segment limit
  599. mov bx, lpfn.lo
  600. cmp bx, cx
  601. jae ValidateTimerCallback_Fail ; Invalid offset
  602. mov es, ax
  603. mov bx, es:[bx]+2
  604. cmp bx, 0581eH ; push ds, pop ax
  605. je ValidateTimerCallback_Fail ; Invalid entry point
  606. cmp bx, 0d88cH ; mov ax, ds
  607. jne ValidateTimerCallback_Exit ; Return TRUE
  608. ValidateTimerCallback_Fail:
  609. cCall LogParamError, <ERR_BAD_FUNC_PTR, ReturnAddr, lpfn>
  610. xor ax, ax ; Return FALSE
  611. ValidateTimerCallback_Exit:
  612. cEnd
  613. sEnd CodeFix
  614. ;--------------------------------------------------------------------------
  615. END