1 /*---------------------------------------------------------------------------*
2   Project: OS - Memory Manager
3   File:    OSAlloc.h
4 
5   Copyright 1998, 1999 Nintendo. All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Log: OSAlloc.h,v $
14   Revision 1.2  2006/02/04 11:56:47  hashida
15   (none)
16 
17   Revision 1.1.1.1  2005/12/29 06:53:28  hiratsu
18   Initial import.
19 
20   Revision 1.1.1.1  2005/05/12 02:41:07  yasuh-to
21   Ported from dolphin source tree.
22 
23 
24     7     1999/11/01 6:16p Tian
25     Added OSVisitAllocated to iterate over all allocated memory
26 
27     6     1999/5/25 9:55p Shiki
28     Modified OSCheckHeap()to return # of available bytes in free.
29 
30     5     1999/05/23 6:59p Shiki
31     Revised declaration of OSSetCurrentHeap() and OSAllocFixed().
32     Added declaration of OSCheckHeap().
33 
34     4     1999/05/21 7:56p Shiki
35     Revised.
36 
37     3     1999/5/11 4:43p Shiki
38     Refreshed include tree.
39 
40     1     1999/4/30 12:49p Tianli01
41 
42     3     1999/4/22 6:55p Tianli01
43     Removed stdlib.h
44 
45     2     1999/3/26 2:07p Tianli01
46     Removed OSEvent reliance.
47 
48     1     1999/03/04 2:22p Tianli01
49     Initial check-in to new tree
50 
51     2     1999/02/04 6:02p Tianli01
52     Minor indentation changes
53 
54     1     1998/12/22 10:30a Tianli01
55     Initial checkin - Memory manager header files
56 
57   Change History:
58     1998/12/10      Tian Lim    Created
59 
60   $NoKeywords: $
61  *---------------------------------------------------------------------------*/
62 
63 #ifndef __OSALLOC_H__
64 #define __OSALLOC_H__
65 
66 #include <revolution/types.h>
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
72 typedef int  OSHeapHandle;
73 typedef void (*OSAllocVisitor)(
74                 void*           obj,
75                 u32             size);
76 
77 void*        OSInitAlloc(
78                 void*           arenaStart,
79                 void*           arenaEnd,
80                 int             maxHeaps);
81 
82 OSHeapHandle OSCreateHeap(
83                 void*           start,
84                 void*           end);
85 void         OSDestroyHeap(
86                 OSHeapHandle    heap);
87 void         OSAddToHeap(
88                 OSHeapHandle    heap,
89                 void*           start,
90                 void*           end);
91 
92 OSHeapHandle OSSetCurrentHeap(
93                 OSHeapHandle    heap);
94 
95 void*        OSAllocFromHeap(
96                 OSHeapHandle    heap,
97                 u32             size);
98 void*        OSAllocFixed(
99                 void**          rstart,
100                 void**          rend);
101 void         OSFreeToHeap(
102                 OSHeapHandle    heap,
103                 void*           ptr);
104 
105 long         OSCheckHeap(
106                 OSHeapHandle    heap);
107 void         OSDumpHeap(
108                 OSHeapHandle    heap);
109 u32          OSReferentSize(
110                 void*           ptr);
111 
112 void         OSVisitAllocated(
113                 OSAllocVisitor visitor);
114 
115 
116 extern volatile OSHeapHandle    __OSCurrHeap;
117 
118 /*---------------------------------------------------------------------------*
119   Name:         OSAlloc
120 
121   Description:  Allocates /size/ bytes from current heap
122 
123   Arguments:    size:        	size of object to be allocated.
124 
125   Returns:      a null pointer or a pointer to the allocated space aligned
126                 with 32 bytes boundaries
127  *---------------------------------------------------------------------------*/
128 #define OSAlloc(size)   OSAllocFromHeap(__OSCurrHeap, (size))
129 
130 /*---------------------------------------------------------------------------*
131   Name:         OSFree
132 
133   Description:  Deallocates /ptr/ to current heap.
134 
135   Arguments:    ptr:         	non-NULL pointer to object previously allocated
136                             by OSAlloc() or OSAllocFromHeap().
137 
138   Returns:      None.
139  *---------------------------------------------------------------------------*/
140 #define OSFree(ptr)     OSFreeToHeap(__OSCurrHeap, (ptr))
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #endif  // __OSALLOC_H__
147