Handle heap

This commit is contained in:
dbalatoni13 2025-04-02 10:19:16 +02:00
parent 14918e187e
commit 670a2c4c62
11 changed files with 746 additions and 161 deletions

View file

@ -19,14 +19,22 @@ extern char _db_stack_end[];
extern char *__OSResetSWInterruptHandler[];
#ifdef TARGET_PC
vu16 __OSDeviceCode;
#else
vu16 __OSDeviceCode : (OS_BASE_CACHED | 0x30E6);
#endif
static DVDDriveInfo DriveInfo ATTRIBUTE_ALIGN(32);
static DVDCommandBlock DriveBlock;
static OSBootInfo *BootInfo;
static u32 *BI2DebugFlag;
static u32 *BI2DebugFlagHolder;
#ifdef _MSC_VER
BOOL __OSIsGcam = FALSE;
#else
__declspec(weak) BOOL __OSIsGcam = FALSE;
#endif
static f64 ZeroF;
static f32 ZeroPS[2];
static BOOL AreWeInitialized = FALSE;
@ -56,6 +64,7 @@ void OSDefaultExceptionHandler(__OSException exception, OSContext *context);
extern BOOL __DBIsExceptionMarked(__OSException);
static void OSExceptionInit(void);
#ifdef __MWERKS__
/* clang-format off */
asm void __OSFPRInit(void)
{
@ -143,6 +152,7 @@ SkipPairedSingles:
blr
}
/* clang-format on */
#endif
u32 OSGetConsoleType()
{
@ -155,8 +165,8 @@ u32 OSGetConsoleType()
void *__OSSavedRegionStart;
void *__OSSavedRegionEnd;
extern u32 BOOT_REGION_START : 0x812FDFF0; //(*(u32 *)0x812fdff0)
extern u32 BOOT_REGION_END : 0x812FDFEC; //(*(u32 *)0x812fdfec)
extern u32 BOOT_REGION_START AT_ADDRESS(0x812FDFF0); //(*(u32 *)0x812fdff0)
extern u32 BOOT_REGION_END AT_ADDRESS(0x812FDFEC); //(*(u32 *)0x812fdfec)
void ClearArena(void)
{
@ -477,6 +487,7 @@ static void OSExceptionInit(void)
DBPrintf("Exceptions initialized...\n");
}
#ifdef __MWERKS__
static asm void __OSDBIntegrator(void)
{
/* clang-format off */
@ -505,6 +516,7 @@ entry __OSDBJUMPEND
/* clang-format on */
}
#endif
__OSExceptionHandler __OSSetExceptionHandler(__OSException exception, __OSExceptionHandler handler)
{
@ -519,6 +531,7 @@ __OSExceptionHandler __OSGetExceptionHandler(__OSException exception)
return OSExceptionTable[exception];
}
#ifdef __MWERKS__
static asm void OSExceptionVector(void)
{
/* clang-format off */
@ -603,8 +616,10 @@ entry __OSEVEnd
nop
/* clang-format on */
}
#endif
void __OSUnhandledException(__OSException exception, OSContext *context, u32 dsisr, u32 dar);
#ifdef __MWERKS__
asm void OSDefaultExceptionHandler(register __OSException exception, register OSContext *context)
{
/* clang-format off */
@ -631,6 +646,7 @@ void __OSPSInit(void)
}
// clang-format on
}
#endif
#define DI_CONFIG_IDX 0x9
#define DI_CONFIG_CONFIG_MASK 0xFF

View file

@ -166,7 +166,6 @@ void *OSAllocFromHeap(int heap, unsigned long size)
return NULL;
}
ASSERTMSG1(0x168, !((s32)cell & 0x1F), "OSAllocFromHeap(): heap is broken.");
ASSERTMSG1(0x169, cell->hd == NULL, "OSAllocFromHeap(): heap is broken.");
leftoverSize = cell->size - size;
if (leftoverSize < 0x40U) {
@ -312,7 +311,6 @@ void OSFreeToHeap(int heap, void *ptr)
ASSERTMSG1(0x241, HeapArray[heap].size >= 0, "OSFreeToHeap(): invalid heap handle.");
cell = (void *)((u32)ptr - 0x20);
hd = &HeapArray[heap];
ASSERTMSG1(0x246, cell->hd == hd, "OSFreeToHeap(): invalid pointer.");
ASSERTMSG1(0x247, DLLookup(hd->allocated, cell), "OSFreeToHeap(): invalid pointer.");
hd->allocated = DLExtract(hd->allocated, cell);
hd->free = DLInsert(hd->free, cell);
@ -488,12 +486,6 @@ unsigned long OSReferentSize(void *ptr)
ASSERTMSG1(0x3BD, InRange(ptr, ArenaStart + HEADERSIZE, ArenaEnd), "OSReferentSize(): invalid pointer.");
ASSERTMSG1(0x3BE, !OFFSET(ptr, 32), "OSReferentSize(): invalid pointer.");
cell = (void *)((u32)ptr - HEADERSIZE);
ASSERTMSG1(0x3C2, cell->hd, "OSReferentSize(): invalid pointer.");
ASSERTMSG1(0x3C4, !(((u32)cell->hd - (u32)HeapArray) % 24), "OSReferentSize(): invalid pointer.");
ASSERTMSG1(0x3C6, ((u32)HeapArray <= (u32)cell->hd) && ((u32)cell->hd < (u32)((u32)HeapArray + (NumHeaps * 0x18))),
"OSReferentSize(): invalid pointer.");
ASSERTMSG1(0x3C7, cell->hd->size >= 0, "OSReferentSize(): invalid pointer.");
ASSERTMSG1(0x3C9, DLLookup(cell->hd->allocated, cell), "OSReferentSize(): invalid pointer.");
return (long)((u32)cell->size - HEADERSIZE);
}