From 1a9ed68d15d9b61d2dab4f059f20eb88873c2008 Mon Sep 17 00:00:00 2001 From: "KJK::Hyperion" Date: Tue, 18 Jun 2002 22:16:53 +0000 Subject: [PATCH] PSAPI initial commit svn path=/trunk/; revision=3120 --- reactos/lib/psapi/enum/module.c | 108 ++++++++++ reactos/lib/psapi/enum/process.c | 138 ++++++++++++ reactos/lib/psapi/include/internal/psapi.h | 61 ++++++ reactos/lib/psapi/makefile | 18 +- reactos/lib/psapi/misc/dllmain.c | 26 +-- reactos/lib/psapi/misc/malloc.c | 62 ++++++ reactos/lib/psapi/misc/stubs.c | 236 ++++++++++++--------- reactos/lib/psapi/misc/win32.c | 136 ++++++++++++ reactos/lib/psapi/psapi.def | 24 +++ reactos/lib/psapi/psapi.edf | 24 +++ reactos/lib/psapi/psapi.rc | 38 ++++ 11 files changed, 752 insertions(+), 119 deletions(-) create mode 100644 reactos/lib/psapi/enum/module.c create mode 100644 reactos/lib/psapi/enum/process.c create mode 100644 reactos/lib/psapi/include/internal/psapi.h create mode 100644 reactos/lib/psapi/misc/malloc.c create mode 100644 reactos/lib/psapi/misc/win32.c create mode 100644 reactos/lib/psapi/psapi.def create mode 100644 reactos/lib/psapi/psapi.edf create mode 100644 reactos/lib/psapi/psapi.rc diff --git a/reactos/lib/psapi/enum/module.c b/reactos/lib/psapi/enum/module.c new file mode 100644 index 00000000000..d052429d2df --- /dev/null +++ b/reactos/lib/psapi/enum/module.c @@ -0,0 +1,108 @@ +/* $Id: module.c,v 1.1 2002/06/18 22:12:51 hyperion Exp $ +*/ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: reactos/lib/psapi/enum/module.c + * PURPOSE: Enumerate system modules + * PROGRAMMER: KJK::Hyperion + * UPDATE HISTORY: + * 10/06/2002: Created + */ + +#include +#include +#include + +NTSTATUS +STDCALL +PsaEnumerateSystemModules +( + OUT PVOID * Modules, + IN ULONG ModulesLength, + OUT ULONG * ReturnLength OPTIONAL +) +{ + NTSTATUS nErrCode = STATUS_SUCCESS; + ULONG nSize = sizeof(ULONG); + PULONG pnModuleCount = NULL; + PSYSTEM_MODULE_ENTRY psmeCurModule; + ULONG nBufSize; + + /* ignore buffer size if buffer is null */ + if(Modules == NULL) + ModulesLength = 0; + /* ignore buffer if buffer size is zero */ + else if(ModulesLength == 0) + Modules = NULL; + + do + { + void * pTmp; + + /* resize and/or move the buffer */ + pTmp = realloc(pnModuleCount, nSize); + + if(pTmp == NULL) + { + /* failure */ + nErrCode = STATUS_NO_MEMORY; + goto end; + } + + pnModuleCount = pTmp; + + /* query the information */ + nErrCode = NtQuerySystemInformation + ( + SystemModuleInformation, + pnModuleCount, + nSize, + NULL + ); + + /* while this is less efficient than doubling the buffer size, it should be + executed only once in most cases */ + nSize += sizeof(SYSTEM_MODULE_ENTRY) * (*pnModuleCount); + } + /* repeat until the buffer is big enough */ + while(nErrCode == STATUS_INFO_LENGTH_MISMATCH); + + /* the array of modules starts right after an ULONG storing their count */ + psmeCurModule = (PSYSTEM_MODULE_ENTRY)(pnModuleCount + 1); + + /* element count */ + nBufSize = ModulesLength / sizeof(*Modules); + + /* not enough elements in the buffer */ + if((*pnModuleCount) > nBufSize) + nErrCode = STATUS_INFO_LENGTH_MISMATCH; + /* too many elements in the buffer */ + else + nBufSize = *pnModuleCount; + + /* return the needed buffer size */ + if(ReturnLength) + (*ReturnLength) = (*pnModuleCount) * sizeof(*Modules); + + /* repeat until the buffer is empty or all modules have been returned */ + while(nBufSize > 0) + { + /* return current module base */ + (*Modules) = psmeCurModule->BaseAddress; + + /* next buffer element */ + Modules ++; + nBufSize --; + + /* next module */ + psmeCurModule ++; + } + +end: + free(pnModuleCount); + return (nErrCode); +} + +/* EOF */ + diff --git a/reactos/lib/psapi/enum/process.c b/reactos/lib/psapi/enum/process.c new file mode 100644 index 00000000000..38de9ff03d9 --- /dev/null +++ b/reactos/lib/psapi/enum/process.c @@ -0,0 +1,138 @@ +/* $Id: process.c,v 1.1 2002/06/18 22:12:51 hyperion Exp $ +*/ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: reactos/lib/psapi/enum/process.c + * PURPOSE: Enumerate process ids + * PROGRAMMER: KJK::Hyperion + * UPDATE HISTORY: + * 10/06/2002: Created + */ + +#include +#include +#include + +NTSTATUS +STDCALL +PsaEnumerateProcessIds +( + OUT ULONG * ProcessIds, + IN ULONG ProcessIdsLength, + OUT ULONG * ReturnLength OPTIONAL +) +{ + NTSTATUS nErrCode = STATUS_SUCCESS; + ULONG nSize = 32768; + SYSTEM_PROCESS_INFORMATION * pInfoBuffer = NULL; + SYSTEM_PROCESS_INFORMATION * pInfoHead = NULL; + ULONG nBufSize; + ULONG nRetLen = 0; + + /* ignore buffer size if buffer is null */ + if(ProcessIds == NULL) + ProcessIdsLength = 0; + /* ignore buffer if buffer size is zero */ + else if(ProcessIdsLength == 0) + ProcessIds = NULL; + + do + { + void * pTmp; + + /* resize and/or move the buffer */ + pTmp = realloc(pInfoBuffer, nSize); + + if(pTmp == NULL) + { + /* failure */ + nErrCode = STATUS_NO_MEMORY; + goto end; + } + + pInfoBuffer = pTmp; + + /* query the information */ + nErrCode = NtQuerySystemInformation + ( + SystemProcessesAndThreadsInformation, + pInfoBuffer, + nSize, + NULL + ); + + /* double the buffer size */ + nSize += nSize; + } + /* repeat until the buffer is big enough */ + while(nErrCode == STATUS_INFO_LENGTH_MISMATCH); + + /* failure */ + if(!NT_SUCCESS(nErrCode)) + goto end; + + /* size of ProcessIds in elements */ + nBufSize = ProcessIdsLength / sizeof(*ProcessIds); + /* list head */ + pInfoHead = pInfoBuffer; + + /* repeat until the buffer is empty */ + while(nBufSize > 0) + { + /* return the current process id */ + (*ProcessIds) = pInfoHead->ProcessId; + + /* move to the next buffer entry */ + ProcessIds ++; + nBufSize --; + nRetLen ++; + + /* end of process list */ + if(pInfoHead->RelativeOffset == 0) + break; + + /* move to the next process */ + pInfoHead = + (SYSTEM_PROCESS_INFORMATION*) + ((ULONG)pInfoHead + pInfoHead->RelativeOffset); + } + + if(pInfoHead->RelativeOffset == 0) + /* all process ids were returned */ + nErrCode = STATUS_SUCCESS; + else + { + /* insufficient buffer */ + nErrCode = STATUS_INFO_LENGTH_MISMATCH; + + /* caller doesn't need buffer size */ + if(ReturnLength == NULL) + goto end; + + /* repeat while there are still processes */ + while(pInfoHead->RelativeOffset != 0) + { + pInfoHead = + (SYSTEM_PROCESS_INFORMATION*) + ((ULONG)pInfoHead + pInfoHead->RelativeOffset); + + nRetLen++; + } + + } + + /* used buffer size */ + if(ReturnLength) + (*ReturnLength) = nRetLen * sizeof(DWORD); + +end: + /* free the buffer */ + free(pInfoBuffer); + + /* return the last status */ + return (nErrCode); +} + +/* EOF */ + diff --git a/reactos/lib/psapi/include/internal/psapi.h b/reactos/lib/psapi/include/internal/psapi.h new file mode 100644 index 00000000000..9d9116eb7f9 --- /dev/null +++ b/reactos/lib/psapi/include/internal/psapi.h @@ -0,0 +1,61 @@ +/* $Id: psapi.h,v 1.1 2002/06/18 22:15:57 hyperion Exp $ +*/ +/* + * internal/psapi.h + * + * Process Status Helper API + * + * This file is part of the ReactOS Operating System. + * + * Contributors: + * Created by KJK::Hyperion + * + * THIS SOFTWARE IS NOT COPYRIGHTED + * + * This source code is offered for use in the public domain. You may + * use, modify or distribute it freely. + * + * This code is distributed in the hope that it will be useful but + * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY + * DISCLAMED. This includes but is not limited to warranties of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + */ + +#ifndef __INTERNAL_PSAPI_H_INCLUDED__ +#define __INTERNAL_PSAPI_H_INCLUDED__ + +/* INCLUDES */ +#include + +/* OBJECTS */ + +/* TYPES */ + +/* CONSTANTS */ + +/* PROTOTYPES */ +NTSTATUS +STDCALL +PsaEnumerateProcessIds +( + OUT ULONG * ProcessIds, + IN ULONG ProcessIdsLength, + OUT ULONG * ReturnLength OPTIONAL +); + +NTSTATUS +STDCALL +PsaEnumerateSystemModules +( + OUT PVOID * Modules, + IN ULONG ModulesLength, + OUT ULONG * ReturnLength OPTIONAL +); + +/* MACROS */ + +#endif /* __INTERNAL_PSAPI_H_INCLUDED__ */ + +/* EOF */ + diff --git a/reactos/lib/psapi/makefile b/reactos/lib/psapi/makefile index 465da9f76b3..f4253f46e70 100644 --- a/reactos/lib/psapi/makefile +++ b/reactos/lib/psapi/makefile @@ -1,24 +1,28 @@ -# $Id: makefile,v 1.1 2001/11/28 23:35:16 ea Exp $ +# $Id: makefile,v 1.2 2002/06/18 22:15:57 hyperion Exp $ PATH_TO_TOP = ../.. TARGET_TYPE = dynlink -TARGET_PATH = misc - TARGET_NAME = psapi TARGET_SDKLIBS = ntdll.a kernel32.a +TARGET_CFLAGS = -I./include -Wall + +TARGET_LFLAGS = -nostdlib + +TARGET_BASE = 0x68F70000 + TARGET_OBJECTS = \ misc/dllmain.o \ + misc/malloc.o \ misc/stubs.o \ - $(TARGET_NAME).coff + misc/win32.o \ + enum/module.o \ + enum/process.o include $(PATH_TO_TOP)/rules.mak - include $(TOOLS_PATH)/helper.mk -TARGET_CLEAN = *.o *.coff misc/*.o - # EOF diff --git a/reactos/lib/psapi/misc/dllmain.c b/reactos/lib/psapi/misc/dllmain.c index 3f01223a690..99b01ba5622 100644 --- a/reactos/lib/psapi/misc/dllmain.c +++ b/reactos/lib/psapi/misc/dllmain.c @@ -1,24 +1,16 @@ -/* $Id: dllmain.c,v 1.1 2001/11/28 23:35:16 ea Exp $ +/* $Id: dllmain.c,v 1.2 2002/06/18 22:15:58 hyperion Exp $ * * ReactOS PSAPI.DLL */ #include -BOOLEAN __stdcall DllMain( - PVOID hinstDll, - ULONG dwReason, - PVOID reserved) + +BOOLEAN STDCALL DllMain +( + PVOID hinstDll, + ULONG dwReason, + PVOID reserved +) { - switch (dwReason) - { - case DLL_PROCESS_ATTACH: - break; - case DLL_THREAD_ATTACH: - break; - case DLL_THREAD_DETACH: - break; - case DLL_PROCESS_DETACH: - break; - } - return (TRUE); + return (TRUE); } /* EOF */ diff --git a/reactos/lib/psapi/misc/malloc.c b/reactos/lib/psapi/misc/malloc.c new file mode 100644 index 00000000000..6353f05c109 --- /dev/null +++ b/reactos/lib/psapi/misc/malloc.c @@ -0,0 +1,62 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: reactos/lib/psapi/misc/malloc.c + * PURPOSE: Memory allocator for PSAPI + * PROGRAMMER: KJK::Hyperion + * UPDATE HISTORY: + * 10/06/2002: Created + */ + +#include +#include +#include + +PVOID STDCALL MemAlloc +( + IN HANDLE Heap, + IN PVOID Ptr, + IN ULONG Size +) +{ + PVOID pBuf = NULL; + + if(Size == 0 && Ptr == NULL) + return (NULL); + + if(Heap == NULL) + Heap = NtCurrentPeb()->ProcessHeap; + + if(Size > 0) + { + if(Ptr == NULL) + /* malloc */ + pBuf = RtlAllocateHeap(Heap, 0, Size); + else + /* realloc */ + pBuf = RtlReAllocateHeap(Heap, 0, Ptr, Size); + } + else + /* free */ + RtlFreeHeap(Heap, 0, Ptr); + + return pBuf; +} + +void *malloc(size_t size) +{ + return MemAlloc(NULL, NULL, size); +} + +void *realloc(void *ptr, size_t size) +{ + return MemAlloc(NULL, ptr, size); +} + +void free(void *ptr) +{ + MemAlloc(NULL, ptr, 0); +} + +/* EOF */ + diff --git a/reactos/lib/psapi/misc/stubs.c b/reactos/lib/psapi/misc/stubs.c index f9e7f9c12a1..ebe3801c909 100644 --- a/reactos/lib/psapi/misc/stubs.c +++ b/reactos/lib/psapi/misc/stubs.c @@ -1,145 +1,191 @@ -/* $Id: stubs.c,v 1.1 2001/11/28 23:35:16 ea Exp $ */ +/* $Id: stubs.c,v 1.2 2002/06/18 22:15:58 hyperion Exp $ */ #include #include -BOOL STDCALL -EmptyWorkingSet(HANDLE hProcess) +#if 0 +BOOL STDCALL EnumPageFiles( + PENUM_PAGE_CALLBACKW pCallbackRoutine, + LPVOID lpContext +) { - return FALSE; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; +} +#endif +BOOL STDCALL EnumProcessModules( + HANDLE hProcess, // handle to process + HMODULE *lphModule, // array of module handles + DWORD cb, // size of array + LPDWORD lpcbNeeded // number of bytes required +) +{ + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -BOOL STDCALL -EnumDeviceDrivers( - LPVOID *lpImageBase, - DWORD cb, - LPDWORD lpcbNeeded) +DWORD STDCALL GetDeviceDriverBaseNameA( + LPVOID ImageBase, // driver load address + LPSTR lpBaseName, // driver base name buffer + DWORD nSize // size of buffer +) { - return FALSE; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -BOOL STDCALL -EnumPageFiles( - PENUM_PAGE_CALLBACKW pCallbackRoutine, - LPVOID lpContext) +DWORD STDCALL GetDeviceDriverBaseNameW( + LPVOID ImageBase, // driver load address + LPWSTR lpBaseName, // driver base name buffer + DWORD nSize // size of buffer +) { - return FALSE; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -BOOL STDCALL EnumProcesses( - DWORD *lpidProcess, - DWORD cb, - DWORD *cbNeeded) +DWORD STDCALL GetDeviceDriverFileNameA( + LPVOID ImageBase, // driver load address + LPSTR lpFilename, // path buffer + DWORD nSize // size of buffer +) { - return FALSE; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -BOOL STDCALL -EnumProcessModules( - HANDLE hProcess, - HMODULE *lphModule, - DWORD cb, - LPDWORD lpcbNeeded) +DWORD STDCALL GetDeviceDriverFileNameW( + LPVOID ImageBase, // driver load address + LPWSTR lpFilename, // path buffer + DWORD nSize // size of buffer +) { - return FALSE; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -DWORD STDCALL -GetDeviceDriverBaseName( - LPVOID ImageBase, - LPTSTR lpBaseName, - DWORD nSize) +DWORD STDCALL GetMappedFileNameA( + HANDLE hProcess, // handle to process + LPVOID lpv, // address to verify + LPSTR lpFilename, // file name buffer + DWORD nSize // size of buffer +) { - return 0; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -DWORD STDCALL GetDeviceDriverFileName( - LPVOID ImageBase, - LPTSTR lpFilename, - DWORD nSize) +DWORD STDCALL GetMappedFileNameW( + HANDLE hProcess, // handle to process + LPVOID lpv, // address to verify + LPWSTR lpFilename, // file name buffer + DWORD nSize // size of buffer +) { - return 0; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -DWORD STDCALL -GetMappedFileName( - HANDLE hProcess, - LPVOID lpv, - LPTSTR lpFilename, - DWORD nSize) +DWORD STDCALL GetModuleBaseNameA( + HANDLE hProcess, // handle to process + HMODULE hModule, // handle to module + LPSTR lpBaseName, // base name buffer + DWORD nSize // maximum characters to retrieve +) { - return 0; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -DWORD STDCALL -GetModuleBaseName( - HANDLE hProcess, - HMODULE hModule, - LPTSTR lpBaseName, - DWORD nSize) +DWORD STDCALL GetModuleBaseNameW( + HANDLE hProcess, // handle to process + HMODULE hModule, // handle to module + LPWSTR lpBaseName, // base name buffer + DWORD nSize // maximum characters to retrieve +) { - return 0; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -DWORD STDCALL -GetModuleFileNameEx( - HANDLE hProcess, - HMODULE hModule, - LPTSTR lpFilename, - DWORD nSize) +DWORD STDCALL GetModuleFileNameExA( + HANDLE hProcess, // handle to process + HMODULE hModule, // handle to module + LPSTR lpFilename, // path buffer + DWORD nSize // maximum characters to retrieve +) { - return 0; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -BOOL STDCALL -GetModuleInformation( - HANDLE hProcess, - HMODULE hModule, - LPMODULEINFO lpmodinfo, - DWORD cb) +DWORD STDCALL GetModuleFileNameExW( + HANDLE hProcess, // handle to process + HMODULE hModule, // handle to module + LPWSTR lpFilename, // path buffer + DWORD nSize // maximum characters to retrieve +) { - return FALSE; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -BOOL STDCALL -GetPerformanceInfo( +BOOL STDCALL GetModuleInformation( + HANDLE hProcess, // handle to process + HMODULE hModule, // handle to module + LPMODULEINFO lpmodinfo, // information buffer + DWORD cb // size of buffer +) +{ + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; +} +#if 0 +BOOL STDCALL GetPerformanceInfo( PPERFORMANCE_INFORMATION pPerformanceInformation, - DWORD cb) + DWORD cb + +) { - return FALSE; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; +} +#endif +BOOL STDCALL GetProcessMemoryInfo( + HANDLE Process, // handle to process + PPROCESS_MEMORY_COUNTERS ppsmemCounters, // buffer + DWORD cb // size of buffer +) +{ + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -BOOL STDCALL -GetProcessMemoryInfo( - HANDLE Process, - PPROCESS_MEMORY_COUNTERS ppsmemCounters, - DWORD cb) +BOOL STDCALL GetWsChanges( + HANDLE hProcess, // handle to process + PPSAPI_WS_WATCH_INFORMATION lpWatchInfo, // buffer + DWORD cb // size of buffer +) { - return FALSE; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -BOOL STDCALL -GetWsChanges( - HANDLE hProcess, - PPSAPI_WS_WATCH_INFORMATION lpWatchInfo, - DWORD cb) +BOOL STDCALL InitializeProcessForWsWatch( + HANDLE hProcess // handle to process +) { - return FALSE; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } -BOOL STDCALL -InitializeProcessForWsWatch( - HANDLE hProcess) +BOOL STDCALL QueryWorkingSet( + HANDLE hProcess, // handle to process + PVOID pv, // information buffer + DWORD cb // size of buffer +) { - return FALSE; -} - -BOOL STDCALL -QueryWorkingSet( - HANDLE hProcess, - PVOID pv, - DWORD cb) -{ - return FALSE; + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; } /* EOF */ diff --git a/reactos/lib/psapi/misc/win32.c b/reactos/lib/psapi/misc/win32.c new file mode 100644 index 00000000000..b4d28005135 --- /dev/null +++ b/reactos/lib/psapi/misc/win32.c @@ -0,0 +1,136 @@ +/* $Id: win32.c,v 1.1 2002/06/18 22:14:07 hyperion Exp $ + */ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: reactos/lib/psapi/misc/win32.c + * PURPOSE: Win32 stubs for PSAPI + * PROGRAMMER: KJK::Hyperion + * UPDATE HISTORY: + * 10/06/2002: Created + */ + +#include +#include +#include + +BOOL STDCALL EmptyWorkingSet(HANDLE hProcess) +{ + NTSTATUS nErrCode; + QUOTA_LIMITS qlProcessQuota; + + /* query the working set */ + nErrCode = NtQueryInformationProcess + ( + hProcess, + ProcessQuotaLimits, + &qlProcessQuota, + sizeof(qlProcessQuota), + NULL + ); + + /* failure */ + if(!NT_SUCCESS(nErrCode)) + goto fail; + + /* empty the working set */ + qlProcessQuota.MinimumWorkingSetSize = -1; + qlProcessQuota.MaximumWorkingSetSize = -1; + + /* set the working set */ + nErrCode = NtSetInformationProcess + ( + hProcess, + ProcessQuotaLimits, + &qlProcessQuota, + sizeof(qlProcessQuota) + ); + + /* success */ + if(NT_SUCCESS(nErrCode)) + return (TRUE); + +fail: + /* failure */ + SetLastError(RtlNtStatusToDosError(nErrCode)); + return (FALSE); +} + +BOOL STDCALL EnumDeviceDrivers +( + LPVOID *lpImageBase, + DWORD cb, + LPDWORD lpcbNeeded +) +{ + NTSTATUS nErrCode; + + /* do nothing if the buffer is empty */ + if(cb < sizeof(DWORD) || lpImageBase == NULL) + { + *lpcbNeeded = 0; + return (TRUE); + } + + /* enumerate the system modules */ + nErrCode = PsaEnumerateSystemModules(lpImageBase, cb, lpcbNeeded); + + /* success */ + if(NT_SUCCESS(nErrCode)) + return (TRUE); + + /* failure or partial success */ + if(nErrCode == STATUS_INFO_LENGTH_MISMATCH) + { + /* insufficient buffer: ignore this error */ + *lpcbNeeded = cb; + return (TRUE); + } + else + { + /* failure */ + SetLastError(RtlNtStatusToDosError(nErrCode)); + return (FALSE); + } +} + +BOOL STDCALL EnumProcesses +( + DWORD *lpidProcess, + DWORD cb, + LPDWORD lpcbNeeded +) +{ + NTSTATUS nErrCode; + + /* do nothing if the buffer is empty */ + if(cb < sizeof(DWORD) || lpidProcess == NULL) + { + *lpcbNeeded = 0; + return (TRUE); + } + + /* enumerate the process ids */ + nErrCode = PsaEnumerateProcessIds(lpidProcess, cb, lpcbNeeded); + + /* success */ + if(NT_SUCCESS(nErrCode)) + return (TRUE); + + /* failure or partial success */ + if(nErrCode == STATUS_INFO_LENGTH_MISMATCH) + { + /* insufficient buffer: ignore this error */ + *lpcbNeeded = cb; + return (TRUE); + } + else + { + /* failure */ + SetLastError(RtlNtStatusToDosError(nErrCode)); + return (FALSE); + } +} + +/* EOF */ + diff --git a/reactos/lib/psapi/psapi.def b/reactos/lib/psapi/psapi.def new file mode 100644 index 00000000000..1da19264a27 --- /dev/null +++ b/reactos/lib/psapi/psapi.def @@ -0,0 +1,24 @@ +; $Id: psapi.def,v 1.1 2002/06/18 22:11:55 hyperion Exp $ +; + +LIBRARY PSAPI.DLL +EXPORTS +EmptyWorkingSet@4 +EnumDeviceDrivers@12 +EnumProcessModules@16 +EnumProcesses@12 +GetDeviceDriverBaseNameA@12 +GetDeviceDriverBaseNameW@12 +GetDeviceDriverFileNameA@12 +GetDeviceDriverFileNameW@12 +GetMappedFileNameA@16 +GetMappedFileNameW@16 +GetModuleBaseNameA@16 +GetModuleBaseNameW@16 +GetModuleFileNameExA@16 +GetModuleFileNameExW@16 +GetModuleInformation@16 +GetProcessMemoryInfo@12 +GetWsChanges@12 +InitializeProcessForWsWatch@4 +QueryWorkingSet@12 diff --git a/reactos/lib/psapi/psapi.edf b/reactos/lib/psapi/psapi.edf new file mode 100644 index 00000000000..78c6423e999 --- /dev/null +++ b/reactos/lib/psapi/psapi.edf @@ -0,0 +1,24 @@ +; $Id: psapi.edf,v 1.1 2002/06/18 22:16:53 hyperion Exp $ +; + +LIBRARY PSAPI.DLL +EXPORTS +EmptyWorkingSet=EmptyWorkingSet@4 +EnumDeviceDrivers=EnumDeviceDrivers@12 +EnumProcessModules=EnumProcessModules@16 +EnumProcesses=EnumProcesses@12 +GetDeviceDriverBaseNameA=GetDeviceDriverBaseNameA@12 +GetDeviceDriverBaseNameW=GetDeviceDriverBaseNameW@12 +GetDeviceDriverFileNameA=GetDeviceDriverFileNameA@12 +GetDeviceDriverFileNameW=GetDeviceDriverFileNameW@12 +GetMappedFileNameA=GetMappedFileNameA@16 +GetMappedFileNameW=GetMappedFileNameW@16 +GetModuleBaseNameA=GetModuleBaseNameA@16 +GetModuleBaseNameW=GetModuleBaseNameW@16 +GetModuleFileNameExA=GetModuleFileNameExA@16 +GetModuleFileNameExW=GetModuleFileNameExW@16 +GetModuleInformation=GetModuleInformation@16 +GetProcessMemoryInfo=GetProcessMemoryInfo@12 +GetWsChanges=GetWsChanges@12 +InitializeProcessForWsWatch=InitializeProcessForWsWatch@4 +QueryWorkingSet=QueryWorkingSet@12 diff --git a/reactos/lib/psapi/psapi.rc b/reactos/lib/psapi/psapi.rc new file mode 100644 index 00000000000..095c4f237c2 --- /dev/null +++ b/reactos/lib/psapi/psapi.rc @@ -0,0 +1,38 @@ +#include +#include + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION RES_UINT_FV_MAJOR,RES_UINT_FV_MINOR,RES_UINT_FV_REVISION,RES_UINT_FV_BUILD + PRODUCTVERSION RES_UINT_PV_MAJOR,RES_UINT_PV_MINOR,RES_UINT_PV_REVISION,RES_UINT_PV_BUILD + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", RES_STR_COMPANY_NAME + VALUE "FileDescription", "Process Status Helper\0" + VALUE "FileVersion", RES_STR_FILE_VERSION + VALUE "InternalName", "psapi\0" + VALUE "LegalCopyright", RES_STR_LEGAL_COPYRIGHT + VALUE "OriginalFilename", "psapi.dll\0" + VALUE "ProductName", RES_STR_PRODUCT_NAME + VALUE "ProductVersion", RES_STR_PRODUCT_VERSION + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END +