forked from keystone-enclave/sm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sm-sbi.c
99 lines (85 loc) · 2.53 KB
/
sm-sbi.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
//******************************************************************************
// Copyright (c) 2018, The Regents of the University of California (Regents).
// All Rights Reserved. See LICENSE for license details.
//------------------------------------------------------------------------------
#include "sm-sbi.h"
#include "pmp.h"
#include "enclave.h"
#include "page.h"
#include "cpu.h"
#include "platform-hook.h"
#include "plugins/plugins.h"
#include <sbi/riscv_asm.h>
#include <sbi/sbi_console.h>
unsigned long sbi_sm_create_enclave(unsigned long* eid, uintptr_t create_args)
{
struct keystone_sbi_create create_args_local;
unsigned long ret;
ret = copy_enclave_create_args(create_args, &create_args_local);
if (ret)
return ret;
ret = create_enclave(eid, create_args_local);
return ret;
}
unsigned long sbi_sm_destroy_enclave(unsigned long eid)
{
unsigned long ret;
ret = destroy_enclave((unsigned int)eid);
return ret;
}
unsigned long sbi_sm_run_enclave(struct sbi_trap_regs *regs, unsigned long eid)
{
regs->a0 = run_enclave(regs, (unsigned int) eid);
regs->mepc += 4;
sbi_trap_exit(regs);
return 0;
}
unsigned long sbi_sm_resume_enclave(struct sbi_trap_regs *regs, unsigned long eid)
{
unsigned long ret;
ret = resume_enclave(regs, (unsigned int) eid);
if (!regs->zero)
regs->a0 = ret;
regs->mepc += 4;
sbi_trap_exit(regs);
return 0;
}
unsigned long sbi_sm_exit_enclave(struct sbi_trap_regs *regs, unsigned long retval)
{
regs->a0 = exit_enclave(regs, cpu_get_enclave_id());
regs->a1 = retval;
regs->mepc += 4;
sbi_trap_exit(regs);
return 0;
}
unsigned long sbi_sm_stop_enclave(struct sbi_trap_regs *regs, unsigned long request)
{
regs->a0 = stop_enclave(regs, request, cpu_get_enclave_id());
regs->mepc += 4;
sbi_trap_exit(regs);
return 0;
}
unsigned long sbi_sm_attest_enclave(uintptr_t report, uintptr_t data, uintptr_t size)
{
unsigned long ret;
ret = attest_enclave(report, data, size, cpu_get_enclave_id());
return ret;
}
unsigned long sbi_sm_get_sealing_key(uintptr_t sealing_key, uintptr_t key_ident,
size_t key_ident_size)
{
unsigned long ret;
ret = get_sealing_key(sealing_key, key_ident, key_ident_size,
cpu_get_enclave_id());
return ret;
}
unsigned long sbi_sm_random()
{
return (unsigned long) platform_random();
}
unsigned long sbi_sm_call_plugin(uintptr_t plugin_id, uintptr_t call_id, uintptr_t arg0, uintptr_t arg1)
{
unsigned long ret;
ret = call_plugin(cpu_get_enclave_id(), plugin_id, call_id, arg0, arg1);
return ret;
}