pal_linux.go 1.5 KB
Newer Older
1 2 3 4 5 6 7
package enclave_runtime_pal // import "github.com/opencontainers/runc/libenclave/internal/runtime/pal"

import (
	"fmt"
	"os"
)

8 9 10 11
const (
	palApiVersion = 2
)

12 13 14 15
func (pal *enclaveRuntimePal) Load(palPath string) (err error) {
	if err = pal.getPalApiVersion(); err != nil {
		return err
	}
16
	return nil
17 18 19
}

func (pal *enclaveRuntimePal) getPalApiVersion() error {
20 21 22 23
	api := &enclaveRuntimePalApiV1{}
	ver := api.get_version()
	if ver > palApiVersion {
		return fmt.Errorf("unsupported pal api version %d", ver)
24
	}
25 26
	pal.version = ver
	return nil
27 28 29 30
}

func (pal *enclaveRuntimePal) Init(args string, logLevel string) error {
	api := &enclaveRuntimePalApiV1{}
31
	return api.init(args, logLevel)
32 33 34 35 36 37 38
}

func (pal *enclaveRuntimePal) Attest() (err error) {
	return nil
}

func (pal *enclaveRuntimePal) Exec(cmd []string, envp []string, stdio [3]*os.File) (int32, error) {
39 40 41 42 43 44
	if pal.version == 1 {
		api := &enclaveRuntimePalApiV1{}
		return api.exec(cmd, envp, stdio)
	}

	api := &enclaveRuntimePalApiV2{}
45
	return api.exec(cmd, envp, stdio)
46 47
}

48 49 50
func (pal *enclaveRuntimePal) Kill(pid int, sig int) error {
	if pal.version == 1 {
		return nil
51
	}
52 53 54

	api := &enclaveRuntimePalApiV2{}
	return api.kill(pid, sig)
55 56 57 58
}

func (pal *enclaveRuntimePal) Destroy() error {
	api := &enclaveRuntimePalApiV1{}
59
	return api.destroy()
60
}
Y
YiLin.Li 已提交
61 62 63 64 65 66 67 68 69

func (pal *enclaveRuntimePal) GetLocalReport(targetInfo []byte) ([]byte, error) {
	if pal.version >= 3 {
		api := &enclaveRuntimePalApiV3{}
		return api.getLocalReport(targetInfo)
	}

	return nil, fmt.Errorf("unsupported pal api version %d", pal.version)
}