diff --git a/rune/libenclave/agent.go b/rune/libenclave/agent.go index 2135c19972e9afab8ffaa967e4f73061063b046b..a3dd11c9fffa1fc8c0ca205ddae6e3c51c18a0a6 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 c106a1d9da27c36dff677ef1ea8b65a090388c26..02432c31a21dd07b088fdbca7bec3a5d6bbab1ad 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 c844ccdf7c67ffb86eb1dcddd7b6acfdff3b95a7..9c9becb0ff8cc457f6ff38c22c61fbdea8089eba 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 52441160ef15e5aea2c907165c73edabde4d6e78..0297d8592e3d9a9a4d61e324cf423fb02c70c0b6 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 88c7dd3ae86334e92b70150233bc893eb12d78f5..6204cd1e78f83756b7b15ebf4304b419603624ee 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 {