-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathapplet.go
53 lines (44 loc) · 1.34 KB
/
applet.go
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
// Copyright (c) WithSecure Corporation
// https://foundry.withsecure.com
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.
// Package applet provides user mode initialization for bare metal Go
// unikernels written using the TamaGo framework.
//
// The package supports trusted applet execution under a GoTEE compatible
// supervisor, linking essential runtime functions with required system calls.
//
// This package is only meant to be used with `GOOS=tamago` as supported by the
// TamaGo framework for bare metal Go, see https://github.com/usbarmory/tamago.
package applet
import (
_ "unsafe"
"github.com/usbarmory/GoTEE/syscall"
)
//go:linkname hwinit runtime.hwinit
func hwinit() {
initTimers()
}
//go:linkname printk runtime.printk
func printk(c byte) {
syscall.Print(c)
}
//go:linkname initRNG runtime.initRNG
func initRNG() {
// no initialization required in supervised mode
}
//go:linkname getRandomData runtime.getRandomData
func getRandomData(b []byte) {
syscall.GetRandom(b, uint(len(b)))
}
// Exit signals the applet termination to its supervisor.
func Exit() {
syscall.Exit()
}
// Crash forces a nil pointer dereference to terminate the applet through an
// exception, it is meant to be used as runtime.Exit to yield to monitor on
// runtime panic.
func Crash(_ int32) {
*(*int)(nil) = 0
}