mirror of
https://github.com/zeldaret/oot.git
synced 2024-11-14 21:40:03 +00:00
[ntsc-1.2] Match system_malloc.c (#2080)
* Match ntsc-1.2 system_malloc.c * CLEAR_INTERRUPTS -> DISABLE_INTERRUPTS
This commit is contained in:
parent
af7bbf9dad
commit
160d8f4192
1 changed files with 56 additions and 4 deletions
|
@ -6,6 +6,16 @@
|
|||
|
||||
Arena gSystemArena;
|
||||
|
||||
#if PLATFORM_N64
|
||||
#define DECLARE_INTERRUPT_MASK OSIntMask __mask;
|
||||
#define DISABLE_INTERRUPTS() __mask = osSetIntMask(OS_IM_NONE)
|
||||
#define RESTORE_INTERRUPTS() osSetIntMask(__mask)
|
||||
#else
|
||||
#define DECLARE_INTERRUPT_MASK
|
||||
#define DISABLE_INTERRUPTS() (void)0
|
||||
#define RESTORE_INTERRUPTS() (void)0
|
||||
#endif
|
||||
|
||||
#if OOT_DEBUG
|
||||
s32 gSystemArenaLogSeverity = LOG_SEVERITY_NOLOG;
|
||||
|
||||
|
@ -27,7 +37,12 @@ void SystemArena_CheckPointer(void* ptr, u32 size, const char* name, const char*
|
|||
#endif
|
||||
|
||||
void* SystemArena_Malloc(u32 size) {
|
||||
void* ptr = __osMalloc(&gSystemArena, size);
|
||||
DECLARE_INTERRUPT_MASK
|
||||
void* ptr;
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
ptr = __osMalloc(&gSystemArena, size);
|
||||
RESTORE_INTERRUPTS();
|
||||
|
||||
SYSTEM_ARENA_CHECK_POINTER(ptr, size, "malloc", "確保"); // "Secure"
|
||||
return ptr;
|
||||
|
@ -35,7 +50,12 @@ void* SystemArena_Malloc(u32 size) {
|
|||
|
||||
#if OOT_DEBUG
|
||||
void* SystemArena_MallocDebug(u32 size, const char* file, int line) {
|
||||
void* ptr = __osMallocDebug(&gSystemArena, size, file, line);
|
||||
DECLARE_INTERRUPT_MASK
|
||||
void* ptr;
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
ptr = __osMallocDebug(&gSystemArena, size, file, line);
|
||||
RESTORE_INTERRUPTS();
|
||||
|
||||
SYSTEM_ARENA_CHECK_POINTER(ptr, size, "malloc_DEBUG", "確保"); // "Secure"
|
||||
return ptr;
|
||||
|
@ -43,7 +63,12 @@ void* SystemArena_MallocDebug(u32 size, const char* file, int line) {
|
|||
#endif
|
||||
|
||||
void* SystemArena_MallocR(u32 size) {
|
||||
void* ptr = __osMallocR(&gSystemArena, size);
|
||||
DECLARE_INTERRUPT_MASK
|
||||
void* ptr;
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
ptr = __osMallocR(&gSystemArena, size);
|
||||
RESTORE_INTERRUPTS();
|
||||
|
||||
SYSTEM_ARENA_CHECK_POINTER(ptr, size, "malloc_r", "確保"); // "Secure"
|
||||
return ptr;
|
||||
|
@ -51,7 +76,12 @@ void* SystemArena_MallocR(u32 size) {
|
|||
|
||||
#if OOT_DEBUG
|
||||
void* SystemArena_MallocRDebug(u32 size, const char* file, int line) {
|
||||
void* ptr = __osMallocRDebug(&gSystemArena, size, file, line);
|
||||
DECLARE_INTERRUPT_MASK
|
||||
void* ptr;
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
ptr = __osMallocRDebug(&gSystemArena, size, file, line);
|
||||
RESTORE_INTERRUPTS();
|
||||
|
||||
SYSTEM_ARENA_CHECK_POINTER(ptr, size, "malloc_r_DEBUG", "確保"); // "Secure"
|
||||
return ptr;
|
||||
|
@ -59,34 +89,56 @@ void* SystemArena_MallocRDebug(u32 size, const char* file, int line) {
|
|||
#endif
|
||||
|
||||
void* SystemArena_Realloc(void* ptr, u32 newSize) {
|
||||
DECLARE_INTERRUPT_MASK
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
ptr = __osRealloc(&gSystemArena, ptr, newSize);
|
||||
RESTORE_INTERRUPTS();
|
||||
|
||||
SYSTEM_ARENA_CHECK_POINTER(ptr, newSize, "realloc", "再確保"); // "Re-securing"
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#if OOT_DEBUG
|
||||
void* SystemArena_ReallocDebug(void* ptr, u32 newSize, const char* file, int line) {
|
||||
DECLARE_INTERRUPT_MASK
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
ptr = __osReallocDebug(&gSystemArena, ptr, newSize, file, line);
|
||||
RESTORE_INTERRUPTS();
|
||||
|
||||
SYSTEM_ARENA_CHECK_POINTER(ptr, newSize, "realloc_DEBUG", "再確保"); // "Re-securing"
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
void SystemArena_Free(void* ptr) {
|
||||
DECLARE_INTERRUPT_MASK
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
__osFree(&gSystemArena, ptr);
|
||||
RESTORE_INTERRUPTS();
|
||||
}
|
||||
|
||||
#if OOT_DEBUG
|
||||
void SystemArena_FreeDebug(void* ptr, const char* file, int line) {
|
||||
DECLARE_INTERRUPT_MASK
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
__osFreeDebug(&gSystemArena, ptr, file, line);
|
||||
RESTORE_INTERRUPTS();
|
||||
}
|
||||
#endif
|
||||
|
||||
void* SystemArena_Calloc(u32 num, u32 size) {
|
||||
DECLARE_INTERRUPT_MASK
|
||||
void* ret;
|
||||
u32 n = num * size;
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
ret = __osMalloc(&gSystemArena, n);
|
||||
RESTORE_INTERRUPTS();
|
||||
|
||||
if (ret != NULL) {
|
||||
bzero(ret, n);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue