From 017cf647901d6306a76f522acdaf4d618e3cb74b Mon Sep 17 00:00:00 2001 From: Tianjia Zhang Date: Wed, 24 Jun 2020 16:24:02 +0800 Subject: [PATCH] rune/libenclave: Move pal_kill to Enclave Runtime PAI API v2 This API is not defined in v1 at all. Signed-off-by: Tianjia Zhang --- rune/libenclave/agent.go | 2 +- .../internal/runtime/enclave_runtime.go | 4 ++-- .../internal/runtime/pal/api_linux_v1.go | 16 --------------- .../internal/runtime/pal/api_linux_v2.go | 20 +++++++++++++++++++ .../internal/runtime/pal/pal_linux.go | 11 +++++----- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/rune/libenclave/agent.go b/rune/libenclave/agent.go index 2135c19..a3dd11c 100644 --- a/rune/libenclave/agent.go +++ b/rune/libenclave/agent.go @@ -214,7 +214,7 @@ func relaySignal(signalPipe *os.File, id int) { return } - err := enclaveRuntime.KillPayload(int(req.Kill.Sig), id) + err := enclaveRuntime.KillPayload(id, int(req.Kill.Sig)) if err != nil { logrus.Errorf("unable to kill payload with sig %d by %d: %v\n", int(req.Kill.Sig), id, err) return diff --git a/rune/libenclave/internal/runtime/enclave_runtime.go b/rune/libenclave/internal/runtime/enclave_runtime.go index c106a1d..02432c3 100644 --- a/rune/libenclave/internal/runtime/enclave_runtime.go +++ b/rune/libenclave/internal/runtime/enclave_runtime.go @@ -74,14 +74,14 @@ func (rt *EnclaveRuntimeWrapper) ExecutePayload(cmd []string, envp []string, std return rt.runtime.Exec(cmd, envp, stdio) } -func (rt *EnclaveRuntimeWrapper) KillPayload(sig int, pid int) error { +func (rt *EnclaveRuntimeWrapper) KillPayload(pid int, sig int) error { if pid != -1 { logrus.Debugf("enclave runtime killing payload %d with signal %d", pid, sig) } else { logrus.Debugf("enclave runtime killing all payloads with signal %d", sig) } - return rt.runtime.Kill(sig, pid) + return rt.runtime.Kill(pid, sig) } func (rt *EnclaveRuntimeWrapper) DestroyInstance() error { diff --git a/rune/libenclave/internal/runtime/pal/api_linux_v1.go b/rune/libenclave/internal/runtime/pal/api_linux_v1.go index c844ccd..9c9becb 100644 --- a/rune/libenclave/internal/runtime/pal/api_linux_v1.go +++ b/rune/libenclave/internal/runtime/pal/api_linux_v1.go @@ -37,11 +37,6 @@ static int palExecV1(void *sym, const char *exe, const char *argv[], (exe, argv, &fds, exit_code); } -static int palKillV1(void *sym, int sig, int pid) -{ - return ((int (*)(int, int))sym)(sig, pid); -} - static int palDestroyV1(void *sym) { return ((int (*)(void))sym)(); @@ -131,17 +126,6 @@ func (pal *enclaveRuntimePalApiV1) exec(cmd []string, envs []string, stdio [3]*o return exitCode, nil } -func (pal *enclaveRuntimePalApiV1) kill(sig int, pid int) error { - sigNum := C.int(sig) - pidNum := C.int(pid) - sym := nsenter.SymAddrPalKill() - ret := C.palKillV1(sym, sigNum, pidNum) - if ret < 0 { - return fmt.Errorf("pal kill() failed with %d", ret) - } - return nil -} - func (pal *enclaveRuntimePalApiV1) destroy() error { logrus.Debugf("pal destroy() called") diff --git a/rune/libenclave/internal/runtime/pal/api_linux_v2.go b/rune/libenclave/internal/runtime/pal/api_linux_v2.go index 5244116..0297d85 100644 --- a/rune/libenclave/internal/runtime/pal/api_linux_v2.go +++ b/rune/libenclave/internal/runtime/pal/api_linux_v2.go @@ -50,6 +50,11 @@ static int palExecV2(void *sym, int pid, int *exit_code) return ((int (*)(pal_exec_args *))sym) (&args); } + +static int palKillV2(void *sym, int pid, int sig) +{ + return ((int (*)(int, int))sym)(pid, sig); +} */ import "C" @@ -115,3 +120,18 @@ func (pal *enclaveRuntimePalApiV2) exec(cmd []string, envs []string, stdio [3]*o } return exitCode, nil } + +func (pal *enclaveRuntimePalApiV2) kill(pid int, sig int) error { + pidNum := C.int(pid) + sigNum := C.int(sig) + sym := nsenter.SymAddrPalKill() + if sym == nil { + return fmt.Errorf("pal kill() not implemented") + } + + ret := C.palKillV2(sym, pidNum, sigNum) + if ret < 0 { + return fmt.Errorf("pal kill() failed with %d", ret) + } + return nil +} diff --git a/rune/libenclave/internal/runtime/pal/pal_linux.go b/rune/libenclave/internal/runtime/pal/pal_linux.go index 88c7dd3..6204cd1 100644 --- a/rune/libenclave/internal/runtime/pal/pal_linux.go +++ b/rune/libenclave/internal/runtime/pal/pal_linux.go @@ -45,12 +45,13 @@ func (pal *enclaveRuntimePal) Exec(cmd []string, envp []string, stdio [3]*os.Fil return api.exec(cmd, envp, stdio) } -func (pal *enclaveRuntimePal) Kill(sig int, pid int) error { - if pal.version >= 2 { - api := &enclaveRuntimePalApiV1{} - return api.kill(sig, pid) +func (pal *enclaveRuntimePal) Kill(pid int, sig int) error { + if pal.version == 1 { + return nil } - return nil + + api := &enclaveRuntimePalApiV2{} + return api.kill(pid, sig) } func (pal *enclaveRuntimePal) Destroy() error { -- GitLab