summaryrefslogtreecommitdiff
path: root/src/boot/libc64/__osMalloc.c
blob: 0d1065238f6f63ab544eeb736e0d77353fe0a08f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
#include "libc64/os_malloc.h"

#include "alignment.h"
#include "stdbool.h"
#include "stdint.h"
#include "string.h"
#include "macros.h"

#define FILL_ALLOCBLOCK (1 << 0)
#define FILL_FREEBLOCK (1 << 1)
#define CHECK_FREE_BLOCK (1 << 2)

#define NODE_MAGIC (0x7373)

#define BLOCK_UNINIT_MAGIC (0xAB)
#define BLOCK_UNINIT_MAGIC_32 (0xABABABAB)
#define BLOCK_ALLOC_MAGIC (0xCD)
#define BLOCK_ALLOC_MAGIC_32 (0xCDCDCDCD)
#define BLOCK_FREE_MAGIC (0xEF)
#define BLOCK_FREE_MAGIC_32 (0xEFEFEFEF)

#define NODE_IS_VALID(node) ((node)->magic == NODE_MAGIC)

#if MM_VERSION >= N64_US
#define SET_DEBUG_INFO(node, f, l, a) ((void)0)

#define CHECK_CORRECT_ARENA(node, arena) (true)

#define CHECK_ALLOC_FAILURE(arena, ptr) (void)0
#else
#define SET_DEBUG_INFO(node, f, l, a)         \
    {                                         \
        node->filename = (f);                 \
        node->line = (l);                     \
        node->threadId = osGetThreadId(NULL); \
        node->arena = (a);                    \
        node->time = osGetTime();             \
    }                                         \
    (void)0

#define CHECK_CORRECT_ARENA(node, arena) ((node)->arena == (arena))

s32 gTotalAllocFailures = 0; // "Arena_failcnt"

#define CHECK_ALLOC_FAILURE(arena, ptr) \
    do {                                \
        if ((ptr) == NULL) {            \
            gTotalAllocFailures++;      \
            (arena)->allocFailures++;   \
        }                               \
    } while (0)
#endif

OSMesg sArenaLockMsg[1];

void __osMallocAddHeap(Arena* arena, void* heap, size_t size);

void ArenaImpl_LockInit(Arena* arena) {
    osCreateMesgQueue(&arena->lock, sArenaLockMsg, ARRAY_COUNT(sArenaLockMsg));
}

void ArenaImpl_Lock(Arena* arena) {
    osSendMesg(&arena->lock, NULL, OS_MESG_BLOCK);
}

void ArenaImpl_Unlock(Arena* arena) {
    osRecvMesg(&arena->lock, NULL, OS_MESG_BLOCK);
}

ArenaNode* ArenaImpl_GetLastBlock(Arena* arena) {
    ArenaNode* last;
    ArenaNode* iter;

    last = arena->head;

    if (last != NULL) {
        iter = last->next;
        while (iter != NULL) {
            last = iter;
            iter = iter->next;
        }
    }
    return last;
}

/**
 * Initializes \p arena to manage the memory region \p heap.
 *
 * @param arena  The Arena to initialize.
 * @param heap   The memory region to use as heap space.
 * @param size   The size of the heap.
 */
void __osMallocInit(Arena* arena, void* heap, size_t size) {
    bzero(arena, sizeof(Arena));

    ArenaImpl_LockInit(arena);

    __osMallocAddHeap(arena, heap, size);
    arena->isInit = true;
}

// Original name: __osMallocAddBlock
void __osMallocAddHeap(Arena* arena, void* heap, size_t size) {
    ptrdiff_t diff;
    s32 alignedSize;
    ArenaNode* firstNode;
    ArenaNode* lastNode;

    if (heap == NULL) {
        return;
    }

    firstNode = (ArenaNode*)ALIGN16((uintptr_t)heap);
    diff = (uintptr_t)firstNode - (uintptr_t)heap;
    alignedSize = ((s32)size - diff) & ~0xF;

    // If the size of the heap is smaller than sizeof(ArenaNode), then the initialization will silently fail
    if (alignedSize > (s32)sizeof(ArenaNode)) {
        firstNode->next = NULL;
        firstNode->prev = NULL;
        firstNode->size = alignedSize - sizeof(ArenaNode);
        firstNode->isFree = true;
        firstNode->magic = NODE_MAGIC;

        ArenaImpl_Lock(arena);

        lastNode = ArenaImpl_GetLastBlock(arena);

        // Checks if there's already a block
        if (lastNode == NULL) {
            arena->head = firstNode;
            arena->start = heap;
        } else {
            // Chain the existing block with the new one
            firstNode->prev = lastNode;
            lastNode->next = firstNode;
        }

        ArenaImpl_Unlock(arena);
    }
}

