source: GPL/trunk/include/linux/slab.h@ 695

Last change on this file since 695 was 695, checked in by David Azarewicz, 4 years ago

Merge changes from next branch.

File size: 4.7 KB
Line 
1/*
2 * linux/mm/slab.h
3 * Written by Mark Hemment, 1996.
4 * (markhe@nextd.demon.co.uk)
5 */
6
7#include <linux/gfp.h>
8#include <linux/overflow.h>
9#include <linux/types.h>
10#include <linux/list.h>
11#include <linux/workqueue.h>
12
13#if !defined(_LINUX_SLAB_H)
14#define _LINUX_SLAB_H
15
16#if defined(__KERNEL__)
17
18typedef struct kmem_cache_s kmem_cache_t;
19
20/* flags for kmem_cache_alloc() */
21#define SLAB_BUFFER GFP_BUFFER
22#define SLAB_ATOMIC GFP_ATOMIC
23#define SLAB_USER GFP_USER
24#define SLAB_KERNEL GFP_KERNEL
25#define SLAB_NFS GFP_NFS
26#define SLAB_DMA GFP_DMA
27
28#define SLAB_LEVEL_MASK 0x0000007fUL
29#define SLAB_NO_GROW 0x00001000UL /* don't grow a cache */
30
31/* flags to pass to kmem_cache_create().
32 * The first 3 are only valid when the allocator as been build
33 * SLAB_DEBUG_SUPPORT.
34 */
35#define SLAB_DEBUG_FREE 0x00000100UL /* Peform (expensive) checks on free */
36#define SLAB_DEBUG_INITIAL 0x00000200UL /* Call constructor (as verifier) */
37#define SLAB_RED_ZONE 0x00000400UL /* Red zone objs in a cache */
38#define SLAB_POISON 0x00000800UL /* Poison objects */
39#define SLAB_NO_REAP 0x00001000UL /* never reap from the cache */
40#define SLAB_HWCACHE_ALIGN 0x00002000UL /* align objs on a h/w cache lines */
41#if 0
42#define SLAB_HIGH_PACK 0x00004000UL /* XXX */
43#endif
44
45/* flags passed to a constructor func */
46#define SLAB_CTOR_CONSTRUCTOR 0x001UL /* if not set, then deconstructor */
47#define SLAB_CTOR_ATOMIC 0x002UL /* tell constructor it can't sleep */
48#define SLAB_CTOR_VERIFY 0x004UL /* tell constructor it's a verify call */
49
50#endif /* __KERNEL__ */
51
52/*
53 * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests.
54 *
55 * Dereferencing ZERO_SIZE_PTR will lead to a distinct access fault.
56 *
57 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
58 * Both make kfree a no-op.
59 */
60#define ZERO_SIZE_PTR ((void *)16)
61
62//NOTE: enabling this in the non-KEE driver causes problems (file name strings
63// put in seperate private segments)
64#ifdef DEBUGHEAP
65extern void near *__kmalloc(int, int, const char *filename, int lineno);
66extern void __kfree(const void near *, const char *filename, int lineno);
67
68static inline void *kmalloc(size_t size, gfp_t flags)
69{
70 return __kmalloc(size, flags, __FILE__, __LINE__);
71}
72
73
74#define kfree(a) __kfree(a, __FILE__, __LINE__)
75#define kfree_s(a,b) __kfree(a, __FILE__, __LINE__)
76#define kfree_nocheck(a) __kfree(a, __FILE__, __LINE__)
77
78#else
79extern void near *__kmalloc(int, int);
80extern void __kfree(const void near *);
81
82#define kmalloc(a,b) __kmalloc(a,b)
83#define kfree(a) __kfree(a)
84
85#define kfree_s(a,b) kfree(a)
86#define kfree_nocheck(a) kfree(a)
87#endif
88
89void *kzalloc(size_t n, gfp_t gfp_flags);
90void *kcalloc(size_t n, size_t size, unsigned int __nocast gfp_flags);
91void *krealloc(const void *, size_t, gfp_t);
92
93#define SIZE_MAX (~(size_t)0)
94
95/**
96 * kmalloc_array - allocate memory for an array.
97 * @n: number of elements.
98 * @size: element size.
99 * @flags: the type of memory to allocate (see kmalloc).
100 */
101static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
102{
103 if (size != 0 && n > SIZE_MAX / size)
104 return NULL;
105 return __kmalloc(n * size, flags);
106}
107
108/**
109 * krealloc_array - reallocate memory for an array.
110 * @p: pointer to the memory chunk to reallocate
111 * @new_n: new number of elements to alloc
112 * @new_size: new size of a single member of the array
113 * @flags: the type of memory to allocate (see kmalloc)
114 */
115static __must_check inline void *
116krealloc_array(void *p, size_t new_n, size_t new_size, gfp_t flags)
117{
118// size_t bytes;
119
120// if (check_mul_overflow(new_n, new_size, &bytes))
121// return NULL;
122
123 return krealloc(p, new_n*new_size, flags);
124}
125
126#define kmalloc_node_track_caller(size, flags, node) \
127 kmalloc_track_caller(size, flags)
128#define kmalloc_track_caller(size, flags) __kmalloc(size, flags)
129#define kvfree(arg) kfree(arg)
130
131struct kmem_cache {
132 unsigned int object_size;/* The original size of the object */
133 unsigned int size; /* The aligned/padded/added on size */
134 unsigned int align; /* Alignment as calculated */
135 unsigned long flags; /* Active flags on the slab */
136 const char *name; /* Slab name for sysfs */
137 int refcount; /* Use counter */
138 void (*ctor)(void *); /* Called on object slot creation */
139 struct list_head list; /* List of all slab caches on the system */
140};
141
142#define kvzalloc kzalloc
143size_t ksize(const void *);
144
145static inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
146{
147 return __kmalloc(size, flags);
148}
149
150static inline void *kmalloc_node(size_t size, gfp_t flags, int node)
151{
152 return __kmalloc_node(size, flags, node);
153}
154
155#endif /* _LINUX_SLAB_H */
Note: See TracBrowser for help on using the repository browser.