2 #include "linux-exts.h"
5 * This is a place holder to ensure that the _lnx_exts section gets created by gcc
9 static struct {} null_ext __attribute__((__used__)) \
10 __attribute__((unused, __section__ ("_lnx_exts"), \
11 aligned(sizeof(void *))));
14 struct linux_ext * impl;
16 struct list_head node;
20 void * get_vm_ext_data(struct v3_guest * guest, char * ext_name) {
21 struct vm_ext * ext = NULL;
23 list_for_each_entry(ext, &(guest->exts), node) {
24 if (strncmp(ext->impl->name, ext_name, strlen(ext->impl->name)) == 0) {
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];
39 while (ext_impl != __stop__lnx_exts[0]) {
40 struct vm_ext * ext = NULL;
42 if (ext_impl->guest_init == NULL) {
43 // We can have global extensions without per guest state
44 ext_impl = __start__lnx_exts[++i];
48 printk("Registering Linux Extension (%s)\n", ext_impl->name);
50 ext = kmalloc(sizeof(struct vm_ext), GFP_KERNEL);
53 printk("Error allocating VM extension (%s)\n", ext_impl->name);
59 ext_impl->guest_init(guest, &(ext->vm_data));
61 list_add(&(ext->node), &(guest->exts));
63 ext_impl = __start__lnx_exts[++i];
71 int deinit_vm_extensions(struct v3_guest * guest) {
72 struct vm_ext * ext = NULL;
73 struct vm_ext * tmp = NULL;
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);
79 printk("WARNING: Extension %s, does not have a guest deinit function\n", ext->impl->name);
82 list_del(&(ext->node));
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];
95 while (tmp_ext != __stop__lnx_exts[0]) {
97 printk("tmp_ext=%p\n", tmp_ext);
99 if (tmp_ext->init != NULL) {
100 printk("Registering Linux Extension (%s)\n", tmp_ext->name);
104 tmp_ext = __start__lnx_exts[++i];
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];
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) {
122 printk("WARNING: Extension %s does not have a global deinit function\n", tmp_ext->name);
125 tmp_ext = __start__lnx_exts[++i];