/**
 * Clears the whole \p arena, invalidating every allocated pointer to it.
 *
 * @param arena  The Arena to clear.
 */
void __osMallocCleanup(Arena* arena) {
    bzero(arena, sizeof(Arena));
}

/**
 * Returns whether or not the \p arena has been initialized.
 *
 * @param arena  The Arena to check.
 * @return u8    `true` if the \p arena has been initialized. `false` otherwise.
 */
u8 __osMallocIsInitialized(Arena* arena) {
    return arena->isInit;
}

#if MM_VERSION < N64_US
void* __osMallocDebug(Arena* arena, size_t size, const char* file, int line) {
    ArenaNode* iter;
    ArenaNode* newNode;
    void* alloc = NULL;

    ArenaImpl_Lock(arena);

    size = ALIGN16(size);

    for (iter = arena->head; iter != NULL; iter = iter->next) {
        if (iter->isFree && (iter->size >= size)) {
            size_t blockSize = ALIGN16(size) + sizeof(ArenaNode);

            if (blockSize < iter->size) {
                ArenaNode* next;

                newNode = (ArenaNode*)((uintptr_t)iter + blockSize);
                newNode->next = iter->next;
                newNode->prev = iter;
                newNode->size = iter->size - blockSize;
                newNode->isFree = true;
                newNode->magic = NODE_MAGIC;

                iter->next = newNode;
                iter->size = size;

                next = newNode->next;
                if (next != NULL) {
                    next->prev = newNode;
                }
            }

            iter->isFree = false;

            SET_DEBUG_INFO(iter, file, line, arena);

            alloc = (void*)((uintptr_t)iter + sizeof(ArenaNode));
            break;
        }
    }

    CHECK_ALLOC_FAILURE(arena, alloc);

    ArenaImpl_Unlock(arena);

    return alloc;
}
#endif

#if MM_VERSION < N64_US
void* __osMallocRDebug(Arena* arena, size_t size, const char* file, int line) {
    ArenaNode* iter;
    ArenaNode* newNode;
    size_t blockSize;
    void* alloc = NULL;

    size = ALIGN16(size);

    ArenaImpl_Lock(arena);

    for (iter = ArenaImpl_GetLastBlock(arena); iter != NULL; iter = iter->prev) {
        if (iter->isFree && (iter->size >= size)) {
            blockSize = ALIGN16(size) + sizeof(ArenaNode);

            if (blockSize < iter->size) {
                ArenaNode* next;

                newNode = (ArenaNode*)(((uintptr_t)iter + iter->size) - size);
                newNode->next = iter->next;
                newNode->prev = iter;
                newNode->size = size;
                newNode->magic = NODE_MAGIC;

                iter->next = newNode;
                iter->size -= blockSize;

                next = newNode->next;
                if (next != NULL) {
                    next->prev = newNode;
                }
                iter = newNode;
            }

            iter->isFree = false;

            SET_DEBUG_INFO(iter, file, line, arena);

            alloc = (void*)((uintptr_t)iter + sizeof(ArenaNode));
            break;
        }
    }

    CHECK_ALLOC_FAILURE(arena, alloc);

    ArenaImpl_Unlock(arena);

    return alloc;
}
#endif

/**
 * Allocates at least \p size bytes of memory using the given \p arena.
 * The block of memory will be allocated at the start of the first sufficiently large free block.
 *
 *  - If there's not enough space in the given \p arena, this function will fail, returning `NULL`.
 *  - If \p size is zero, then an empty region of memory is returned.
 *
 * To avoid memory leaks, the returned pointer should be eventually deallocated using either `__osFree` or
 * `__osRealloc`.
 *
 * @param[in, out] arena  The specific Arena to be used for the allocation.
 * @param[in] size        The size in bytes that will be allocated.
 * @return void*          On success, the allocated area of the \p arena memory. Otherwise, `NULL`.
 */
