[compiler-rt] [scudo] Improve readability of MemMapFuchsia's error handling (PR #90102)
Fabio D'Urso via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 25 11:45:56 PDT 2024
https://github.com/fabio-d created https://github.com/llvm/llvm-project/pull/90102
By expressing the conditions covered by MAP_ALLOWNOMEM in a more
direct way.
>From 0b17cc2b3014d1a43aa0d52f4c78ee07d3839025 Mon Sep 17 00:00:00 2001
From: Fabio D'Urso <fdurso at google.com>
Date: Thu, 25 Apr 2024 20:31:42 +0200
Subject: [PATCH] [scudo] Improve readability of MemMapFuchsia's error handling
By expressing the conditions covered by MAP_ALLOWNOMEM in a more
direct way.
---
.../lib/scudo/standalone/mem_map_fuchsia.cpp | 34 +++++++++----------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/compiler-rt/lib/scudo/standalone/mem_map_fuchsia.cpp b/compiler-rt/lib/scudo/standalone/mem_map_fuchsia.cpp
index 5f3c8b81c07b31..fc793abf44cda5 100644
--- a/compiler-rt/lib/scudo/standalone/mem_map_fuchsia.cpp
+++ b/compiler-rt/lib/scudo/standalone/mem_map_fuchsia.cpp
@@ -108,9 +108,9 @@ bool MemMapFuchsia::mapImpl(UNUSED uptr Addr, uptr Size, const char *Name,
// Create the VMO.
zx_status_t Status = _zx_vmo_create(Size, 0, &Vmo);
if (UNLIKELY(Status != ZX_OK)) {
- if (!IsNoMemError(Status) || !AllowNoMem)
- dieOnError(Status, "zx_vmo_create", Size);
- return false;
+ if (AllowNoMem && IsNoMemError(Status))
+ return false;
+ dieOnError(Status, "zx_vmo_create", Size);
}
if (Name != nullptr)
@@ -123,15 +123,15 @@ bool MemMapFuchsia::mapImpl(UNUSED uptr Addr, uptr Size, const char *Name,
Status =
_zx_vmar_map(_zx_vmar_root_self(), MapFlags, 0, Vmo, 0, Size, &MapAddr);
if (UNLIKELY(Status != ZX_OK)) {
- if (!IsNoMemError(Status) || !AllowNoMem)
- dieOnError(Status, "zx_vmar_map", Size);
-
- Status = _zx_handle_close(Vmo);
- CHECK_EQ(Status, ZX_OK);
+ if (AllowNoMem && IsNoMemError(Status)) {
+ Status = _zx_handle_close(Vmo);
+ CHECK_EQ(Status, ZX_OK);
- MapAddr = 0;
- Vmo = ZX_HANDLE_INVALID;
- return false;
+ MapAddr = 0;
+ Vmo = ZX_HANDLE_INVALID;
+ return false;
+ }
+ dieOnError(Status, "zx_vmar_map", Size);
}
if (PreCommit) {
@@ -194,9 +194,9 @@ bool MemMapFuchsia::remapImpl(uptr Addr, uptr Size, const char *Name,
_zx_vmar_map(_zx_vmar_root_self(), MapFlags, Addr - getRootVmarBase(),
Vmo, Addr - MapAddr, Size, &MappedAddr);
if (UNLIKELY(Status != ZX_OK)) {
- if (!IsNoMemError(Status) || !AllowNoMem)
- dieOnError(Status, "zx_vmar_map", Size);
- return false;
+ if (AllowNoMem && IsNoMemError(Status))
+ return false;
+ dieOnError(Status, "zx_vmar_map", Size);
}
DCHECK_EQ(Addr, MappedAddr);
@@ -234,9 +234,9 @@ bool ReservedMemoryFuchsia::createImpl(UNUSED uptr Addr, uptr Size,
zx_status_t Status = _zx_vmar_map(_zx_vmar_root_self(), ZX_VM_ALLOW_FAULTS, 0,
getPlaceholderVmo(), 0, Size, &Base);
if (UNLIKELY(Status != ZX_OK)) {
- if (!IsNoMemError(Status) || !AllowNoMem)
- dieOnError(Status, "zx_vmar_map", Size);
- return false;
+ if (AllowNoMem && IsNoMemError(Status))
+ return false;
+ dieOnError(Status, "zx_vmar_map", Size);
}
Capacity = Size;
More information about the llvm-commits
mailing list