This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathsgx_api.h
84 lines (73 loc) · 2.44 KB
/
sgx_api.h
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
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2014 Stony Brook University */
#ifndef SGX_API_H
#define SGX_API_H
#include "pal_error.h"
#include "sgx_arch.h"
long sgx_ocall(uint64_t code, void* ms);
bool sgx_is_completely_within_enclave(const void* addr, uint64_t size);
bool sgx_is_completely_outside_enclave(const void* addr, uint64_t size);
void* sgx_prepare_ustack(void);
void* sgx_alloc_on_ustack_aligned(uint64_t size, size_t alignment);
void* sgx_alloc_on_ustack(uint64_t size);
void* sgx_copy_to_ustack(const void* ptr, uint64_t size);
void sgx_reset_ustack(const void* old_ustack);
bool sgx_copy_ptr_to_enclave(void** ptr, void* uptr, size_t size);
bool sgx_copy_to_enclave(void* ptr, size_t maxsize, const void* uptr, size_t usize);
/*!
* \brief Low-level wrapper around EREPORT instruction leaf.
*
* Caller is responsible for parameter alignment: 512B for `targetinfo`, 128B for `reportdata`,
* and 512B for `report`.
*/
static inline int sgx_report(const sgx_target_info_t* targetinfo, const void* reportdata,
sgx_report_t* report) {
__asm__ volatile(
ENCLU "\n"
:: "a"(EREPORT), "b"(targetinfo), "c"(reportdata), "d"(report)
: "memory");
return 0;
}
/*!
* \brief Low-level wrapper around EGETKEY instruction leaf.
*
* Caller is responsible for parameter alignment: 512B for `keyrequest` and 16B for `key`.
*/
static inline int64_t sgx_getkey(sgx_key_request_t* keyrequest, sgx_key_128bit_t* key) {
int64_t rax = EGETKEY;
__asm__ volatile(
ENCLU "\n"
: "+a"(rax)
: "b"(keyrequest), "c"(key)
: "memory");
return rax;
}
/*!
* \brief Low-level wrapper around EACCEPT instruction leaf.
*
* Caller is responsible for parameter alignment: 64B for `si` and 4KB(page size) for `addr`.
*/
static inline int64_t sgx_accept(sgx_arch_sec_info_t* si, const void* addr) {
int64_t rax = EACCEPT;
__asm__ volatile(
ENCLU "\n"
: "+a"(rax)
: "b"(si), "c"(addr)
: "memory");
return rax;
}
/*!
* \brief Low-level wrapper around EMODPE instruction leaf.
*
* Caller is responsible for parameter alignment: 64B for `si` and 4KB(page size) for `addr`.
*/
static inline int64_t sgx_modpe(sgx_arch_sec_info_t* si, const void* addr) {
int64_t rax = EMODPE;
__asm__ volatile(
ENCLU "\n"
: "+a"(rax)
: "b"(si), "c"(addr)
: "memory");
return rax;
}
#endif /* SGX_API_H */