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.

410 lines
12 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_KERNEL equ 01000h
  53. DBF_USER equ 00800h
  54. DBF_GDI equ 00400h
  55. DBF_MMSYSTEM equ 00040h
  56. DBF_PENWIN equ 00020h
  57. DBF_APPLICATION equ 00010h
  58. DBF_DRIVER equ 00008h
  59. ;--------------------------------------------------------------------------
  60. AssertF macro reg
  61. local assert_ok
  62. ifdef DEBUG
  63. or reg,reg
  64. jnz assert_ok
  65. int 3
  66. assert_ok:
  67. endif
  68. endm
  69. AssertT macro reg
  70. local assert_ok
  71. ifdef DEBUG
  72. or reg,reg
  73. jz assert_ok
  74. int 3
  75. assert_ok:
  76. endif
  77. endm
  78. ;--------------------------------------------------------------------------
  79. ;
  80. ; DebugErr() macro
  81. ;
  82. ifdef DEBUG_RETAIL
  83. externFP _DebugOutput ; in KERNEL (3.1 or above)
  84. DebugErr macro flags,msg
  85. local a,b
  86. push cs
  87. push offset a
  88. push flags or DBF_DRIVER
  89. call _DebugOutput
  90. add sp,6
  91. jmp short b
  92. a:
  93. db "MSVIDEO: "
  94. db msg
  95. db 13,10,0
  96. b:
  97. endm
  98. else ; DEBUG
  99. DebugErr macro flags,msg
  100. endm
  101. endif ; DEBUG
  102. ;--------------------------------------------------------------------------
  103. ; Define the return address as a type using the DefD macro in order to
  104. ; be able to pass it as a parameter to the LogParamError function.
  105. ReturnAddr equ (dword ptr [bp+2])
  106. DefD ReturnAddr
  107. ;--------------------------------------------------------------------------
  108. NSTYPE equ 00007h ; Segment type mask
  109. NSCODE equ 00000h ; Code segment
  110. NSDATA equ 00001h ; Data segment
  111. NSITER equ 00008h ; Iterated segment flag
  112. NSMOVE equ 00010h ; Movable segment flag
  113. NSPURE equ 00020h ; Pure segment flag
  114. NSPRELOAD equ 00040h ; Preload segment flag
  115. NSRELOC equ 00100h ; Segment has relocations
  116. NSDEBUG equ 00200h ; Segment has debug info
  117. NSDPL equ 00C00h ; 286 DPL bits
  118. NSDISCARD equ 01000h ; Discard bit for segment
  119. CODEINFO struc
  120. ns_sector dw ? ; File sector of start of segment
  121. ns_cbseg dw ? ; Number of bytes in file
  122. ns_flags dw ? ; Attribute flags
  123. ns_minalloc dw ? ; Minimum allocation in bytes
  124. ns_handle dw ? ; handle to object
  125. ns_align dw ? ; file alignment
  126. CODEINFO ends
  127. DSC_CODE_BIT equ 08h
  128. ;--------------------------------------------------------------------------
  129. externA __AHINCR
  130. externA __WINFLAGS
  131. externFP LogParamError ;(WORD wError, FARPROC lpfn, DWORD dValue);
  132. externFP IsWindow ;(HWND hwnd);
  133. externFP GetCodeInfo ;(FARPROC lpfnProc, LPVOID lpSegInfo);
  134. externFP GetCurrentTask ;(void);
  135. externFP IsTask ;(HANDLE hTask);
  136. ; Windows internal pointer validation tools.
  137. externFP IsBadReadPtr ;(LPVOID lp, WORD cb);
  138. externFP IsBadWritePtr ;(LPVOID lp, WORD cb);
  139. externFP IsBadHugeReadPtr ;(LPVOID lp, DWORD cb);
  140. externFP IsBadHugeWritePtr ;(LPVOID lp, DWORD cb);
  141. externFP IsBadCodePtr ;(FARPROC lp);
  142. externFP IsBadStringPtr ;(LPSTR lpsz, WORD wMaxLen);
  143. externFP IsSharedSelector ;(WORD wSelector);
  144. ;--------------------------------------------------------------------------
  145. sBegin Data
  146. sEnd Data
  147. ;--------------------------------------------------------------------------
  148. ;;;createSeg _TEXT, CodeRes, word, public, CODE
  149. ;;;createSeg FIX, CodeFix, word, public, CODE
  150. createSeg MSVIDEO, CodeRes, word, public, CODE
  151. sBegin CodeRes
  152. assumes cs, CodeRes
  153. assumes ds, Data
  154. ;--------------------------------------------------------------------------
  155. ; @doc INTERNAL
  156. ;
  157. ; @func BOOL | ValidateReadPointer | validates that a pointer is valid to
  158. ; read from.
  159. ;
  160. ; @parm LPVOID | lpPoint| pointer to validate
  161. ; @parm DWORD | dLen | supposed length of said pointer
  162. ;
  163. ; @rdesc Returns TRUE if <p> is a valid pointer
  164. ; Returns FALSE if <p> is not a valid pointer
  165. ;
  166. ; @comm will generate error if the pointer is invalid
  167. ;
  168. cProc ValidateReadPointer, <FAR, PUBLIC, PASCAL> <>
  169. parmD lpPoint
  170. parmD dLen
  171. cBegin
  172. cCall IsBadHugeReadPtr, <lpPoint, dLen>
  173. or ax,ax
  174. jz ValidateReadPointer_Exit ; Return TRUE
  175. cCall LogParamError, <ERR_BAD_PTR, ReturnAddr, lpPoint>
  176. mov ax,-1 ; Return FALSE
  177. ValidateReadPointer_Exit:
  178. not ax
  179. cEnd
  180. ;--------------------------------------------------------------------------
  181. ; @doc INTERNAL
  182. ;
  183. ; @func BOOL | ValidateWritePointer | validates that a pointer is valid to
  184. ; write to.
  185. ;
  186. ; @parm LPVOID | lpPoint| pointer to validate
  187. ; @parm DWORD | dLen | supposed length of said pointer
  188. ;
  189. ; @rdesc Returns TRUE if <p> is a valid pointer
  190. ; Returns FALSE if <p> is not a valid pointer
  191. ;
  192. ; @comm will generate error if the pointer is invalid
  193. ;
  194. cProc ValidateWritePointer, <FAR, PUBLIC, PASCAL> <>
  195. parmD lpPoint
  196. parmD dLen
  197. cBegin
  198. cCall IsBadHugeWritePtr, <lpPoint, dLen>
  199. or ax,ax ; If not fail,
  200. jz ValidateWritePointer_Exit ; Return TRUE
  201. cCall LogParamError, <ERR_BAD_PTR, ReturnAddr, lpPoint>
  202. mov ax,-1 ; Return FALSE
  203. ValidateWritePointer_Exit:
  204. not ax
  205. cEnd
  206. ;--------------------------------------------------------------------------
  207. ; @doc INTERNAL
  208. ;
  209. ; @func WORD | ValidDriverCallback |
  210. ;
  211. ; validates that a driver callback is valid, to be valid a driver
  212. ; callback must be a valid window, task, or a function in a FIXED DLL
  213. ; code segment.
  214. ;
  215. ; @parm DWORD | dwCallback | callback to validate
  216. ; @parm WORD | wFlags | driver callback flags
  217. ;
  218. ; @rdesc Returns 0 if <dwCallback> is a valid callback
  219. ; Returns error condition if <dwCallback> is not a valid callback
  220. ;
  221. cProc ValidDriverCallback, <NEAR, PASCAL> <>
  222. parmD dCallback
  223. parmW wFlags
  224. localV ci, %(SIZE CODEINFO)
  225. cBegin
  226. mov ax, wFlags ; switch on callback type
  227. and ax, DCB_TYPEMASK
  228. errnz <DCB_NULL>
  229. jnz ValidDriverCallback_Window ; case DCB_NULL
  230. jmp ValidDriverCallback_Exit ; return zero for success
  231. ValidDriverCallback_Window:
  232. dec ax
  233. errnz <DCB_WINDOW - 1>
  234. jnz ValidDriverCallback_Task ; case DCB_WINDOW
  235. cmp dCallback.hi, 0 ; HIWORD must be NULL
  236. jnz ValidDriverCallback_BadWindow ; Set error
  237. push dCallback.lo ; Check for valid HWND
  238. cCall IsWindow, <>
  239. or ax, ax ; If HWND,
  240. jnz ValidDriverCallback_Success ; Set successful return
  241. ValidDriverCallback_BadWindow: ; Else set error return
  242. mov ax, ERR_BAD_HWND
  243. jmp ValidDriverCallback_Exit ; Return error
  244. ValidDriverCallback_Task:
  245. dec ax
  246. errnz <DCB_TASK - 2>
  247. jnz ValidDriverCallback_Function ; case DCB_TASK
  248. cmp dCallback.hi, 0 ; HIWORD must be NULL
  249. jnz ValidDriverCallback_BadTask ; Set error
  250. push dCallback.lo ; Check for valid Task
  251. cCall IsTask, <>
  252. or ax, ax ; If Task,
  253. jnz ValidDriverCallback_Success ; Set successful return
  254. ValidDriverCallback_BadTask: ; Else set error return
  255. mov ax, ERR_BAD_HANDLE
  256. jmp ValidDriverCallback_Exit ; Return error
  257. ValidDriverCallback_Function:
  258. dec ax
  259. errnz <DCB_FUNCTION - 3> ; case DCB_FUNCTION
  260. jnz ValidDriverCallback_Default
  261. lea ax, ci
  262. cCall GetCodeInfo, <dCallback, ss, ax>
  263. or ax, ax
  264. jz ValidDriverCallback_BadFunction ; Set error return
  265. mov ax, ci.ns_flags ; Check for valid flags
  266. and ax, NSDATA or NSMOVE or NSDISCARD
  267. jz ValidDriverCallback_Exit ; Return zero for success
  268. jnz ValidDriverCallback_BadFunction
  269. ValidDriverCallback_Default:
  270. mov ax, ERR_BAD_FLAGS ; default to error condition
  271. jmp ValidDriverCallback_Exit
  272. ValidDriverCallback_Success:
  273. xor ax, ax
  274. ValidDriverCallback_Exit:
  275. cEnd
  276. ValidDriverCallback_BadFunction: ; Else set error return
  277. DebugErr DBF_ERROR, "Driver callbacks MUST be in a FIXED segment of a DLL."
  278. mov ax, ERR_BAD_FUNC_PTR
  279. jmp ValidDriverCallback_Exit ; Return error
  280. ;--------------------------------------------------------------------------
  281. ; @doc INTERNAL
  282. ;
  283. ; @func BOOL | ValidateDriverCallback |
  284. ;
  285. ; validates that a driver callback is valid, to be valid a driver
  286. ; callback must be a valid window, task, or a function in a FIXED DLL
  287. ; code segment.
  288. ;
  289. ; @parm DWORD | dwCallback | callback to validate
  290. ; @parm WORD | wFlags | driver callback flags
  291. ;
  292. ; @rdesc Returns TRUE if <dwCallback> is a valid callback
  293. ; Returns FALSE if <dwCallback> is not a valid callback
  294. ;
  295. ; @comm will generate error if the callback is invalid
  296. ;
  297. cProc ValidateDriverCallback, <FAR, PUBLIC, PASCAL> <>
  298. parmD dCallback
  299. parmW wFlags
  300. cBegin
  301. cCall ValidDriverCallback, <dCallback, wFlags>
  302. or ax, ax ; If no error return
  303. jz ValidateDriverCallback_Exit ; Return TRUE
  304. cCall LogParamError, <ax, ReturnAddr, dCallback>
  305. mov ax, -1 ; Return FALSE
  306. ValidateDriverCallback_Exit:
  307. not ax
  308. cEnd
  309. ;--------------------------------------------------------------------------
  310. ; @doc INTERNAL
  311. ;
  312. ; @func BOOL | ValidateCallback |
  313. ;
  314. ; validates that a callback is valid.
  315. ;
  316. ; @parm FARPROC | dCallback | callback to validate
  317. ;
  318. ; @rdesc Returns TRUE if <lpfnCallback> is a valid callback
  319. ; Returns FALSE if <lpfnCallback> is not a valid callback
  320. ;
  321. ; @comm will generate error if the callback is invalid
  322. ;
  323. cProc ValidateCallback, <FAR, PUBLIC, PASCAL> <>
  324. parmD dCallback
  325. cBegin
  326. cCall IsBadCodePtr, <dCallback>
  327. or ax,ax ; If not fail,
  328. jz ValidateCallback_Exit ; Return TRUE
  329. cCall LogParamError, <ERR_BAD_FUNC_PTR, ReturnAddr, dCallback>
  330. mov ax, -1 ; Return FALSE
  331. ValidateCallback_Exit:
  332. not ax
  333. cEnd
  334. ;--------------------------------------------------------------------------
  335. ; @doc INTERNAL
  336. ;
  337. ; @func BOOL | ValidateString | Validates taht a string is valid
  338. ;
  339. ;
  340. ; validates that a callback is valid.
  341. cProc ValidateString, <FAR, PUBLIC, PASCAL> <>
  342. parmD lsz
  343. parmW max_len
  344. cBegin
  345. cCall IsBadStringPtr, <lsz, max_len> ; Maximum length
  346. or ax,ax ; If not fail,
  347. jz ValidateString_Exit ; Return TRUE
  348. cCall LogParamError, <ERR_BAD_STRING_PTR, ReturnAddr, lsz>
  349. mov ax, -1 ; Return FALSE
  350. ValidateString_Exit:
  351. not ax
  352. cEnd
  353. sEnd
  354. end