Message360245
The warning would not apply to Windows. The environment block is part of the Process Environment Block (PEB) record, which is protected by a critical-section lock. The runtime library acquires the PEB lock before accessing mutable PEB values. For example:
Getting an environment variable:
>>> win32api.GetEnvironmentVariable('foo')
Breakpoint 0 hit
ntdll!RtlQueryEnvironmentVariable:
00007ffc`d737a2f0 48895c2408 mov qword ptr [rsp+8],rbx
ss:00000094`ec9ef470=0000000000000000
RtlQueryEnvironmentVariable acquires the PEB lock (i.e. ntdll!FastPebLock) before getting the value. The lock is passed to RtlEnterCriticalSection in register rcx:
0:000> be 2; g
Breakpoint 2 hit
ntdll!RtlEnterCriticalSection:
00007ffc`d737b400 4883ec28 sub rsp,28h
0:000> kc 3
Call Site
ntdll!RtlEnterCriticalSection
ntdll!RtlQueryEnvironmentVariable
KERNELBASE!GetEnvironmentVariableW
0:000> ?? @rcx == (_RTL_CRITICAL_SECTION *)@@(ntdll!FastPebLock)
bool true
Setting an environment variable:
>>> win32api.SetEnvironmentVariable('foo', 'eggs')
Breakpoint 1 hit
ntdll!RtlSetEnvironmentVar:
00007ffc`d73bc7d0 4c894c2420 mov qword ptr [rsp+20h],r9 ss:00000094`ec9ef488=0000000000000000
RtlSetEnvironmentVar acquires the PEB lock before setting the environment variable:
0:000> be 2; g
Breakpoint 2 hit
ntdll!RtlEnterCriticalSection:
00007ffc`d737b400 4883ec28 sub rsp,28h
0:000> kc 3
Call Site
ntdll!RtlEnterCriticalSection
ntdll!RtlSetEnvironmentVar
KERNELBASE!SetEnvironmentVariableW
0:000> ?? @rcx == (_RTL_CRITICAL_SECTION *)@@(ntdll!FastPebLock)
bool true |
|
Date |
User |
Action |
Args |
2020-01-22 00:50:05 | eryksun | unlink | issue39375 messages |
2020-01-18 14:07:03 | eryksun | set | recipients:
+ eryksun, gregory.p.smith, docs@python |
2020-01-18 14:07:02 | eryksun | set | messageid: <1579356422.98.0.720330231724.issue39375@roundup.psfhosted.org> |
2020-01-18 14:07:02 | eryksun | link | issue39375 messages |
2020-01-18 14:07:02 | eryksun | create | |
|