31 #include <linux/string.h>
32 #include <linux/module.h>
33 #include <linux/virgo_mempool.h>
34 #include <linux/string.h>
36 #include <linux/ctype.h>
38 unsigned int virgo_parse_integer(
const char *s,
unsigned int base,
unsigned long long *p);
39 void printBytes(
const char* str);
40 char* toKernelAddress(
const char*);
46 struct virgo_mempool_args* parse_virgomempool_command_kernelspace(
char* mempoolFunction);
49 virgo_cloud_mempool_kernelspace_init(
void)
51 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace_init(): doing init() of virgo cloud kernel space test module\n");
52 unsigned long test_ul;
53 char* test_str=
"ef098363";
54 kstrtoul(test_str,16,&test_ul);
55 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace_init(): test_str=%s, test_ul=%u\n",test_str,test_ul);
58 EXPORT_SYMBOL(virgo_cloud_mempool_kernelspace_init);
62 virgo_cloud_mempool_kernelspace_exit(
void)
64 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace_exit(): exiting virgo cloud test kernel space module \n");
67 EXPORT_SYMBOL(virgo_cloud_mempool_kernelspace_exit);
73 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace.c:Executing virgo_cloud_mempool on cloud node, Invoking virgo_cloud_malloc_kernelspace(), Writing to file opened by Kernel, Kernel Space to User space communication works\n");
75 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace.c:virgo_cloud_malloc_kernelspace(): size str=%s\n",vmargs->mempool_args[0]);
77 int size=toInteger(vmargs->mempool_args[0]);
78 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace.c:virgo_cloud_malloc_kernelspace(): size=%d\n",size);
79 void* ptr=kmalloc(size,GFP_KERNEL);
80 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace.c:virgo_cloud_malloc_kernelspace(): ptr=%p\n",ptr);
81 vmargs->ptr=(
char*)ptr;
82 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace.c:virgo_cloud_malloc_kernelspace(): setting ptr=%p in vmargs as an out arg\n",ptr);
85 EXPORT_SYMBOL(virgo_cloud_malloc_kernelspace);
89 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace.c:Executing virgo_cloud_mempool on cloud node, Invoking virgo_cloud_get_kernelspace(), Writing to file opened by Kernel, Kernel Space to User space communication works\n");
91 char* ptr=toKernelAddress(vmargs->mempool_args[0]);
92 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace.c: virgo_cloud_get_kernelspace(): data at ptr parsed by toKernelAddress() = [%s]\n",ptr);
93 char virgodata_prefix[500];
94 strcpy(virgodata_prefix,
"virgodata:");
95 char* data=kstrdup(strcat(virgodata_prefix,ptr),GFP_KERNEL);
96 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace.c: virgo_cloud_get_kernelspace(): address=%p, data=%s, data with added prefix=%s\n",ptr,ptr,data);
99 EXPORT_SYMBOL(virgo_cloud_get_kernelspace);
103 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace.c:Executing virgo_cloud_mempool on cloud node, Invoking virgo_cloud_set_kernelspace(), Writing to file opened by Kernel, Kernel Space to User space communication works\n");
105 printk(KERN_INFO
"virgo_cloud_set_kernelspace(): vmargs->mempool_cmd=%s, vmargs->mempool_args[0] = %s\n, vmargs->mempool_args[1]=%s \n",vmargs->mempool_cmd, vmargs->mempool_args[0],vmargs->mempool_args[1]);
106 char* ptr=toKernelAddress(vmargs->mempool_args[0]);
115 printk(KERN_INFO
"virgo_cloud_set_kernelspace(): ptr set by toKernelAddress=%p\n",ptr);
124 strcpy(ptr,kstrdup(vmargs->mempool_args[1],GFP_KERNEL));
125 printk(KERN_INFO
"virgo_cloud_set_kernelspace(): address=%p, data to be set=%s, data after set=%s\n",ptr,vmargs->mempool_args[1], ptr);
128 EXPORT_SYMBOL(virgo_cloud_set_kernelspace);
132 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace.c:Executing virgo_cloud_mempool on cloud node, Invoking virgo_cloud_free_kernelspace(), Writing to file opened by Kernel, Kernel Space to User space communication works\n");
134 char* ptr=toKernelAddress(vmargs->mempool_args[0]);
135 printk(KERN_INFO
"virgo_cloud_mempool_kernelspace.c: virgo_cloud_free_kernelspace(): address=%p\n",ptr);
139 EXPORT_SYMBOL(virgo_cloud_free_kernelspace);
147 inline char* toKernelAddress(
const char* strAddress)
180 unsigned long long ll3;
181 virgo_parse_integer(strAddress,16,&ll3);
182 printk(KERN_INFO
"toKernelAddress(): virgo_parse_integer: ll3=%ld, (char*)ll3=%p, (void*)ll3=%p, strAddress=[%s]\n", ll3, (
char*)ll3, (
void*)ll3, strAddress);
183 printk(KERN_INFO
"toKernelAddress(): virgo_parse_integer: data at (char*)ll3=[%s]\n", (
char*)ll3);
197 EXPORT_SYMBOL(toKernelAddress);
199 int toInteger(
char* strInt)
202 sscanf(strInt,
"%d", &n);
203 printk(KERN_INFO
"toInteger(): strInt=[%s], integer=%d\n", strInt, n);
207 void printBytes(
const char* str)
212 printk(KERN_INFO
"printBytes(): %c\n",*p);
225 unsigned int virgo_parse_integer(
const char *s,
unsigned int base,
unsigned long long *p)
227 unsigned long long res;
235 printk(KERN_INFO
"virgo_parse_integer(): *s=%c, res=%ld\n",*s, res);
242 if (
'0' <= *s && *s <=
'9')
244 else if (
'a' <= tolower(*s) && tolower(*s) <=
'f')
245 val = tolower(*s) -
'a' + 10;
259 res = res * base + val;
269 MODULE_LICENSE(
"GPL");
270 module_init(virgo_cloud_mempool_kernelspace_init);
271 module_exit(virgo_cloud_mempool_kernelspace_exit);