From 6d864b3abd8a4298edae65d20fe62c10bccdbe00 Mon Sep 17 00:00:00 2001 From: ToyB-Chan Date: Mon, 8 Jun 2026 09:32:44 +0200 Subject: [PATCH] =?UTF-8?q?further=20cleanup=20=F0=9F=97=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- minimal_heap.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/minimal_heap.h b/minimal_heap.h index a80037b..0883dc5 100644 --- a/minimal_heap.h +++ b/minimal_heap.h @@ -1,5 +1,7 @@ #pragma once +/* Version 1.0 */ + #include #include #include @@ -8,8 +10,22 @@ #define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_MAGIC_NUMBER 1 #define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_CHECKSUM 2 +/* Defines to be configured by the library user */ #define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_CHECKSUM +#define MIHP_ASSERT(Condition) while(1) { if (Condition) break; *(volatile char*)(0x0) = 0; } + +#define MIHP_HEAP_LOCK_TYPE uint8_t // Does NOT have to be reentred safe +#define MIHP_LOCK_HEAP(LockVarPtr) { while (*(LockVarPtr)) {}; *(LockVarPtr) = true; } +#define MIHP_UNLOCK_HEAP(LockVarPtr) { *(LockVarPtr) = false; } +/* */ + +/* Hooks to be implemented by the library user */ +void* MIHP_PlatformRequestMemory(size_t size); // Alignment must at least be alignment of size_t +bool MIHP_PlatformFreeMemory(void* ptr, size_t size); +void MIHP_PlatformOnHeapCorruptionDetected(struct _MIHP_HeapCorruptionInfo info); +/* */ + #define MIHP_HEAP_CORRUPTION_TYPE_MEMORY_AREA_CHECKSUM_MISMATCH 0 #define MIHP_HEAP_CORRUPTION_TYPE_SEGMENT_CHECKSUM_MISMATCH 1 #define MIHP_HEAP_CORRUPTION_TYPE_FRONT_CANARY_MISMATCH 2 @@ -76,20 +92,6 @@ typedef struct _MIHP_HeapCorruptionInfo uint32_t ActualValue; } MIHP_HeapCorruptionInfo; -/* Hooks to be implemented by the library user */ -void* MIHP_PlatformRequestMemory(size_t size); // Alignment must at least be alignment of size_t -bool MIHP_PlatformFreeMemory(void* ptr, size_t size); -void MIHP_PlatformOnHeapCorruptionDetected(MIHP_HeapCorruptionInfo info); -/* === */ - -/* Defines to be configured by the library user */ -#define MIHP_ASSERT(Condition) while(1) { if (Condition) break; *(volatile char*)(0x0) = 0; } - -#define MIHP_HEAP_LOCK_TYPE uint8_t // Does NOT have to be reentred safe -#define MIHP_LOCK_HEAP(LockVarPtr) { while (*(LockVarPtr)) {}; *(LockVarPtr) = true; } -#define MIHP_UNLOCK_HEAP(LockVarPtr) { *(LockVarPtr) = false; } -/* === */ - typedef struct _MIHP_HeapInfo { MIHP_HeapConfig Config;