summaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
authorMichael Brown2005-05-12 18:34:57 +0200
committerMichael Brown2005-05-12 18:34:57 +0200
commiteff4fa5a04ba63faefdc2ffdc51ba9981e5d1e68 (patch)
treef29d2fc793729b672321539c97b1f7e46d6f9d93 /src/include
parentUse the global load_buffer, and the boot_image function. (diff)
downloadipxe-eff4fa5a04ba63faefdc2ffdc51ba9981e5d1e68.tar.gz
ipxe-eff4fa5a04ba63faefdc2ffdc51ba9981e5d1e68.tar.xz
ipxe-eff4fa5a04ba63faefdc2ffdc51ba9981e5d1e68.zip
Merged the unaligned and aligned heap APIs and simplified the code.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/heap.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/include/heap.h b/src/include/heap.h
new file mode 100644
index 000000000..2b25a45e0
--- /dev/null
+++ b/src/include/heap.h
@@ -0,0 +1,62 @@
+#ifndef HEAP_H
+#define HEAP_H
+
+/*
+ * Allocate a block with specified (physical) alignment
+ *
+ * "align" must be a power of 2.
+ *
+ * Note that "align" affects the alignment of the physical address,
+ * not the virtual address. This is almost certainly what you want.
+ *
+ */
+extern void * emalloc ( size_t size, unsigned int align );
+
+/*
+ * Allocate a block, with no particular alignment requirements.
+ *
+ */
+static inline void * malloc ( size_t size ) {
+ return emalloc ( size, sizeof ( void * ) );
+}
+
+/*
+ * Allocate all remaining space on the heap
+ *
+ */
+extern void * emalloc_all ( size_t *size );
+
+/*
+ * Free a block.
+ *
+ * The caller must ensure that the block being freed is the last (most
+ * recent) block allocated on the heap, otherwise heap corruption will
+ * occur.
+ *
+ */
+extern void efree ( void *ptr );
+
+static inline void free ( void *ptr ) {
+ efree ( ptr );
+}
+
+/*
+ * Free all allocated blocks on the heap
+ *
+ */
+extern void efree_all ( void );
+
+/*
+ * Resize a block.
+ *
+ * The caller must ensure that the block being resized is the last
+ * (most recent) block allocated on the heap, otherwise heap
+ * corruption will occur.
+ *
+ */
+static inline void * erealloc ( void *ptr, size_t size, unsigned int align ) {
+ efree ( ptr );
+ return emalloc ( size, align );
+}
+
+#endif /* HEAP_H */