forked from oscarlab/graphene-sgx-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsgx_main.c
107 lines (87 loc) · 2.05 KB
/
gsgx_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* (C) Copyright 2015 Intel Corporation
* Author: Chia-Che Tsai <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include "gsgx.h"
#define DRV_DESCRIPTION "Graphene SGX Driver"
#define DRV_VERSION "0.10-" SDK_DRIVER_VERSION_STRING
MODULE_DESCRIPTION(DRV_DESCRIPTION);
MODULE_AUTHOR("Chia-Che Tsai <[email protected]>");
MODULE_VERSION(DRV_VERSION);
static const struct file_operations gsgx_fops = {
.owner = THIS_MODULE,
.open = gsgx_open,
#if SDK_DRIVER_VERSION < KERNEL_VERSION(1, 8, 0)
.unlocked_ioctl = gsgx_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = gsgx_ioctl,
#endif
.mmap = gsgx_mmap,
.get_unmapped_area = gsgx_get_unmapped_area,
#endif
};
static struct miscdevice gsgx_dev = {
.minor = GSGX_MINOR,
.name = "gsgx",
.fops = &gsgx_fops,
.mode = S_IRUGO | S_IWUGO,
};
static int gsgx_setup(void)
{
int ret;
ret = misc_register(&gsgx_dev);
if (ret) {
pr_err("gsgx: misc_register() failed\n");
gsgx_dev.this_device = NULL;
return ret;
}
#if SDK_DRIVER_VERSION < KERNEL_VERSION(1, 8, 0)
isgx_dev = filp_open("/dev/isgx", O_RDONLY, 0);
if (!isgx_dev) {
return PTR_ERR(isgx_dev);
}
ret = gsgx_lookup_ksyms();
if (ret) {
pr_err("gsgx: lookup kernel symbols failed\n");
return ret;
}
#endif
return 0;
}
static void gsgx_teardown(void)
{
if (gsgx_dev.this_device)
misc_deregister(&gsgx_dev);
#if SDK_DRIVER_VERSION < KERNEL_VERSION(1, 8, 0)
if (isgx_dev)
filp_close(isgx_dev, NULL);
#endif
}
static int __init gsgx_init(void)
{
int ret;
pr_info("gsgx: " DRV_DESCRIPTION " v" DRV_VERSION "\n");
ret = gsgx_setup();
if (ret) {
gsgx_teardown();
return ret;
}
return 0;
}
static void __exit gsgx_exit(void)
{
gsgx_teardown();
}
module_init(gsgx_init);
module_exit(gsgx_exit);
MODULE_LICENSE("GPL");