aboutsummaryrefslogtreecommitdiffstats
path: root/extras/mini-os/include
diff options
context:
space:
mode:
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2005-08-26 10:35:36 +0000
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2005-08-26 10:35:36 +0000
commit393415f09c80d9846cba6b7462d152bc0f032ede (patch)
tree3ae768c32dc6ff5d55be75a5263fad1a64a06f6c /extras/mini-os/include
parent4fb2acfb09468669ebbeaa6570d42403bb8ffc4f (diff)
downloadxen-393415f09c80d9846cba6b7462d152bc0f032ede.tar.gz
xen-393415f09c80d9846cba6b7462d152bc0f032ede.tar.bz2
xen-393415f09c80d9846cba6b7462d152bc0f032ede.zip
The patch removes broken, and very complicated malloc in
favour of much simpler (and working) Xen's allocator (xmalloc by Rusty). Signed-off-by: Grzegorz Milos <gm281@cam.ac.uk>
Diffstat (limited to 'extras/mini-os/include')
-rw-r--r--extras/mini-os/include/lib.h32
-rw-r--r--extras/mini-os/include/mm.h14
-rw-r--r--extras/mini-os/include/types.h2
-rw-r--r--extras/mini-os/include/xmalloc.h23
4 files changed, 38 insertions, 33 deletions
diff --git a/extras/mini-os/include/lib.h b/extras/mini-os/include/lib.h
index 0b405ee006..dcf5a84e08 100644
--- a/extras/mini-os/include/lib.h
+++ b/extras/mini-os/include/lib.h
@@ -79,36 +79,4 @@ char *strchr(const char *s, int c);
char *strstr(const char *s1, const char *s2);
-/* dlmalloc functions */
-struct mallinfo {
- int arena; /* non-mmapped space allocated from system */
- int ordblks; /* number of free chunks */
- int smblks; /* number of fastbin blocks */
- int hblks; /* number of mmapped regions */
- int hblkhd; /* space in mmapped regions */
- int usmblks; /* maximum total allocated space */
- int fsmblks; /* space available in freed fastbin blocks */
- int uordblks; /* total allocated space */
- int fordblks; /* total free space */
- int keepcost; /* top-most, releasable (via malloc_trim) space */
-};
-
-void *malloc(size_t n);
-void *calloc(size_t n_elements, size_t element_size);
-void free(void* p);
-void *realloc(void* p, size_t n);
-void *memalign(size_t alignment, size_t n);
-void *valloc(size_t n);
-struct mallinfo mallinfo(void);
-int mallopt(int parameter_number, int parameter_value);
-
-void **independent_calloc(size_t n_elements, size_t size, void* chunks[]);
-void **independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]);
-void *pvalloc(size_t n);
-void cfree(void* p);
-int malloc_trim(size_t pad);
-size_t malloc_usable_size(void* p);
-void malloc_stats(void);
-
-
#endif /* _LIB_H_ */
diff --git a/extras/mini-os/include/mm.h b/extras/mini-os/include/mm.h
index d841aae8ca..27af789315 100644
--- a/extras/mini-os/include/mm.h
+++ b/extras/mini-os/include/mm.h
@@ -126,6 +126,18 @@ static __inline__ unsigned long machine_to_phys(unsigned long machine)
void init_mm(void);
unsigned long alloc_pages(int order);
-int is_mfn_mapped(unsigned long mfn);
+#define alloc_page() alloc_pages(0);
+void free_pages(void *pointer, int order);
+//int is_mfn_mapped(unsigned long mfn);
+
+static __inline__ int get_order(unsigned long size)
+{
+ int order;
+ size = (size-1) >> PAGE_SHIFT;
+ for ( order = 0; size; order++ )
+ size >>= 1;
+ return order;
+}
+
#endif /* _MM_H_ */
diff --git a/extras/mini-os/include/types.h b/extras/mini-os/include/types.h
index 7bf103ab9c..c87ae161b8 100644
--- a/extras/mini-os/include/types.h
+++ b/extras/mini-os/include/types.h
@@ -49,4 +49,6 @@ typedef long quad_t;
typedef unsigned long u_quad_t;
typedef unsigned long uintptr_t;
#endif
+
+#define UINT_MAX (~0U)
#endif /* _TYPES_H_ */
diff --git a/extras/mini-os/include/xmalloc.h b/extras/mini-os/include/xmalloc.h
new file mode 100644
index 0000000000..e29a0387fc
--- /dev/null
+++ b/extras/mini-os/include/xmalloc.h
@@ -0,0 +1,23 @@
+#ifndef __XMALLOC_H__
+#define __XMALLOC_H__
+
+/* Allocate space for typed object. */
+#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type)))
+
+/* Allocate space for array of typed objects. */
+#define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num))
+
+/* Free any of the above. */
+extern void xfree(const void *);
+
+/* Underlying functions */
+extern void *_xmalloc(size_t size, size_t align);
+static inline void *_xmalloc_array(size_t size, size_t align, size_t num)
+{
+ /* Check for overflow. */
+ if (size && num > UINT_MAX / size)
+ return NULL;
+ return _xmalloc(size * num, align);
+}
+
+#endif /* __XMALLOC_H__ */