Skip to content

Add aligned memory allocation API (aligned_alloc) #4884

@lum1n0us

Description

@lum1n0us

Overview

Add mem_allocator_malloc_aligned() API to support POSIX-compliant aligned memory allocation in the EMS allocator.

API

in mem-alloc/ems/

void *mem_allocator_malloc_aligned(mem_allocator_t allocator,
                                   uint32_t size, uint32_t alignment);

Key Features

  • Supports alignments from 8 bytes to page size (powers of 2)
  • Size must be multiple of alignment (POSIX requirement)
  • Transparent free - mem_allocator_free() works for both normal and aligned allocations
  • Realloc not supported for aligned allocations (returns NULL)

Implementation

  • Over-allocation with metadata storage (8-byte header before returned pointer)
  • Magic value detection in obj_to_hmu() for transparent free operation
  • Full unit test suite with CMocka

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions