-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use GetTempPath2W
if available.
#72452
Conversation
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsSince Windows 11 there is a new API to get the temporary files path called This PR tries to find I also fixed a bug where the original
|
Does this behavior change need to be treated as a breaking change? |
src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs
Outdated
Show resolved
Hide resolved
d966908
to
c1c76ca
Compare
This would be something like -- I wrote a file to temp, upgrade my .NET or OS, and try to read it? That seems unlikely to be something we want to guarantee. In general it is good to not assume that a reboot will preserve temp. |
And the path would change only if the program runs as SYSTEM. Most user apps are unaffected. |
Have people tried running .NET code as SYSTEM? |
It's not uncommon for Windows services to run as SYSTEM. It's also possible that |
…s.cs Co-authored-by: Stephen Toub <[email protected]>
src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs
Outdated
Show resolved
Hide resolved
…s.cs Co-authored-by: David Cantú <[email protected]>
GetGCMemoryInfo failure is already resolved. |
@teo-tsirpanis could you please resolve the conflict so we can merge? |
Conflicts were resolved. |
Failure is #73679 |
@@ -42,7 +42,8 @@ public static unsafe Architecture OSArchitecture | |||
// If we are running an x64 process on a non-x64 windows machine, we will report x64 as OS architecture. | |||
// | |||
// IsWow64Process2 is only available on Windows 10+, so we will perform run-time introspection via indirect load | |||
if (NativeLibrary.TryGetExport(NativeLibrary.Load(Interop.Libraries.Kernel32), "IsWow64Process2", out IntPtr isWow64Process2Ptr)) | |||
IntPtr kernel32 = Interop.Kernel32.LoadLibraryEx(Interop.Libraries.Kernel32, 0, Interop.Kernel32.LOAD_LIBRARY_SEARCH_SYSTEM32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change to make load library more secure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes: #72452 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you for your contribution @teo-tsirpanis !
The failure is unrelated (#73679), merging |
Since Windows 11 there is a new API to get the temporary files path called
GetTempPath2
. This API returns a directory inaccessible to non-SYSTEM processes if the calling process runs as SYSTEM, and it is recommended to call this function instead ofGetTempPath
.This PR tries to find
GetTempPath2W
and uses that, otherwise it falls back toGetTempPathW
.I also fixed a bug where the original
GetTempPathW
P/Invoke was not marked withSetLastError
and would fail withOperation Completed Successfuly
in case of a failure.