Skip to content

Commit 724ab6b

Browse files
committed
Platform (Windows): prefers info inside TEB/PEB
1 parent 6370485 commit 724ab6b

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/common/impl/FFPlatform_windows.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,12 @@ static void getSystemArchitecture(FFPlatformSysinfo* info)
286286

287287
static void getCwd(FFPlatform* platform)
288288
{
289-
#if _WIN64
290289
static_assert(
291-
offsetof(RTL_USER_PROCESS_PARAMETERS, Reserved2[5]) == 0x38,
292-
"CurrentDirectory should be at offset 0x38 in RTL_USER_PROCESS_PARAMETERS. Structure layout mismatch detected.");
293-
#endif
290+
offsetof(RTL_USER_PROCESS_PARAMETERS, Reserved2[5]) == sizeof(ULONG) * 5 + sizeof(HANDLE) * 4
291+
#if __amd64__ || __aarch64__
292+
+ sizeof(ULONG) // Padding
293+
#endif
294+
, "Structure layout mismatch detected.");
294295
PCURDIR cwd = (PCURDIR) &NtCurrentTeb()->ProcessEnvironmentBlock->ProcessParameters->Reserved2[5];
295296
ffStrbufSetNWS(&platform->cwd, cwd->DosPath.Length / sizeof(WCHAR), cwd->DosPath.Buffer);
296297
ffStrbufReplaceAllC(&platform->cwd, '\\', '/');
@@ -299,7 +300,8 @@ static void getCwd(FFPlatform* platform)
299300

300301
void ffPlatformInitImpl(FFPlatform* platform)
301302
{
302-
platform->pid = (uint32_t) GetCurrentProcessId();
303+
static_assert(offsetof(TEB, Reserved1[8]) == sizeof(NT_TIB) + sizeof(PVOID) /*EnvironmentPointer*/, "Structure layout mismatch detected.");
304+
platform->pid = (uint32_t) (uintptr_t) ((CLIENT_ID*) &NtCurrentTeb()->Reserved1[8])->UniqueProcess;
303305
getExePath(platform);
304306
getCwd(platform);
305307
getHomeDir(platform);

0 commit comments

Comments
 (0)