summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio D'Urso <fdurso@google.com>2024-04-24 15:06:25 +0200
committerCopybara-Service <copybara-worker@google.com>2024-04-24 06:32:30 -0700
commite7c3a3d5418206d54b278c3f76613e00910f5350 (patch)
treeee7082dc2c86542161974b49abb6741117413b0c
parent04c08798ae3feb87eb97497c28d91103bcaf8639 (diff)
downloadscudo-e7c3a3d5418206d54b278c3f76613e00910f5350.tar.gz
Allow ZX_ERR_NO_RESOURCES with MAP_ALLOWNOMEM on Fuchsia (#89767)
This can occur if the virtual address space is (almost) entirely mapped or heavily fragmented. GitOrigin-RevId: 9cbf96ad5b6fe777bf5acd43b65abfb062381f8c Change-Id: I40c9a924c5f3c0287e2497b2879d16813bcf4e83
-rw-r--r--standalone/mem_map_fuchsia.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/standalone/mem_map_fuchsia.cpp b/standalone/mem_map_fuchsia.cpp
index 28e5a11a37f..5f3c8b81c07 100644
--- a/standalone/mem_map_fuchsia.cpp
+++ b/standalone/mem_map_fuchsia.cpp
@@ -84,6 +84,13 @@ static zx_handle_t getPlaceholderVmo() {
return Vmo;
}
+// Checks if MAP_ALLOWNOMEM allows the given error code.
+static bool IsNoMemError(zx_status_t Status) {
+ // Note: _zx_vmar_map returns ZX_ERR_NO_RESOURCES if the VMAR does not contain
+ // a suitable free spot.
+ return Status == ZX_ERR_NO_MEMORY || Status == ZX_ERR_NO_RESOURCES;
+}
+
MemMapFuchsia::MemMapFuchsia(uptr Base, uptr Capacity)
: MapAddr(Base), WindowBase(Base), WindowSize(Capacity) {
// Create the VMO.
@@ -101,7 +108,7 @@ 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 (Status != ZX_ERR_NO_MEMORY || !AllowNoMem)
+ if (!IsNoMemError(Status) || !AllowNoMem)
dieOnError(Status, "zx_vmo_create", Size);
return false;
}
@@ -116,7 +123,7 @@ 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 (Status != ZX_ERR_NO_MEMORY || !AllowNoMem)
+ if (!IsNoMemError(Status) || !AllowNoMem)
dieOnError(Status, "zx_vmar_map", Size);
Status = _zx_handle_close(Vmo);
@@ -187,7 +194,7 @@ 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 (Status != ZX_ERR_NO_MEMORY || !AllowNoMem)
+ if (!IsNoMemError(Status) || !AllowNoMem)
dieOnError(Status, "zx_vmar_map", Size);
return false;
}
@@ -227,7 +234,7 @@ 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 (Status != ZX_ERR_NO_MEMORY || !AllowNoMem)
+ if (!IsNoMemError(Status) || !AllowNoMem)
dieOnError(Status, "zx_vmar_map", Size);
return false;
}