19#ifndef _COBALT_KERNEL_HEAP_H
20#define _COBALT_KERNEL_HEAP_H
22#include <linux/string.h>
23#include <linux/rbtree.h>
24#include <cobalt/kernel/lock.h>
25#include <cobalt/kernel/list.h>
26#include <cobalt/uapi/kernel/types.h>
27#include <cobalt/uapi/kernel/heap.h>
34#define XNHEAP_PAGE_SHIFT 9
35#define XNHEAP_PAGE_SIZE (1UL << XNHEAP_PAGE_SHIFT)
36#define XNHEAP_PAGE_MASK (~(XNHEAP_PAGE_SIZE - 1))
37#define XNHEAP_MIN_LOG2 4
42#define XNHEAP_MAX_BUCKETS (XNHEAP_PAGE_SHIFT - XNHEAP_MIN_LOG2)
43#define XNHEAP_MIN_ALIGN (1U << XNHEAP_MIN_LOG2)
45#define XNHEAP_MAX_HEAPSZ (4294967295U - PAGE_SIZE + 1)
47#define XNHEAP_PGENT_BITS (32 - XNHEAP_PAGE_SHIFT)
49#define XNHEAP_PGMAP_BYTES sizeof(struct xnheap_pgentry)
51struct xnheap_pgentry {
53 unsigned int prev : XNHEAP_PGENT_BITS;
54 unsigned int next : XNHEAP_PGENT_BITS;
56 unsigned int type : 6;
76 struct rb_node addr_node;
77 struct rb_node size_node;
83 struct rb_root addr_tree;
84 struct rb_root size_tree;
85 struct xnheap_pgentry *pagemap;
88 u32 buckets[XNHEAP_MAX_BUCKETS];
89 char name[XNOBJECT_NAME_LEN];
91 struct list_head next;
94extern struct xnheap cobalt_heap;
96#define xnmalloc(size) xnheap_alloc(&cobalt_heap, size)
97#define xnfree(ptr) xnheap_free(&cobalt_heap, ptr)
99static inline void *xnheap_get_membase(
const struct xnheap *heap)
101 return heap->membase;
105size_t xnheap_get_size(
const struct xnheap *heap)
107 return heap->usable_size;
111size_t xnheap_get_used(
const struct xnheap *heap)
113 return heap->used_size;
117size_t xnheap_get_free(
const struct xnheap *heap)
119 return heap->usable_size - heap->used_size;
122int xnheap_init(
struct xnheap *heap,
123 void *membase,
size_t size);
131ssize_t xnheap_check_block(
struct xnheap *heap,
void *block);
134 const char *name, ...);
136void *xnheap_vmalloc(
size_t size);
138void xnheap_vfree(
void *p);
140static inline void *xnheap_zalloc(
struct xnheap *heap,
size_t size)
151static inline char *xnstrdup(
const char *s)
155 p = xnmalloc(strlen(s) + 1);
162#ifdef CONFIG_XENO_OPT_VFILE
163void xnheap_init_proc(
void);
164void xnheap_cleanup_proc(
void);
166static inline void xnheap_init_proc(
void) { }
167static inline void xnheap_cleanup_proc(
void) { }
void xnheap_free(struct xnheap *heap, void *block)
Release a block to a memory heap.
Definition heap.c:618
void xnheap_destroy(struct xnheap *heap)
Destroys a memory heap.
Definition heap.c:797
void * xnheap_alloc(struct xnheap *heap, size_t size)
Allocate a memory block from a memory heap.
Definition heap.c:532
void xnheap_set_name(struct xnheap *heap, const char *name,...)
Set the heap's name string.
Definition heap.c:825