Skip to content

Commit

Permalink
- Reformatted and reorganized.
Browse files Browse the repository at this point in the history
- Match names with decaf-emu.

--HG--
branch : coreinit-allocator-api
  • Loading branch information
Daniel K. O. (dkosmari) committed Oct 1, 2024
1 parent b178978 commit 73beeb5
Showing 1 changed file with 41 additions and 22 deletions.
63 changes: 41 additions & 22 deletions include/coreinit/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,61 @@ extern "C" {
#endif

typedef struct MEMAllocatorFunctions MEMAllocatorFunctions;
typedef struct MEMAllocator MEMAllocator;

typedef struct MEMAllocator {
typedef void * (*MEMAllocatorAllocFn)(MEMAllocator *allocator,
uint32_t size);
typedef void (*MEMAllocatorFreeFn) (MEMAllocator *allocator,
void *ptr);

struct MEMAllocator {
MEMAllocatorFunctions *funcs;
MEMHeapHandle heap;
uint32_t arg1;
uint32_t arg2;
} MEMAllocator;
uint32_t align;
WUT_UNKNOWN_BYTES(4);
};
WUT_CHECK_OFFSET(MEMAllocator, 0x0, funcs);
WUT_CHECK_OFFSET(MEMAllocator, 0x4, heap);
WUT_CHECK_OFFSET(MEMAllocator, 0x8, alignment);
WUT_CHECK_SIZE(MEMAllocator, 0x10);

typedef void* (*MEMAllocatorAlloc)(MEMAllocator *allocator, uint32_t size);
typedef void (*MEMAllocatorFree)(MEMAllocator *allocator, void *ptr);

struct MEMAllocatorFunctions {
MEMAllocatorAlloc alloc;
MEMAllocatorFree free;
MEMAllocatorAllocFn alloc;
MEMAllocatorFreeFn free;
};
WUT_CHECK_OFFSET(MEMAllocatorFunctions, 0x0, alloc);
WUT_CHECK_OFFSET(MEMAllocatorFunctions, 0x4, free);
WUT_CHECK_SIZE(MEMAllocatorFunctions, 0x8);

void* MEMAllocFromAllocator(MEMAllocator *allocator, uint32_t size);
void MEMFreeToAllocator(MEMAllocator *allocator, void *ptr);
void *
MEMAllocFromAllocator(MEMAllocator *allocator,
uint32_t size);

void
MEMFreeToAllocator(MEMAllocator *allocator,
void *ptr);

void MEMInitAllocatorForExpHeap(MEMAllocator *allocator,
MEMHeapHandle heap,
uint32_t alignment);
void
MEMInitAllocatorForExpHeap(MEMAllocator *allocator,
MEMHeapHandle heap,
uint32_t alignment);

void MEMInitAllocatorForFrmHeap(MEMAllocator *allocator,
MEMHeapHandle heap,
uint32_t alignment);
void
MEMInitAllocatorForFrmHeap(MEMAllocator *allocator,
MEMHeapHandle heap,
uint32_t alignment);

void MEMInitAllocatorForUnitHeap(MEMAllocator *allocator, MEMHeapHandle heap);
void
MEMInitAllocatorForUnitHeap(MEMAllocator *allocator,
MEMHeapHandle heap);

void MEMInitAllocatorForDefaultHeap(MEMAllocator *allocator);
void
MEMInitAllocatorForDefaultHeap(MEMAllocator *allocator);

void MEMInitAllocatorForBlockHeap(MEMAllocator *allocator,
MEMHeapHandle heap,
uint32_t alignment);
void
MEMInitAllocatorForBlockHeap(MEMAllocator *allocator,
MEMHeapHandle heap,
uint32_t alignment);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 73beeb5

Please sign in to comment.