Skip to content

Commit 9cbf96a

Browse files
authored
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.
1 parent d577518 commit 9cbf96a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

compiler-rt/lib/scudo/standalone/mem_map_fuchsia.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ static zx_handle_t getPlaceholderVmo() {
8484
return Vmo;
8585
}
8686

87+
// Checks if MAP_ALLOWNOMEM allows the given error code.
88+
static bool IsNoMemError(zx_status_t Status) {
89+
// Note: _zx_vmar_map returns ZX_ERR_NO_RESOURCES if the VMAR does not contain
90+
// a suitable free spot.
91+
return Status == ZX_ERR_NO_MEMORY || Status == ZX_ERR_NO_RESOURCES;
92+
}
93+
8794
MemMapFuchsia::MemMapFuchsia(uptr Base, uptr Capacity)
8895
: MapAddr(Base), WindowBase(Base), WindowSize(Capacity) {
8996
// Create the VMO.
@@ -101,7 +108,7 @@ bool MemMapFuchsia::mapImpl(UNUSED uptr Addr, uptr Size, const char *Name,
101108
// Create the VMO.
102109
zx_status_t Status = _zx_vmo_create(Size, 0, &Vmo);
103110
if (UNLIKELY(Status != ZX_OK)) {
104-
if (Status != ZX_ERR_NO_MEMORY || !AllowNoMem)
111+
if (!IsNoMemError(Status) || !AllowNoMem)
105112
dieOnError(Status, "zx_vmo_create", Size);
106113
return false;
107114
}
@@ -116,7 +123,7 @@ bool MemMapFuchsia::mapImpl(UNUSED uptr Addr, uptr Size, const char *Name,
116123
Status =
117124
_zx_vmar_map(_zx_vmar_root_self(), MapFlags, 0, Vmo, 0, Size, &MapAddr);
118125
if (UNLIKELY(Status != ZX_OK)) {
119-
if (Status != ZX_ERR_NO_MEMORY || !AllowNoMem)
126+
if (!IsNoMemError(Status) || !AllowNoMem)
120127
dieOnError(Status, "zx_vmar_map", Size);
121128

122129
Status = _zx_handle_close(Vmo);
@@ -187,7 +194,7 @@ bool MemMapFuchsia::remapImpl(uptr Addr, uptr Size, const char *Name,
187194
_zx_vmar_map(_zx_vmar_root_self(), MapFlags, Addr - getRootVmarBase(),
188195
Vmo, Addr - MapAddr, Size, &MappedAddr);
189196
if (UNLIKELY(Status != ZX_OK)) {
190-
if (Status != ZX_ERR_NO_MEMORY || !AllowNoMem)
197+
if (!IsNoMemError(Status) || !AllowNoMem)
191198
dieOnError(Status, "zx_vmar_map", Size);
192199
return false;
193200
}
@@ -227,7 +234,7 @@ bool ReservedMemoryFuchsia::createImpl(UNUSED uptr Addr, uptr Size,
227234
zx_status_t Status = _zx_vmar_map(_zx_vmar_root_self(), ZX_VM_ALLOW_FAULTS, 0,
228235
getPlaceholderVmo(), 0, Size, &Base);
229236
if (UNLIKELY(Status != ZX_OK)) {
230-
if (Status != ZX_ERR_NO_MEMORY || !AllowNoMem)
237+
if (!IsNoMemError(Status) || !AllowNoMem)
231238
dieOnError(Status, "zx_vmar_map", Size);
232239
return false;
233240
}

0 commit comments

Comments
 (0)