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.

839 lines
16 KiB

  1. /*++
  2. Copyright (c) 1991-1998 Microsoft Corporation
  3. Module Name:
  4. amlitest
  5. Abstract:
  6. Environment:
  7. kernel mode only
  8. Notes:
  9. --*/
  10. /*
  11. #include "wdm.h"
  12. #include "stdarg.h"
  13. #include "stdio.h" */
  14. #include "pch.h"
  15. //#include "amlihook.h"
  16. //#include "amlitest.h"
  17. #define AMLIHOOK_DEBUG_ASYNC_AMLI ((ULONG)0x1)
  18. #ifdef DBG
  19. ULONG AmliTestDebugFlags=0x00;
  20. #define AmliTest_DebugPrint(x) AmliTestDebugPrintFunc x
  21. CHAR AmliTestDebugBuffer[200];
  22. //
  23. // Internal functions.
  24. //
  25. VOID
  26. AmliTestDebugPrintFunc(
  27. ULONG DebugPrintLevel,
  28. PCCHAR DebugMessage,
  29. ...)
  30. {
  31. va_list ap;
  32. va_start(ap, DebugMessage);
  33. if(DebugPrintLevel & AmliTestDebugFlags)
  34. {
  35. if(_vsnprintf(AmliTestDebugBuffer,
  36. 200,
  37. DebugMessage,
  38. ap) < 0)
  39. {
  40. //
  41. // _vsnprintf failed, don't print out anything.
  42. //
  43. AmliTestDebugBuffer[0] = '\0';
  44. }
  45. AmliTestDebugBuffer[199] = '\0';
  46. DbgPrint(AmliTestDebugBuffer);
  47. }
  48. }
  49. #endif
  50. //
  51. // AMLITest_Post_Generic
  52. //
  53. NTSTATUS
  54. AMLITest_Post_Generic(
  55. PAMLIHOOK_DATA * ppData,
  56. NTSTATUS _Status)
  57. {
  58. //
  59. //--- Notify test driver off call status
  60. //
  61. NTSTATUS Status =
  62. AmliHook_TestNotifyRet(
  63. *ppData,
  64. _Status);
  65. ExFreePool(*ppData);
  66. *ppData = NULL;
  67. return(Status);
  68. }
  69. //
  70. // Exported functions.
  71. //
  72. //
  73. // Pre/Post GetNameSpaceObject
  74. //
  75. NTSTATUS
  76. AMLITest_Pre_GetNameSpaceObject(
  77. IN PSZ pszObjPath,
  78. IN PNSOBJ pnsScope,
  79. OUT PPNSOBJ ppns,
  80. IN ULONG dwfFlags,
  81. PAMLIHOOK_DATA * ppData)
  82. {
  83. //
  84. // Alocate and init AMLIHOOK_DATA
  85. //
  86. *ppData =
  87. AmliHook_AllocAndInitTestData();
  88. if(!(*ppData))
  89. {
  90. AmliHook_ProcessInternalError();
  91. return(STATUS_INSUFFICIENT_RESOURCES);
  92. }
  93. //
  94. //--- Notify test driver off call
  95. //
  96. (*ppData)->Type = ACPIVER_DATA_TYPE_AMLI;
  97. (*ppData)->SubType = ACPIVER_DATA_SUBTYPE_GET_NAME_SPACE_OBJECT;
  98. (*ppData)->State = AMLIHOOK_TEST_DATA_STATE_CALL;
  99. (*ppData)->Arg1 = (ULONG_PTR)pszObjPath;
  100. (*ppData)->Arg2 = (ULONG_PTR)pnsScope;
  101. (*ppData)->Arg3 = (ULONG_PTR)ppns;
  102. (*ppData)->Arg4 = (ULONG_PTR)dwfFlags;
  103. return(AmliHook_TestNotify(*ppData));
  104. }
  105. NTSTATUS
  106. AMLITest_Post_GetNameSpaceObject(
  107. PAMLIHOOK_DATA * ppData,
  108. NTSTATUS Status)
  109. {
  110. return(AMLITest_Post_Generic(ppData,Status));
  111. }
  112. //
  113. // Pre/Post GetFieldUnitRegionObj
  114. //
  115. NTSTATUS
  116. AMLITest_Pre_GetFieldUnitRegionObj(
  117. IN PFIELDUNITOBJ pfu,
  118. OUT PPNSOBJ ppns,
  119. PAMLIHOOK_DATA * ppData)
  120. {
  121. //
  122. // Allocate and init AMLIHOOK_DATA
  123. //
  124. *ppData =
  125. AmliHook_AllocAndInitTestData();
  126. if(!(*ppData))
  127. return(STATUS_INSUFFICIENT_RESOURCES);
  128. //
  129. //--- Notify test driver off call
  130. //
  131. (*ppData)->Type = ACPIVER_DATA_TYPE_AMLI;
  132. (*ppData)->SubType = ACPIVER_DATA_SUBTYPE_GET_FIELD_UNIT_REGION_OP;
  133. (*ppData)->State = AMLIHOOK_TEST_DATA_STATE_CALL;
  134. (*ppData)->Arg1 = (ULONG_PTR)pfu;
  135. (*ppData)->Arg2 = (ULONG_PTR)ppns;
  136. return(AmliHook_TestNotify(*ppData));
  137. }
  138. NTSTATUS
  139. AMLITest_Post_GetFieldUnitRegionObj(
  140. PAMLIHOOK_DATA * ppData,
  141. NTSTATUS _Status)
  142. {
  143. return(AMLITest_Post_Generic(ppData,_Status));
  144. }
  145. //
  146. // Pre/Post EvalNameSpaceObject
  147. //
  148. NTSTATUS
  149. AMLITest_Pre_EvalNameSpaceObject(
  150. IN PNSOBJ pns,
  151. OUT POBJDATA pdataResult,
  152. IN int icArgs,
  153. IN POBJDATA pdataArgs,
  154. PAMLIHOOK_DATA * ppData)
  155. {
  156. //
  157. // Alocate and init AMLIHOOK_DATA
  158. //
  159. *ppData =
  160. AmliHook_AllocAndInitTestData();
  161. if(!(*ppData))
  162. return(STATUS_INSUFFICIENT_RESOURCES);
  163. //
  164. //--- Notify test driver off call
  165. //
  166. (*ppData)->Type = ACPIVER_DATA_TYPE_AMLI;
  167. (*ppData)->SubType = ACPIVER_DATA_SUBTYPE_EVAL_NAME_SPACE_OBJECT;
  168. (*ppData)->State = AMLIHOOK_TEST_DATA_STATE_CALL;
  169. (*ppData)->Arg1 = (ULONG_PTR)pns;
  170. (*ppData)->Arg2 = (ULONG_PTR)pdataResult;
  171. (*ppData)->Arg3 = (ULONG_PTR)icArgs;
  172. (*ppData)->Arg4 = (ULONG_PTR)pdataArgs;
  173. return(AmliHook_TestNotify(*ppData));
  174. }
  175. NTSTATUS
  176. AMLITest_Post_EvalNameSpaceObject(
  177. PAMLIHOOK_DATA * Data,
  178. NTSTATUS _Status)
  179. {
  180. return(AMLITest_Post_Generic(Data,_Status));
  181. }
  182. //
  183. // CallBack Pre/Post AsyncEvalObject
  184. //
  185. VOID EXPORT
  186. AMLITest_AsyncEvalObjectCallBack(
  187. IN PNSOBJ pns,
  188. IN NTSTATUS status,
  189. IN POBJDATA pdataResult,
  190. IN PVOID Context)
  191. {
  192. PAMLIHOOK_DATA pData = (PAMLIHOOK_DATA)Context;
  193. NTSTATUS RetStatus ;
  194. PFNACB AcpiAsyncCallBack;
  195. PVOID AcpiContext;
  196. AcpiAsyncCallBack = (PFNACB)pData->Arg5;
  197. AcpiContext = (PVOID)pData->Arg6;
  198. if( (VOID*)(pData->Arg2) != (VOID*)pdataResult)
  199. AmliHook_ProcessInternalError();
  200. //
  201. //--- Notify test driver off call status
  202. //
  203. RetStatus = AmliHook_TestNotifyRet(
  204. pData,
  205. status);
  206. AmliTest_DebugPrint((
  207. AMLIHOOK_DEBUG_ASYNC_AMLI,
  208. "DEBUG: AMLITest_AsyncEvalObjectCallBack Data=%lx\n",
  209. pData));
  210. ExFreePool(pData);
  211. if(AcpiAsyncCallBack)
  212. {
  213. AcpiAsyncCallBack(
  214. pns,
  215. RetStatus,
  216. pdataResult,
  217. AcpiContext);
  218. }
  219. }
  220. NTSTATUS
  221. AMLITest_Pre_AsyncEvalObject(
  222. IN PNSOBJ pns,
  223. OUT POBJDATA pdataResult,
  224. IN int icArgs,
  225. IN POBJDATA pdataArgs,
  226. IN PFNACB * pfnAsyncCallBack,
  227. IN PVOID * pvContext,
  228. PAMLIHOOK_DATA * Data)
  229. {
  230. //
  231. // Alocate and init AMLIHOOK_DATA
  232. //
  233. *Data =
  234. AmliHook_AllocAndInitTestData();
  235. if(!Data)
  236. return(STATUS_INSUFFICIENT_RESOURCES);
  237. //
  238. //--- Notify test driver off call
  239. //
  240. (*Data)->Type = ACPIVER_DATA_TYPE_AMLI;
  241. (*Data)->SubType = ACPIVER_DATA_SUBTYPE_ASYNC_EVAL_OBJECT;
  242. (*Data)->State = AMLIHOOK_TEST_DATA_STATE_CALL;
  243. (*Data)->Arg1 = (ULONG_PTR)pns;
  244. (*Data)->Arg2 = (ULONG_PTR)pdataResult;
  245. (*Data)->Arg3 = (ULONG_PTR)icArgs;
  246. (*Data)->Arg4 = (ULONG_PTR)pdataArgs;
  247. (*Data)->Arg5 = (ULONG_PTR)*pfnAsyncCallBack;
  248. (*Data)->Arg6 = (ULONG_PTR)*pvContext;
  249. //
  250. // Hook my callback function , and conext.
  251. //
  252. *pfnAsyncCallBack = AMLITest_AsyncEvalObjectCallBack;
  253. *pvContext = *Data;
  254. return(AmliHook_TestNotify(*Data));
  255. }
  256. NTSTATUS
  257. AMLITest_Post_AsyncEvalObject(
  258. PAMLIHOOK_DATA * ppData,
  259. NTSTATUS Status)
  260. {
  261. AmliTest_DebugPrint((
  262. AMLIHOOK_DEBUG_ASYNC_AMLI,
  263. "DEBUG: AMLITest_Post_AsyncEvalObject Data=%lx Pending=%s\n",
  264. *ppData,
  265. (Status == STATUS_PENDING)? "TRUE" : "FALSE"));
  266. if(Status == STATUS_PENDING)
  267. return(Status);
  268. //
  269. //--- Call back will not be called.
  270. //
  271. return(AMLITest_Post_Generic(ppData,Status));
  272. }
  273. //
  274. // Pre/Post NestAsyncEvalObject
  275. //
  276. NTSTATUS
  277. AMLITest_Pre_NestAsyncEvalObject(
  278. PNSOBJ pns,
  279. POBJDATA pdataResult,
  280. int icArgs,
  281. POBJDATA pdataArgs,
  282. PFNACB * pfnAsyncCallBack,
  283. PVOID * pvContext,
  284. PAMLIHOOK_DATA * ppData)
  285. {
  286. //
  287. // Alocate and init AMLIHOOK_DATA
  288. //
  289. *ppData =
  290. AmliHook_AllocAndInitTestData();
  291. if(!(*ppData))
  292. return(STATUS_INSUFFICIENT_RESOURCES);
  293. //
  294. //--- Notify test driver off call
  295. //
  296. (*ppData)->Type = ACPIVER_DATA_TYPE_AMLI;
  297. (*ppData)->SubType = ACPIVER_DATA_SUBTYPE_NEST_ASYNC_EVAL_OBJECT;
  298. (*ppData)->State = AMLIHOOK_TEST_DATA_STATE_CALL;
  299. (*ppData)->Arg1 = (ULONG_PTR)pns;
  300. (*ppData)->Arg2 = (ULONG_PTR)pdataResult;
  301. (*ppData)->Arg3 = (ULONG_PTR)icArgs;
  302. (*ppData)->Arg4 = (ULONG_PTR)pdataArgs;
  303. (*ppData)->Arg5 = (ULONG_PTR)pfnAsyncCallBack;
  304. (*ppData)->Arg6 = (ULONG_PTR)pvContext;
  305. //
  306. // Hook my callback function , and conext.
  307. //
  308. *pfnAsyncCallBack = AMLITest_AsyncEvalObjectCallBack;
  309. *pvContext = *ppData;
  310. return(AmliHook_TestNotify(*ppData));
  311. }
  312. NTSTATUS
  313. AMLITest_Post_NestAsyncEvalObject(
  314. PAMLIHOOK_DATA * ppData,
  315. NTSTATUS Status)
  316. {
  317. if(Status == STATUS_PENDING)
  318. return(Status);
  319. //
  320. //--- Work is done.
  321. //--- AMLITest_AsyncEvalObjectCallBack will not be called.
  322. //
  323. return(AMLITest_Post_Generic(ppData,Status));
  324. }
  325. //
  326. // Pre/Post EvalPackageElement
  327. //
  328. NTSTATUS
  329. AMLITest_Pre_EvalPackageElement(
  330. PNSOBJ pns,
  331. int iPkgIndex,
  332. POBJDATA pdataResult,
  333. PAMLIHOOK_DATA * ppData)
  334. {
  335. //
  336. // Alocate and init AMLIHOOK_DATA
  337. //
  338. *ppData =
  339. AmliHook_AllocAndInitTestData();
  340. if(!(*ppData))
  341. return(STATUS_INSUFFICIENT_RESOURCES);
  342. //
  343. //--- Notify test driver off call
  344. //
  345. (*ppData)->Type = ACPIVER_DATA_TYPE_AMLI;
  346. (*ppData)->SubType = ACPIVER_DATA_SUBTYPE_EVAL_PACKAGE_ELEMENT;
  347. (*ppData)->State = AMLIHOOK_TEST_DATA_STATE_CALL;
  348. (*ppData)->Arg1 = (ULONG_PTR)pns;
  349. (*ppData)->Arg2 = (ULONG_PTR)iPkgIndex;
  350. (*ppData)->Arg3 = (ULONG_PTR)pdataResult;
  351. return(AmliHook_TestNotify(*ppData));
  352. }
  353. NTSTATUS
  354. AMLITest_Post_EvalPackageElement(
  355. PAMLIHOOK_DATA * Data,
  356. NTSTATUS Status)
  357. {
  358. return(AMLITest_Post_Generic(Data,Status));
  359. }
  360. //
  361. // Pre/Post EvalPkgDataElement
  362. //
  363. NTSTATUS
  364. AMLITest_Pre_EvalPkgDataElement(
  365. POBJDATA pdataPkg,
  366. int iPkgIndex,
  367. POBJDATA pdataResult,
  368. PAMLIHOOK_DATA * ppData)
  369. {
  370. //
  371. // Alocate and init AMLIHOOK_DATA
  372. //
  373. *ppData =
  374. AmliHook_AllocAndInitTestData();
  375. if(!(*ppData))
  376. return(STATUS_INSUFFICIENT_RESOURCES);
  377. //
  378. //--- Notify test driver off call
  379. //
  380. (*ppData)->Type = ACPIVER_DATA_TYPE_AMLI;
  381. (*ppData)->SubType = ACPIVER_DATA_SUBTYPE_EVAL_PKG_DATA_ELEMENT;
  382. (*ppData)->State = AMLIHOOK_TEST_DATA_STATE_CALL;
  383. (*ppData)->Arg1 = (ULONG_PTR)pdataPkg;
  384. (*ppData)->Arg2 = (ULONG_PTR)iPkgIndex;
  385. (*ppData)->Arg3 = (ULONG_PTR)pdataResult;
  386. return(AmliHook_TestNotify(*ppData));
  387. }
  388. NTSTATUS
  389. AMLITest_Post_EvalPkgDataElement(
  390. PAMLIHOOK_DATA * ppData,
  391. NTSTATUS Status)
  392. {
  393. return(AMLITest_Post_Generic(ppData,Status));
  394. }
  395. //
  396. // Pre/Post FreeDataBuffs
  397. //
  398. NTSTATUS
  399. AMLITest_Pre_FreeDataBuffs(
  400. POBJDATA pdata,
  401. int icData,
  402. PAMLIHOOK_DATA * ppData)
  403. {
  404. //
  405. // Alocate and init AMLIHOOK_DATA
  406. //
  407. *ppData =
  408. AmliHook_AllocAndInitTestData();
  409. if(!(*ppData))
  410. return(STATUS_INSUFFICIENT_RESOURCES);
  411. //
  412. //--- Notify test driver off call
  413. //
  414. (*ppData)->Type = ACPIVER_DATA_TYPE_AMLI;
  415. (*ppData)->SubType = ACPIVER_DATA_SUBTYPE_FREE_DATA_BUFFS;
  416. (*ppData)->State = AMLIHOOK_TEST_DATA_STATE_CALL;
  417. (*ppData)->Arg1 = (ULONG_PTR)pdata;
  418. (*ppData)->Arg2 = (ULONG_PTR)icData;
  419. return(AmliHook_TestNotify(*ppData));
  420. }
  421. NTSTATUS
  422. AMLITest_Post_FreeDataBuffs(
  423. PAMLIHOOK_DATA * ppData,
  424. NTSTATUS Status)
  425. {
  426. return(AMLITest_Post_Generic(ppData,Status));
  427. }
  428. //
  429. // Pre/Post RegEventHandler.
  430. //
  431. NTSTATUS
  432. AMLIHook_Pre_RegEventHandler(
  433. ULONG dwEventType,
  434. ULONG_PTR uipEventData,
  435. PFNHND * pfnHandler,
  436. ULONG_PTR * uipParam,
  437. PAMLIHOOK_DATA * ppData)
  438. {
  439. NTSTATUS Status;
  440. PFNHND EventHandler;
  441. ULONG_PTR EventParam;
  442. //
  443. // Alocate and init AMLIHOOK_DATA
  444. //
  445. *ppData =
  446. AmliHook_AllocAndInitTestData();
  447. if(!(*ppData))
  448. return(STATUS_INSUFFICIENT_RESOURCES);
  449. //
  450. //--- Querry the test driver for Event handler to
  451. //--- register.
  452. //
  453. (*ppData)->Type = ACPIVER_DATA_TYPE_AMLI;
  454. (*ppData)->SubType = ACPIVER_DATA_SUBTYPE_REG_EVENT_HANDLER;
  455. (*ppData)->State = AMLIHOOK_TEST_DATA_STATE_QUERY;
  456. (*ppData)->Arg1 = (ULONG_PTR)dwEventType;
  457. (*ppData)->Arg2 = (ULONG_PTR)uipEventData;
  458. (*ppData)->Arg3 = (ULONG_PTR)*pfnHandler;
  459. (*ppData)->Arg4 = (ULONG_PTR)*uipParam;
  460. AmliHook_TestNotify(*ppData);
  461. if((*ppData)->Ret != STATUS_SUCCESS)
  462. DbgBreakPoint();
  463. EventHandler = (PFNHND)(*ppData)->Arg3;
  464. EventParam = (ULONG_PTR)(*ppData)->Arg4;
  465. if(EventHandler != *pfnHandler)
  466. {
  467. //
  468. // Test driver will hook this call
  469. // I will need values for both
  470. // params.
  471. //
  472. if(!EventHandler)
  473. AmliHook_ProcessInternalError();
  474. if(!EventParam)
  475. AmliHook_ProcessInternalError();
  476. *pfnHandler = EventHandler;
  477. *uipParam = EventParam;
  478. }
  479. //
  480. //--- Notify test driver off call
  481. //
  482. AmliHook_InitTestData(*ppData);
  483. (*ppData)->Type = ACPIVER_DATA_TYPE_AMLI;
  484. (*ppData)->SubType = ACPIVER_DATA_SUBTYPE_REG_EVENT_HANDLER;
  485. (*ppData)->State = AMLIHOOK_TEST_DATA_STATE_CALL;
  486. (*ppData)->Arg1 = (ULONG_PTR)dwEventType;
  487. (*ppData)->Arg2 = (ULONG_PTR)uipEventData;
  488. return(AmliHook_TestNotify(*ppData));
  489. }
  490. NTSTATUS
  491. AMLIHook_Post_RegEventHandler(
  492. PAMLIHOOK_DATA * ppData,
  493. NTSTATUS Status)
  494. {
  495. return(AMLITest_Post_Generic(ppData,Status));
  496. }
  497. //
  498. // CallBack , Pre/Post PauseInterpreter
  499. //
  500. VOID EXPORT
  501. AMLITest_PauseInterpreterCallBack(
  502. PVOID Context)
  503. {
  504. NTSTATUS Status;
  505. PFNAA AcpiCallBack=NULL;
  506. PVOID AcpiContext=NULL;
  507. PAMLIHOOK_DATA Data = (PAMLIHOOK_DATA)Context;
  508. //
  509. //--- Notify test driver off call status
  510. //
  511. Status = AmliHook_TestNotifyRet(
  512. Data,
  513. STATUS_SUCCESS);
  514. AcpiCallBack = (PFNAA)Data->Arg1;
  515. AcpiContext = (PVOID)Data->Arg2;
  516. ExFreePool(Data);
  517. if(AcpiCallBack)
  518. {
  519. AcpiCallBack(AcpiContext);
  520. }
  521. }
  522. NTSTATUS
  523. AMLITest_Pre_PauseInterpreter(
  524. PFNAA * pfnCallBack,
  525. PVOID * Context,
  526. PAMLIHOOK_DATA * ppData)
  527. {
  528. //
  529. // Alocate and init AMLIHOOK_DATA
  530. //
  531. *ppData =
  532. AmliHook_AllocAndInitTestData();
  533. if(!(*ppData))
  534. return(STATUS_INSUFFICIENT_RESOURCES);
  535. //
  536. //--- Notify test driver off call
  537. //
  538. (*ppData)->Type = ACPIVER_DATA_TYPE_AMLI;
  539. (*ppData)->SubType = ACPIVER_DATA_SUBTYPE_PAUSE_INTERPRETER;
  540. (*ppData)->State = AMLIHOOK_TEST_DATA_STATE_CALL;
  541. (*ppData)->Arg1 = (ULONG_PTR)*pfnCallBack;
  542. (*ppData)->Arg2 = (ULONG_PTR)*Context;
  543. //
  544. // Hook my Callback context
  545. //
  546. *pfnCallBack = AMLITest_PauseInterpreterCallBack;
  547. *Context = *ppData;
  548. return(AmliHook_TestNotify(*ppData));
  549. }
  550. NTSTATUS
  551. AMLITest_Post_PauseInterpreter(
  552. PAMLIHOOK_DATA * ppData,
  553. NTSTATUS Status)
  554. {
  555. if(Status == STATUS_PENDING)
  556. return(Status);
  557. //
  558. //--- Call back will not be called.
  559. //
  560. Status = AmliHook_TestNotifyRet(
  561. *ppData,
  562. Status);
  563. ExFreePool(*ppData);
  564. *ppData = NULL;
  565. return(Status);
  566. }
  567. //
  568. // Pre/Post ResumeInterpreter
  569. //
  570. NTSTATUS
  571. AMLITest_Pre_ResumeInterpreter(
  572. PAMLIHOOK_DATA * ppData)
  573. {
  574. //
  575. // Alocate and init AMLIHOOK_DATA
  576. //
  577. *ppData =
  578. AmliHook_AllocAndInitTestData();
  579. if(!(*ppData))
  580. return(STATUS_INSUFFICIENT_RESOURCES);
  581. //
  582. //--- Notify test driver off call
  583. //
  584. (*ppData)->Type = ACPIVER_DATA_TYPE_AMLI;
  585. (*ppData)->SubType = ACPIVER_DATA_SUBTYPE_RESUME_INTERPRETER;
  586. (*ppData)->State = AMLIHOOK_TEST_DATA_STATE_CALL;
  587. return(AmliHook_TestNotify(*ppData));
  588. }
  589. NTSTATUS
  590. AMLITest_Post_ResumeInterpreter(
  591. PAMLIHOOK_DATA * ppData,
  592. NTSTATUS Status)
  593. {
  594. return(AMLITest_Post_Generic(ppData,Status));
  595. }