diff options
| author | cadmic <cadmic24@gmail.com> | 2024-08-26 18:49:33 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-26 21:49:33 -0400 |
| commit | 160d8f41920f9cefa174b9cf665f1e9a2892fd73 (patch) | |
| tree | 8ba8e294b33338bf7c260b2be187b0000dc4af21 /src/code | |
| parent | af7bbf9dad0c717308c8ebfd99977e149ab6e088 (diff) | |
[ntsc-1.2] Match system_malloc.c (#2080)
* Match ntsc-1.2 system_malloc.c
* CLEAR_INTERRUPTS -> DISABLE_INTERRUPTS
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/system_malloc.c | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/src/code/system_malloc.c b/src/code/system_malloc.c index f389aa0b0..8385a883c 100644 --- a/src/code/system_malloc.c +++ b/src/code/system_malloc.c @@ -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); } |
