ia64/xen-unstable

view extras/mini-os/include/xmalloc.h @ 16827:5f3c236d1711

minios: Add align support to _xmalloc().

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jan 22 09:45:54 2008 +0000 (2008-01-22)
parents 8984cc0a1d80
children 945820bfedb6
line source
1 #ifndef __XMALLOC_H__
2 #define __XMALLOC_H__
4 /* Allocate space for typed object. */
5 #define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type)))
7 /* Allocate space for array of typed objects. */
8 #define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num))
10 #define DEFAULT_ALIGN (sizeof(unsigned long))
11 #define malloc(size) _xmalloc(size, DEFAULT_ALIGN)
12 #define free(ptr) xfree(ptr)
13 #define realloc(ptr, size) _realloc(ptr, size)
15 /* Free any of the above. */
16 extern void xfree(const void *);
18 /* Underlying functions */
19 extern void *_xmalloc(size_t size, size_t align);
20 extern void *_realloc(void *ptr, size_t size);
22 static inline void *_xmalloc_array(size_t size, size_t align, size_t num)
23 {
24 /* Check for overflow. */
25 if (size && num > UINT_MAX / size)
26 return NULL;
27 return _xmalloc(size * num, align);
28 }
30 #endif /* __XMALLOC_H__ */