19 #ifndef _COBALT_KERNEL_HEAP_H
20 #define _COBALT_KERNEL_HEAP_H
22 #include <linux/string.h>
23 #include <cobalt/kernel/lock.h>
24 #include <cobalt/kernel/list.h>
25 #include <cobalt/uapi/kernel/types.h>
26 #include <cobalt/uapi/kernel/heap.h>
47 #define XNHEAP_PAGESZ PAGE_SIZE
48 #define XNHEAP_MINLOG2 3
49 #define XNHEAP_MAXLOG2 22
50 #define XNHEAP_MINALLOCSZ (1 << XNHEAP_MINLOG2)
51 #define XNHEAP_MINALIGNSZ (1 << 4)
52 #define XNHEAP_NBUCKETS (XNHEAP_MAXLOG2 - XNHEAP_MINLOG2 + 2)
53 #define XNHEAP_MAXHEAPSZ (1 << 31)
55 #define XNHEAP_PFREE 0
56 #define XNHEAP_PCONT 1
57 #define XNHEAP_PLIST 2
78 struct xnpagemap *pagemap;
80 struct list_head next;
85 } buckets[XNHEAP_NBUCKETS];
86 char name[XNOBJECT_NAME_LEN];
93 extern struct xnheap cobalt_heap;
95 #define xnmalloc(size) xnheap_alloc(&cobalt_heap, size)
96 #define xnfree(ptr) xnheap_free(&cobalt_heap, ptr)
98 static inline u32 xnheap_get_size(
const struct xnheap *heap)
103 static inline u32 xnheap_get_free(
const struct xnheap *heap)
105 return heap->size - heap->used;
108 static inline void *xnheap_get_membase(
const struct xnheap *heap)
110 return heap->membase;
113 static inline u32 xnheap_rounded_size(u32 size)
115 if (size < 2 * XNHEAP_PAGESZ)
116 return 2 * XNHEAP_PAGESZ;
118 return ALIGN(size, XNHEAP_PAGESZ);
123 #ifdef CONFIG_XENO_OPT_VFILE
124 void xnheap_init_proc(
void);
125 void xnheap_cleanup_proc(
void);
127 static inline void xnheap_init_proc(
void) { }
128 static inline void xnheap_cleanup_proc(
void) { }
133 int xnheap_init(
struct xnheap *heap,
void *membase, u32 size);
136 const char *name, ...);
142 void xnheap_free(
struct xnheap *heap,
void *block);
144 int xnheap_check_block(
struct xnheap *heap,
void *block);
146 static inline char *xnstrdup(
const char *s)
150 p = xnmalloc(strlen(s) + 1);
void xnheap_free(struct xnheap *heap, void *block)
Release a block to a memory heap.
Definition: heap.c:490
int xnheap_init(struct xnheap *heap, void *membase, u32 size)
Initialize a memory heap.
Definition: heap.c:194
void * xnheap_alloc(struct xnheap *heap, u32 size)
Allocate a memory block from a memory heap.
Definition: heap.c:404
void xnheap_destroy(struct xnheap *heap)
Destroys a memory heap.
Definition: heap.c:255
void xnheap_set_name(struct xnheap *heap, const char *name,...)
Set the heap's name string.
Definition: heap.c:283
log2 bucket list
Definition: heap.h:82