Skip to content

Feat: aligned allocation#4886

Draft
lum1n0us wants to merge 18 commits intobytecodealliance:mainfrom
lum1n0us:feat/aligned-allocation
Draft

Feat: aligned allocation#4886
lum1n0us wants to merge 18 commits intobytecodealliance:mainfrom
lum1n0us:feat/aligned-allocation

Conversation

@lum1n0us
Copy link
Contributor

No description provided.

lum1n0us and others added 18 commits March 20, 2026 15:26
Add mem_allocator_malloc_aligned() API with support for both
GC_VERIFY enabled and disabled modes.

Related to DESIGN_ALIGNED_ALLOC.md
Add MEM_ALLOC_API_INTER macro for exposing internal functions
in test builds and magic value constants for aligned allocation
detection.
Convert obj_to_hmu to function that detects aligned allocations
via magic value and calculates correct HMU offset.
Add CMocka support and mem-alloc test subdirectory.
Create basic test infrastructure with helper functions.
Fix INTERP setting and add include directories for ems headers.
Verify existing mem_allocator_malloc still works correctly.
Add aligned allocation with over-allocation and metadata storage.
Supports alignments from 8 bytes to page size.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Verify aligned allocations work for powers of 2.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
gc_realloc_vo now detects and rejects aligned allocations
per POSIX behavior.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Verify realloc correctly rejects aligned allocations and
still works for normal allocations.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Verify invalid alignments and size requirements are enforced.
Fix alignment validation to reject zero.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Verify normal and aligned allocations can coexist and
obj_to_hmu works correctly for both.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Test many allocations and mixed allocation patterns.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add public API for aligned memory allocation, exposing the existing
mem_allocator_malloc_aligned infrastructure through wasm_export.h.

- Add wasm_runtime_aligned_alloc() API declaration with documentation
- Implement internal helper wasm_runtime_aligned_alloc_internal()
- Add public function with size/alignment validation
- POOL mode only, returns NULL for other memory modes
- Follows wasm_runtime_malloc() patterns for consistency

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive tests for the new public aligned allocation API:
- Valid allocation in POOL mode with alignment verification
- Zero size/alignment rejection
- Non-POOL mode returns NULL
- Realloc rejection for aligned allocations
- Multiple alignment values (8, 16, 32, 64, 128, 256)

Tests cover all scenarios from the implementation plan including
error handling and mode-specific behavior.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Simplify wasm_runtime_aligned_alloc_internal control flow using guard clause
- Remove redundant wasm_runtime_init() calls in tests (wasm_runtime_full_init handles it)

No functional changes, improves code readability and follows existing patterns.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant