fix(libc): return ENOMEM from posix_memalign for sizes the default heap rejects

This commit is contained in:
Nahuel Genchi 2026-10-09 15:03:07 -03:00
parent f8c2f07246
commit 230625e080
2 changed files with 4 additions and 0 deletions

View File

@ -46,6 +46,7 @@ int APS5_VABI defaultPosixAlign(void** pointer, std::size_t alignment, std::size
if (pointer == nullptr || alignment < sizeof(void*) || (alignment & (alignment - 1)) != 0) return 22;
try { *pointer = defaultAlign(alignment, bytes); return 0; }
catch (const std::bad_alloc&) { return 12; }
catch (const std::length_error&) { return 12; }
}
std::array<void*, 10> defaultApi() {

View File

@ -156,6 +156,9 @@ int main(int argc, char** argv) {
require(ApplicationHeapPosixAlign_nid_no_patch(&aligned, 256, 99) == 0);
require(reinterpret_cast<std::uintptr_t>(aligned) % 256 == 0);
ApplicationHeapFree_nid_no_patch(aligned);
void* refused = nullptr;
require(ApplicationHeapPosixAlign_nid_no_patch(&refused, 256, SIZE_MAX) == 12 && refused == nullptr);
require(posix_memalign_nid_postfix(&refused, 4096, SIZE_MAX - 4096) == 12 && refused == nullptr);
ApplicationHeapFree_nid_no_patch(nullptr);
reject([] { ApplicationHeapCalloc_nid_no_patch(SIZE_MAX, 2); });
reject([] { ApplicationHeapAlign_nid_no_patch(3, 16); });