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.


d6409b8ad715f8f53970a8b98dd3dd3ac211e875
[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
21 int init_vm_extensions(struct v3_guest * guest) {
22     extern struct linux_ext * __start__lnx_exts[];
23     extern struct linux_ext * __stop__lnx_exts[];
24     struct linux_ext * ext_impl = __start__lnx_exts[0];
25     int i = 0;
26
27     while (ext_impl != __stop__lnx_exts[0]) {
28         struct vm_ext * ext = NULL;
29
30         if (ext_impl->guest_init == NULL) {
31             // We can have global extensions without per guest state
32             continue;
33         }
34         
35         printk("Registering Linux Extension (%s)\n", ext_impl->name);
36
37         ext = kmalloc(sizeof(struct vm_ext), GFP_KERNEL);
38         
39         if (!ext) {
40             printk("Error allocating VM extension (%s)\n", ext_impl->name);
41             return -1;
42         }
43
44         ext->impl = ext_impl;
45
46         ext_impl->guest_init(guest, &(ext->vm_data));
47
48         list_add(&(ext->node), &(guest->exts));
49
50         ext_impl = __start__lnx_exts[++i];
51     }
52     
53     return 0;
54 }
55
56
57 int deinit_vm_extensions(struct v3_guest * guest) {
58     struct vm_ext * ext = NULL;
59     struct vm_ext * tmp = NULL;
60
61     list_for_each_entry_safe(ext, tmp, &(guest->exts), node) {
62         if (ext->impl->guest_deinit) {
63             ext->impl->guest_deinit(guest, ext->vm_data);
64         } else {
65             printk("WARNING: Extension %s, does not have a guest deinit function\n", ext->impl->name);
66         }
67
68         list_del(&(ext->node));
69         kfree(ext);
70     }
71
72     return 0;
73 }
74
75 int init_lnx_extensions( void ) {
76     extern struct linux_ext * __start__lnx_exts[];
77     extern struct linux_ext * __stop__lnx_exts[];
78     struct linux_ext * tmp_ext = __start__lnx_exts[0];
79     int i = 0;
80
81     while (tmp_ext != __stop__lnx_exts[0]) {
82
83         printk("tmp_ext=%p\n", tmp_ext);
84
85         if (tmp_ext->init != NULL) {
86             printk("Registering Linux Extension (%s)\n", tmp_ext->name);
87             tmp_ext->init();
88         }
89
90         tmp_ext = __start__lnx_exts[++i];
91     }
92     
93     return 0;
94 }
95
96
97 int deinit_lnx_extensions( void ) {
98     extern struct linux_ext * __start__lnx_exts[];
99     extern struct linux_ext * __stop__lnx_exts[];
100     struct linux_ext * tmp_ext = __start__lnx_exts[0];
101     int i = 0;
102
103     while (tmp_ext != __stop__lnx_exts[0]) {
104         printk("Cleaning up Linux Extension (%s)\n", tmp_ext->name);
105         if (tmp_ext->deinit != NULL) {
106             tmp_ext->deinit();
107         } else {
108             printk("WARNING: Extension %s does not have a global deinit function\n", tmp_ext->name);
109         }
110
111         tmp_ext = __start__lnx_exts[++i];
112     }
113     
114     return 0;
115 }