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.

123 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. MidTownMadness2.cpp
  5. Abstract:
  6. This app has a funky timing system whereby it waits for the processor that
  7. it's running on to return a 'stable' speed. The calculation is especially
  8. prone to problems on faster machines because there is greater uncertainty.
  9. Not sure why we hit this so easily on dual-procs - perhaps something about
  10. the scheduler wrt sleep and timeGetTime.
  11. Notes:
  12. This is an app specific shim.
  13. History:
  14. 11/15/2001 linstev Created
  15. --*/
  16. #include "precomp.h"
  17. IMPLEMENT_SHIM_BEGIN(MidTownMadness2)
  18. #include "ShimHookMacro.h"
  19. APIHOOK_ENUM_BEGIN
  20. APIHOOK_ENUM_ENTRY(Sleep)
  21. APIHOOK_ENUM_ENTRY(timeGetTime)
  22. APIHOOK_ENUM_END
  23. DWORD g_dwState;
  24. DWORD g_dwTimer;
  25. DWORD g_dwLastTime;
  26. /*++
  27. After we call GetDlgItemTextA we convert the long path name to the short path name.
  28. --*/
  29. DWORD
  30. APIHOOK(timeGetTime)(VOID)
  31. {
  32. DWORD dwRet = ORIGINAL_API(timeGetTime)();
  33. switch (g_dwState) {
  34. case 0:
  35. // Initial state
  36. g_dwLastTime = dwRet;
  37. g_dwState++;
  38. break;
  39. case 1:
  40. // Shouldn't get here, reset state
  41. g_dwState = 0;
  42. break;
  43. case 2:
  44. // We're in the known bad zone, return our precalculated value
  45. dwRet = g_dwLastTime + g_dwTimer;
  46. g_dwState = 0;
  47. break;
  48. }
  49. return dwRet;
  50. }
  51. VOID
  52. APIHOOK(Sleep)(
  53. DWORD dwMilliseconds
  54. )
  55. {
  56. //
  57. // Check for their specific sleep and update our state if required
  58. //
  59. if (dwMilliseconds == 100 && g_dwState == 1) {
  60. g_dwState = 2;
  61. }
  62. ORIGINAL_API(Sleep)(dwMilliseconds);
  63. }
  64. /*++
  65. Register hooked functions
  66. --*/
  67. BOOL
  68. NOTIFY_FUNCTION(
  69. DWORD fdwReason)
  70. {
  71. if (fdwReason == SHIM_STATIC_DLLS_INITIALIZED) {
  72. // Make the calculation that the app does
  73. DWORD dwTimer = timeGetTime();
  74. Sleep(100);
  75. g_dwTimer = timeGetTime() - dwTimer;
  76. // Set initial state to 0
  77. g_dwState = 0;
  78. }
  79. return TRUE;
  80. }
  81. HOOK_BEGIN
  82. CALL_NOTIFY_FUNCTION
  83. APIHOOK_ENTRY(KERNEL32.DLL, Sleep)
  84. APIHOOK_ENTRY(WINMM.DLL, timeGetTime)
  85. HOOK_END
  86. IMPLEMENT_SHIM_END