1
/*********************************************************
2
* Copyright (C) 2005 VMware, Inc. All rights reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation version 2 and no later version.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* You should have received a copy of the GNU General Public License along
14
* with this program; if not, write to the Free Software Foundation, Inc.,
15
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
*********************************************************/
19
#ifndef __COMPAT_SLAB_H__
20
# define __COMPAT_SLAB_H__
23
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 2, 0)
24
# include <linux/slab.h>
26
# include <linux/malloc.h>
30
* Before 2.6.20, kmem_cache_t was the accepted way to refer to a kmem_cache
31
* structure. Prior to 2.6.15, this structure was called kmem_cache_s, and
32
* afterwards it was renamed to kmem_cache. Here we keep things simple and use
33
* the accepted typedef until it became deprecated, at which point we switch
34
* over to the kmem_cache name.
36
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
37
# define compat_kmem_cache struct kmem_cache
39
# define compat_kmem_cache kmem_cache_t
43
* Up to 2.6.22 kmem_cache_create has 6 arguments - name, size, alignment, flags,
44
* constructor, and destructor. Then for some time kernel was asserting that
45
* destructor is NULL, and since 2.6.23-pre1 kmem_cache_create takes only 5
46
* arguments - destructor is gone.
48
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22) || defined(VMW_KMEMCR_HAS_DTOR)
49
#define compat_kmem_cache_create(name, size, align, flags, ctor) \
50
kmem_cache_create(name, size, align, flags, ctor, NULL)
52
#define compat_kmem_cache_create(name, size, align, flags, ctor) \
53
kmem_cache_create(name, size, align, flags, ctor)
57
* Up to 2.6.23 kmem_cache constructor has three arguments - pointer to block to
58
* prepare (aka "this"), from which cache it came, and some unused flags. After
59
* 2.6.23 flags were removed, and order of "this" and cache parameters was swapped...
60
* Since 2.6.27-rc2 everything is different again, and ctor has only one argument.
62
* HAS_3_ARGS has precedence over HAS_2_ARGS if both are defined.
64
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) && !defined(VMW_KMEMCR_CTOR_HAS_3_ARGS)
65
# define VMW_KMEMCR_CTOR_HAS_3_ARGS
67
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26) && !defined(VMW_KMEMCR_CTOR_HAS_2_ARGS)
68
# define VMW_KMEMCR_CTOR_HAS_2_ARGS
71
#if defined(VMW_KMEMCR_CTOR_HAS_3_ARGS)
72
typedef void compat_kmem_cache_ctor(void *, compat_kmem_cache *, unsigned long);
73
#define COMPAT_KMEM_CACHE_CTOR_ARGS(arg) void *arg, \
74
compat_kmem_cache *cache, \
76
#elif defined(VMW_KMEMCR_CTOR_HAS_2_ARGS)
77
typedef void compat_kmem_cache_ctor(compat_kmem_cache *, void *);
78
#define COMPAT_KMEM_CACHE_CTOR_ARGS(arg) compat_kmem_cache *cache, \
81
typedef void compat_kmem_cache_ctor(void *);
82
#define COMPAT_KMEM_CACHE_CTOR_ARGS(arg) void *arg
85
#endif /* __COMPAT_SLAB_H__ */