LibXenon
Bare-metal Xbox 360 homebrew library
Loading...
Searching...
No Matches
lib_malloc.h
Go to the documentation of this file.
1/* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Local memory manager File: mempool.h
5 *
6 * This routine is used to manage memory allocated within the
7 * firmware. You give it a chunk of memory to manage, and then
8 * these routines manage suballocations from there.
9 *
10 * Author: Mitch Lichtenberg (mpl@broadcom.com)
11 *
12 *********************************************************************
13 *
14 * Copyright 2000,2001
15 * Broadcom Corporation. All rights reserved.
16 *
17 * This software is furnished under license and may be used and
18 * copied only in accordance with the following terms and
19 * conditions. Subject to these conditions, you may download,
20 * copy, install, use, modify and distribute modified or unmodified
21 * copies of this software in source and/or binary form. No title
22 * or ownership is transferred hereby.
23 *
24 * 1) Any source code used, modified or distributed must reproduce
25 * and retain this copyright notice and list of conditions as
26 * they appear in the source file.
27 *
28 * 2) No right is granted to use any trade name, trademark, or
29 * logo of Broadcom Corporation. Neither the "Broadcom
30 * Corporation" name nor any trademark or logo of Broadcom
31 * Corporation may be used to endorse or promote products
32 * derived from this software without the prior written
33 * permission of Broadcom Corporation.
34 *
35 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
36 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
37 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
39 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
40 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
41 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
42 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
43 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
44 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
45 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
46 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
47 * THE POSSIBILITY OF SUCH DAMAGE.
48 ********************************************************************* */
49
50#ifndef _LIB_MALLOC_H
51#define _LIB_MALLOC_H
52
53typedef struct memstats_s {
61
63
64typedef struct memnode_s {
65 unsigned int seal;
66 struct memnode_s *next; /* pointer to next node */
67 unsigned int length; /* length of the entire data section */
68 memnode_status_t status; /* alloc/free status */
69 unsigned char *data; /* points to actual user data */
70 void *memnodeptr; /* memnode back pointer (see comments) */
72
73struct mempool_s {
74 memnode_t *root; /* pointer to root node */
75 unsigned char *base; /* base of memory region */
76 unsigned int length; /* size of memory region */
77};
78
79typedef struct mempool_s mempool_t;
80void kmeminit(mempool_t *pool,unsigned char *buffer,int length);
81void kfree(mempool_t *pool,void *ptr);
82void *kmalloc(mempool_t *pool,unsigned int size,unsigned int align);
83int kmemchk(mempool_t *pool,int verbose);
84extern mempool_t kmempool;
85void *kmempoolbase(mempool_t *pool);
86int kmempoolsize(mempool_t *pool);
87int kmemstats(mempool_t *pool,memstats_t *stats);
88
89#define KMEMINIT(buffer,length) kmeminit(&kmempool,(buffer),(length))
90#define KMEMPOOLBASE() kmempoolbase(&kmempool)
91#define KMEMPOOLSIZE() kmempoolsize(&kmempool)
92#define KMALLOC(size,align) kmalloc(&kmempool,(size),(align))
93#define KFREE(ptr) kfree(&kmempool,(ptr))
94#define KMEMSTATS(s) kmemstats(&kmempool,(s))
95
96#endif
uint16_t length
Definition: ata.h:4
u32 ptr
Definition: iso9660.c:536
u32 size
Definition: iso9660.c:537
int kmemchk(mempool_t *pool, int verbose)
void kfree(mempool_t *pool, void *ptr)
Definition: lib_malloc.c:205
int kmempoolsize(mempool_t *pool)
Definition: lib_malloc.c:135
int kmemstats(mempool_t *pool, memstats_t *stats)
Definition: lib_malloc.c:396
struct memnode_s memnode_t
memnode_status_t
Definition: lib_malloc.h:62
@ memnode_free
Definition: lib_malloc.h:62
@ memnode_alloc
Definition: lib_malloc.h:62
void * kmalloc(mempool_t *pool, unsigned int size, unsigned int align)
Definition: lib_malloc.c:266
struct memstats_s memstats_t
void * kmempoolbase(mempool_t *pool)
Definition: lib_malloc.c:118
mempool_t kmempool
Definition: lib_malloc.c:74
void kmeminit(mempool_t *pool, unsigned char *buffer, int length)
Definition: lib_malloc.c:93
memnode_status_t status
Definition: lib_malloc.h:68
void * memnodeptr
Definition: lib_malloc.h:70
unsigned int seal
Definition: lib_malloc.h:65
unsigned int length
Definition: lib_malloc.h:67
unsigned char * data
Definition: lib_malloc.h:69
struct memnode_s * next
Definition: lib_malloc.h:66
unsigned char * base
Definition: lib_malloc.h:75
memnode_t * root
Definition: lib_malloc.h:74
unsigned int length
Definition: lib_malloc.h:76
int mem_allocbytes
Definition: lib_malloc.h:55
int mem_totalbytes
Definition: lib_malloc.h:54
int mem_freebytes
Definition: lib_malloc.h:56
int mem_freenodes
Definition: lib_malloc.h:58
int mem_largest
Definition: lib_malloc.h:59
int mem_allocnodes
Definition: lib_malloc.h:57