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.

98 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. LowerThreadPriority.cpp
  5. Abstract:
  6. Includes the following hooks:
  7. SetThreadPriority: if the thread priority is THREAD_PRIORITY_TIME_CRITICAL,
  8. change it to THREAD_PRIORITY_HIGHEST.
  9. SetPriorityClass: if the process priority is HIGH_PRIORITY_CLASS or
  10. REALTIME_PRIORITY_CLASS, change it to
  11. NORMAL_PRIORITY_CLASS.
  12. Notes:
  13. This is a general purpose shim.
  14. History:
  15. 05/23/2001 qzheng Created
  16. --*/
  17. #include "precomp.h"
  18. IMPLEMENT_SHIM_BEGIN(LowerThreadPriority)
  19. #include "ShimHookMacro.h"
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_ENTRY(SetThreadPriority)
  22. APIHOOK_ENUM_ENTRY(SetPriorityClass)
  23. APIHOOK_ENUM_END
  24. BOOL
  25. APIHOOK(SetThreadPriority)(
  26. HANDLE hThread,
  27. int nPriority
  28. )
  29. {
  30. BOOL bReturnValue;
  31. int nNewPriority;
  32. LOGN( eDbgLevelInfo,
  33. "Original SetThreadPriority(hThread: 0x%08lx, nPriority: %d).", hThread, nPriority );
  34. nNewPriority = (nPriority == THREAD_PRIORITY_TIME_CRITICAL) ? THREAD_PRIORITY_HIGHEST : nPriority;
  35. bReturnValue = ORIGINAL_API(SetThreadPriority)(hThread, nNewPriority);
  36. if( bReturnValue && (nNewPriority != nPriority) ) {
  37. LOGN( eDbgLevelInfo,
  38. "New SetThreadPriority(hThread: 0x%08lx, nPriority: %d).", hThread, nNewPriority );
  39. }
  40. return bReturnValue;
  41. }
  42. BOOL
  43. APIHOOK(SetPriorityClass)(
  44. HANDLE hProcess,
  45. DWORD dwPriorityClass
  46. )
  47. {
  48. BOOL bReturnValue;
  49. DWORD dwNewPriorityClass;
  50. LOGN( eDbgLevelInfo,
  51. "Original SetPriorityClass(hProcess: 0x%08lx, dwPriorityClass: %d).", hProcess, dwPriorityClass );
  52. dwNewPriorityClass = ( (dwPriorityClass == HIGH_PRIORITY_CLASS) || (dwPriorityClass == REALTIME_PRIORITY_CLASS) ) ?
  53. NORMAL_PRIORITY_CLASS : dwPriorityClass;
  54. bReturnValue = ORIGINAL_API(SetPriorityClass)(hProcess, dwNewPriorityClass);
  55. if( bReturnValue && (dwNewPriorityClass != dwPriorityClass) ) {
  56. LOGN( eDbgLevelInfo,
  57. "New SetPriorityClass (hProcess: 0x%08lx, dwPriorityClass: %d).", hProcess, dwNewPriorityClass );
  58. }
  59. return bReturnValue;
  60. }
  61. /*++
  62. Register hooked functions
  63. --*/
  64. HOOK_BEGIN
  65. APIHOOK_ENTRY(KERNEL32.DLL, SetThreadPriority)
  66. APIHOOK_ENTRY(KERNEL32.DLL, SetPriorityClass)
  67. HOOK_END
  68. IMPLEMENT_SHIM_END