pal_linux.go 1.7 KB
Newer Older
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
package enclave_runtime_pal // import "github.com/opencontainers/runc/libenclave/internal/runtime/pal"

import (
	"fmt"
	"os"
	"path"
	"strings"
)

const (
	palPrefix = "liberpal-"
	palSuffix = ".so"
)

func (pal *enclaveRuntimePal) Load(palPath string) (err error) {
	bp := path.Base(palPath)
	if !strings.HasPrefix(bp, palPrefix) {
		return fmt.Errorf("not found pal prefix pattern in pal %s\n", palPath)
	}
	if !strings.HasSuffix(bp, palSuffix) {
		return fmt.Errorf("not found pal suffix pattern in pal %s\n", palPath)
	}
	palName := strings.TrimSuffix(strings.TrimPrefix(bp, palPrefix), palSuffix)

	pal.name = palName

	if err = pal.getPalApiVersion(); err != nil {
		return err
	}
30
	return nil
31 32 33
}

func (pal *enclaveRuntimePal) getPalApiVersion() error {
34 35 36 37
	api := &enclaveRuntimePalApiV1{}
	ver := api.get_version()
	if ver > palApiVersion {
		return fmt.Errorf("unsupported pal api version %d", ver)
38
	}
39 40
	pal.version = ver
	return nil
41 42 43 44 45 46 47 48
}

func (pal *enclaveRuntimePal) Name() string {
	return fmt.Sprintf("%s (API version %d)", pal.name, pal.version)
}

func (pal *enclaveRuntimePal) Init(args string, logLevel string) error {
	api := &enclaveRuntimePalApiV1{}
49
	return api.init(args, logLevel)
50 51 52 53 54 55 56 57
}

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

func (pal *enclaveRuntimePal) Exec(cmd []string, envp []string, stdio [3]*os.File) (int32, error) {
	api := &enclaveRuntimePalApiV1{}
58
	return api.exec(cmd, envp, stdio)
59 60 61 62 63
}

func (pal *enclaveRuntimePal) Kill(sig int, pid int) error {
	if pal.version >= 2 {
		api := &enclaveRuntimePalApiV1{}
64
		return api.kill(sig, pid)
65 66 67 68 69 70
	}
	return nil
}

func (pal *enclaveRuntimePal) Destroy() error {
	api := &enclaveRuntimePalApiV1{}
71
	return api.destroy()
72
}