Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel' of newskysaw.cs.northwestern.edu:/home/palacios/palacios into...
[palacios.git] / linux_module / linux-exts.c
1
2 #include "linux-exts.h"
3
4 /* 
5  * This is a place holder to ensure that the _lnx_exts section gets created by gcc
6  */
7
8
9 static struct {} null_ext  __attribute__((__used__))                    \
10     __attribute__((unused, __section__ ("_lnx_exts"),                   \
11                    aligned(sizeof(void *))));
12
13 struct vm_ext {
14     struct linux_ext * impl;
15     void * vm_data;
16     struct list_head node;
17 };
18
19
20 void * get_vm_ext_data(struct v3_guest * guest, char * ext_name) {
21     struct vm_ext * ext = NULL;
22
23     list_for_each_entry(ext, &(guest->exts), node) {
24         if (strncmp(ext->impl->name, ext_name, strlen(ext->impl->name)) == 0) {
25             return ext->vm_data;
26         }
27     }
28
29     return NULL;
30 }
31
32
33 int init_vm_extensions(struct v3_guest * guest) {
34     extern struct linux_ext * __start__lnx_exts[];
35     extern struct linux_ext * __stop__lnx_exts[];
36     struct linux_ext * ext_impl = __start__lnx_exts[0];
37     int i = 0;
38
39     while (ext_impl != __stop__lnx_exts[0]) {
40         struct vm_ext * ext = NULL;
41
42         if (ext_impl->guest_init == NULL) {
43             // We can have global extensions without per guest state
44             ext_impl = __start__lnx_exts[++i];
45             continue;
46         }
47         
48         printk("Registering Linux Extension (%s)\n", ext_impl->name);
49
50         ext = kmalloc(sizeof(struct vm_ext), GFP_KERNEL);
51         
52         if (!ext) {
53             printk("Error allocating VM extension (%s)\n", ext_impl->name);
54             return -1;
55         }
56
57         ext->impl = ext_impl;
58
59         ext_impl->guest_init(guest, &(ext->vm_data));
60
61         list_add(&(ext->node), &(guest->exts));
62
63         ext_impl = __start__lnx_exts[++i];
64     }
65     
66     return 0;
67 }
68
69
70
71 int deinit_vm_extensions(struct v3_guest * guest) {
72     struct vm_ext * ext = NULL;
73     struct vm_ext * tmp = NULL;
74
75     list_for_each_entry_safe(ext, tmp, &(guest->exts), node) {
76         if (ext->impl->guest_deinit) {
77             ext->impl->guest_deinit(guest, ext->vm_data);
78         } else {
79             printk("WARNING: Extension %s, does not have a guest deinit function\n", ext->impl->name);
80         }
81
82         list_del(&(ext->node));
83         kfree(ext);
84     }
85
86     return 0;
87 }
88
89 int init_lnx_extensions( void ) {
90     extern struct linux_ext * __start__lnx_exts[];
91     extern struct linux_ext * __stop__lnx_exts[];
92     struct linux_ext * tmp_ext = __start__lnx_exts[0];
93     int i = 0;
94
95     while (tmp_ext != __stop__lnx_exts[0]) {
96
97         printk("tmp_ext=%p\n", tmp_ext);
98
99         if (tmp_ext->init != NULL) {
100             printk("Registering Linux Extension (%s)\n", tmp_ext->name);
101             tmp_ext->init();
102         }
103
104         tmp_ext = __start__lnx_exts[++i];
105     }
106     
107     return 0;
108 }
109
110
111 int deinit_lnx_extensions( void ) {
112     extern struct linux_ext * __start__lnx_exts[];
113     extern struct linux_ext * __stop__lnx_exts[];
114     struct linux_ext * tmp_ext = __start__lnx_exts[0];
115     int i = 0;
116
117     while (tmp_ext != __stop__lnx_exts[0]) {
118         printk("Cleaning up Linux Extension (%s)\n", tmp_ext->name);
119         if (tmp_ext->deinit != NULL) {
120             tmp_ext->deinit();
121         } else {
122             printk("WARNING: Extension %s does not have a global deinit function\n", tmp_ext->name);
123         }
124
125         tmp_ext = __start__lnx_exts[++i];
126     }
127     
128     return 0;
129 }