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.

464 lines
16 KiB

  1. /*** amlipriv.h - AML Interpreter Private Definitions
  2. *
  3. * Copyright (c) 1996,1997 Microsoft Corporation
  4. * Author: Michael Tsang (MikeTs)
  5. * Created 08/14/96
  6. *
  7. * MODIFICATION HISTORY
  8. */
  9. #ifndef _AMLIPRIV_H
  10. #define _AMLIPRIV_H
  11. /*** Macros
  12. */
  13. /*XLATOFF*/
  14. #define MODNAME "AMLI"
  15. #ifndef DEBUG
  16. #define AMLI_WARN(x)
  17. #define AMLI_ERROR(x)
  18. #define CHKGLOBALHEAP()
  19. #else
  20. #define AMLI_WARN(x) ConPrintf(MODNAME "_WARN: "); \
  21. ConPrintf x; \
  22. ConPrintf("\n");
  23. #define AMLI_ERROR(x) ConPrintf(MODNAME "_ERROR: "); \
  24. ConPrintf x; \
  25. ConPrintf("\n"); \
  26. KdBreakPoint(); \
  27. CHKDEBUGGERREQ();
  28. #define CHKGLOBALHEAP()
  29. #endif
  30. #ifndef DEBUGGER
  31. #define PRINTF
  32. #define AMLI_LOGERR(rc,p) (rc)
  33. #define RESETERR()
  34. #define CHKDEBUGGERREQ()
  35. #define LOGSCHEDEVENT(ev,d1,d2,d3)
  36. #define LOGEVENT(ev,d1,d2,d3,d4,d5,d6,d7)
  37. #define LOGMUTEXEVENT(ev,d1,d2,d3,d4,d5,d6,d7)
  38. #else
  39. #define PRINTF ConPrintf
  40. #define AMLI_LOGERR(rc,p) (LogError(rc), CatError p, (rc))
  41. #define RESETERR() {gDebugger.rcLastError = STATUS_SUCCESS;\
  42. gDebugger.szLastError[0] = '\0'; \
  43. }
  44. #define CHKDEBUGGERREQ() if (gDebugger.dwfDebugger & DBGF_DEBUGGER_REQ) \
  45. { \
  46. ConPrintf("\nProcess AML Debugger Request.\n");\
  47. gDebugger.dwfDebugger &= \
  48. ~DBGF_DEBUGGER_REQ; \
  49. AMLIDebugger(FALSE); \
  50. }
  51. #define LOGEVENT LogEvent
  52. #define LOGSCHEDEVENT LogSchedEvent
  53. #define LOGMUTEXEVENT(ev,d1,d2,d3,d4,d5,d6,d7) \
  54. if (gDebugger.dwfDebugger & DBGF_LOGEVENT_MUTEX)\
  55. { \
  56. LogEvent(ev,d1,d2,d3,d4,d5,d6,d7); \
  57. }
  58. #endif
  59. #define LOCAL __cdecl
  60. #define DEREF(x) ((x) = (x))
  61. #define BYTEOF(d,i) (((PUCHAR)&d)[i])
  62. #define WORDOF(d,i) (((PUSHORT)&d)[i])
  63. //
  64. // NTRAID#60804-2000/06/20-splante Remove dependence on static translation
  65. //
  66. #define HalTranslateBusAddress(InterfaceType,BusNumber,BusAddress,AddressSpace,TranslatedAddress) \
  67. (*(TranslatedAddress) = (BusAddress), TRUE)
  68. //
  69. // The various tags
  70. //
  71. #define CTOBJ_TAG 'ClmA'
  72. #define HPOBJ_TAG 'HlmA'
  73. #define PRIV_TAG 'IlmA'
  74. #define PHOBJ_TAG 'PlmA'
  75. #define RSOBJ_TAG 'RlmA'
  76. #define SYOBJ_TAG 'SlmA'
  77. #define RTOBJ_TAG 'TlmA'
  78. // Memory management macros
  79. #define ALLOCPOOL ExAllocatePool
  80. #define ALLOCPOOLWITHTAG ExAllocatePoolWithTag
  81. #ifdef DEBUG
  82. #ifndef MAXWINNT_DEBUG
  83. #define MALLOC_PAGED(n,t) (++gdwcMemObjs, \
  84. ALLOCPOOLWITHTAG( \
  85. (gdwfAMLI & AMLIF_LOCKED)? \
  86. NonPagedPool: PagedPool, n, t))
  87. #define MALLOC_LOCKED(n,t) (++gdwcMemObjs, \
  88. ALLOCPOOLWITHTAG( \
  89. NonPagedPool, n, t))
  90. #else
  91. #define MALLOC_PAGED(n,t) (++gdwcMemObjs, \
  92. ExAllocatePoolWithTagPriority( \
  93. (gdwfAMLI & AMLIF_LOCKED)? \
  94. NonPagedPool: PagedPool, n, t, \
  95. HighPoolPrioritySpecialPoolOverrun))
  96. #define MALLOC_LOCKED(n,t) (++gdwcMemObjs, \
  97. ExAllocatePoolWithTagPriority( \
  98. NonPagedPool, n, t, \
  99. HighPoolPrioritySpecialPoolOverrun))
  100. #endif
  101. #define MALLOC MALLOC_LOCKED
  102. #define MFREE(p) FreeMem(p, &gdwcMemObjs)
  103. #define NEWHPOBJ(n) (++gdwcHPObjs, MALLOC(n, HPOBJ_TAG))
  104. #define FREEHPOBJ(p) {MFREE(p); --gdwcHPObjs;}
  105. #define NEWSYOBJ(n) (++gdwcSYObjs, MALLOC_LOCKED(n, SYOBJ_TAG))
  106. #define FREESYOBJ(p) {MFREE(p); --gdwcSYObjs;}
  107. #define NEWRSOBJ(n) (++gdwcRSObjs, MALLOC_LOCKED(n, RSOBJ_TAG))
  108. #define FREERSOBJ(p) {MFREE(p); --gdwcRSObjs;}
  109. #define NEWPHOBJ(n) (++gdwcPHObjs, MALLOC_LOCKED(n, PHOBJ_TAG))
  110. #define FREEPHOBJ(p) {MFREE(p); --gdwcPHObjs;}
  111. #define NEWRESTOBJ(n) (MALLOC_LOCKED(n, RTOBJ_TAG))
  112. #define FREERESTOBJ(p) (MFREE(p))
  113. #define NEWOBJDATA(h,p) NewObjData(h, p)
  114. #define FREEOBJDATA(p) FreeObjData(p)
  115. #define NEWODOBJ(h,n) (++gdwcODObjs, HeapAlloc(h, 'TADH', n))
  116. #define FREEODOBJ(p) {HeapFree(p); --gdwcODObjs;}
  117. #define NEWNSOBJ(h,n) (++gdwcNSObjs, HeapAlloc(h, 'OSNH', n))
  118. #define FREENSOBJ(p) {HeapFree(p); --gdwcNSObjs;}
  119. #define NEWOOOBJ(h,n) (++gdwcOOObjs, HeapAlloc(h, 'NWOH', n))
  120. #define FREEOOOBJ(p) {HeapFree(p); --gdwcOOObjs;}
  121. #define NEWSDOBJ(h,n) (++gdwcSDObjs, HeapAlloc(h, 'RTSH', n))
  122. #define FREESDOBJ(p) {HeapFree(p); --gdwcSDObjs;}
  123. #define NEWBDOBJ(h,n) (++gdwcBDObjs, HeapAlloc(h, 'FUBH', n))
  124. #define FREEBDOBJ(p) {HeapFree(p); --gdwcBDObjs;}
  125. #define NEWPKOBJ(h,n) (++gdwcPKObjs, HeapAlloc(h, 'GKPH', n))
  126. #define FREEPKOBJ(p) {HeapFree(p); --gdwcPKObjs;}
  127. #define NEWBFOBJ(h,n) (++gdwcBFObjs, HeapAlloc(h, 'DFBH', n))
  128. #define FREEBFOBJ(p) {HeapFree(p); --gdwcBFObjs;}
  129. #define NEWFUOBJ(h,n) (++gdwcFUObjs, HeapAlloc(h, 'UDFH', n))
  130. #define FREEFUOBJ(p) {HeapFree(p); --gdwcFUObjs;}
  131. #define NEWKFOBJ(h,n) (++gdwcKFObjs, HeapAlloc(h, 'FKBH', n))
  132. #define FREEKFOBJ(p) {HeapFree(p); --gdwcKFObjs;}
  133. #define NEWFOBJ(h,n) (++gdwcFObjs, HeapAlloc(h, 'ODFH', n))
  134. #define FREEFOBJ(p) {HeapFree(p); --gdwcFObjs;}
  135. #define NEWIFOBJ(h,n) (++gdwcIFObjs, HeapAlloc(h, 'FXIH', n))
  136. #define FREEIFOBJ(p) {HeapFree(p); --gdwcIFObjs;}
  137. #define NEWOROBJ(h,n) (++gdwcORObjs, HeapAlloc(h, 'GROH', n))
  138. #define FREEOROBJ(p) {HeapFree(p); --gdwcORObjs;}
  139. #define NEWMTOBJ(h,n) (++gdwcMTObjs, HeapAlloc(h, 'TUMH', n))
  140. #define FREEMTOBJ(p) {HeapFree(p); --gdwcMTObjs;}
  141. #define NEWEVOBJ(h,n) (++gdwcEVObjs, HeapAlloc(h, 'NVEH', n))
  142. #define FREEEVOBJ(p) {HeapFree(p); --gdwcEVObjs;}
  143. #define NEWMEOBJ(h,n) (++gdwcMEObjs, HeapAlloc(h, 'TEMH', n))
  144. #define FREEMEOBJ(p) {HeapFree(p); --gdwcMEObjs;}
  145. #define NEWPROBJ(h,n) (++gdwcPRObjs, HeapAlloc(h, 'SRPH', n))
  146. #define FREEPROBJ(p) {HeapFree(p); --gdwcPRObjs;}
  147. #define NEWPCOBJ(h,n) (++gdwcPCObjs, HeapAlloc(h, 'ORPH', n))
  148. #define FREEPCOBJ(p) {HeapFree(p); --gdwcPCObjs;}
  149. #define NEWCROBJ(h,n) (++gdwcCRObjs, HeapAlloc(h, 'RNWO', n))
  150. #define FREECROBJ(p) {HeapFree(p); --gdwcCRObjs;}
  151. #else
  152. #define MALLOC_PAGED(n,t) ALLOCPOOLWITHTAG(PagedPool, n, t)
  153. #define MALLOC_LOCKED(n,t) ALLOCPOOLWITHTAG(NonPagedPool, n, t)
  154. #define MALLOC MALLOC_LOCKED
  155. #define MFREE(p) ExFreePool(p)
  156. #define NEWHPOBJ(n) MALLOC(n, HPOBJ_TAG)
  157. #define FREEHPOBJ(p) MFREE(p)
  158. #define NEWSYOBJ(n) MALLOC_LOCKED(n, SYOBJ_TAG)
  159. #define FREESYOBJ(p) MFREE(p)
  160. #define NEWRSOBJ(n) MALLOC_LOCKED(n, RSOBJ_TAG)
  161. #define FREERSOBJ(p) MFREE(p)
  162. #define NEWPHOBJ(n) MALLOC_LOCKED(n, PHOBJ_TAG)
  163. #define FREEPHOBJ(p) MFREE(p)
  164. #define NEWRESTOBJ(n) MALLOC_LOCKED(n, RTOBJ_TAG)
  165. #define FREERESTOBJ(p) MFREE(p)
  166. #define NEWOBJDATA(h,p) NewObjData(h,p)
  167. #define FREEOBJDATA(p) FreeObjData(p)
  168. #define NEWODOBJ(h,n) HeapAlloc(h, 'TADH', n)
  169. #define FREEODOBJ(p) HeapFree(p)
  170. #define NEWNSOBJ(h,n) HeapAlloc(h, 'OSNH', n)
  171. #define FREENSOBJ(p) HeapFree(p)
  172. #define NEWOOOBJ(h,n) HeapAlloc(h, 'NWOH', n)
  173. #define FREEOOOBJ(p) HeapFree(p)
  174. #define NEWSDOBJ(h,n) HeapAlloc(h, 'RTSH', n)
  175. #define FREESDOBJ(p) HeapFree(p)
  176. #define NEWBDOBJ(h,n) HeapAlloc(h, 'FUBH', n)
  177. #define FREEBDOBJ(p) HeapFree(p)
  178. #define NEWPKOBJ(h,n) HeapAlloc(h, 'GKPH', n)
  179. #define FREEPKOBJ(p) HeapFree(p)
  180. #define NEWBFOBJ(h,n) HeapAlloc(h, 'DFBH', n)
  181. #define FREEBFOBJ(p) HeapFree(p)
  182. #define NEWFUOBJ(h,n) HeapAlloc(h, 'UDFH', n)
  183. #define FREEFUOBJ(p) HeapFree(p)
  184. #define NEWKFOBJ(h,n) HeapAlloc(h, 'FKBH', n)
  185. #define FREEKFOBJ(p) HeapFree(p)
  186. #define NEWFOBJ(h,n) HeapAlloc(h, 'ODFH', n)
  187. #define FREEFOBJ(p) HeapFree(p)
  188. #define NEWIFOBJ(h,n) HeapAlloc(h, 'FXIH', n)
  189. #define FREEIFOBJ(p) HeapFree(p)
  190. #define NEWOROBJ(h,n) HeapAlloc(h, 'GROH', n)
  191. #define FREEOROBJ(p) HeapFree(p)
  192. #define NEWMTOBJ(h,n) HeapAlloc(h, 'TUMH', n)
  193. #define FREEMTOBJ(p) HeapFree(p)
  194. #define NEWEVOBJ(h,n) HeapAlloc(h, 'NVEH', n)
  195. #define FREEEVOBJ(p) HeapFree(p)
  196. #define NEWMEOBJ(h,n) HeapAlloc(h, 'TEMH', n)
  197. #define FREEMEOBJ(p) HeapFree(p)
  198. #define NEWPROBJ(h,n) HeapAlloc(h, 'SRPH', n)
  199. #define FREEPROBJ(p) HeapFree(p)
  200. #define NEWPCOBJ(h,n) HeapAlloc(h, 'ORPH', n)
  201. #define FREEPCOBJ(p) HeapFree(p)
  202. #define NEWCROBJ(h,n) HeapAlloc(h, 'RNWO', n)
  203. #define FREECROBJ(p) HeapFree(p)
  204. #endif
  205. #define MEMCPY RtlCopyMemory
  206. #define MEMZERO RtlZeroMemory
  207. #define ISLEADNAMECHAR(c) (((c) >= 'A') && ((c) <= 'Z') || ((c) == '_'))
  208. #define ISNAMECHAR(c) (ISLEADNAMECHAR(c) || ((c) >= '0') && ((c) <= '9'))
  209. #define SHIFTLEFT(d,c) (((c) >= 32)? 0: (d) << (c))
  210. #define SHIFTRIGHT(d,c) (((c) >= 32)? 0: (d) >> (c))
  211. #define MIN(a,b) (((a) > (b))? (b): (a))
  212. #define MAX(a,b) (((a) > (b))? (a): (b))
  213. /*XLATON*/
  214. /*** Constants
  215. */
  216. // These are internal error codes which aren't really errors
  217. #define AMLISTA_DONE 0x00008000
  218. #define AMLISTA_BREAK 0x00008001
  219. #define AMLISTA_RETURN 0x00008002
  220. #define AMLISTA_CONTINUE 0x00008003
  221. #define AMLISTA_PENDING 0x00008004
  222. #define AMLISTA_TIMEOUT 0x00008005
  223. // Global AMLI flags
  224. #define AMLIF_LOCKED 0x00000001
  225. #define AMLIF_IN_LOCKPHASE 0x00000002
  226. #define AMLIF_LOADING_DDB 0x80000000
  227. // Error Log
  228. #define READ_ERROR_NOTED 0x00000001
  229. #define WRITE_ERROR_NOTED 0x00000002
  230. //
  231. // AMLI Override FLAGS
  232. //
  233. #define AMLI_OVERRIDE_IO_ADDRESS_CHECK 0x00000001
  234. // Global Hack flags
  235. #define HACKF_OLDSLEEP 0x00000001
  236. //
  237. // AMLI Reg Attributes key
  238. //
  239. #define AMLI_ATTRIBUTES "AMLIAttributes"
  240. #define ARGTYPE_NAME 'N' //name argument
  241. #define ARGTYPE_DATAOBJ 'O' //data argument
  242. #define ARGTYPE_DWORD 'D' //numeric dword argument
  243. #define ARGTYPE_WORD 'W' //numeric word argument
  244. #define ARGTYPE_BYTE 'B' //numeric byte argument
  245. #define ARGTYPE_SNAME 'S' //supername argument
  246. #define ARGTYPE_SNAME2 's' //supername argument
  247. // object can be non-existing
  248. #define ARGTYPE_OPCODE 'C' //opcode argument
  249. // Argument object type (used for type validation)
  250. #define ARGOBJ_UNKNOWN 'U' //OBJTYPE_UNKNOWN - don't care
  251. #define ARGOBJ_INTDATA 'I' //OBJTYPE_INTDATA
  252. #define ARGOBJ_STRDATA 'Z' //OBJTYPE_STRDATA
  253. #define ARGOBJ_BUFFDATA 'B' //OBJTYPE_BUFFDATA
  254. #define ARGOBJ_PKGDATA 'P' //OBJTYPE_PKGDATA
  255. #define ARGOBJ_FIELDUNIT 'F' //OBJTYPE_FIELDUNIT
  256. #define ARGOBJ_OBJALIAS 'O' //OBJTYPE_OBJALIAS
  257. #define ARGOBJ_DATAALIAS 'A' //OBJTYPE_DATAALIAS
  258. #define ARGOBJ_BASICDATA 'D' //INTDATA,STRDATA,BUFFDATA
  259. #define ARGOBJ_COMPLEXDATA 'C' //BUFFDATA,PKGDATA
  260. #define ARGOBJ_REFERENCE 'R' //OBJALIAS,DATAALIAS,BUFFFIELD
  261. #define MAX_BYTE 0xff
  262. #define MAX_WORD 0xffff
  263. #define MAX_DWORD 0xffffffff
  264. #define MAX_NUM_LOCALS 8
  265. #define MAX_NUM_ARGS 7
  266. #define MAX_NAME_LEN 255
  267. #if defined (_WIN64)
  268. #define DEF_CTXTBLK_SIZE (4096*4) //16K context block
  269. #else
  270. #define DEF_CTXTBLK_SIZE (4096*2) //8K context block
  271. #endif
  272. #define DEF_CTXTMAX_SIZE 16 //16 Contexts
  273. #define DEF_GLOBALHEAPBLK_SIZE (4096*16) //64K global heap block
  274. #define DEF_TIMESLICE_LENGTH 100 //100ms
  275. #define DEF_TIMESLICE_INTERVAL 100 //100ms
  276. #if defined(_WIN64)
  277. #define DEF_HEAP_ALIGNMENT 8 //QWord aligned
  278. #else
  279. #define DEF_HEAP_ALIGNMENT 4 //DWord aligned
  280. #endif
  281. #define AMLI_REVISION 1
  282. #define NAMESEG_ROOT 0x5f5f5f5c // "\___"
  283. #define NAMESEG_BLANK 0x5f5f5f5f // "____"
  284. #define NAMESEG_NONE 0x00000000 // ""
  285. #define NAMESTR_ROOT "\\"
  286. #define CREATORID_MSFT "MSFT"
  287. #define MIN_CREATOR_REV 0x01000000
  288. // dwfNS local flags
  289. #define NSF_EXIST_OK 0x00010000 //for CreateNameSpaceObject
  290. #define NSF_WARN_NOTFOUND 0x80000000 //for GetNameSpaceObject
  291. /*** Type and Structure definitions
  292. */
  293. typedef NTSTATUS (LOCAL *PFNOP)(PFRAME, PPNSOBJ);
  294. typedef struct _amlterm
  295. {
  296. PSZ pszTermName;
  297. ULONG dwOpcode;
  298. PSZ pszArgTypes;
  299. ULONG dwTermClass;
  300. ULONG dwfOpcode;
  301. PFNOH pfnCallBack;
  302. ULONG dwCBData;
  303. PFNOP pfnOpcode;
  304. } AMLTERM, *PAMLTERM;
  305. // dwfOpcode flags
  306. #define OF_VARIABLE_LIST 0x00000001
  307. #define OF_ARG_OBJECT 0x00000002
  308. #define OF_LOCAL_OBJECT 0x00000004
  309. #define OF_DATA_OBJECT 0x00000008
  310. #define OF_STRING_OBJECT 0x00000010
  311. #define OF_NAME_OBJECT 0x00000020
  312. #define OF_DEBUG_OBJECT 0x00000040
  313. #define OF_REF_OBJECT 0x00000080
  314. #define OF_CALLBACK_EX 0x80000000
  315. // dwTermClass
  316. #define TC_NAMESPACE_MODIFIER 0x00000001
  317. #define TC_NAMED_OBJECT 0x00000002
  318. #define TC_OPCODE_TYPE1 0x00000003
  319. #define TC_OPCODE_TYPE2 0x00000004
  320. #define TC_OTHER 0x00000005
  321. typedef struct _opcodemap
  322. {
  323. ULONG dwOpcode;
  324. PAMLTERM pamlterm;
  325. } OPCODEMAP, *POPCODEMAP;
  326. typedef struct _objowner
  327. {
  328. LIST list;
  329. ULONG dwSig;
  330. PNSOBJ pnsObjList;
  331. } OBJOWNER, *POBJOWNER;
  332. #define SIG_OBJOWNER 'RNWO'
  333. typedef struct _evhandle
  334. {
  335. PFNHND pfnHandler;
  336. ULONG_PTR uipParam;
  337. } EVHANDLE, *PEVHANDLE;
  338. typedef struct _rsaccess
  339. {
  340. struct _rsaccess *prsaNext;
  341. ULONG dwRegionSpace;
  342. PFNCA pfnCookAccess;
  343. ULONG_PTR uipCookParam;
  344. PFNRA pfnRawAccess;
  345. ULONG_PTR uipRawParam;
  346. } RSACCESS, *PRSACCESS;
  347. typedef struct _passivehook
  348. {
  349. struct _ctxt *pctxt;
  350. ULONG_PTR uipAddr;
  351. ULONG dwLen;
  352. PULONG_PTR puipMappedAddr;
  353. WORK_QUEUE_ITEM WorkItem;
  354. } PASSIVEHOOK, *PPASSIVEHOOK;
  355. typedef struct _mutex
  356. {
  357. KSPIN_LOCK SpinLock;
  358. KIRQL OldIrql;
  359. } MUTEX, *PMUTEX;
  360. typedef struct _badioaddr
  361. {
  362. ULONG BadAddrBegin;
  363. ULONG BadAddrSize;
  364. ULONG OSVersionTrigger;
  365. } BADIOADDR, *PBADIOADDR;
  366. typedef struct _AMLI_Log_WorkItem_Context
  367. {
  368. BOOLEAN fRead;
  369. ULONG Address;
  370. ULONG Index;
  371. PIO_WORKITEM pIOWorkItem;
  372. } AMLI_LOG_WORKITEM_CONTEXT, *PAMLI_LOG_WORKITEM_CONTEXT;
  373. #endif //ifndef _AMLIPRIV_H