[llvm] [Support] Handle delete_pending case for Windows fs::status (PR #90655)
Tristan Labelle via llvm-commits
llvm-commits at lists.llvm.org
Fri May 10 07:23:36 PDT 2024
================
@@ -236,14 +236,41 @@ void LLVMResetFatalErrorHandler() {
#ifdef _WIN32
+#define WIN32_NO_STATUS
+#include "llvm/Support/Windows/WindowsSupport.h"
+#undef WIN32_NO_STATUS
+#include <ntstatus.h>
#include <winerror.h>
+// This is equivalent to NtCurrentTeb()->LastStatusValue, but the public
+// _TEB definition does not expose the LastStatusValue field directly.
+// Avoid offsetting into this structure by calling RtlGetLastNtStatus
+// from ntdll.dll.
+//
+// The return of this function will roughly match that of
+// GetLastError, but this lower level API disambiguates some cases
+// that GetLastError does not.
+//
+// For more information, see:
+// https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm
+// https://github.com/llvm/llvm-project/issues/89137
+extern "C" NTSYSAPI NTSTATUS NTAPI RtlGetLastNtStatus();
+
// I'd rather not double the line count of the following.
#define MAP_ERR_TO_COND(x, y) \
case x: \
return make_error_code(errc::y)
std::error_code llvm::mapWindowsError(unsigned EV) {
+ // The mapping of NTSTATUS to Win32 error loses some information; special
+ // case the generic ERROR_ACCESS_DENIED code to check the underlying
+ // NTSTATUS and potentially return a more accurate error code.
+ if (EV == ERROR_ACCESS_DENIED) {
----------------
tristanlabelle wrote:
I feel like this block should be in https://github.com/llvm/llvm-project/blob/52271a5c11f6abde1fa1221db304212b5eb8ec7c/llvm/lib/Support/Windows/Path.inc#L770 because previously it did not assume that it was called just after `GetLastError` but now it relies on the current stored error state. `getStatus` calls `GetLastError`, so it knows it is also in a place to call `RtlGetLastNtStatus`.
https://github.com/llvm/llvm-project/pull/90655
More information about the llvm-commits
mailing list