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.

312 lines
7.1 KiB

  1. /*++
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, 1992, 1993 Microsoft Corporation
  6. *
  7. * WOWTBL.C
  8. * WOW32 API thunks
  9. *
  10. * The reason for having one huge table is so the thunks can be dispatched
  11. * faster. When in separate tables, you had to do shifting and
  12. * multiplication to derive the thunk routine from the function ID.
  13. *
  14. *
  15. * History:
  16. * barry bradie (barryb) 1-dec-92 combined individual tables
  17. --*/
  18. #include "precomp.h"
  19. #pragma hdrstop
  20. #ifdef FE_IME
  21. #include "winnls32.h"
  22. #include "wownls.h"
  23. #include "wnman.h"
  24. #endif // FE_IME
  25. #ifdef FE_SB // suports WIFE API (MiscGetEUDCLeadByteRange)
  26. #include "wowwife.h"
  27. #include "wwmman.h"
  28. #endif // FE_SB
  29. #include "wowit.h"
  30. MODNAME(wowtbl.c);
  31. //
  32. // DON'T CHANGE THE ORDER IN WHICH THESE FILES ARE INCLUDED!
  33. //
  34. // see W32GetTableOffsets (wow32.c) and kernel31\kdata.asm
  35. //
  36. W32 aw32WOW[] = {
  37. #include "wktbl2.h"
  38. {W32FUN((LPFNW32)-1, "TABLESEPARATOR", 0, 0)},
  39. #include "wutbl2.h"
  40. {W32FUN((LPFNW32)-1, "TABLESEPARATOR", 0, 0)},
  41. #include "wgtbl2.h"
  42. {W32FUN((LPFNW32)-1, "TABLESEPARATOR", 0, 0)},
  43. #include "wkbdtbl2.h"
  44. {W32FUN((LPFNW32)-1, "TABLESEPARATOR", 0, 0)},
  45. #include "wstbl2.h"
  46. {W32FUN((LPFNW32)-1, "TABLESEPARATOR", 0, 0)},
  47. #include "wshtbl2.h"
  48. {W32FUN((LPFNW32)-1, "TABLESEPARATOR", 0, 0)},
  49. #include "wwstbl2.h"
  50. {W32FUN((LPFNW32)-1, "TABLESEPARATOR", 0, 0)},
  51. #include "wthtbl2.h"
  52. {W32FUN((LPFNW32)-1, "TABLESEPARATOR", 0, 0)},
  53. #include "wmmtbl2.h"
  54. {W32FUN((LPFNW32)-1, "TABLESEPARATOR", 0, 0)},
  55. #include "wcmdgtbl.h"
  56. {W32FUN((LPFNW32)-1, "TABLESEPARATOR", 0, 0)},
  57. #ifdef FE_SB
  58. #ifdef FE_IME
  59. #include "wntbl2.h"
  60. {W32FUN((LPFNW32)-1, "TABLESEPARATOR", 0, 0)},
  61. #endif // FE_IME
  62. #include "wwmtbl2.h"
  63. {W32FUN((LPFNW32)-1, "TABLESEPARATOR", 0, 0)},
  64. #endif // !FE_SB
  65. };
  66. TABLEOFFSETS tableoffsets;
  67. // REMOVECODE Remove comments below before shipping NT 5. See Also WOW32Unimplemented95API in wow32.c and wowtbl.h
  68. // #ifdef DEBUG_OR_WOWPROFILE
  69. INT cAPIThunks;
  70. // #endif
  71. #ifdef WOWPROFILE
  72. PW32 pawThunkTable = aw32WOW;
  73. #endif
  74. VOID InitThunkTableOffsets(VOID)
  75. {
  76. WORD current;
  77. WORD offsetarray[(MOD_LAST - MOD_KERNEL) / FUN_MASK + 1];
  78. UINT i;
  79. for (current = 0; current < sizeof(aw32WOW)/sizeof(aw32WOW[0]); current++) {
  80. if (current == 0) {
  81. i = 0;
  82. offsetarray[i++] = current;
  83. }
  84. else if (aw32WOW[current].lpfnW32 == (LPFNW32)-1) {
  85. offsetarray[i++] = current + 1;
  86. }
  87. }
  88. tableoffsets.kernel =
  89. tableoffsets.dkernel = offsetarray[MOD_KERNEL / FUN_MASK];
  90. tableoffsets.user =
  91. tableoffsets.duser = offsetarray[MOD_USER / FUN_MASK];
  92. tableoffsets.gdi =
  93. tableoffsets.dgdi = offsetarray[MOD_GDI / FUN_MASK];
  94. tableoffsets.keyboard = offsetarray[MOD_KEYBOARD / FUN_MASK];
  95. tableoffsets.sound = offsetarray[MOD_SOUND / FUN_MASK];
  96. tableoffsets.shell = offsetarray[MOD_SHELL / FUN_MASK];
  97. tableoffsets.winsock = offsetarray[MOD_WINSOCK / FUN_MASK];
  98. tableoffsets.toolhelp = offsetarray[MOD_TOOLHELP / FUN_MASK];
  99. tableoffsets.mmedia = offsetarray[MOD_MMEDIA / FUN_MASK];
  100. tableoffsets.commdlg = offsetarray[MOD_COMMDLG / FUN_MASK];
  101. #ifdef FE_IME
  102. tableoffsets.winnls = offsetarray[MOD_WINNLS / FUN_MASK];
  103. #endif // FE_IME
  104. #ifdef FE_SB
  105. tableoffsets.wifeman = offsetarray[MOD_WIFEMAN / FUN_MASK];
  106. #endif // FE_SB
  107. #ifdef DEBUG_OR_WOWPROFILE
  108. cAPIThunks = sizeof(aw32WOW) / sizeof(aw32WOW[0]);
  109. #endif
  110. }
  111. #ifdef DEBUG_OR_WOWPROFILE
  112. INT ModFromCallID(INT iFun)
  113. {
  114. PTABLEOFFSETS pto = &tableoffsets;
  115. if (iFun < pto->user)
  116. return MOD_KERNEL;
  117. if (iFun < pto->gdi)
  118. return MOD_USER;
  119. if (iFun < pto->keyboard)
  120. return MOD_GDI;
  121. if (iFun < pto->sound)
  122. return MOD_KEYBOARD;
  123. if (iFun < pto->shell)
  124. return MOD_SOUND;
  125. if (iFun < pto->winsock)
  126. return MOD_SHELL;
  127. if (iFun < pto->toolhelp)
  128. return MOD_WINSOCK;
  129. if (iFun < pto->mmedia)
  130. return MOD_TOOLHELP;
  131. if (iFun < pto->commdlg) {
  132. return(MOD_MMEDIA);
  133. }
  134. #if defined(FE_SB)
  135. #if defined(FE_IME)
  136. if (iFun < pto->winnls)
  137. return MOD_COMMDLG;
  138. if (iFun < pto->wifeman)
  139. return MOD_WINNLS;
  140. if (iFun < cAPIThunks)
  141. return MOD_WIFEMAN;
  142. #else
  143. if (iFun < pto->wifeman)
  144. return MOD_COMMDLG;
  145. if (iFun < cAPIThunks)
  146. return MOD_WIFEMAN;
  147. #endif
  148. #elif defined(FE_IME)
  149. if (iFun < pto->winnls)
  150. return MOD_COMMDLG;
  151. if (iFun < cAPIThunks)
  152. return MOD_WINNLS;
  153. #else
  154. if (iFun < cAPIThunks)
  155. return MOD_COMMDLG;
  156. #endif
  157. return -1;
  158. }
  159. PSZ apszModNames[] = { "Kernel",
  160. "User",
  161. "Gdi",
  162. "Keyboard",
  163. "Sound",
  164. "Shell",
  165. "Winsock",
  166. "Toolhelp",
  167. "MMedia",
  168. "Commdlg"
  169. #ifdef FE_IME
  170. ,"WinNLS"
  171. #endif
  172. #ifdef FE_SB
  173. ,"WifeMan"
  174. #endif
  175. };
  176. INT nModNames = NUMEL(apszModNames);
  177. PSZ GetModName(INT iFun)
  178. {
  179. INT nMod;
  180. nMod = ModFromCallID(iFun);
  181. if (nMod == -1) {
  182. return "BOGUS!!";
  183. }
  184. nMod = nMod >> 12; // get the value into the low byte
  185. return apszModNames[nMod];
  186. }
  187. INT GetOrdinal(INT iFun)
  188. {
  189. INT nMod;
  190. nMod = ModFromCallID(iFun);
  191. if (nMod == -1) {
  192. return 0;
  193. }
  194. return (iFun - TableOffsetFromName(apszModNames[nMod >> 12]));
  195. }
  196. INT TableOffsetFromName(PSZ szTab)
  197. {
  198. INT i;
  199. PTABLEOFFSETS pto = &tableoffsets;
  200. for (i = 0; i < NUMEL(apszModNames); i++) {
  201. if (!WOW32_strcmp(szTab, apszModNames[i]))
  202. break;
  203. }
  204. if (i >= NUMEL(apszModNames))
  205. return 0;
  206. switch (i << 12) {
  207. case MOD_KERNEL:
  208. return pto->kernel;
  209. case MOD_USER:
  210. return pto->user;
  211. case MOD_DGDI:
  212. return pto->gdi;
  213. case MOD_KEYBOARD:
  214. return pto->keyboard;
  215. case MOD_SOUND:
  216. return pto->sound;
  217. case MOD_SHELL:
  218. return pto->shell;
  219. case MOD_WINSOCK:
  220. return pto->winsock;
  221. case MOD_TOOLHELP:
  222. return pto->toolhelp;
  223. case MOD_MMEDIA:
  224. return pto->mmedia;
  225. case MOD_COMMDLG:
  226. return(pto->commdlg);
  227. #ifdef FE_IME
  228. case MOD_WINNLS:
  229. return pto->winnls;
  230. #endif
  231. #ifdef FE_SB
  232. case MOD_WIFEMAN:
  233. return pto->wifeman;
  234. #endif
  235. default:
  236. return(-1);
  237. }
  238. }
  239. #endif