summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-02-20 04:25:45 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2019-02-20 04:25:45 -0800
commit5ebac31f1e349a78aa8acdbfa640e7b8aacfa774 (patch)
treea007961624f9444b10e8bc86519e4d43b92d4b78
parent4277cf2a64866f6945bb2d17a3151033ca930991 (diff)
downloadpsutil-5ebac31f1e349a78aa8acdbfa640e7b8aacfa774.tar.gz
port NtQueryInformationProcess
-rw-r--r--psutil/_psutil_windows.c8
-rw-r--r--psutil/arch/windows/global.c2
-rw-r--r--psutil/arch/windows/global.h6
-rw-r--r--psutil/arch/windows/process_info.c38
4 files changed, 20 insertions, 34 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index a6b31470..c7667d78 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -2116,19 +2116,13 @@ psutil_proc_io_priority_get(PyObject *self, PyObject *args) {
long pid;
HANDLE hProcess;
DWORD IoPriority;
- _NtQueryInformationProcess NtQueryInformationProcess;
- NtQueryInformationProcess = \
- psutil_GetProcAddress("ntdll.dll", "NtQueryInformationProcess");
- if (NtQueryInformationProcess == NULL)
- return NULL;
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_LIMITED_INFORMATION);
if (hProcess == NULL)
return NULL;
-
- NtQueryInformationProcess(
+ psutil_NtQueryInformationProcess(
hProcess,
ProcessIoPriority,
&IoPriority,
diff --git a/psutil/arch/windows/global.c b/psutil/arch/windows/global.c
index 4e464355..ffc29263 100644
--- a/psutil/arch/windows/global.c
+++ b/psutil/arch/windows/global.c
@@ -58,12 +58,12 @@ psutil_load_globals() {
if (psutil_NtQuerySystemInformation == NULL)
return 1;
-/*
psutil_NtQueryInformationProcess = ps_GetProcAddress(
"ntdll.dll", "NtQueryInformationProcess");
if (! psutil_NtQueryInformationProcess)
return 1;
+/*
psutil_NtSetInformationProcess = ps_GetProcAddress(
"ntdll.dll", "NtSetInformationProcess");
if (! psutil_NtSetInformationProcess)
diff --git a/psutil/arch/windows/global.h b/psutil/arch/windows/global.h
index b61d844b..aee5b986 100644
--- a/psutil/arch/windows/global.h
+++ b/psutil/arch/windows/global.h
@@ -28,9 +28,6 @@ typedef DWORD (WINAPI * _GetExtendedUdpTable)(PVOID, PDWORD, BOOL, ULONG,
_RtlIpv4AddressToStringA \
psutil_rtlIpv4AddressToStringA;
-_NtQueryInformationProcess \
- psutil_NtQueryInformationProcess;
-
_RtlIpv6AddressToStringA \
psutil_rtlIpv6AddressToStringA;
@@ -56,5 +53,8 @@ _GetExtendedUdpTable \
NTQSI_PROC \
psutil_NtQuerySystemInformation;
+_NtQueryInformationProcess \
+ psutil_NtQueryInformationProcess;
+
int psutil_load_globals();
diff --git a/psutil/arch/windows/process_info.c b/psutil/arch/windows/process_info.c
index afc37fd3..5b5e8239 100644
--- a/psutil/arch/windows/process_info.c
+++ b/psutil/arch/windows/process_info.c
@@ -518,7 +518,6 @@ psutil_get_process_data(long pid,
http://stackoverflow.com/a/14012919
http://www.drdobbs.com/embracing-64-bit-windows/184401966
*/
- _NtQueryInformationProcess NtQueryInformationProcess = NULL;
#ifndef _WIN64
static _NtQueryInformationProcess NtWow64QueryInformationProcess64 = NULL;
static _NtWow64ReadVirtualMemory64 NtWow64ReadVirtualMemory64 = NULL;
@@ -536,11 +535,6 @@ psutil_get_process_data(long pid,
#endif
DWORD access = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ;
- NtQueryInformationProcess = \
- psutil_GetProcAddress("ntdll.dll", "NtQueryInformationProcess");
- if (NtQueryInformationProcess == NULL)
- return -1;
-
hProcess = psutil_handle_from_pid(pid, access);
if (hProcess == NULL)
return -1;
@@ -548,11 +542,13 @@ psutil_get_process_data(long pid,
#ifdef _WIN64
/* 64 bit case. Check if the target is a 32 bit process running in WoW64
* mode. */
- if (!NT_SUCCESS(NtQueryInformationProcess(hProcess,
- ProcessWow64Information,
- &ppeb32,
- sizeof(LPVOID),
- NULL))) {
+ if (!NT_SUCCESS(psutil_NtQueryInformationProcess(
+ hProcess,
+ ProcessWow64Information,
+ &ppeb32,
+ sizeof(LPVOID),
+ NULL)))
+ {
PyErr_SetFromWindowsErr(0);
goto error;
}
@@ -679,11 +675,13 @@ psutil_get_process_data(long pid,
PEB_ peb;
RTL_USER_PROCESS_PARAMETERS_ procParameters;
- if (!NT_SUCCESS(NtQueryInformationProcess(hProcess,
- ProcessBasicInformation,
- &pbi,
- sizeof(pbi),
- NULL))) {
+ if (!NT_SUCCESS(psutil_NtQueryInformationProcess(
+ hProcess,
+ ProcessBasicInformation,
+ &pbi,
+ sizeof(pbi),
+ NULL)))
+ {
PyErr_SetFromWindowsErr(0);
goto error;
}
@@ -789,12 +787,6 @@ psutil_get_cmdline_data(long pid, WCHAR **pdata, SIZE_T *psize) {
WCHAR * cmdline_buffer_wchar = NULL;
PUNICODE_STRING tmp = NULL;
DWORD string_size;
- _NtQueryInformationProcess NtQueryInformationProcess;
-
- NtQueryInformationProcess = \
- psutil_GetProcAddress("ntdll.dll", "NtQueryInformationProcess");
- if (NtQueryInformationProcess == NULL)
- goto error;
cmdline_buffer = calloc(ret_length, 1);
if (cmdline_buffer == NULL) {
@@ -805,7 +797,7 @@ psutil_get_cmdline_data(long pid, WCHAR **pdata, SIZE_T *psize) {
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_LIMITED_INFORMATION);
if (hProcess == NULL)
goto error;
- status = NtQueryInformationProcess(
+ status = psutil_NtQueryInformationProcess(
hProcess,
60, // ProcessCommandLineInformation
cmdline_buffer,