/
eevee_stones.h
59 lines (44 loc) · 1.51 KB
/
eevee_stones.h
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
#include "platform_definition.h"
#ifdef EEVEE_STONES
#include "eevee_os.h"
// The stone system uses #pragma to fail out on accidental usage of malloc() and free()
#ifdef STONE
#pragma GCC poison malloc free realloc
#endif
// The rest of this stuff should only be defined once
#ifndef EEVEE_STONES_H
#define EEVEE_STONES_H
// Linked list for extensions (called stones ;) )
struct eevee_stone {
// An identifying string for the stone
char name[8];
// Hook and handler
int (*hook)(struct eevee_payload *, void **bp);
int (*handler)(struct eevee_payload *, void **bp);
// A pointer to 4 bytes of allocated memory.
// This allocated memory (*bp) = NULL initially.
// bp is passed to the stone, and it can store
// its state there. Note that the stone cannot
// (easily) clobber the eevee_stone data
// structure this way.
void **bp;
// Allocated memory and sizes, for reporting and garbage collection
struct alloc_list *gchead;
// The next stone
struct eevee_stone *next;
};
// Backward linked list for garbage collection
// This is for efficiency, since we are usually freeing things we allocated recently
struct alloc_list {
void *mem;
u16 size;
struct alloc_list *older;
};
// Convenience typedefs
typedef int (*stoneCallback_fp)(struct eevee_payload *, void **bp);
int registerStone(char *name, stoneCallback_fp hook, stoneCallback_fp handler);
int unregisterStone(u8 n);
void *stoneMalloc(u16 size, stoneCallback_fp who);
int stoneFree(void *mem, stoneCallback_fp who);
#endif
#endif