Skip to content

Allow ZX_ERR_NO_RESOURCES with MAP_ALLOWNOMEM on Fuchsia #89767

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

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions compiler-rt/lib/scudo/standalone/mem_map_fuchsia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down