Skip to content

CreateMem

Creates a memory object that can be mapped, shared, injected and used for DMA.

Number Selector Blocking Since
0x04 SVC_CREATE OBJECT_MEMORY (4) no 2.0
Handle CreateMem(size_t page_count, CreateMemoryFlags flags);

Registers: (pages, flags) -> r0 memory handle or error

Without flags, pages are allocated on first touch. MEM_CONTIG allocates physically contiguous, zeroed pages up front (required for DMA); MEM_UNCACHED makes mappings uncached and needs MEM_CONTIG.

Parameters

Name Direction Description
page_count in Size in pages; must be at least 1.
flags in MEM_CONTIG and/or MEM_UNCACHED, or 0.

Returns

A memory handle with all permissions, or a negative error code.

Errors

Error Condition
ERR_BADARG page_count is 0, flags has unknown bits, or MEM_UNCACHED without MEM_CONTIG.
ERR_NOMEM Not enough free (or contiguous) memory, or the handle table is full.