Use CreateToolhelp32Snapshot instead of NtQueryInformationProcess to get ppid on Windows
Try to get rid of a spec error.
This commit is contained in:
parent
b7d9ec8caa
commit
09022b6d70
@ -42,6 +42,7 @@
|
|||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
#include <mbstring.h>
|
#include <mbstring.h>
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
|
#include <tlhelp32.h>
|
||||||
#if _MSC_VER >= 1400
|
#if _MSC_VER >= 1400
|
||||||
#include <crtdbg.h>
|
#include <crtdbg.h>
|
||||||
#include <rtcapi.h>
|
#include <rtcapi.h>
|
||||||
@ -6139,6 +6140,26 @@ rb_w32_getppid(void)
|
|||||||
static query_func *pNtQueryInformationProcess = (query_func *)-1;
|
static query_func *pNtQueryInformationProcess = (query_func *)-1;
|
||||||
rb_pid_t ppid = 0;
|
rb_pid_t ppid = 0;
|
||||||
|
|
||||||
|
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||||
|
if (hSnap != INVALID_HANDLE_VALUE) {
|
||||||
|
BOOL ok;
|
||||||
|
PROCESSENTRY32 pe;
|
||||||
|
DWORD pid = GetCurrentProcessId();
|
||||||
|
pe.dwSize = sizeof(pe);
|
||||||
|
ok = Process32First(hSnap, &pe);
|
||||||
|
while (ok) {
|
||||||
|
if (pe.th32ProcessID == pid) {
|
||||||
|
ppid = (rb_pid_t)pe.th32ParentProcessID;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ok = Process32Next(hSnap, &pe);
|
||||||
|
}
|
||||||
|
CloseHandle(hSnap);
|
||||||
|
if (ppid != 0) {
|
||||||
|
return ppid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (pNtQueryInformationProcess == (query_func *)-1)
|
if (pNtQueryInformationProcess == (query_func *)-1)
|
||||||
pNtQueryInformationProcess = (query_func *)get_proc_address("ntdll.dll", "NtQueryInformationProcess", NULL);
|
pNtQueryInformationProcess = (query_func *)get_proc_address("ntdll.dll", "NtQueryInformationProcess", NULL);
|
||||||
if (pNtQueryInformationProcess) {
|
if (pNtQueryInformationProcess) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user