From 724ab6ba69d7698557f7b404b733dad10fc81a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 9 Mar 2026 20:25:10 +0800 Subject: [PATCH] Platform (Windows): prefers info inside TEB/PEB --- src/common/impl/FFPlatform_windows.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/common/impl/FFPlatform_windows.c b/src/common/impl/FFPlatform_windows.c index c3a06f3c8..e4b99e010 100644 --- a/src/common/impl/FFPlatform_windows.c +++ b/src/common/impl/FFPlatform_windows.c @@ -286,11 +286,12 @@ static void getSystemArchitecture(FFPlatformSysinfo* info) static void getCwd(FFPlatform* platform) { - #if _WIN64 static_assert( - offsetof(RTL_USER_PROCESS_PARAMETERS, Reserved2[5]) == 0x38, - "CurrentDirectory should be at offset 0x38 in RTL_USER_PROCESS_PARAMETERS. Structure layout mismatch detected."); - #endif + offsetof(RTL_USER_PROCESS_PARAMETERS, Reserved2[5]) == sizeof(ULONG) * 5 + sizeof(HANDLE) * 4 + #if __amd64__ || __aarch64__ + + sizeof(ULONG) // Padding + #endif + , "Structure layout mismatch detected."); PCURDIR cwd = (PCURDIR) &NtCurrentTeb()->ProcessEnvironmentBlock->ProcessParameters->Reserved2[5]; ffStrbufSetNWS(&platform->cwd, cwd->DosPath.Length / sizeof(WCHAR), cwd->DosPath.Buffer); ffStrbufReplaceAllC(&platform->cwd, '\\', '/'); @@ -299,7 +300,8 @@ static void getCwd(FFPlatform* platform) void ffPlatformInitImpl(FFPlatform* platform) { - platform->pid = (uint32_t) GetCurrentProcessId(); + static_assert(offsetof(TEB, Reserved1[8]) == sizeof(NT_TIB) + sizeof(PVOID) /*EnvironmentPointer*/, "Structure layout mismatch detected."); + platform->pid = (uint32_t) (uintptr_t) ((CLIENT_ID*) &NtCurrentTeb()->Reserved1[8])->UniqueProcess; getExePath(platform); getCwd(platform); getHomeDir(platform);