/daten/src/linux-2.4.27-rsbac-v1.2.3/rsbac/help/rkmem.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
#include <rsbac/types.h>
00011
#include <rsbac/rkmem.h>
00012
#include <rsbac/debug.h>
00013
#include <linux/init.h>
00014
#include <linux/kernel.h>
00015
#include <linux/module.h>
00016
#include <linux/slab.h>
00017
#include <linux/vmalloc.h>
00018
00019
00020 typedef struct rsbac_cache_sizes {
00021 size_t
cs_size;
00022 kmem_cache_t *
cs_cachep;
00023 char name[15];
00024 }
rsbac_cache_sizes_t;
00025
00026 static rsbac_cache_sizes_t rsbac_cache_sizes[] = {
00027
#if PAGE_SIZE == 4096
00028
{ 32,
NULL,
"rsbac-32"},
00029
#endif
00030
{ 64,
NULL,
"rsbac-64"},
00031
#if PAGE_SIZE == 4096
00032
{ 96,
NULL,
"rsbac-96"},
00033
#endif
00034
{ 128,
NULL,
"rsbac-128"},
00035 { 192,
NULL,
"rsbac-192"},
00036 { 256,
NULL,
"rsbac-256"},
00037 { 512,
NULL,
"rsbac-512"},
00038 { 1024,
NULL,
"rsbac-1024"},
00039 { 2048,
NULL,
"rsbac-2048"},
00040 { 4096,
NULL,
"rsbac-4096"},
00041 { 8192,
NULL,
"rsbac-8192"},
00042
00043
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
00044
{ 16384,
NULL,
"rsbac-16384"},
00045 { 32768,
NULL,
"rsbac-32768"},
00046 { 65536,
NULL,
"rsbac-65536"},
00047 {131072,
NULL,
"rsbac-131072"},
00048
#ifndef CONFIG_MMU
00049
{262144,
NULL,
"rsbac-262144"},
00050 {524288,
NULL,
"rsbac-524288"},
00051 {1048576,
NULL,
"rsbac-1048576"},
00052
#ifdef CONFIG_LARGE_ALLOCS
00053
{2097152,
NULL,
"rsbac-2097152"},
00054 {4194304,
NULL,
"rsbac-4194304"},
00055 {8388608,
NULL,
"rsbac-8388608"},
00056 {16777216,
NULL,
"rsbac-16777216"},
00057 {33554432,
NULL,
"rsbac-33554432"},
00058
#endif
00059
#endif
00060
#endif
00061
{ 0,
NULL,
"rsbac0"}
00062 };
00063
#ifdef CONFIG_RSBAC_INIT_DELAY
00064
void rsbac_kmem_cache_sizes_init(
void)
00065 #
else
00066 void __init
rsbac_kmem_cache_sizes_init(
void)
00067 #endif
00068 {
00069
rsbac_cache_sizes_t *sizes =
rsbac_cache_sizes;
00070
00071
while (sizes->
cs_size) {
00072 sizes->
cs_cachep = kmem_cache_create(
00073 sizes->
name, sizes->
cs_size,
00074 0, SLAB_HWCACHE_ALIGN,
NULL,
NULL);
00075
if (!sizes->
cs_cachep)
00076 BUG();
00077
00078 sizes++;
00079 }
00080 }
00081
00082
00092
#if defined(CONFIG_RSBAC_REG) || defined(CONFIG_RSBAC_REG_MAINT)
00093
EXPORT_SYMBOL(rsbac_kmalloc);
00094
#endif
00095 void *
rsbac_kmalloc (size_t size)
00096 {
00097
rsbac_cache_sizes_t *csizep =
rsbac_cache_sizes;
00098
00099
if(!size)
00100
return NULL;
00101
for (; csizep->
cs_size; csizep++) {
00102
if (size > csizep->
cs_size)
00103
continue;
00104
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
00105
return kmem_cache_alloc(csizep->
cs_cachep, GFP_ATOMIC);
00106
#else
00107
return kmem_cache_alloc(csizep->
cs_cachep, GFP_KERNEL);
00108
#endif
00109
}
00110
#ifdef CONFIG_RSBAC_RMSG
00111
rsbac_printk(KERN_WARNING
00112
"rsbac_kmalloc: size %u requested, max size is %u!\n",
00113 size,
RSBAC_MAX_KMALLOC);
00114
#endif
00115
printk(KERN_WARNING
00116
"rsbac_kmalloc: size %u requested, max size is %u!\n",
00117 size,
RSBAC_MAX_KMALLOC);
00118 BUG();
00119
return NULL;
00120 }
00121
00122
#if defined(CONFIG_RSBAC_REG) || defined(CONFIG_RSBAC_REG_MAINT)
00123
EXPORT_SYMBOL(rsbac_vkmalloc);
00124
#endif
00125 void *
rsbac_vkmalloc (size_t size,
boolean * vmalloc_used_p)
00126 {
00127
rsbac_cache_sizes_t *csizep =
rsbac_cache_sizes;
00128
void * result;
00129
00130
if(!size)
00131
return NULL;
00132
for (; csizep->
cs_size; csizep++) {
00133
if (size > csizep->
cs_size)
00134
continue;
00135
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
00136
result = kmem_cache_alloc(csizep->
cs_cachep, GFP_ATOMIC);
00137
#else
00138
result = kmem_cache_alloc(csizep->
cs_cachep, GFP_KERNEL);
00139
#endif
00140
if(result)
00141 {
00142
if(vmalloc_used_p)
00143 *vmalloc_used_p =
FALSE;
00144
return result;
00145 }
00146 }
00147
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
00148
return NULL;
00149
#else
00150
if(vmalloc_used_p)
00151 *vmalloc_used_p =
TRUE;
00152
return vmalloc(size);
00153
#endif
00154
}
00155
00165
#if defined(CONFIG_RSBAC_REG) || defined(CONFIG_RSBAC_REG_MAINT)
00166
EXPORT_SYMBOL(rsbac_kfree);
00167
#endif
00168 void rsbac_kfree (
const void *objp)
00169 {
00170 kfree(objp);
00171 }
00172
00173
#if defined(CONFIG_RSBAC_REG) || defined(CONFIG_RSBAC_REG_MAINT)
00174
EXPORT_SYMBOL(rsbac_vkfree);
00175
#endif
00176 void rsbac_vkfree(
void *objp,
boolean vmalloc_used)
00177 {
00178
if(vmalloc_used)
00179 vfree(objp);
00180
else
00181 kfree(objp);
00182 }
00183
00184
Generated on Tue Aug 31 10:05:26 2004 for RSBAC by
1.3.8