forked from intel/sgx-ra-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sgx_detect_linux.c
75 lines (53 loc) · 1.65 KB
/
sgx_detect_linux.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
/*
Copyright 2018 Intel Corporation
This software and the related documents are Intel copyrighted materials,
and your use of them is governed by the express license under which they
were provided to you (License). Unless the License provides otherwise,
you may not use, modify, copy, publish, distribute, disclose or transmit
this software or the related documents without Intel's prior written
permission.
This software and the related documents are provided as is, with no
express or implied warranties, other than those that are expressly stated
in the License.
*/
#include "config.h"
#include <sgx_urts.h>
#include <sgx_capable.h>
#include "sgx_stub.h"
#include "sgx_detect.h"
#ifndef NULL
#define NULL 0
#endif
int sgx_support = SGX_SUPPORT_UNKNOWN;
int get_sgx_support()
{
#ifdef SGX_HW_SIM
return SGX_SUPPORT_YES|SGX_SUPPORT_ENABLED;
#else
sgx_device_status_t sgx_device_status;
if (sgx_support != SGX_SUPPORT_UNKNOWN) return sgx_support;
sgx_support = SGX_SUPPORT_NO;
/* Check for the PSW */
if (! have_sgx_psw()) return sgx_support;
sgx_support = SGX_SUPPORT_YES;
/* Try to enable SGX */
if (sgx_cap_get_status(&sgx_device_status) != SGX_SUCCESS)
return sgx_support;
/* If SGX isn't enabled yet, perform the software opt-in/enable. */
if (sgx_device_status != SGX_ENABLED) {
switch (sgx_device_status) {
case SGX_DISABLED_REBOOT_REQUIRED:
/* A reboot is required. */
sgx_support |= SGX_SUPPORT_REBOOT_REQUIRED;
break;
case SGX_DISABLED_LEGACY_OS:
/* BIOS enabling is required */
sgx_support |= SGX_SUPPORT_ENABLE_REQUIRED;
break;
}
return sgx_support;
}
sgx_support |= SGX_SUPPORT_ENABLED;
return sgx_support;
#endif
}