void* __osMalloc(Arena* arena, size_t size) {
    ArenaNode* iter;
    ArenaNode* newNode;
    void* alloc = NULL;

    size = ALIGN16(size);

    ArenaImpl_Lock(arena);

    // Start iterating from the head of the arena.
    iter = arena->head;

    // Iterate over the arena looking for a big enough space of memory.
    while (iter != NULL) {
        if (iter->isFree && (iter->size >= size)) {
            size_t blockSize = ALIGN16(size) + sizeof(ArenaNode);

            // If the block is larger than the requested size, then split it and just use the required size of the
            // current block.
            if (blockSize < iter->size) {
                ArenaNode* next;

                newNode = (ArenaNode*)((uintptr_t)iter + blockSize);
                newNode->next = iter->next;
                newNode->prev = iter;
                newNode->size = iter->size - blockSize;
                newNode->isFree = true;
                newNode->magic = NODE_MAGIC;

                iter->next = newNode;
                iter->size = size;

                next = newNode->next;
                if (next != NULL) {
                    next->prev = newNode;
                }
            }

            iter->isFree = false;

            SET_DEBUG_INFO(iter, NULL, 0, arena);

            alloc = (void*)((uintptr_t)iter + sizeof(ArenaNode));
            break;
        }

        iter = iter->next;
    }

    CHECK_ALLOC_FAILURE(arena, alloc);

    ArenaImpl_Unlock(arena);

    return alloc;
}

/**
 * Allocates at least \p size bytes of memory using the given \p arena.
 * Unlike __osMalloc, the block of memory will be allocated from the end of the \p arena.
 *
 * - If there's not enough space in the given \p arena, this function will fail, returning `NULL`.
 * - If \p size is zero, then an empty region of memory is returned.
 *
 * To avoid memory leaks, the returned pointer should be eventually deallocated using `__osFree` or `__osRealloc`.
 *
 * @param[in, out] arena  The specific Arena to be used for the allocation.
 * @param[in] size        The size in bytes that will be allocated.
 * @return void*          On success, the allocated area of the \p arena memory. Otherwise, `NULL`.
 */
void* __osMallocR(Arena* arena, size_t size) {
    ArenaNode* iter;
    ArenaNode* newNode;
    size_t blockSize;
    void* alloc = NULL;

    size = ALIGN16(size);

    ArenaImpl_Lock(arena);

    // Start iterating from the last block of the arena.
    iter = ArenaImpl_GetLastBlock(arena);

    // Iterate in reverse the arena looking for a big enough space of memory.
    while (iter != NULL) {
        if (iter->isFree && iter->size >= size) {
            blockSize = ALIGN16(size) + sizeof(ArenaNode);

            // If the block is larger than the requested size, then split it and just use the required size of the
            // current block.
            if (blockSize < iter->size) {
                ArenaNode* next;

                newNode = (ArenaNode*)((uintptr_t)iter + (iter->size - size));
                newNode->next = iter->next;
                newNode->prev = iter;
                newNode->size = size;
                newNode->magic = NODE_MAGIC;

                iter->next = newNode;
                iter->size -= blockSize;

                next = newNode->next;
                if (next != NULL) {
                    next->prev = newNode;
                }
                iter = newNode;
            }

            iter->isFree = false;

            SET_DEBUG_INFO(iter, NULL, 0, arena);

            alloc = (void*)((uintptr_t)iter + sizeof(ArenaNode));
            break;
        }
        iter = iter->prev;
    }

    CHECK_ALLOC_FAILURE(arena, alloc);

    ArenaImpl_Unlock(arena);

    return alloc;
}

/**
 * Deallocates the pointer \p ptr previously allocated by `__osMalloc`, `__osMallocR` or `__osRealloc`.
 * If \p ptr is `NULL` or it has been already been freed, then this function does nothing.
 *
 * - The behaviour is undefined if \p ptr is not a memory region returned by one of the cited allocating
 * functions.
 * - The behaviour is undefined if \p ptr doesn't correspond to the given \p arena.
 * - Any access to the freed pointer is undefined behaviour.
 *
 * @param[in, out] arena  The specific Arena to be used for the allocation.
 * @param[in, out] ptr    The allocated memory block to deallocate.
 */
void __osFree(Arena* arena, void* ptr) {
    ArenaNode* node;
    ArenaNode* next;
    ArenaNode* prev;

    ArenaImpl_Lock(arena);

    if (ptr == NULL) {
        goto cleanup;
    }

    node = (ArenaNode*)((uintptr_t)ptr - sizeof(ArenaNode));

    if (!NODE_IS_VALID(node)) {
        PRINTF(T("__osFree:不正解放(%08x)\n", "__osFree:Unauthorized release(%08x)\n"));
        goto cleanup;
    }

    if (node->isFree) {
        PRINTF(T("__osFree:二重解放(%08x)\n", "__osFree:Double release(%08x)\n"));
        goto cleanup;
    }

    if (!CHECK_CORRECT_ARENA(node, arena)) {
        PRINTF(T("__osFree:arena(%08x)が__osMallocのarena(%08x)と一致しない\n",
                 "__osFree:arena(%08x) and __osMallocのarena(%08x) do not match\n"));
        goto cleanup;
    }

    next = node->next;
    prev = node->prev;
    node->isFree = true;

    SET_DEBUG_INFO(node, NULL, 0, arena);

    // Checks if the next node is contiguous to the current node and if it isn't currently allocated. Then merge the
    // two nodes into one.
    if (((uintptr_t)next == (uintptr_t)node + sizeof(ArenaNode) + node->size) && next->isFree) {
        ArenaNode* newNext = next->next;

        if (newNext != NULL) {
            newNext->prev = node;
        }

        node->size += next->size + sizeof(ArenaNode);

        node->next = newNext;
        next = newNext;
    }

    // Checks if the previous node is contiguous to the current node and if it isn't currently allocated. Then merge
    // the two nodes into one.
    if ((prev != NULL) && prev->isFree && ((uintptr_t)node == (uintptr_t)prev + sizeof(ArenaNode) + prev->size)) {
        if (next != NULL) {
            next->prev = prev;
        }

        prev->next = next;
        prev->size += node->size + sizeof(ArenaNode);
    }

cleanup:
    ArenaImpl_Unlock(arena);
}

#if MM_VERSION < N64_US
void __osFreeDebug(Arena* arena, void* ptr, const char* file, int line) {
    ArenaNode* node;
    ArenaNode* next;
    ArenaNode* prev;

    ArenaImpl_Lock(arena);

    if (ptr == NULL) {
        goto cleanup;
    }

    node = (ArenaNode*)((uintptr_t)ptr - sizeof(ArenaNode));

    if (!NODE_IS_VALID(node)) {
        PRINTF(T("__osFree:不正解放(%08x)\n", "__osFree:Unauthorized release(%08x)\n"));
        goto cleanup;
    }

    if (node->isFree) {
        PRINTF(T("__osFree:二重解放(%08x)\n", "__osFree:Double release(%08x)\n"));
        goto cleanup;
    }

    if (!CHECK_CORRECT_ARENA(node, arena)) {
        PRINTF(T("__osFree:arena(%08x)が__osMallocのarena(%08x)と一致しない\n",
                 "__osFree:arena(%08x) and __osMallocのarena(%08x) do not match\n"));
        goto cleanup;
    }

    next = node->next;
    prev = node->prev;
    node->isFree = true;

    SET_DEBUG_INFO(node, file, line, arena);

    // Checks if the next node is contiguous to the current node and if it isn't currently allocated. Then merge the
    // two nodes into one.
    if (((uintptr_t)next == (uintptr_t)node + sizeof(ArenaNode) + node->size) && next->isFree) {
        ArenaNode* newNext = next->next;

        if (newNext != NULL) {
            newNext->prev = node;
        }

        node->size += next->size + sizeof(ArenaNode);

        node->next = newNext;
        next = newNext;
    }

    // Checks if the previous node is contiguous to the current node and if it isn't currently allocated. Then merge
    // the two nodes into one.
    if ((prev != NULL) && prev->isFree && ((uintptr_t)node == (uintptr_t)prev + sizeof(ArenaNode) + prev->size)) {
        if (next != NULL) {
            next->prev = prev;
        }

        prev->next = next;
        prev->size += node->size + sizeof(ArenaNode);
    }

cleanup:
    ArenaImpl_Unlock(arena);
}
#endif

/**
 * Reallocates the pointer \p ptr.
 * \p ptr must be either a pointer previously allocated by `__osMalloc`, `__osMallocR` or `__osRealloc` and
 * not freed yet, or a `NULL` pointer.
 *
 * - If \p ptr is `NULL` a new pointer is allocated. See `__osMalloc` for more details.
 * - If \p newSize is 0, then the given pointer is freed and `NULL` is returned. See `__osFree` for more details.
 * - If \p newSize is bigger than the currently allocated allocated pointer, then the area of memory is expanded to a
 * size big enough to fit the requested size.
 *
 * - The behaviour is undefined if \p ptr is not a memory region returned by one of the cited allocating
 * functions.
 * - The behaviour is undefined if \p ptr doesn't correspond to the given \p arena.
 * - If the pointer is freed, then any access to the original freed pointer is undefined behaviour.
 *
 * @param[in, out] arena  The specific Arena to be used for the allocation.
 * @param[in, out] ptr    The allocated memory block to deallocate.
 * @param[in] newSize     The new requested size.
 * @return void*          On success, the pointer to the reallocated area of memory. On failure, `NULL` is returned,
 * and the original parameter \p ptr remains valid.
 */
