ia64/xen-unstable

view extras/mini-os/include/xmalloc.h @ 19836:d9890e67d2b7

tools: add SHAREDIR to buildmakevars2file

c/s 19818 dropped SHAREDIR from xen/util/path.py, which broke the "xm
new" command. This patch adds SHAREDIR back to the new
buildmakevars2file-closure function.

Signed-off-by: Ryan O'Connor <rjo@cs.ubc.ca>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 25 13:05:10 2009 +0100 (2009-06-25)
parents 433d1b26fd51
children
line source
1 #ifndef __XMALLOC_H__
2 #define __XMALLOC_H__
4 #ifdef HAVE_LIBC
6 #include <stdlib.h>
7 #include <malloc.h>
8 /* Allocate space for typed object. */
9 #define _xmalloc(size, align) memalign(align, size)
10 #define xfree(ptr) free(ptr)
12 #else
14 #include <limits.h>
16 #define DEFAULT_ALIGN (sizeof(unsigned long))
17 #define malloc(size) _xmalloc(size, DEFAULT_ALIGN)
18 #define free(ptr) xfree(ptr)
19 #define realloc(ptr, size) _realloc(ptr, size)
21 /* Free any of the above. */
22 extern void xfree(const void *);
24 /* Underlying functions */
25 extern void *_xmalloc(size_t size, size_t align);
26 extern void *_realloc(void *ptr, size_t size);
28 #endif
30 static inline void *_xmalloc_array(size_t size, size_t align, size_t num)
31 {
32 /* Check for overflow. */
33 if (size && num > UINT_MAX / size)
34 return NULL;
35 return _xmalloc(size * num, align);
36 }
38 /* Allocate space for typed object. */
39 #define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type)))
41 /* Allocate space for array of typed objects. */
42 #define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num))
44 #endif /* __XMALLOC_H__ */