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.

527 lines
16 KiB

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;
  3. ;; Copyright (c) 1998-1999 Microsoft Corporation
  4. ;;
  5. ;; Module Name:
  6. ;;
  7. ;; msgthnk.tpl
  8. ;;
  9. ;; Abstract:
  10. ;;
  11. ;; This template files defines the thunks for outbound 32bit to 64bit messages.
  12. ;;
  13. ;; Author:
  14. ;;
  15. ;; 6-Oct-98 mzoran
  16. ;;
  17. ;; Revision History:
  18. ;;
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. [Macros]
  21. ; Generate an api call, passing the name of the variable to use for the return
  22. ; value and the name of the API to call.
  23. ; eg. @CallApi(ApiName, RetVal)
  24. TemplateName=CallApi
  25. NumArgs=2
  26. Begin=
  27. @IfApiRet(@MArg(2)=)MSG_THUNK_CALLPROC(@ArgList(@ArgName@ArgMore(,))); @NL
  28. End=
  29. ; Expand all parameters into local variables
  30. TemplateName=ApiLocals
  31. NumArgs=0
  32. Begin=
  33. @IfArgs(@ListCol@ArgList(@ArgLocal;))
  34. End=
  35. MacroName=CallNameFromApiName
  36. NumArgs=1
  37. Begin=
  38. @ApiName
  39. End=
  40. TemplateName=MsgProlog
  41. NumArgs=0
  42. Begin=
  43. // @NL
  44. // @ApiName - @ApiNum @NL
  45. MSG_THUNK_BEGIN(@ApiName,@ArgList(@ArgNameHost@ArgMore(,))) @NL
  46. End=
  47. TemplateName=ApiExit
  48. NumArgs=0
  49. Begin=
  50. MSG_THUNK_END(@ApiName, wParamHost, lParamHost) @NL
  51. End=
  52. ; Generate the epilog for a thunked API.
  53. MacroName=ApiEpilog
  54. NumArgs=0
  55. Begin=
  56. return @IfApiRet(RetVal); @NL
  57. End=
  58. MacroName=GenMsgThunk
  59. NumArgs=1
  60. Begin=
  61. @IfApiCode(Header)
  62. @MsgProlog
  63. // Begin: IfApiCode(ApiEntry) @NL
  64. @IfApiCode(ApiEntry)
  65. @NL
  66. @Indent(
  67. @IfApiRet(@ApiFnRet RetVal;) @NL
  68. @NL
  69. // Begin: ApiLocals @NL
  70. @ApiLocals
  71. @NL
  72. // Begin: Types(Locals) @NL
  73. @Types(Locals)
  74. @NL
  75. // Begin: IfApiCode(Locals) @NL
  76. @IfApiCode(Locals)
  77. @NL
  78. //Begin: Types(PreCall) @NL
  79. @Types(PreCall)
  80. @NL
  81. // Begin: IfApiCode(PreCall) @NL
  82. @IfApiCode(PreCall)
  83. @NL
  84. // Begin: CallApi(MArg(1), RetVal) @NL
  85. @CallApi(@MArg(1), RetVal)
  86. @NL
  87. // Begin: Types(PostCall) @NL
  88. @Types(PostCall)
  89. @NL
  90. // Begin: ApiCode(PostCall) @NL
  91. @IfApiCode(PostCall)
  92. @NL
  93. // @NL
  94. // Begin: ApiEpilog @NL
  95. @ApiEpilog
  96. @NL
  97. )
  98. // Begin: IfApiCode(ApiExit) @NL
  99. @IfApiCode(ApiExit)
  100. @NL
  101. // Begin: ApiExit @NL
  102. @ApiExit
  103. @NL
  104. End=
  105. [IFunc]
  106. TemplateName=Thunks
  107. Header=
  108. End=
  109. ApiEntry=
  110. End=
  111. Begin=
  112. @GenMsgThunk(@CallNameFromApiName(@ApiName))
  113. End=
  114. ApiExit=
  115. End=
  116. [Types]
  117. TemplateName=LPHELPINFO
  118. IndLevel=0
  119. Direction=IN
  120. Locals=
  121. // @ArgName(@ArgType) is an IN LPHELPINFO. @NL
  122. End=
  123. PreCall=
  124. // @ArgName(@ArgType) is an IN LPHELPINFO. @NL
  125. @ArgName = Wow64ShallowAllocThunkHELPINFO32TO64((NT32HELPINFO *)@ArgHostName); @NL
  126. End=
  127. TemplateName=LPHLP
  128. IndLevel=0
  129. Direction=IN
  130. Locals=
  131. // @ArgName(@ArgType) is an IN LPHLP
  132. End=
  133. PreCall=
  134. // @ArgName(@ArgType) is an IN LPHLP. @NL
  135. @ArgName = Wow64ShallowAllocThunkHLP32TO64((NT32HLP *)@ArgHostName); @NL
  136. End=
  137. TemplateName=HKL
  138. IndLevel=0
  139. Direction=IN OUT
  140. PreCall=
  141. @ArgName=(HKL)(LongToPtr(@ArgHostName)); @NL
  142. End=
  143. PostCall=
  144. @ArgHostName=(NT32HKL)(@ArgName); @NL
  145. End=
  146. TemplateName=HKL
  147. IndLevel=0
  148. Direction=IN
  149. PreCall=
  150. @ArgName=(HKL)(LongToPtr(@ArgHostName)); @NL
  151. End=
  152. [EFunc]
  153. TemplateName=Wow64MsgFncWM_GETDLGCODE
  154. Begin=
  155. @NoFormat(
  156. //
  157. // This message is special in that it contains a pointer to another message.
  158. // It turns out that the kernel does not work correctly if this message points
  159. // to another structure. The kernel will not deep copy the message and thus
  160. // it wont work correctly cross process.
  161. // Here the inter message will be stuffed back through the message thunks.
  162. // If the message points to a structure, it will be converted to 64bit.
  163. // Unfortunatly, this can break an app that depends on the kernel not deep
  164. // copying the message. This can be fixed later if the messsage table
  165. // were augmented to say which parameters are pointers to structures and this
  166. // thunk could set them to NULL before passing in through and reset them in the
  167. // unpack stage.
  168. // Note: The message pointed to is an IN MSG.
  169. typedef struct _WM_GETDLGCODE_PARAMS {
  170. WPARAM wParamOld;
  171. PMSG_THUNKCB_FUNC wrapfuncOld;
  172. PVOID pContextOld;
  173. MSG *pMsg;
  174. } WM_GETDLGCODE_PARAMS, *PWM_GETDLGCODE_PARAMS;
  175. LONG_PTR whNT32Wow64MsgFncWM_GETDLGCODECB(WPARAM wParam, LPARAM lParam, PVOID pContext) {
  176. PWM_GETDLGCODE_PARAMS params;
  177. params = (PWM_GETDLGCODE_PARAMS)pContext;
  178. // Put the wParam and lParam back in the message that they came from.
  179. params->pMsg->wParam = wParam;
  180. params->pMsg->lParam = lParam;
  181. return (*(params->wrapfuncOld))(params->wParamOld, (LPARAM)params->pMsg, params->pContextOld);
  182. }
  183. MSG_THUNK_BEGIN(MSGFN(WM_GETDLGCODE),wParamHost, lParamHost)
  184. WM_GETDLGCODE_PARAMS params;
  185. WPARAM wParam;
  186. LPARAM lParam;
  187. MSG msg;
  188. NT32MSG *pmsg32;
  189. if ((PVOID)lParamHost == NULL) {
  190. wParam = (WPARAM)wParamHost;
  191. lParam = (LPARAM)lParamHost;
  192. return MSG_THUNK_CALLPROC(wParam, lParam);
  193. }
  194. // not used, but pass it for safety.
  195. params.wParamOld = (WPARAM)wParamHost;
  196. pmsg32 = (NT32MSG *)lParamHost;
  197. msg.hwnd = (HWND)pmsg32->hwnd;
  198. msg.message = pmsg32->message;
  199. msg.wParam = (WPARAM)pmsg32->wParam;
  200. msg.lParam = (LPARAM)pmsg32->lParam;
  201. msg.time = pmsg32->time;
  202. msg.pt.x = pmsg32->pt.x;
  203. msg.pt.y = pmsg32->pt.y;
  204. params.pMsg = &msg;
  205. params.wrapfuncOld = wrapfunc;
  206. params.pContextOld = pContext;
  207. return Wow64DoMessageThunk(whNT32Wow64MsgFncWM_GETDLGCODECB, msg.message, msg.wParam, msg.lParam, &params);
  208. MSG_THUNK_END(WM_NULL, wParamHost, lParamHost)
  209. )
  210. End=
  211. TemplateName=Wow64MsgFncWM_NCCALCSIZE
  212. NoType=lpncsp
  213. Locals=
  214. @ForceType(Locals,lpncsp,lpncspHost,LPNCCALCSIZE_PARAMS,IN OUT)
  215. End=
  216. PreCall=
  217. if (fCalcValidRectsHost) { @NL
  218. @ForceType(PreCall,lpncsp,lpncspHost,LPNCCALCSIZE_PARAMS,IN)
  219. } else { @NL
  220. // lpncsp is really a LPRECT @NL
  221. lpncsp=(LPNCCALCSIZE_PARAMS)lpncspHost; @NL
  222. } @NL
  223. End=
  224. PostCall=
  225. if (fCalcValidRectsHost) { @NL
  226. @ForceType(PostCall,lpncsp,lpncspHost,LPNCCALCSIZE_PARAMS,OUT)
  227. } else { @NL
  228. // lpncsp is really a LPRECT @NL
  229. } @NL
  230. End=
  231. TemplateName=Wow64MsgFncWM_SYSTIMER
  232. PreCall=
  233. if (tmprcHost != 0) { @NL
  234. WOWASSERT(gdwWM_SYSTIMERProcHiBits != 0); @NL
  235. tmprc = (TIMERPROC)(tmprcHost | (((UINT64) gdwWM_SYSTIMERProcHiBits) << 32)); @NL
  236. } @NL
  237. End=
  238. TemplateName=Wow64MsgFncLB_GETSELITEMS
  239. Locals=
  240. PINT lpiTemp;
  241. End=
  242. PreCall=
  243. if ((ARGUMENT_PRESENT (lpiItems) != 0) && @NL
  244. (((ULONG_PTR)lpiItems & (sizeof(INT) -1)) != 0)) { @NL
  245. @NL
  246. lpiTemp = Wow64AllocateTemp (sizeof (INT) * MaxSel); @NL
  247. if (lpiTemp != NULL) { @NL
  248. lpiItems = lpiTemp; @NL
  249. } @NL
  250. } @NL
  251. End=
  252. PostCall=
  253. if (PtrToUlong(lpiItems) != lpiItemsHost) { @NL
  254. try { @NL
  255. if (RetVal != -1) { @NL
  256. RtlCopyMemory (UlongToPtr(lpiItemsHost), lpiItems, RetVal * sizeof (INT)); @NL
  257. } @NL
  258. } except (EXCEPTION_EXECUTE_HANDLER) { @NL
  259. LOGPRINT((ERRORLOG, "Wow64MsgFncLB_GETSELITEMS Exception- %lx\n", GetExceptionCode ())); @NL
  260. RetVal = -1; @NL
  261. } @NL
  262. } @NL
  263. End=
  264. TemplateName=Wow64MsgFncLB_GETTEXT
  265. Locals=
  266. NTUSERMESSAGECALL_PARMS *MsgParams = (NTUSERMESSAGECALL_PARMS *)pContext;
  267. ULONG_PTR lParam64; @NL
  268. PWND pwnd; @NL
  269. BOOL bNotString = FALSE; @NL
  270. DWORD dw; @NL
  271. End=
  272. PreCall=
  273. try { @NL
  274. pwnd = Wow64ValidateHwnd(MsgParams->hwnd); @NL
  275. @NL
  276. dw = pwnd->style; @NL
  277. @NL
  278. /* @NL
  279. * See if the control is ownerdraw and does not have the LBS_HASSTRINGS @NL
  280. * style. If so, treat lParam as a DWORD. @NL
  281. */ @NL
  282. bNotString = (!(dw & LBS_HASSTRINGS) && @NL
  283. (dw & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)));@NL
  284. @NL
  285. if (bNotString != FALSE) { @NL
  286. lpszBuffer = (LPCSTR) &lParam64; @NL
  287. } @NL
  288. } except (EXCEPTION_EXECUTE_HANDLER) { @NL
  289. return -1; @NL
  290. } @NL
  291. End=
  292. PostCall=
  293. if ((RetVal != -1) && @NL
  294. (bNotString != FALSE)) { @NL
  295. try { @NL
  296. *((PULONG)lpszBufferHost) = (ULONG)lParam64;@NL
  297. RetVal >>= 1; @NL
  298. } except (EXCEPTION_EXECUTE_HANDLER) { @NL
  299. RetVal = -1; @NL
  300. } @NL
  301. } @NL
  302. End=
  303. [Code]
  304. TemplateName=msgthnk
  305. CGenBegin=
  306. @NoFormat(
  307. /*
  308. * genthunk generated code: Do Not Modify
  309. * Thunks for messages.
  310. *
  311. */
  312. #include "whwin32p.h"
  313. ASSERTNAME;
  314. #pragma warning(disable : 4311) //Disable pointer truncation warning
  315. #define MSGFN(id) Wow64MsgFnc##id
  316. #define MSG_THUNK_BEGIN(name,wparamname, lparamname) \
  317. LONG_PTR name(PMSG_THUNKCB_FUNC wrapfunc, WPARAM wParamArg, LPARAM lParamArg, PVOID pContext) { \
  318. \
  319. UINT wparamname; \
  320. LONG lparamname; \
  321. \
  322. wparamname = (UINT)wParamArg; \
  323. lparamname = (LONG)lParamArg; \
  324. \
  325. { \
  326. #define MSG_THUNK_CALLPROC(wParam, lParam) \
  327. (*wrapfunc)((WPARAM)wParam, (LPARAM)lParam, pContext)
  328. #define MSG_THUNK_END(name,wparamname, lparamname) \
  329. \
  330. } \
  331. \
  332. } \
  333. )
  334. @Template(Thunks)
  335. @NoFormat(
  336. typedef struct _MSG_ENTRY {
  337. PMSG_THUNK_FUNC ThunkFunc;
  338. UINT Id;
  339. LPSTR Name;
  340. } MSG_ENTRY, *PMSG_ENTRY;
  341. //
  342. //
  343. // This is the default thunk for messages. It sign extends lParam and zero extends wParam.
  344. //
  345. MSG_THUNK_BEGIN(MSGFN(WM_NULL),wParamHost, lParamHost)
  346. WPARAM wParam;
  347. LPARAM lParam;
  348. wParam = (WPARAM)wParamHost;
  349. lParam = (LPARAM)lParamHost;
  350. return MSG_THUNK_CALLPROC(wParam, lParam);
  351. MSG_THUNK_END(WM_NULL, wParamHost, lParamHost)
  352. //
  353. // Include messages.h to get the jump table.
  354. #define MSG_ENTRY_NOPARAM(entrynumber, id) {Wow64MsgFncWM_NULL, id, #id},
  355. #define MSG_ENTRY_WPARAM(entrynumber, id, wparam) {Wow64MsgFnc##id, id, #id},
  356. #define MSG_ENTRY_LPARAM(entrynumber, id, lparam) {Wow64MsgFnc##id, id, #id},
  357. #define MSG_ENTRY_STD(entrynumber, id, wparam, lparam) {Wow64MsgFnc##id, id, #id},
  358. #define MSG_ENTRY_UNREFERENCED(entrynumber, id) {Wow64MsgFncWM_NULL, entrynumber, NULL},
  359. #define MSG_ENTRY_KERNELONLY(entrynumber, id) {Wow64MsgFncWM_NULL, entrynumber, NULL},
  360. #define MSG_ENTRY_EMPTY(entrynumber) {Wow64MsgFncWM_NULL, entrynumber, NULL},
  361. #define MSG_ENTRY_RESERVED(entrynumber) {Wow64MsgFncWM_NULL, entrynumber, NULL},
  362. #define MSG_ENTRY_TODO(entrynumber) {Wow64MsgFncWM_NULL, entrynumber, NULL},
  363. #define MSG_TABLE_BEGIN CONST MSG_ENTRY MsgTable[] = {
  364. #define MSG_TABLE_END {0, 0, NULL} };
  365. #include "messages.h"
  366. //
  367. // Include messages.h again to get the profile table.
  368. #if defined(WOW64DOPROFILE)
  369. #undef MSG_ENTRY_NOPARAM
  370. #undef MSG_ENTRY_WPARAM
  371. #undef MSG_ENTRY_LPARAM
  372. #undef MSG_ENTRY_STD
  373. #undef MSG_ENTRY_UNREFERENCED
  374. #undef MSG_ENTRY_KERNELONLY
  375. #undef MSG_ENTRY_EMPTY
  376. #undef MSG_ENTRY_RESERVED
  377. #undef MSG_ENTRY_TODO
  378. #undef MSG_TABLE_BEGIN
  379. #undef MSG_TABLE_END
  380. #define MSG_ENTRY_NOPARAM(entrynumber, id) {L#id,0,NULL,TRUE},
  381. #define MSG_ENTRY_WPARAM(entrynumber, id, wparam) {L#id,0,NULL,TRUE},
  382. #define MSG_ENTRY_LPARAM(entrynumber, id, lparam) {L#id,0,NULL,TRUE},
  383. #define MSG_ENTRY_STD(entrynumber, id, wparam, lparam) {L#id,0,NULL,TRUE},
  384. #define MSG_ENTRY_UNREFERENCED(entrynumber, id) {L"Unreferenced",0,NULL,FALSE},
  385. #define MSG_ENTRY_KERNELONLY(entrynumber, id) {L"KernelOnly",0,NULL,FALSE},
  386. #define MSG_ENTRY_EMPTY(entrynumber) {L"Empty",0,NULL,FALSE},
  387. #define MSG_ENTRY_RESERVED(entrynumber) {L"Reserved",0,NULL,FALSE},
  388. #define MSG_ENTRY_TODO(entrynumber) {L"TODO",0,NULL,TRUE},
  389. #define MSG_TABLE_BEGIN WOW64SERVICE_PROFILE_TABLE_ELEMENT ptemsgthnk[] = {
  390. #define MSG_TABLE_END {NULL, 0} };
  391. #include "messages.h"
  392. WOW64SERVICE_PROFILE_TABLE ptmsgthnk = {L"MSGTHNK", L"Outbound Message Thunks",
  393. ptemsgthnk, (sizeof(ptemsgthnk)/sizeof(WOW64SERVICE_PROFILE_TABLE_ELEMENT))-1}; @NL
  394. #endif
  395. LONG_PTR
  396. Wow64DoMessageThunk(PMSG_THUNKCB_FUNC func,
  397. UINT msg,
  398. WPARAM wParam,
  399. LPARAM lParam,
  400. PVOID pContext)
  401. /*++
  402. Routine Description:
  403. This function is called to dispatch a message through the message thunks.
  404. Arguments:
  405. func - supplies the callback function.
  406. msg - supplies the id of the message.
  407. wParam - supplies the wParam of the message.
  408. lParam - supplies the lParam of the message.
  409. pContext - supplies the context that is passed to the callback function.
  410. Return Value:
  411. Return value of the actual function call, called by the callback function.
  412. --*/
  413. {
  414. LONG_PTR retval;
  415. //
  416. // For now, do not thunk messages greater then or equal to WM_USER.
  417. if (WM_USER <= msg) {
  418. LOGPRINT((TRACELOG, "Wow64DoMessageThunk: skipping thunking of outbound %x since it is >= WM_USER\n", msg));
  419. return (*func)(wParam, lParam, pContext);
  420. }
  421. LOGPRINT((TRACELOG, "Wow64DoMessageThunk: starting thunk of outbound %s(%x)\n",
  422. MsgTable[msg].Name, MsgTable[msg].Id));
  423. WOWASSERT(MsgTable[msg].Id == msg);
  424. #if defined(WOW64DOPROFILE)
  425. ptemsgthnk[msg].HitCount++;
  426. #endif
  427. retval = (*(MsgTable[msg].ThunkFunc))(func, wParam, lParam, pContext);
  428. LOGPRINT((TRACELOG, "Wow64DoMessageThunk: finished thunk of outbound %s(%x), retval %I64x\n",
  429. MsgTable[msg].Name, MsgTable[msg].Id, retval));
  430. return retval;
  431. }
  432. )
  433. End=