Commit d418460f authored by Felix Nawothnig's avatar Felix Nawothnig Committed by Alexandre Julliard

- Replaced server requests in EnumProcesses by native APIs

- Fixed third parameter (should return the amount of used and not needed memory).
parent 8dd4ee76
......@@ -75,61 +75,49 @@ BOOL WINAPI EnumPageFilesW( PENUM_PAGE_FILE_CALLBACKW callback, LPVOID context )
/***********************************************************************
* EnumProcesses (PSAPI.@)
*/
BOOL WINAPI EnumProcesses(DWORD *lpidProcess, DWORD cb, DWORD *lpcbNeeded)
BOOL WINAPI EnumProcesses(DWORD *lpdwProcessIDs, DWORD cb, DWORD *lpcbUsed)
{
HANDLE hSnapshot;
DWORD count;
DWORD countMax;
DWORD pid;
int ret;
SYSTEM_PROCESS_INFORMATION *spi;
NTSTATUS status;
PVOID pBuf = NULL;
ULONG nAlloc = 0x8000;
TRACE("(%p, %ld, %p)\n", lpidProcess,cb, lpcbNeeded);
do {
if (pBuf != NULL)
{
HeapFree(GetProcessHeap(), 0, pBuf);
nAlloc *= 2;
}
if ( lpidProcess == NULL )
cb = 0;
if ( lpcbNeeded != NULL )
*lpcbNeeded = 0;
pBuf = HeapAlloc(GetProcessHeap(), 0, nAlloc);
if (pBuf == NULL)
return FALSE;
SERVER_START_REQ( create_snapshot )
{
req->flags = SNAP_PROCESS;
req->inherit = FALSE;
req->pid = 0;
wine_server_call_err( req );
hSnapshot = reply->handle;
}
SERVER_END_REQ;
status = NtQuerySystemInformation(SystemProcessInformation, pBuf,
nAlloc, NULL);
} while (status == STATUS_INFO_LENGTH_MISMATCH);
if ( hSnapshot == 0 )
if (status != STATUS_SUCCESS)
{
FIXME("cannot create snapshot\n");
HeapFree(GetProcessHeap(), 0, pBuf);
SetLastError(RtlNtStatusToDosError(status));
return FALSE;
}
count = 0;
countMax = cb / sizeof(DWORD);
for (;;)
spi = pBuf;
for(*lpcbUsed = 0; cb >= sizeof(DWORD); cb -= sizeof(DWORD))
{
SERVER_START_REQ( next_process )
{
req->handle = hSnapshot;
req->reset = (count == 0);
if ((ret = !wine_server_call_err( req )))
pid = reply->pid;
}
SERVER_END_REQ;
if (!ret) break;
TRACE("process 0x%08lx\n", pid);
if ( count < countMax )
lpidProcess[count] = pid;
count++;
}
CloseHandle( hSnapshot );
*lpdwProcessIDs++ = spi->dwProcessID;
*lpcbUsed += sizeof(DWORD);
if ( lpcbNeeded != NULL )
*lpcbNeeded = sizeof(DWORD) * count;
if(spi->dwOffset == 0)
break;
TRACE("return %lu processes\n", count);
spi = (SYSTEM_PROCESS_INFORMATION *)(((PCHAR)spi) + spi->dwOffset);
}
HeapFree(GetProcessHeap(), 0, pBuf);
return TRUE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment