-
Notifications
You must be signed in to change notification settings - Fork 72
/
OSArena.c
53 lines (43 loc) · 951 Bytes
/
OSArena.c
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
#include <dolphin/os/OSArena.h>
#define ROUND(n, a) (((u32) (n) + (a) - 1) & ~((a) - 1))
#define TRUNC(n, a) (((u32) (n)) & ~((a) - 1))
void* __OSArenaHi;
void* __OSArenaLo = (void*) -1;
void* OSGetArenaHi(void)
{
return __OSArenaHi;
}
void* OSGetArenaLo(void)
{
return __OSArenaLo;
}
void OSSetArenaHi(void* addr)
{
__OSArenaHi = addr;
}
void OSSetArenaLo(void* addr)
{
__OSArenaLo = addr;
}
void* OSAllocFromArenaLo(u32 size, u32 align)
{
void* ptr;
u8* arenaLo;
ptr = OSGetArenaLo();
arenaLo = ptr = (void*) ROUND(ptr, align);
arenaLo += size;
arenaLo = (u8*) ROUND(arenaLo, align);
OSSetArenaLo(arenaLo);
return ptr;
}
void* OSAllocFromArenaHi(u32 size, u32 align)
{
void* ptr;
u8* arenaHi;
arenaHi = OSGetArenaHi();
arenaHi = (u8*) TRUNC(arenaHi, align);
arenaHi -= size;
arenaHi = ptr = (void*) TRUNC(arenaHi, align);
OSSetArenaHi(arenaHi);
return ptr;
}