void* __osRealloc(Arena* arena, void* ptr, size_t newSize) {
    ArenaImpl_Lock(arena);

    (void)"__osRealloc(%08x, %d)\n";

    if (ptr == NULL) {
        // if the `ptr` is NULL, then allocate a new pointer with the specified size
        // if newSize is 0, then __osMalloc would return a NULL pointer
        ptr = __osMalloc(arena, newSize);
    } else if (newSize == 0) {
        // if the requested size is zero, then free the pointer
        __osFree(arena, ptr);
        ptr = NULL;
    } else {
        size_t diff;
        void* newPtr;
        // Gets the start of the ArenaNode pointer embedded
        ArenaNode* node = (void*)((uintptr_t)ptr - sizeof(ArenaNode));

        newSize = ALIGN16(newSize);

        if (newSize == node->size) {
            // Do nothing
        } else if (node->size < newSize) {
            ArenaNode* next = node->next;

            diff = newSize - node->size;
            // Checks if the next node is contiguous to the current allocated node and it has enough space to fit the
            // new requested size
            if (((uintptr_t)next == (uintptr_t)node + node->size + sizeof(ArenaNode)) && next->isFree &&
                (next->size >= diff)) {
                ArenaNode* next2 = next->next;

                next->size = next->size - diff;
                if (next2 != NULL) {
                    // Update the previous element of the linked list
                    next2->prev = (void*)((uintptr_t)next + diff);
                }

                next2 = (void*)((uintptr_t)next + diff);
                node->next = next2;
                node->size = newSize;
                memmove(next2, next, sizeof(ArenaNode));
            } else {
                // Create a new pointer and manually copy the data from the old pointer to the new one
                newPtr = __osMalloc(arena, newSize);
                if (newPtr != NULL) {
                    bcopy(newPtr, ptr, node->size);
                    __osFree(arena, ptr);
                }
                ptr = newPtr;
            }
        } else if (newSize < node->size) {
        }
    }

    CHECK_ALLOC_FAILURE(arena, ptr);

    ArenaImpl_Unlock(arena);

    return ptr;
}

#if MM_VERSION < N64_US
void* __osReallocDebug(Arena* arena, void* ptr, size_t newSize, const char* file, int line) {
    return __osRealloc(arena, ptr, newSize);
}
#endif

/**
 * Gets the size of the largest free block, the total free space and the total allocated space.
 *
 * @param[in, out] arena   The Arena which will be used to get the values from.
 * @param[out] outMaxFree  The size of the largest free block.
 * @param[out] outFree     The total free space.
 * @param[out] outAlloc    The total allocated space.
 */
void __osGetSizes(Arena* arena, size_t* outMaxFree, size_t* outFree, size_t* outAlloc) {
    ArenaNode* iter;

    ArenaImpl_Lock(arena);

    *outMaxFree = 0;
    *outFree = 0;
    *outAlloc = 0;

    iter = arena->head;
    while (iter != NULL) {
        if (iter->isFree) {
            *outFree += iter->size;
            if (*outMaxFree < iter->size) {
                *outMaxFree = iter->size;
            }
        } else {
            *outAlloc += iter->size;
        }

        iter = iter->next;
    }

    ArenaImpl_Unlock(arena);
}

/**
 * Checks the validity of every node of the \p arena.
 *
 * @param arena  The Arena to check.
 * @return s32   0 if every pointer is valid. 1 otherwise.
 */
s32 __osCheckArena(Arena* arena) {
    ArenaNode* iter;
    s32 err = 0;

    ArenaImpl_Lock(arena);

    (void)T("アリーナの内容をチェックしています... (%08x)\n", "Checking the contents of the arena... (%08x)\n");

    for (iter = arena->head; iter != NULL; iter = iter->next) {
        if (!NODE_IS_VALID(iter)) {
            (void)T("おおっと!! (%08x %08x)\n", "Oops!! (%08x %08x)\n");

            err = 1;
            break;
        }
    }

    (void)T("アリーナはまだ、いけそうです\n", "The arena still looks good\n");

    ArenaImpl_Unlock(arena);

    return err;
}

#if MM_VERSION < N64_US
u8 ArenaImpl_GetAllocFailures(Arena* arena) {
    return arena->allocFailures;
}
#endif