[QUOTE=bujin888;1228863]
谁说-1无效的? 在这个函数中-1和0xFFFFFFFF是等效的!其次在win7 ring3层没看见说-1 无效 只有为0时才无效
BOOL __stdcall SetProcessWorkingSetSize(HANDLE hProcess, SIZE_T dwMinimumWorkingSetSize, SIZE_T dwMaximumWorkingSetSize)
{
return SetProcessWorkingSetSizeEx(hProcess, dwMinimumWorkingSetSize, dwMaximumWorkingSetSize, 0);
}
BOOL __stdcall SetProcessWorkingSetSizeEx(HANDLE hProcess, SIZE_T dwMinimumWorkingSetSize, SIZE_T dwMaximumWorkingSetSize, DWORD Flags)
{
int v4; // edi@3
signed int v5; // esi@3
int ProcessInformation; // [sp+8h] [bp-40h]@1
char Dst; // [sp+Ch] [bp-3Ch]@1
SIZE_T v9; // [sp+10h] [bp-38h]@3
SIZE_T v10; // [sp+14h] [bp-34h]@3
DWORD v11; // [sp+38h] [bp-10h]@3
int v12; // [sp+40h] [bp-8h]@1
int v13; // [sp+44h] [bp-4h]@1
bool dwMinimumWorkingSetSizea; // [sp+54h] [bp+Ch]@3
v12 = 33;
v13 = 14;
ProcessInformation = 0;
memset(&Dst, 0, 0x34u);
if ( dwMinimumWorkingSetSize && dwMaximumWorkingSetSize )
{
v10 = dwMaximumWorkingSetSize;
v11 = Flags;
v9 = dwMinimumWorkingSetSize;
v4 = RtlAcquirePrivilege(&v12, 2, 0, &dwMaximumWorkingSetSize);
v5 = Nt
SetInformationProcess(hProcess, ProcessQuotaLimits, &ProcessInformation, 0x38u);
dwMinimumWorkingSetSizea = v5 >= 0;
if ( v4 >= 0 )
{
RtlReleasePrivilege(dwMaximumWorkingSetSize);
dwMaximumWorkingSetSize = 0;
}
}
else
{
v5 = -1073741811;
dwMinimumWorkingSetSizea = 0;
}
if ( !dwMinimumWorkingSetSizea )
BaseSetLastNTError(v5);
return dwMinimumWorkingSetSizea;
}
内核中也没看见
case ProcessQuotaLimits:
Length = sizeof(QUOTA_LIMITS);
if (ProcessInformationLength != Length)
{
Status = STATUS_INFO_LENGTH_MISMATCH;
break;
}
Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_QUERY_INFORMATION,
PsProcessType,
PreviousMode,
(PVOID*)&Process,
NULL);
if (!NT_SUCCESS(Status)) break;
Status = STATUS_SUCCESS;
_SEH2_TRY
{
QuotaLimits->MaximumWorkingSetSize =
Process->Vm.MaximumWorkingSetSize << PAGE_SHIFT;
QuotaLimits->MinimumWorkingSetSize =
Process->Vm.MinimumWorkingSetSize << PAGE_SHIFT;
QuotaLimits->TimeLimit.LowPart = MAXULONG;
QuotaLimits->TimeLimit.HighPart = MAXULONG;
if (Process->QuotaBlock == &PspDefaultQuotaBlock)
{
QuotaLimits->PagedPoolLimit = (SIZE_T)-1;
QuotaLimits->NonPagedPoolLimit = (SIZE_T)-1;
QuotaLimits->PagefileLimit = (SIZE_T)-1;
}
else
{
QuotaLimits->PagedPoolLimit =
Process->QuotaBlock->QuotaEntry[PagedPool].Limit;
QuotaLimits->NonPagedPoolLimit =
Process->QuotaBlock->QuotaEntry[NonPagedPool].Limit;
QuotaLimits->PagefileLimit =
Process->QuotaBlock->QuotaEntry[2].Limit;
}
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
Status = _SEH2_GetExceptionCode();
}
_SEH2_END;
[/QUOTE]
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
SIZE_T min, max;
GetProcessWorkingSetSize(GetCurrentProcess(), &min, &max);
cout << min << "\t" << max << endl;
if (!SetProcessWorkingSetSize(GetCurrentProcess(), -1, -1))
{
cout << "failed";
}
else
{
GetProcessWorkingSetSize(GetCurrentProcess(), &min, &max);
cout << min << "\t" << max << endl;
}
}
另外你的代码是从ReactOS中提取出来的,不是Windows NT的实现
另外你的代码是Nt
QueryInformationProcess的片段,不是Nt
SetInformationProcess的片段,这真是哈哈哈哈.那么就让我给大家展示一下ReactOS的NtSetInformationProcess中对这个功能的实现吧!
case ProcessQuotaLimits:
DPRINT1("Quota Limits not implemented\n");
Status = STATUS_NOT_IMPLEMENTED;
break;
关于具体实现大家可以自己去WRK的ps\psquery.c:1889(PspSetQuotaLimits)一探究竟