Merge pull request #2397 from NahuelGenchi/fix/libc-posix-memalign-huge

fix(libc): return ENOMEM from posix_memalign for sizes the default heap rejects
This commit is contained in:
Adrià 2026-10-10 11:15:44 +02:00 committed by GitHub
commit 11cb1b75ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 0 deletions

View File

@ -47,6 +47,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

@ -157,6 +157,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); });