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.

74 lines
1.8 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include "psapi.h"
  6. BOOL
  7. WINAPI
  8. EmptyWorkingSet(
  9. HANDLE hProcess
  10. )
  11. {
  12. NTSTATUS Status;
  13. QUOTA_LIMITS QuotaLimits;
  14. SYSTEM_INFO SystemInfo;
  15. GetSystemInfo(&SystemInfo);
  16. Status = NtQueryInformationProcess(hProcess,
  17. ProcessQuotaLimits,
  18. &QuotaLimits,
  19. sizeof(QuotaLimits),
  20. NULL);
  21. if ( !NT_SUCCESS(Status) ) {
  22. SetLastError( RtlNtStatusToDosError( Status ) );
  23. return(FALSE);
  24. }
  25. // The following signals a desire to empty the working set
  26. QuotaLimits.MinimumWorkingSetSize = (SIZE_T)-1;
  27. QuotaLimits.MaximumWorkingSetSize = (SIZE_T)-1;
  28. Status = NtSetInformationProcess(hProcess,
  29. ProcessQuotaLimits,
  30. &QuotaLimits,
  31. sizeof(QuotaLimits));
  32. if ( !NT_SUCCESS(Status) && Status != STATUS_PRIVILEGE_NOT_HELD ) {
  33. SetLastError( RtlNtStatusToDosError( Status ) );
  34. return(FALSE);
  35. }
  36. return(TRUE);
  37. }
  38. BOOL
  39. WINAPI
  40. QueryWorkingSet(
  41. HANDLE hProcess,
  42. PVOID pv,
  43. DWORD cb
  44. )
  45. {
  46. NTSTATUS Status;
  47. Status = NtQueryVirtualMemory(hProcess,
  48. NULL,
  49. MemoryWorkingSetInformation,
  50. pv,
  51. cb,
  52. NULL);
  53. if ( !NT_SUCCESS(Status) ) {
  54. SetLastError( RtlNtStatusToDosError( Status ) );
  55. return(FALSE);
  56. }
  57. return(TRUE);
  58. }