debuggers.hg

view xen/include/xen/slab.h @ 3652:10a0f6b0a996

bitkeeper revision 1.1159.238.3 (4200cd90cCW2XIYxAgdkWL28Tzf-8g)

Introduce _xmalloc for when you really want just bytes.

Signed-off-by: ian.pratt@cl.cam.ac.uk
author iap10@labyrinth.cl.cam.ac.uk
date Wed Feb 02 12:54:40 2005 +0000 (2005-02-02)
parents beb0887c54bc
children 49103eca5edb
line source
1 /*
2 * Written by Mark Hemment, 1996.
3 * (markhe@nextd.demon.co.uk)
4 */
6 #ifndef __SLAB_H__
7 #define __SLAB_H__
9 #include <xen/config.h>
11 #ifdef __ARCH_HAS_SLAB_ALLOCATOR
13 #include <asm/slab.h>
15 #else
17 typedef struct xmem_cache_s xmem_cache_t;
19 #include <xen/mm.h>
20 #include <xen/cache.h>
21 #include <xen/types.h>
23 /* Flags to pass to xmem_cache_create(). */
24 /* NB. The first 3 are only valid when built with SLAB_DEBUG_SUPPORT. */
25 #define SLAB_DEBUG_INITIAL 0x00000200UL /* Call constructor */
26 #define SLAB_RED_ZONE 0x00000400UL /* Red zone objs in a cache */
27 #define SLAB_POISON 0x00000800UL /* Poison objects */
28 #define SLAB_NO_REAP 0x00001000UL /* never reap from the cache */
29 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* align obj on a cache line */
31 /* Flags passed to a constructor function. */
32 #define SLAB_CTOR_CONSTRUCTOR 0x001UL /* if not set, then deconstructor */
33 #define SLAB_CTOR_ATOMIC 0x002UL /* tell cons. it can't sleep */
34 #define SLAB_CTOR_VERIFY 0x004UL /* tell cons. it's a verify call */
36 extern void xmem_cache_init(void);
37 extern void xmem_cache_sizes_init(unsigned long);
39 extern xmem_cache_t *xmem_find_general_cachep(size_t);
40 extern xmem_cache_t *xmem_cache_create(
41 const char *, size_t, size_t, unsigned long,
42 void (*)(void *, xmem_cache_t *, unsigned long),
43 void (*)(void *, xmem_cache_t *, unsigned long));
44 extern int xmem_cache_destroy(xmem_cache_t *);
45 extern int xmem_cache_shrink(xmem_cache_t *);
46 extern void *xmem_cache_alloc(xmem_cache_t *);
47 extern void xmem_cache_free(xmem_cache_t *, void *);
49 extern void *_xmalloc(size_t);
50 extern void xfree(const void *);
52 extern int xmem_cache_reap(void);
54 extern void dump_slabinfo();
56 /* Nicely typesafe for you. */
57 #define xmalloc(type) ((type *)_xmalloc(sizeof(type)))
58 #define xmalloc_array(type, num) ((type *)_xmalloc_array(sizeof(type), (num)))
60 static inline void *_xmalloc_array(size_t size, size_t num)
61 {
62 /* Check for overflow. */
63 if (size && num > UINT_MAX / size)
64 return NULL;
65 return _xmalloc(size * num);
66 }
67 #endif /* __ARCH_HAS_SLAB_ALLOCATOR */
69 #endif /* __SLAB_H__ */