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.

924 lines
25 KiB

  1. ; Copyright (c) Microsoft Corporation. All rights reserved.
  2. [Macros]
  3. ; Generate the prolog stuff for a thunked API.
  4. ; pBaseArgs is a 64-bit pointer pointing at the 32-bit
  5. ; arguments on the 32-bit stack (fetched from EDX when
  6. ; the syscall was executed).
  7. MacroName=ApiProlog
  8. Begin=
  9. // @NL
  10. // @ApiName - @ApiNum @NL
  11. // @NL
  12. @ApiFnRet @ApiFnMod @NL
  13. wh@ApiName(PULONG pBaseArgs) { @NL
  14. PULONG pBaseArgsCopy = pBaseArgs; // prevent unreferenced formal parameter errors @NL
  15. @IfArgs(@ArgList(@ListCol@ArgMod @ArgHostType @ArgNameHost = *(@ArgHostType *)&pBaseArgs[@ArgOff];
  16. ))
  17. End=
  18. MacroName=DeclareIndex
  19. NumArgs=0
  20. Begin=
  21. int @ArgValue_Index;@NL
  22. End=
  23. MacroName=ElementCopy
  24. NumArgs=1
  25. Begin=
  26. for(@ArgValue_Index = 0; @ArgValue_Index < @ArrayElements; @ArgValue_Index++) {@NL
  27. @Indent(
  28. @MArg(1)
  29. )
  30. } @NL
  31. End=
  32. MacroName=StdH2NCopy
  33. NumArgs=0
  34. Begin=
  35. @ArgName = @IfNotIsBitfield(@UnalignedTag64)(@ArgType)(@ArgHostName); @NL
  36. End=
  37. MacroName=StdAEH2NCopy
  38. NumArgs=0
  39. Begin=
  40. @ArgName[@ArgValue_Index] = (@ArgType)@ArgHostName[@ArgValue_Index]; @NL
  41. End=
  42. MacroName=StdN2HCopy
  43. NumArgs=0
  44. Begin=
  45. @ArgHostName = @IfNotIsBitfield((@ArgHostType))@ArgName; @NL
  46. End=
  47. MacroName=StdAEN2HCopy
  48. NumArgs=0
  49. Begin=
  50. @ArgHostName[@ArgValue_Index] = (@ArgHostType)@ArgName[@ArgValue_Index]; @NL
  51. End=
  52. MacroName=StructLocal
  53. NumArgs=0
  54. Begin=
  55. @IfPtrDep(
  56. @IfIsArray(
  57. // Note: @ArgName(@ArgType) is pointer dependent and is an array. @NL
  58. // Note: Declaring array index. @NL
  59. @DeclareIndex
  60. )
  61. @IfNotIsArray(
  62. // Note: @ArgName(@ArgType) is a pointer dependent struct. @NL
  63. )
  64. @MemberTypes(Locals,.)
  65. )
  66. @IfNotPtrDep(
  67. // Note: @ArgName(@ArgType) is a non pointer dependent struct. @NL
  68. @MemberTypes(Locals,.)
  69. )
  70. End=
  71. MacroName=StructIN
  72. NumArgs=0
  73. Begin=
  74. @IfPtrDep(
  75. @IfNotIsArray(
  76. // Note: @ArgName(@ArgType) is pointer dependent and is not an array. @NL
  77. @MemberTypes(PreCall,.)
  78. )
  79. @IfIsArray(
  80. // Note: @ArgName(@ArgType) is pointer dependent and is an array. @NL
  81. #error Error: don't know how to thunk an array of ptr dep structures. @NL
  82. )
  83. )
  84. @IfNotPtrDep(
  85. @IfIsArray(
  86. // Note: @ArgName(@ArgType) is not pointer dependent and is and array. @NL
  87. RtlCopyMemory(@ArgName, @ArgHostName, sizeof(@ArgType) * @ArrayElements);@NL
  88. )
  89. @IfNotIsArray(
  90. // Note: ArgName(ArgType) is not pointer dependent and is not an array. @NL
  91. RtlCopyMemory(&(@ArgName), &(@ArgHostName), sizeof(@ArgType));@NL
  92. )
  93. )
  94. End=
  95. MacroName=StructOUT
  96. NumArgs=0
  97. Begin=
  98. @IfIsMember(
  99. @IfPtrDep(
  100. @IfNotIsArray(
  101. // Note: @ArgName(@ArgType) is pointer dependent and is not an array.@NL
  102. @MemberTypes(PostCall,.)
  103. )
  104. @IfIsArray(
  105. // Note: @ArgName(@ArgType) is pointer dependent and is an array. @NL
  106. { @NL
  107. @ArgType *___ptr = (@ArgType *)@ArgName; @NL
  108. @ArgHostType *___hostptr = (@ArgHostType*)@ArgHostName; @NL
  109. while (___ptr < ((@ArgType *)(sizeof(@ArgName) + (PBYTE)@ArgName))) { @NL
  110. @ForceType(PostCall, ___ptr, ___hostptr, @ArgType *,OUT);
  111. ___ptr++; @NL
  112. ___hostptr++; @NL
  113. } @NL
  114. } @NL
  115. )
  116. )
  117. @IfNotPtrDep(
  118. @IfIsArray(
  119. // Note: @ArgName(@ArgType) is not pointer dependent and is an array. @NL
  120. RtlCopyMemory(@ArgHostName, @ArgName, sizeof(@ArgType) * @ArrayElements); @NL
  121. )
  122. @IfNotIsArray(
  123. // Note: @ArgName(@ArgType) is not pointer dependent and is not an array. @NL
  124. RtlCopyMemory(&(@ArgHostName), &(@ArgName), sizeof(@ArgType));@NL
  125. )
  126. )
  127. )
  128. End=
  129. MacroName=StructPtrLocal
  130. NumArgs=0
  131. Begin=
  132. @IfPointerToPtrDep(
  133. @IfIsArray(
  134. // Note: @ArgName(@ArgType) is an array of pointers to a pointer dependent structure. @NL
  135. @DeclareIndex
  136. BYTE @ArgValCopy[sizeof(*@ArgName)]; @NL
  137. @MemberTypes(Locals)
  138. )
  139. @IfNotIsArray(
  140. BYTE @ArgValCopy[sizeof(*@ArgName)]; // Note: a pointer to a pointer dependent structure. @NL
  141. @MemberTypes(Locals)
  142. )
  143. )
  144. @IfNotPointerToPtrDep(
  145. // Note: @ArgName(@ArgType) is a pointer to structure that is not pointer dependent - nothing to do. @NL
  146. )
  147. End=
  148. MacroName=StructPtrIN
  149. NumArgs=0
  150. Begin=
  151. @IfPointerToPtrDep(
  152. @IfIsArray(
  153. // Note: @ArgName(@ArgType) is an array of pointers to pointer dependent structures. @NL
  154. #error Error: don't know how to thunk an array of pointers to ptr dep. @NL
  155. )
  156. @IfNotIsArray(
  157. // Note: @ArgName(@ArgType) is a pointer to a pointer dependent structure. @NL
  158. if (WOW64_ISPTR(@ArgHostName)) { @NL
  159. try { @NL
  160. @Indent(
  161. @ArgName = (@ArgType)@ArgValCopy; @NL
  162. @MemberTypes(PreCall)
  163. )
  164. } except (EXCEPTION_EXECUTE_HANDLER) { @NL
  165. #if defined _NTBASE_API_ @NL
  166. return GetExceptionCode(); @NL
  167. #elif defined _WIN32_API_ @NL
  168. return 0; @NL
  169. #endif @NL
  170. } @NL
  171. } @NL
  172. else { @NL
  173. @Indent(
  174. @ArgName = (@ArgType)@ArgHostName; @NL
  175. )
  176. } @NL
  177. )
  178. )
  179. @IfNotPointerToPtrDep(
  180. @IfIsArray(
  181. // Note: @ArgName(@ArgType) is an array of pointers to non pointer dependent structures. @NL
  182. @ElementCopy(StdAEN2HCopy)
  183. )
  184. @IfNotIsArray(
  185. // Note: @ArgName(@ArgType) is pointer to a non pointer dependent structure. @NL
  186. @StdH2NCopy
  187. )
  188. )
  189. End=
  190. MacroName=StructPtrOUTInit
  191. NumArgs=0
  192. Begin=
  193. @IfPointerToPtrDep(
  194. @IfIsArray(
  195. // Note: @ArgName(@ArgType) is an array of pointers to pointer dependent structures. @NL
  196. #error Error: don't know how to thunk an array of pointers to ptr dep. @NL
  197. )
  198. @IfNotIsArray(
  199. try { @NL
  200. // Note: @ArgName(@ArgType) is a pointer to a pointer dependent structure. @NL
  201. @ArgName = WOW64_ISPTR(@ArgHostName) ? (@ArgType)@ArgValCopy : (@ArgType)@ArgHostName; @NL
  202. } except (EXCEPTION_EXECUTE_HANDLER) { @NL
  203. #if defined _NTBASE_API_ @NL
  204. return GetExceptionCode(); @NL
  205. #elif defined _WIN32_API_ @NL
  206. return 0; @NL
  207. #endif @NL
  208. } @NL
  209. )
  210. )
  211. @IfNotPointerToPtrDep(
  212. @IfIsArray(
  213. // Note: @ArgName(@ArgType) is an array of pointers to non pointer dependent structures. @NL
  214. @ElementCopy(StdAEN2HCopy)
  215. )
  216. @IfNotIsArray(
  217. // Note: @ArgName(@ArgType) is pointer to a non pointer dependent structure. @NL
  218. @StdH2NCopy
  219. )
  220. )
  221. End=
  222. MacroName=StructPtrOUT
  223. NumArgs=0
  224. Begin=
  225. @IfPointerToPtrDep(
  226. @IfIsArray(
  227. // Note: @ArgName(@ArgType) is a array of pointers to a pointer dependent structure. @NL
  228. #error Error: don't know how to thunk an array of pointers to ptr dep@NL
  229. )
  230. @IfNotIsArray(
  231. // Note: @ArgName(@ArgType) is a pointer to a pointer dependent structure. @NL
  232. if (WOW64_ISPTR(@ArgHostName)) { @NL
  233. try { @NL
  234. @Indent(
  235. @MemberTypes(PostCall)
  236. )
  237. } except (EXCEPTION_EXECUTE_HANDLER) { @NL
  238. #if defined _NTBASE_API_ @NL
  239. return GetExceptionCode(); @NL
  240. #elif defined _WIN32_API_ @NL
  241. return 0; @NL
  242. #endif @NL
  243. } @NL
  244. } @NL
  245. )
  246. )
  247. @IfNotPointerToPtrDep(
  248. @IfIsMember(
  249. // Note: @ArgName(@ArgType) is a member of a structure. Copying. @NL
  250. @IfIsArray(
  251. RtlCopyMemory(@ArgHostName, @ArgName, sizeof(@ArgType) * @ArrayElements); @NL
  252. )
  253. @IfNotIsArray(
  254. @StdN2HCopy
  255. )
  256. @NL
  257. )
  258. @IfNotIsMember(
  259. // Note: @ArgName(@ArgType) is a pointer to a non pointer dependent type. @NL
  260. // Note: Type is not a member of a structure. Nothing to do. @NL
  261. )
  262. )
  263. End=
  264. MacroName=PointerLocal
  265. NumArgs=0
  266. Begin=
  267. @IfPointerToPtrDep(
  268. // Note: @ArgName(@ArgType) is a pointer to a pointer dependent type. @NL
  269. BYTE @ArgValCopy[sizeof(*@ArgName)];@NL
  270. )
  271. @IfNotPointerToPtrDep(
  272. @IfIsArray(
  273. // Note: @ArgName(@ArgTypes) is an array of pointers to a non pointer dependent type. @NL
  274. @DeclareIndex
  275. )
  276. @IfNotIsArray(
  277. // Note: @ArgName(@ArgType) is a pointer to a non pointer dependent type - Nothing to do. @NL
  278. )
  279. )
  280. End=
  281. MacroName=PointerIN
  282. NumArgs=0
  283. Begin=
  284. @IfPointerToPtrDep(
  285. @IfIsArray(
  286. // Note: @ArgName(@ArgType) is an array of pointers to pointer dependent types. @NL
  287. #error Error: don't know how to thunk an array of pointers to ptr dep. @NL
  288. )
  289. @IfNotIsArray(
  290. // Note: @ArgName(@ArgType) is a pointer to a pointer dependent type. @NL
  291. if (WOW64_ISPTR(@ArgHostName)) { @NL
  292. try { @NL
  293. @Indent(
  294. @IfInt64DepUnion(
  295. //Special Case union having LARGE_INTEGER member @NL
  296. @ArgName = (@ArgType)@ArgValCopy; @NL
  297. *(LONG *)((PBYTE)@ArgValCopy) = *(LONG *)((PBYTE)@ArgHostName); @NL
  298. *(LONG *)(4+(PBYTE)@ArgValCopy) = *(LONG *)(4+(PBYTE)@ArgHostName); @NL
  299. )
  300. @IfNotInt64DepUnion(
  301. @ArgName = (@ArgType)@ArgValCopy; @NL
  302. *((@ArgType)@ArgValCopy) = (@ArgTypeInd)*((@ArgHostTypeInd *)@ArgHostName); @NL
  303. )
  304. )
  305. } except (EXCEPTION_EXECUTE_HANDLER) { @NL
  306. #if defined _NTBASE_API_ @NL
  307. return GetExceptionCode(); @NL
  308. #elif defined _WIN32_API_ @NL
  309. return 0; @NL
  310. #endif @NL
  311. } @NL
  312. } @NL
  313. else { @NL
  314. @Indent(
  315. @ArgName = (@ArgType)@ArgHostName; @NL
  316. )
  317. } @NL
  318. )
  319. )
  320. @IfNotPointerToPtrDep(
  321. @IfIsArray(
  322. // Note: @ArgName(@ArgType) is an array of pointers to a non pointer dependent type.@NL
  323. @ElementCopy(@StdAEH2NCopy)
  324. )
  325. @IfNotIsArray(
  326. // Note: @ArgName(@ArgType) is a pointer to a non pointer dependent type.@NL
  327. @StdH2NCopy
  328. )
  329. )
  330. End=
  331. MacroName=PointerOUTInit
  332. NumArgs=0
  333. Begin=
  334. @IfPointerToPtrDep(
  335. @IfIsArray(
  336. // Note: @ArgName(@ArgType) is an array of pointers to a pointer dependent type. @NL
  337. #error Error: don't know how to thunk an array of pointers to ptr dep @NL
  338. )
  339. @IfNotIsArray(
  340. // Note: @ArgName(@ArgType) is a pointer to a pointer dependent type. @NL
  341. try { @NL
  342. @ArgName = WOW64_ISPTR(@ArgHostName) ? (@ArgType)@ArgValCopy : (@ArgType)@ArgHostName; @NL
  343. } except (EXCEPTION_EXECUTE_HANDLER) { @NL
  344. #if defined _NTBASE_API_ @NL
  345. return GetExceptionCode(); @NL
  346. #elif defined _WIN32_API_ @NL
  347. return 0; @NL
  348. #endif @NL
  349. } @NL
  350. )
  351. )
  352. @IfNotPointerToPtrDep(
  353. // Note: @ArgName(@ArgType) is a pointer to a non pointer dependent type. @NL
  354. @StdH2NCopy
  355. )
  356. End=
  357. MacroName=PointerOUT
  358. NumArgs=0
  359. Begin=
  360. @IfPointerToPtrDep(
  361. @IfIsArray(
  362. // Note: @ArgName(@ArgType) is an array of pointers to a pointer dependent type. @NL
  363. #error Error: don't know how to thunk an array of pointers to ptr dep @NL
  364. )
  365. @IfNotIsArray(
  366. // Note: @ArgName(@ArgType) is a pointer to a pointer dependent type. @NL
  367. if (WOW64_ISPTR(@ArgHostName)) { @NL
  368. try { @NL
  369. @Indent(
  370. @IfInt64DepUnion(
  371. //8byte long integer @NL
  372. *(LONG *)(PBYTE)@ArgHostName = *(LONG *)(PBYTE)@ArgName; @NL
  373. *(LONG *)(4+(PBYTE)@ArgHostName) = *(LONG *)(4+(PBYTE)@ArgName); @NL
  374. )
  375. @IfNotInt64DepUnion(
  376. *((@ArgHostTypeInd *)@ArgHostName) = *(@ArgHostTypeInd *)((@ArgType)@ArgName);@NL
  377. )
  378. )
  379. } except (EXCEPTION_EXECUTE_HANDLER) { @NL
  380. #if defined _NTBASE_API_ @NL
  381. return GetExceptionCode(); @NL
  382. #elif defined _WIN32_API_ @NL
  383. return 0; @NL
  384. #endif @NL
  385. } @NL
  386. } @NL
  387. )
  388. )
  389. @IfNotPointerToPtrDep(
  390. @IfIsMember(
  391. // Note: @ArgName(@ArgType) is a member of a structure. Copying. @NL
  392. @IfIsArray(
  393. @ElementCopy(@StdAEN2HCopy)
  394. )
  395. @IfNotIsArray(
  396. @StdN2HCopy
  397. )
  398. @NL
  399. )
  400. @IfNotIsMember(
  401. // Note: @ArgName(@ArgType) is a pointer to a non pointer dependent type - Nothing to do. @NL
  402. )
  403. )
  404. End=
  405. MacroName=GenericPtrAllocSize
  406. Begin=
  407. @IfPointerToPtrDep(
  408. AllocSize += LENGTH + sizeof(@ArgTypeInd) - sizeof(@ArgHostTypeInd); @NL
  409. )
  410. @IfNotPointerToPtrDep(
  411. // Note: Type is not pointer dependent. @NL
  412. // Note: Signal code to pass the pointer along. @NL
  413. AllocSize = 0; @NL
  414. )
  415. End=
  416. MacroName=TypeStructPtrINLocal
  417. Begin=
  418. @StructPtrLocal
  419. End=
  420. MacroName=TypeStructPtrINPreCall
  421. Begin=
  422. @StructPtrIN
  423. End=
  424. MacroName=TypeStructPtrINPostCall
  425. Begin=
  426. End=
  427. MacroName=TypeStructPtrOUTLocal
  428. Begin=
  429. @StructPtrLocal
  430. End=
  431. MacroName=TypeStructPtrOUTPreCall
  432. Begin=
  433. @StructPtrOUTInit
  434. End=
  435. MacroName=TypeStructPtrOUTPostCall
  436. Begin=
  437. @StructPtrOUT
  438. End=
  439. MacroName=TypeStructPtrINOUTLocal
  440. Begin=
  441. @StructPtrLocal
  442. End=
  443. MacroName=TypeStructPtrINOUTPreCall
  444. Begin=
  445. @StructPtrIN
  446. End=
  447. MacroName=TypeStructPtrINOUTPostCall
  448. Begin=
  449. @StructPtrOUT
  450. End=
  451. MacroName=TypeStructPtrNONELocal
  452. Begin=
  453. @TypeStructPtrINOUTLocal
  454. End=
  455. MacroName=TypeStructPtrNONEPreCall
  456. Begin=
  457. @TypeStructPtrINOUTPreCall
  458. End=
  459. MacroName=TypeStructPtrNONEPostCall
  460. Begin=
  461. @TypeStructPtrINOUTPostCall
  462. End=
  463. MacroName=DbgNonPtrDepCases
  464. NumArgs=1
  465. Begin=
  466. switch(@MArg(1)) { @Indent( @NL
  467. @ForCase(case @CArg(1): @NL)
  468. @Indent(
  469. break; @NL
  470. )
  471. default: @Indent( @NL
  472. LOGPRINT((ERRORLOG, "@ApiName: Called with unsupported class.\n"));
  473. WOWASSERT(FALSE); @NL
  474. return STATUS_NOT_IMPLEMENTED; @NL
  475. )
  476. )} @NL
  477. End=
  478. MacroName=GenProfileSubTable
  479. NumArgs=0
  480. Begin=
  481. @NL
  482. #if defined WOW64DOPROFILE @NL
  483. WOW64SERVICE_PROFILE_TABLE_ELEMENT @ApiNameProfileSublistElements[] = { @Indent( @NL
  484. @ForCase({L"@CArg(1)", 0, NULL, TRUE}, @NL)
  485. {NULL, 0, NULL, FALSE} // For Debugging @NL
  486. )}; @NL
  487. @NL
  488. WOW64SERVICE_PROFILE_TABLE @ApiNameProfileSublist = { @Indent( @NL
  489. NULL,NULL,@ApiNameProfileSublistElements,
  490. (sizeof(@ApiNameProfileSublistElements)/sizeof(WOW64SERVICE_PROFILE_TABLE_ELEMENT))-1
  491. )};@NL
  492. @NL
  493. #if defined @ApiName_PROFILE_SUBLIST @NL
  494. #undef @ApiName_PROFILE_SUBLIST @NL
  495. #endif @NL
  496. #define @ApiName_PROFILE_SUBLIST &@ApiNameProfileSublist @NL
  497. #endif
  498. @NL
  499. End=
  500. MacroName=GenDebugNonPtrDepCases
  501. NumArgs=2
  502. Begin=
  503. @NL
  504. @IfApiCode(Header)
  505. @NL
  506. @GenProfileSubTable
  507. @NL
  508. @ForCase(
  509. @ApiFnRet @NL
  510. wh@ApiName_@CArg(1)(@ArgList(@ListCol@ArgMod @ArgType @IfArgs(@ArgName)@ArgMore(,))) { @Indent( @NL
  511. @IfApiRet(@ApiFnRet RetVal); @NL
  512. #if defined WOW64DOPROFILE @NL
  513. @ApiNameProfileSublistElements[@CNumber].HitCount++; @NL
  514. #endif @NL
  515. @CallApi(@MArg(1), RetVal)
  516. return @IfApiRet(RetVal); @NL
  517. )} @NL
  518. @NL
  519. )
  520. @ApiProlog
  521. // @NL
  522. // Begin: IfApiCode(ApiEntry) @NL
  523. @IfApiCode(ApiEntry)
  524. @NL
  525. @Indent(
  526. @IfApiRet(@ApiFnRet RetVal;) @NL
  527. @NL
  528. // @NL
  529. // Begin: ApiLocals @NL
  530. @ApiLocals
  531. @NL
  532. // @NL
  533. // Begin: Types(Locals) @NL
  534. @Types(Locals)
  535. @NL
  536. // @NL
  537. // Begin: IfApiCode(Locals) @NL
  538. @IfApiCode(Locals)
  539. @NL
  540. APIPROFILE(@ApiNum); @NL
  541. // @NL
  542. //Begin: Types(PreCall) @NL
  543. @Types(PreCall)
  544. @NL
  545. // @NL
  546. // Begin: IfApiCode(PreCall) @NL
  547. @IfApiCode(PreCall)
  548. @NL
  549. // @NL
  550. // Begin: CallApi(MArg(1), RetVal) @NL
  551. switch(@MArg(2)) { @Indent( @NL
  552. @ForCase(
  553. case @CArg(1): @Indent( @NL
  554. @CallApi(wh@ApiName_@CArg(1),RetVal)
  555. break; @NL
  556. ))
  557. default: @Indent( @NL
  558. LOGPRINT((ERRORLOG, "@ApiName: Called with unsupported class %x.\n", @MArg(2)));
  559. WOWASSERT(FALSE); @NL
  560. return STATUS_NOT_IMPLEMENTED; @NL
  561. )
  562. )} @NL
  563. @NL
  564. // @NL
  565. // Begin: Types(PostCall) @NL
  566. @Types(PostCall)
  567. @NL
  568. // @NL
  569. // Begin: ApiCode(PostCall) @NL
  570. @IfApiCode(PostCall)
  571. @NL
  572. // @NL
  573. // Begin: ApiEpilog @NL
  574. @ApiEpilog
  575. @NL
  576. )
  577. // @NL
  578. // Begin: IfApiCode(ApiExit) @NL
  579. @IfApiCode(ApiExit)
  580. @NL
  581. //
  582. // Begin: ApiExit @NL
  583. @ApiExit
  584. @NL
  585. End=
  586. MacroName=GenQuerySetDispatch
  587. NumArgs=2
  588. Begin=
  589. //Switch on the subapi. @NL
  590. switch(@MArg(2)) { @Indent(@NL
  591. // @NL
  592. // Begin Ptr dependent cases. @NL
  593. @ForCase(
  594. case @CArg(1): @Indent( @NL
  595. @If(@CArgExist(2))(
  596. //Handle Automatically generated cases. @NL
  597. #if defined WOW64DOPROFILE @NL
  598. @ApiNameProfileSublistElements[@CNumber].HitCount++; @NL
  599. #endif @NL
  600. @CallApi(wh@ApiName_@CArg(1), RetVal)
  601. break; @NL
  602. )@Else(
  603. //Handle Special cases. @NL
  604. #if defined WOW64DOPROFILE @NL
  605. @ApiNameProfileSublistElements[@CNumber].HitCount++; @NL
  606. #endif @NL
  607. @CallApi(wh@ApiName_Special@MArg(1)Case, RetVal)
  608. break; @NL
  609. )
  610. )
  611. )
  612. default: @Indent( @NL
  613. LOGPRINT((ERRORLOG, "@ApiName: called with unsupported class : %lx\n", @MArg(2))); @NL
  614. WOWASSERT(FALSE); @NL
  615. return STATUS_NOT_IMPLEMENTED; @NL
  616. break; @NL
  617. )@NL
  618. )} @NL
  619. End=
  620. ;
  621. ; Macro Args:
  622. ; 1. Api to call.
  623. ; 2. SwitchParam.
  624. ; 3. DataParam.
  625. ; 4. LengthParam.
  626. ; Case Args:
  627. ; 1. Case for switch
  628. ; 2. Datatype(Optional, If absent indicates a custom thunk)
  629. MacroName=GenSetThunk
  630. NumArgs=4
  631. Begin=
  632. // @NL
  633. // Begin: IfApiCode(Header) @NL
  634. @NL
  635. @NL
  636. @IfApiCode(Header)
  637. @NL
  638. @GenProfileSubTable
  639. @NL
  640. #define SETLENGTH @MArg(4) @NL
  641. @NL
  642. // Special Set Case for @ApiName @NL
  643. @ApiFnRet @NL
  644. wh@ApiName_SpecialSetCase(@ArgList(@ListCol@ArgMod @ArgType @IfArgs(@ArgName)@ArgMore(,))) { @Indent( @NL
  645. @IfApiRet(@ApiFnRet RetVal = STATUS_UNSUCCESSFUL); @NL
  646. ULONG @MArg(4)Host = @MArg(4); @NL
  647. NT32PVOID @MArg(3)Host = (NT32PVOID)@MArg(3); @NL
  648. // @NL
  649. // Begin: IfApiCode(SpecialSetCase) @NL
  650. @NL
  651. switch(@MArg(2)) { @Indent( @NL
  652. @IfApiCode(SpecialSetCase)
  653. )} @NL
  654. return @IfApiRet(RetVal); @NL
  655. )} @NL
  656. @NL
  657. @ForCase(@If(@CArgExist(2))(
  658. @ApiFnRet @NL
  659. wh@ApiName_@CArg(1)(@ArgList(@ListCol@ArgMod @ArgType @IfArgs(@ArgName)@ArgMore(,))) { @Indent( @NL
  660. @IfApiRet(@ApiFnRet RetVal); @NL
  661. @If(@IsPointerToPtrDep(@CArg(2)))(
  662. ULONG @MArg(4)Host = @MArg(4); @NL
  663. NT32PVOID @MArg(3)Host = (NT32PVOID)@MArg(3); @NL
  664. @Types(Locals,@MArg(3),@CArg(2))
  665. // By default: set the length to be 64bit size of the type. @NL
  666. @MArg(4) = sizeof(*((@CArg(2))(@MArg(3)))); @NL
  667. @Types(PreCall,@MArg(3),@CArg(2))
  668. @CallApi(@MArg(1), RetVal)
  669. @Types(PostCall,@MArg(3),@CArg(2))
  670. )@Else(
  671. @CallApi(@MArg(1), RetVal)
  672. )
  673. return @IfApiRet(RetVal); @NL
  674. )} @NL
  675. @NL
  676. ))
  677. @NL
  678. @ApiProlog
  679. // @NL
  680. // Begin: IfApiCode(ApiEntry) @NL
  681. @IfApiCode(ApiEntry)
  682. @NL
  683. @Indent(
  684. NTSTATUS RetVal; @NL
  685. @NL
  686. // @NL
  687. // Begin: ApiLocals @NL
  688. @ApiLocals
  689. @NL
  690. // @NL
  691. // Begin: Types(Locals) @NL
  692. @Types(Locals)
  693. @NL
  694. // @NL
  695. // Begin: IfApiCode(Locals) @NL
  696. @IfApiCode(Locals)
  697. @NL
  698. APIPROFILE(@ApiNum); @NL
  699. @NL
  700. // @NL
  701. //Begin: Types(PreCall) @NL
  702. @Types(PreCall)
  703. @NL
  704. // @NL
  705. // Begin: IfApiCode(PreCall) @NL
  706. @IfApiCode(PreCall)
  707. @NL
  708. @GenQuerySetDispatch(Set,@MArg(2))
  709. // @NL
  710. // Begin: Types(PostCall) @NL
  711. @Types(PostCall)
  712. @NL
  713. // @NL
  714. // Begin: ApiCode(PostCall) @NL
  715. @IfApiCode(PostCall)
  716. @NL
  717. @NL
  718. // @NL
  719. // Begin: ApiEpilog @NL
  720. @ApiEpilog
  721. @NL
  722. )
  723. // @NL
  724. // Begin: IfApiCode(ApiExit) @NL
  725. @IfApiCode(ApiExit)
  726. #undef SETLENGTH @NL
  727. }@NL
  728. @NL
  729. End=
  730. ;
  731. ; Macro Args:
  732. ; 1. Api to call.
  733. ; 2. SwitchParam.
  734. ; 3. DataParam.
  735. ; 4. LengthParam.
  736. ; 5. ReturnLengthParam
  737. ; 6. ReturnLengthType (without pointer decorator)
  738. ; Case Args:
  739. ; 1. Case for switch
  740. ; 2. Datatype
  741. MacroName=GenQueryThunk
  742. NumArgs=6
  743. Begin=
  744. // @NL
  745. // Begin: IfApiCode(Header) @NL
  746. @NL
  747. @NL
  748. @IfApiCode(Header)
  749. @NL
  750. @GenProfileSubTable
  751. @NL
  752. #define LENGTH @MArg(4) @NL
  753. @NL
  754. // Special Query Case for @ApiName @NL
  755. @ApiFnRet @NL
  756. wh@ApiName_SpecialQueryCase(@ArgList(@ListCol@ArgMod @ArgType @IfArgs(@ArgName)@ArgMore(,))) { @Indent( @NL
  757. @IfApiRet(@ApiFnRet RetVal = STATUS_UNSUCCESSFUL); @NL
  758. ULONG @MArg(4)Host = @MArg(4); @NL
  759. PVOID @MArg(3)Host = @MArg(3); @NL
  760. NT32P@MArg(6) @MArg(5)Host = (NT32P@MArg(6))@MArg(5); @NL
  761. // @NL
  762. // Begin: IfApiCode(SpecialQueryCase) @NL
  763. @NL
  764. switch(@MArg(2)) { @Indent( @NL
  765. @IfApiCode(SpecialQueryCase)
  766. )} @NL
  767. return @IfApiRet(RetVal); @NL
  768. )} @NL
  769. @NL
  770. @ForCase(@If(@CArgExist(2))(
  771. @ApiFnRet @NL
  772. wh@ApiName_@CArg(1)(@ArgList(@ListCol@ArgMod @ArgType @IfArgs(@ArgName)@ArgMore(,))) { @Indent( @NL
  773. @IfApiRet(@ApiFnRet RetVal); @NL
  774. @If(@IsPointerToPtrDep(@CArg(2)))(
  775. ULONG @MArg(4)Host = @MArg(4); @NL
  776. PVOID @MArg(3)Host = @MArg(3); @NL
  777. NT32P@MArg(6) @MArg(5)Host = (NT32P@MArg(6))@MArg(5); @NL
  778. SIZE_T RetInfoLen = 0; @NL
  779. SIZE_T AllocSize = 0; @NL
  780. SIZE_T OldLength = 0; @NL
  781. PVOID @MArg(3)Copy = NULL;@NL
  782. @MArg(6) ApiReturnLength; @NL
  783. P@MArg(6) pApiReturnLengthOld; @NL
  784. @Types(AllocSize,@MArg(3),@CArg(2))
  785. if (WOW64_ISPTR(@MArg(3))) { @NL
  786. @MArg(3) = @MArg(3)Copy = Wow64AllocateTemp(AllocSize); @NL
  787. } else { @NL
  788. @MArg(3)Copy = @MArg(3);
  789. } @NL
  790. pApiReturnLengthOld = ReturnLength;@NL
  791. ReturnLength = &ApiReturnLength;@NL
  792. OldLength = LENGTH; @NL
  793. LENGTH = (NT32SIZE_T)AllocSize; @NL
  794. @CallApi(@MArg(1), RetVal)
  795. if (NT_ERROR(RetVal)) { @NL @Indent(
  796. WriteReturnLength(pApiReturnLengthOld, ApiReturnLength); @NL
  797. return RetVal; @NL
  798. )}@NL
  799. try { @NL
  800. @Types(RetSize,@MArg(3),@CArg(2))
  801. if (RetInfoLen > OldLength) { @NL @Indent(
  802. return STATUS_INFO_LENGTH_MISMATCH; @NL
  803. )}@NL
  804. @Types(PostCall,@MArg(3),@CArg(2))
  805. } except (EXCEPTION_EXECUTE_HANDLER) { @NL
  806. return GetExceptionCode (); @NL
  807. } @NL
  808. WriteReturnLength(pApiReturnLengthOld, RetInfoLen); @NL
  809. )@Else(
  810. @CallApi(@MArg(1), RetVal)
  811. )
  812. return @IfApiRet(RetVal); @NL
  813. )} @NL
  814. @NL
  815. ))
  816. @NL
  817. @ApiProlog
  818. // @NL
  819. // Begin: IfApiCode(ApiEntry) @NL
  820. @IfApiCode(ApiEntry)
  821. @NL
  822. @Indent(
  823. @IfApiRet(@ApiFnRet RetVal;) @NL
  824. @NL
  825. // @NL
  826. // Begin: ApiLocals @NL
  827. @ApiLocals
  828. @NL
  829. // @NL
  830. // Begin: Types(Locals) @NL
  831. @Types(Locals)
  832. @NL
  833. // @NL
  834. // Begin: IfApiCode(Locals) @NL
  835. @IfApiCode(Locals)
  836. @NL
  837. APIPROFILE(@ApiNum); @NL
  838. @NL
  839. // @NL
  840. //Begin: Types(PreCall) @NL
  841. @Types(PreCall)
  842. @NL
  843. // @NL
  844. // Begin: IfApiCode(PreCall) @NL
  845. @IfApiCode(PreCall)
  846. @NL
  847. @GenQuerySetDispatch(Query,@MArg(2))
  848. // @NL
  849. // Begin: Types(PostCall) @NL
  850. @Types(PostCall)
  851. @NL
  852. // @NL
  853. // Begin: ApiCode(PostCall) @NL
  854. @IfApiCode(PostCall)
  855. @NL
  856. @NL
  857. // @NL
  858. // Begin: ApiEpilog @NL
  859. @ApiEpilog
  860. @NL
  861. )
  862. // @NL
  863. // Begin: IfApiCode(ApiExit) @NL
  864. @IfApiCode(ApiExit)
  865. #undef LENGTH @NL
  866. }@NL
  867. @NL
  868. End=