24 #include <linux/module.h> 25 #include <linux/uaccess.h> 26 #include <linux/miscdevice.h> 27 #include <linux/vmalloc.h> 28 #include <linux/kallsyms.h> 29 #include <linux/notifier.h> 30 #include <linux/reboot.h> 56 dev_open(
struct inode *inode,
struct file *
file)
61 DEBUG(
"dev_open succeeded\n");
66 dev_release(
struct inode *inode,
struct file *
file)
71 DEBUG(
"dev_release succeeded\n");
76 ioctl_add_module(
char *
file)
83 ALERT(
"IOCTL_ADD_MODULE: too many modules have been loaded\n");
103 ALERT(
"IOCTL_ADD_MODULE: failed to allocate memory for the module\n");
110 ALERT(
"IOCTL_ADD_MODULE: failed to copy memory from userspace\n");
117 ALERT(
"IOCTL_ADD_MODULE: common_add_module failed: %p - %s\n", \
118 (
void *)ret, ec_to_str(ret));
127 DEBUG(
"IOCTL_ADD_MODULE: succeeded\n");
134 ALERT(
"IOCTL_ADD_MODULE: failed\n");
139 ioctl_add_module_length(uint64_t *len)
145 ALERT(
"IOCTL_ADD_MODULE_LENGTH: failed with len == NULL\n");
152 ALERT(
"IOCTL_ADD_MODULE_LENGTH: failed to copy memory from userspace\n");
156 DEBUG(
"IOCTL_ADD_MODULE_LENGTH: succeeded\n");
161 ioctl_unload_vmm(
void)
170 ALERT(
"IOCTL_UNLOAD_VMM: common_unload_vmm failed: %p - %s\n", \
171 (
void *)ret, ec_to_str(ret));
186 DEBUG(
"IOCTL_UNLOAD_VMM: succeeded\n");
199 ALERT(
"IOCTL_LOAD_VMM: common_load_vmm failed: %p - %s\n", \
200 (
void *)ret, ec_to_str(ret));
204 DEBUG(
"IOCTL_LOAD_VMM: succeeded\n");
223 ALERT(
"IOCTL_STOP_VMM: common_stop_vmm failed: %p - %s\n", \
224 (
void *)ret, ec_to_str(ret));
229 DEBUG(
"IOCTL_STOP_VMM: succeeded\n");
235 ioctl_start_vmm(
void)
242 ALERT(
"IOCTL_START_VMM: common_start_vmm failed: %p - %s\n", \
243 (
void *)ret, ec_to_str(ret));
247 DEBUG(
"IOCTL_START_VMM: succeeded\n");
265 ALERT(
"IOCTL_DUMP_VMM: common_dump_vmm failed: %p - %s\n", \
266 (
void *)ret, ec_to_str(ret));
273 ALERT(
"IOCTL_DUMP_VMM: failed to copy memory from userspace\n");
277 DEBUG(
"IOCTL_DUMP_VMM: succeeded\n");
282 ioctl_vmm_status(int64_t *status)
289 ALERT(
"IOCTL_VMM_STATUS: common_vmm_status failed: NULL\n");
293 ret = copy_to_user(status, &vmm_status,
sizeof(int64_t));
296 ALERT(
"IOCTL_VMM_STATUS: failed to copy memory from userspace\n");
304 ioctl_set_cpuid(uint64_t *
cpuid)
310 ALERT(
"IOCTL_SET_CPUID: failed with cpuid == NULL\n");
314 ret = copy_from_user(&
g_cpuid, cpuid,
sizeof(uint64_t));
317 ALERT(
"IOCTL_SET_CPUID: failed to copy memory from userspace\n");
325 ioctl_set_vcpuid(uint64_t *
vcpuid)
331 ALERT(
"IOCTL_SET_VCPUID: failed with vcpuid == NULL\n");
335 ret = copy_from_user(&
g_vcpuid, vcpuid,
sizeof(uint64_t));
338 ALERT(
"IOCTL_SET_VCPUID: failed to copy memory from userspace\n");
353 ALERT(
"IOCTL_VMCALL: regs == NULL\n");
360 ALERT(
"IOCTL_VMCALL: failed to copy memory from userspace\n");
367 ALERT(
"IOCTL_VMCALL: common_vmcall failed: %p - %s\n", \
368 (
void *)ret, ec_to_str(ret));
375 ALERT(
"IOCTL_VMCALL: failed to copy memory to userspace\n");
383 dev_unlocked_ioctl(
struct file *file,
391 case IOCTL_ADD_MODULE:
392 return ioctl_add_module((
char *)arg);
394 case IOCTL_ADD_MODULE_LENGTH:
395 return ioctl_add_module_length((uint64_t *)arg);
398 return ioctl_load_vmm();
400 case IOCTL_UNLOAD_VMM:
401 return ioctl_unload_vmm();
403 case IOCTL_START_VMM:
404 return ioctl_start_vmm();
407 return ioctl_stop_vmm();
412 case IOCTL_VMM_STATUS:
413 return ioctl_vmm_status((int64_t *)arg);
415 case IOCTL_SET_CPUID:
416 return ioctl_set_cpuid((uint64_t *)arg);
418 case IOCTL_SET_VCPUID:
419 return ioctl_set_vcpuid((uint64_t *)arg);
429 static struct file_operations fops =
432 .release = dev_release,
433 .unlocked_ioctl = dev_unlocked_ioctl,
436 static struct miscdevice bareflank_dev =
449 unsigned long code,
void *unused)
460 static struct notifier_block bareflank_notifier_block =
468 register_reboot_notifier(&bareflank_notifier_block);
470 if (misc_register(&bareflank_dev) != 0)
472 ALERT(
"misc_register failed\n");
478 ALERT(
"common_init failed\n");
482 DEBUG(
"dev_init succeeded\n");
491 misc_deregister(&bareflank_dev);
492 unregister_reboot_notifier(&bareflank_notifier_block);
494 DEBUG(
"dev_exit succeeded\n");
int64_t common_add_module(const char *file, uint64_t fsize)
int64_t common_load_vmm(void)
int64_t common_fini(void)
int64_t common_dump_vmm(struct debug_ring_resources_t **drr, uint64_t vcpuid)
debug_ring_resources_t * drr
uint64_t files_size[MAX_NUM_MODULES]
int64_t common_vmcall(struct vmcall_registers_t *regs, uint64_t cpuid)
int64_t common_stop_vmm(void)
int64_t common_start_vmm(void)
int64_t common_init(void)
int64_t common_unload_vmm(void)
int64_t common_vmm_status(void)
int dev_reboot(struct notifier_block *nb, unsigned long code, void *unused)
char * files[MAX_NUM_MODULES]