From 393415f09c80d9846cba6b7462d152bc0f032ede Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Fri, 26 Aug 2005 10:35:36 +0000 Subject: 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 --- extras/mini-os/include/xmalloc.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 extras/mini-os/include/xmalloc.h (limited to 'extras/mini-os/include/xmalloc.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__ */ -- cgit v1.2.3