Physical memory allocator#

group Physical memory allocator

Functions

error_t pmallocator_get_header(memory_area_t area, const memory_area_t *reserved_areas, u32 count, memory_area_t *headerOUT)#

Looks for an area of suitable size and alignmnet to store all metadata about the area that the allocator needs.

Parameters:
  • area – The phiscal memory area to allocate from. Will be aligned to at least 4KiB boundry

  • reserved_areas – An array of reserved areas from which allocations are not allowed

  • count – The count of reserved areas

Return values:
  • ERR_NONE – Success

  • ERR_BAD_ARG – if reserved_areas is null and count is non zero or vice versa.

error_t pmallocator_init_region(memory_area_t area, memory_region_t header, const memory_area_t *reserved_areas, u32 count)#

Note

The header region overlaps with area, it must be marked and not be allocated from. area.

Note

All pointers will break upon change of address space, because this is initialized before and will be used after the change, no pointers can be stored inside the header region.

Parameters:
  • area – The phiscal memory area to allocate from. Will be aligned to at least 4KiB boundry

  • header – A memory region of size at least pmallocator_get_header_size(@p area) aligned to 4KiB boundry

  • reserved_areas – An array of reserved areas from which allocations are not allowed

  • count – The count of reserved areas

Return values:
  • ERR_NONE – Success

  • ERR_BAD_ARG – if reserved_areas is null and count is non zero or vice versa.

error_t pmallocator_allocate(u8 frame_order, memory_region_t header, memory_area_t *areaOUT)#

Note

4KiB frame (or frame_order = 12) must be a valid frame size.

Parameters:
  • frame_order – The frame size gives as (1 << frame_order)

  • addrOUT – Pointer the the variable to which the return address will be written to. The return address will be aligned to the frame size

  • header

Return values:
  • ERR_NONE – Success

  • ERR_NOT_VALID – The requested frame size is not supported by the allocator

  • ERR_PHYSICAL_MEMORY_FULL – Not enough memory in the area represented by header to allocate a frame of desired size

error_t pmallocator_free(memory_area_t area, memory_region_t header)#
Parameters:
  • addr

  • header

Return values:
  • ERR_NONE – Success

  • ERR_NOT_VALID – The area represented by addr is already free.