From 015e1246f8bf63135a2ec4cdab9916f251e51401 Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Thu, 10 Sep 2026 03:36:25 +0100 Subject: [PATCH 1/6] Add and apply some allocation-related attributes `WUT_ALLOC_SIZE` was left off `MEMAllocFromExpHeapEx` because the allocated region may be resized via `MEMResizeForMBlockExpHeap`, but is always accessed via the same pointer. Some functions had to have the free and allocate function order swapped because the two-parameter `malloc` attribute relies on declaration order --- include/coreinit/ipcbufpool.h | 9 +++++---- include/coreinit/memexpheap.h | 11 ++++++----- include/sndcore2/voice.h | 11 +++++++---- include/wut.h | 9 ++++++++- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/include/coreinit/ipcbufpool.h b/include/coreinit/ipcbufpool.h index 2b69572af..81b9e0938 100644 --- a/include/coreinit/ipcbufpool.h +++ b/include/coreinit/ipcbufpool.h @@ -123,14 +123,15 @@ IPCBufPoolCreate(void *buffer, uint32_t *outNumMessages, uint32_t unk0x0c); -void * -IPCBufPoolAllocate(IPCBufPool *pool, - uint32_t size); - IOSError IPCBufPoolFree(IPCBufPool *pool, void *message); +void * +IPCBufPoolAllocate(IPCBufPool *pool, + uint32_t size) + WUT_MALLOC WUT_FREED_BY(IPCBufPoolFree, 2) WUT_ALLOC_SIZE(2); + IOSError IPCBufPoolGetAttributes(IPCBufPool *pool, IPCBufPoolAttributes *attribs); diff --git a/include/coreinit/memexpheap.h b/include/coreinit/memexpheap.h index a218e4450..1e71f448a 100644 --- a/include/coreinit/memexpheap.h +++ b/include/coreinit/memexpheap.h @@ -84,15 +84,16 @@ MEMCreateExpHeapEx(void *heap, void * MEMDestroyExpHeap(MEMHeapHandle heap); -void * -MEMAllocFromExpHeapEx(MEMHeapHandle heap, - uint32_t size, - int alignment); - void MEMFreeToExpHeap(MEMHeapHandle heap, void *block); +void * +MEMAllocFromExpHeapEx(MEMHeapHandle heap, + uint32_t size, + int alignment) + WUT_MALLOC WUT_FREED_BY(MEMFreeToExpHeap, 2) WUT_ALLOC_ALIGN(3); + MEMExpHeapMode MEMSetAllocModeForExpHeap(MEMHeapHandle heap, MEMExpHeapMode mode); diff --git a/include/sndcore2/voice.h b/include/sndcore2/voice.h index bc1e5a94e..105c89863 100644 --- a/include/sndcore2/voice.h +++ b/include/sndcore2/voice.h @@ -259,21 +259,24 @@ AXVoiceBegin(AXVoice *v); int32_t AXVoiceEnd(AXVoice *v); +void +AXFreeVoice(AXVoice *voice); + AXVoice * AXAcquireVoice(uint32_t priority, AXVoiceCallbackFn callback, - void *userContext); + void *userContext) + WUT_FREED_BY(AXFreeVoice, 1); AXVoice * AXAcquireVoiceEx(uint32_t priority, AXVoiceCallbackExFn callback, - void *userContext); + void *userContext) + WUT_FREED_BY(AXFreeVoice, 1); BOOL AXCheckVoiceOffsets(AXVoiceOffsets *offsets); -void -AXFreeVoice(AXVoice *voice); uint32_t AXGetMaxVoices(); diff --git a/include/wut.h b/include/wut.h index c280cc113..463da8142 100644 --- a/include/wut.h +++ b/include/wut.h @@ -10,12 +10,19 @@ #define WUT_DEPRECATED(reason) __attribute__((__deprecated__(reason))) #define WUT_FORMAT_PRINTF(fmt, args) __attribute__((__format__(__printf__, fmt, args))) +#define WUT_MALLOC __attribute__((malloc)) +#define WUT_FREED_BY(freeFn, ptrIndex) __attribute__((malloc(freeFn, ptrIndex))) +#define WUT_ALLOC_SIZE(posIndex) __attribute__((alloc_size(posIndex))) +#define WUT_ALLOC_ALIGN(posIndex) __attribute__((alloc_align(posIndex))) #else // not __GNUC__ and not __clang__ #define WUT_DEPRECATED(reason) #define WUT_FORMAT_PRINTF(fmt, args) - +#define WUT_MALLOC __attribute__((malloc)) +#define WUT_FREED_BY(freeFn, ptrIndex) +#define WUT_ALLOC_SIZE(posIndex) +#define WUT_ALLOC_ALIGN(posIndex) #endif //__GNUC__ or __clang__ #ifdef DEBUG From b89ad6ab6d6ca5f36a1be90a91c739d419f3dbe3 Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Thu, 10 Sep 2026 03:45:57 +0100 Subject: [PATCH 2/6] Add attrs to `MEMAllocFromDefaultHeapFn` and `MEMAllocFromDefaultHeapExFn` --- include/coreinit/memdefaultheap.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/coreinit/memdefaultheap.h b/include/coreinit/memdefaultheap.h index cbb087877..5d62ad9b5 100644 --- a/include/coreinit/memdefaultheap.h +++ b/include/coreinit/memdefaultheap.h @@ -12,8 +12,8 @@ extern "C" { #endif -typedef void *(*MEMAllocFromDefaultHeapFn)(uint32_t size); -typedef void *(*MEMAllocFromDefaultHeapExFn)(uint32_t size, int32_t alignment); +typedef WUT_ALLOC_SIZE(1) void *(*MEMAllocFromDefaultHeapFn)(uint32_t size); +typedef WUT_ALLOC_SIZE(1) WUT_ALLOC_ALIGN(2) void *(*MEMAllocFromDefaultHeapExFn)(uint32_t size, int32_t alignment); typedef void (*MEMFreeToDefaultHeapFn)(void *ptr); extern MEMAllocFromDefaultHeapFn MEMAllocFromDefaultHeap; From f8493e9c1fd027e379910250c3a3c33f5941801a Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Thu, 10 Sep 2026 05:56:26 +0100 Subject: [PATCH 3/6] Add attrs to `MEMAllocFromBlockHeapEx`, `MEMAllocFromBlockHeapAt` and `MEMAllocFromFrmHeapEx` --- include/coreinit/memblockheap.h | 14 ++++++++------ include/coreinit/memfrmheap.h | 11 ++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/coreinit/memblockheap.h b/include/coreinit/memblockheap.h index d8fb33ef0..455996ed1 100644 --- a/include/coreinit/memblockheap.h +++ b/include/coreinit/memblockheap.h @@ -103,19 +103,21 @@ MEMAddBlockHeapTracking(MEMHeapHandle heap, MEMBlockHeapTracking *tracking, uint32_t size); +void +MEMFreeToBlockHeap(MEMHeapHandle heap, + void *data); + void * MEMAllocFromBlockHeapAt(MEMHeapHandle heap, void *addr, - uint32_t size); + uint32_t size) + WUT_MALLOC WUT_FREED_BY(MEMFreeToBlockHeap, 2) WUT_ALLOC_SIZE(3); void * MEMAllocFromBlockHeapEx(MEMHeapHandle heap, uint32_t size, - int32_t align); - -void -MEMFreeToBlockHeap(MEMHeapHandle heap, - void *data); + int32_t align) + WUT_MALLOC WUT_FREED_BY(MEMFreeToBlockHeap, 2) WUT_ALLOC_SIZE(2) WUT_ALLOC_ALIGN(3); uint32_t MEMGetAllocatableSizeForBlockHeapEx(MEMHeapHandle heap, diff --git a/include/coreinit/memfrmheap.h b/include/coreinit/memfrmheap.h index ee816d94e..2d749dcaa 100644 --- a/include/coreinit/memfrmheap.h +++ b/include/coreinit/memfrmheap.h @@ -56,15 +56,16 @@ MEMCreateFrmHeapEx(void *heap, void * MEMDestroyFrmHeap(MEMHeapHandle heap); -void * -MEMAllocFromFrmHeapEx(MEMHeapHandle heap, - uint32_t size, - int alignment); - void MEMFreeToFrmHeap(MEMHeapHandle heap, MEMFrmHeapFreeMode mode); +void * +MEMAllocFromFrmHeapEx(MEMHeapHandle heap, + uint32_t size, + int alignment) + WUT_MALLOC WUT_ALLOC_SIZE(2) WUT_ALLOC_ALIGN(3); + BOOL MEMRecordStateForFrmHeap(MEMHeapHandle heap, uint32_t tag); From 0c1e04063b3c7224eaf645707c207c56aa9e42c1 Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Thu, 10 Sep 2026 06:14:37 +0100 Subject: [PATCH 4/6] whoops --- include/wut.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wut.h b/include/wut.h index 463da8142..50adb02f0 100644 --- a/include/wut.h +++ b/include/wut.h @@ -19,7 +19,7 @@ #define WUT_DEPRECATED(reason) #define WUT_FORMAT_PRINTF(fmt, args) -#define WUT_MALLOC __attribute__((malloc)) +#define WUT_MALLOC #define WUT_FREED_BY(freeFn, ptrIndex) #define WUT_ALLOC_SIZE(posIndex) #define WUT_ALLOC_ALIGN(posIndex) From 75f1fe3c814becc249388aa9c3eeb218d48aefad Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Thu, 10 Sep 2026 06:27:43 +0100 Subject: [PATCH 5/6] Add attrs to `MEMAllocFromUnitHeap` --- include/coreinit/memunitheap.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/coreinit/memunitheap.h b/include/coreinit/memunitheap.h index c1df857bb..c6f3a5c10 100644 --- a/include/coreinit/memunitheap.h +++ b/include/coreinit/memunitheap.h @@ -43,13 +43,14 @@ MEMCreateUnitHeapEx(void *heap, void * MEMDestroyUnitHeap(MEMHeapHandle heap); -void * -MEMAllocFromUnitHeap(MEMHeapHandle heap); - void MEMFreeToUnitHeap(MEMHeapHandle heap, void *block); +void * +MEMAllocFromUnitHeap(MEMHeapHandle heap) + WUT_MALLOC WUT_FREED_BY(MEMFreeToUnitHeap, 2); + void MEMiDumpUnitHeap(MEMHeapHandle heap); From 276fb9c7b3f1ba28b97341649cb744fab2c5ec5d Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Thu, 10 Sep 2026 18:05:19 +0100 Subject: [PATCH 6/6] Formatting --- include/wut.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/wut.h b/include/wut.h index 50adb02f0..554837927 100644 --- a/include/wut.h +++ b/include/wut.h @@ -8,12 +8,12 @@ #if defined(__GNUC__) || defined(__clang__) -#define WUT_DEPRECATED(reason) __attribute__((__deprecated__(reason))) -#define WUT_FORMAT_PRINTF(fmt, args) __attribute__((__format__(__printf__, fmt, args))) -#define WUT_MALLOC __attribute__((malloc)) -#define WUT_FREED_BY(freeFn, ptrIndex) __attribute__((malloc(freeFn, ptrIndex))) -#define WUT_ALLOC_SIZE(posIndex) __attribute__((alloc_size(posIndex))) -#define WUT_ALLOC_ALIGN(posIndex) __attribute__((alloc_align(posIndex))) +#define WUT_DEPRECATED(reason) __attribute__((__deprecated__(reason))) +#define WUT_FORMAT_PRINTF(fmt, args) __attribute__((__format__(__printf__, fmt, args))) +#define WUT_MALLOC __attribute__((malloc)) +#define WUT_FREED_BY(freeFn, ptrIndex) __attribute__((malloc(freeFn, ptrIndex))) +#define WUT_ALLOC_SIZE(posIndex) __attribute__((alloc_size(posIndex))) +#define WUT_ALLOC_ALIGN(posIndex) __attribute__((alloc_align(posIndex))) #else // not __GNUC__ and not __clang__ @@ -31,9 +31,9 @@ #define WUT_DEBUG_REPORT(fmt, ...) #endif +#include "wut_rplwrap.h" #include "wut_structsize.h" #include "wut_types.h" -#include "wut_rplwrap.h" #ifdef DEBUG #include #endif