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.

80 lines
1.5 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. GlobalMemoryStatusTrim.cpp
  5. Abstract:
  6. Limits the amount of swap space and physical memory returned from the
  7. GlobalMemoryStatus API. This is necessary for some apps run on 64 bit
  8. machines which have over 2 gig of memory.
  9. Notes:
  10. This is a general purpose shim.
  11. History:
  12. 04/19/2002 mnikkel Created
  13. --*/
  14. #include "precomp.h"
  15. #include "CharVector.h"
  16. IMPLEMENT_SHIM_BEGIN(GlobalMemoryStatusTrim)
  17. #include "ShimHookMacro.h"
  18. APIHOOK_ENUM_BEGIN
  19. APIHOOK_ENUM_ENTRY(GlobalMemoryStatus)
  20. APIHOOK_ENUM_END
  21. /*++
  22. Limit the swap space and physical memory size
  23. --*/
  24. VOID
  25. APIHOOK(GlobalMemoryStatus)(
  26. LPMEMORYSTATUS lpBuffer
  27. )
  28. {
  29. ORIGINAL_API(GlobalMemoryStatus)(lpBuffer);
  30. // change page file to always be 2 gig or less
  31. if (lpBuffer->dwTotalPageFile > 0x7FFFFFFF) {
  32. lpBuffer->dwTotalPageFile = 0x7FFFFFFF;
  33. }
  34. if (lpBuffer->dwAvailPageFile > 0x7FFFFFFF) {
  35. lpBuffer->dwAvailPageFile = 0x7FFFFFFF;
  36. }
  37. // change physical memory to always be 1 gig or less
  38. if (lpBuffer->dwTotalPhys > 0x3FFFFFFF) {
  39. lpBuffer->dwTotalPhys = 0x3FFFFFFF;
  40. }
  41. if (lpBuffer->dwAvailPhys > 0x3FFFFFFF) {
  42. lpBuffer->dwAvailPhys = 0x3FFFFFFF;
  43. }
  44. return;
  45. }
  46. /*++
  47. Register hooked functions
  48. --*/
  49. HOOK_BEGIN
  50. APIHOOK_ENTRY(KERNEL32.DLL, GlobalMemoryStatus)
  51. HOOK_END
  52. IMPLEMENT_SHIM_END