Compare commits

..

2 Commits

Author SHA1 Message Date
a632291f07 bump version 2026-11-05 18:09:27 +01:00
dcd6c58394 fixed some bugs (tm) 2026-11-05 17:57:07 +01:00
2 changed files with 10 additions and 13 deletions

View File

@@ -2,16 +2,12 @@
#define __MINIMAL_HEAP_H__ #define __MINIMAL_HEAP_H__
#define MIHP_VERSION_MAJOR 1 #define MIHP_VERSION_MAJOR 1
#define MIHP_VERSION_MINOR 12 #define MIHP_VERSION_MINOR 13
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#ifndef MIHP_IMPLEMENTATION
#define MIHP_IMPLEMENTATION 0
#endif
/* Defines to be configured by the library user */ /* Defines to be configured by the library user */
#ifndef MIHP_ASSERT #ifndef MIHP_ASSERT
#define MIHP_ASSERT(Condition) while(1) { if (Condition) break; *(volatile char*)(0x0) = 0; } #define MIHP_ASSERT(Condition) while(1) { if (Condition) break; *(volatile char*)(0x0) = 0; }

View File

@@ -24,7 +24,7 @@ MIHP_HeapConfig MIHP_MakeDefaultConfigPreset()
cfg.AllocateFillValue = 0xbe; cfg.AllocateFillValue = 0xbe;
cfg.FreeFillValue = 0xee; cfg.FreeFillValue = 0xee;
cfg.HeapValidationMode = MIHP_HVM_MagicNumber; cfg.HeapValidationMode = MIHP_HVM_None;
return cfg; return cfg;
} }
@@ -43,6 +43,12 @@ MIHP_HeapError MIHP_InitializeHeap(MIHP_Heap* heap, MIHP_HeapConfig config)
if (config.PlatformFreeMemoryFn == NULL) if (config.PlatformFreeMemoryFn == NULL)
return MIHP_HE_BadConfig; return MIHP_HE_BadConfig;
if (config.OnHeapCorruptionDetectedFn == NULL && config.HeapValidationMode != MIHP_HVM_None)
return MIHP_HE_BadConfig;
if (config.MinMemoryAreaSize < MIHP_GetMinimalPayloadSize(heap) * 2)
return MIHP_HE_BadConfig;
if (config.MaxHeapSize < config.MinMemoryAreaSize) if (config.MaxHeapSize < config.MinMemoryAreaSize)
return MIHP_HE_BadConfig; return MIHP_HE_BadConfig;
@@ -260,7 +266,7 @@ MIHP_HeapResult MIHP_Reallocate(MIHP_Heap* heap, void* ptr, size_t newSize)
segment->Checksum = MIHP_GenerateHeapSegmentChecksum(heap, segment); segment->Checksum = MIHP_GenerateHeapSegmentChecksum(heap, segment);
MIHP_UnlockHeap(heap); MIHP_UnlockHeap(heap);
return MIHP_MAKE_RESULT(NULL, MIHP_HE_Success); return MIHP_MAKE_RESULT(ptr, MIHP_HE_Success);
} }
if (segment->NextSegment) if (segment->NextSegment)
@@ -402,6 +408,7 @@ MIHP_HeapError MIHP_SetPointerCustomMetadata(MIHP_Heap* heap, void* ptr, MIHP_Al
MIHP_HeapSegmentHeader* segment = MIHP_GetHeapSegmentHeaderPtr(heap, ptr); MIHP_HeapSegmentHeader* segment = MIHP_GetHeapSegmentHeaderPtr(heap, ptr);
MIHP_ValidateHeapSegmentHeader(heap, segment); MIHP_ValidateHeapSegmentHeader(heap, segment);
segment->CustomMetadata = metadata; segment->CustomMetadata = metadata;
segment->Checksum = MIHP_GenerateHeapSegmentChecksum(heap, segment);
return MIHP_HE_Success; return MIHP_HE_Success;
} }
@@ -829,9 +836,6 @@ uint32_t MIHP_GenerateHeapSegmentChecksum(const MIHP_Heap* heap, const MIHP_Heap
void MIHP_ValidateHeapMemoryAreaHeader(const MIHP_Heap* heap, const MIHP_HeapMemoryAreaHeader* area) void MIHP_ValidateHeapMemoryAreaHeader(const MIHP_Heap* heap, const MIHP_HeapMemoryAreaHeader* area)
{ {
if (heap->Config.OnHeapCorruptionDetectedFn == NULL)
return;
uint32_t newChecksum; uint32_t newChecksum;
if (heap->Config.HeapValidationMode == MIHP_HVM_None) if (heap->Config.HeapValidationMode == MIHP_HVM_None)
@@ -858,9 +862,6 @@ void MIHP_ValidateHeapMemoryAreaHeader(const MIHP_Heap* heap, const MIHP_HeapMem
void MIHP_ValidateHeapSegmentHeader(const MIHP_Heap* heap, const MIHP_HeapSegmentHeader* segment) void MIHP_ValidateHeapSegmentHeader(const MIHP_Heap* heap, const MIHP_HeapSegmentHeader* segment)
{ {
if (heap->Config.OnHeapCorruptionDetectedFn == NULL)
return;
uint32_t newChecksum; uint32_t newChecksum;
if (heap->Config.HeapValidationMode == MIHP_HVM_None) if (heap->Config.HeapValidationMode == MIHP_HVM_None)