未验证 提交 017cf647 编写于 作者: T Tianjia Zhang 提交者: GitHub

rune/libenclave: Move pal_kill to Enclave Runtime PAI API v2

This API is not defined in v1 at all.
Signed-off-by: NTianjia Zhang <tianjia.zhang@linux.alibaba.com>
上级 aa17829f
...@@ -214,7 +214,7 @@ func relaySignal(signalPipe *os.File, id int) { ...@@ -214,7 +214,7 @@ func relaySignal(signalPipe *os.File, id int) {
return return
} }
err := enclaveRuntime.KillPayload(int(req.Kill.Sig), id) err := enclaveRuntime.KillPayload(id, int(req.Kill.Sig))
if err != nil { if err != nil {
logrus.Errorf("unable to kill payload with sig %d by %d: %v\n", int(req.Kill.Sig), id, err) logrus.Errorf("unable to kill payload with sig %d by %d: %v\n", int(req.Kill.Sig), id, err)
return return
......
...@@ -74,14 +74,14 @@ func (rt *EnclaveRuntimeWrapper) ExecutePayload(cmd []string, envp []string, std ...@@ -74,14 +74,14 @@ func (rt *EnclaveRuntimeWrapper) ExecutePayload(cmd []string, envp []string, std
return rt.runtime.Exec(cmd, envp, stdio) 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 { if pid != -1 {
logrus.Debugf("enclave runtime killing payload %d with signal %d", pid, sig) logrus.Debugf("enclave runtime killing payload %d with signal %d", pid, sig)
} else { } else {
logrus.Debugf("enclave runtime killing all payloads with signal %d", sig) 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 { func (rt *EnclaveRuntimeWrapper) DestroyInstance() error {
......
...@@ -37,11 +37,6 @@ static int palExecV1(void *sym, const char *exe, const char *argv[], ...@@ -37,11 +37,6 @@ static int palExecV1(void *sym, const char *exe, const char *argv[],
(exe, argv, &fds, exit_code); (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) static int palDestroyV1(void *sym)
{ {
return ((int (*)(void))sym)(); return ((int (*)(void))sym)();
...@@ -131,17 +126,6 @@ func (pal *enclaveRuntimePalApiV1) exec(cmd []string, envs []string, stdio [3]*o ...@@ -131,17 +126,6 @@ func (pal *enclaveRuntimePalApiV1) exec(cmd []string, envs []string, stdio [3]*o
return exitCode, nil 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 { func (pal *enclaveRuntimePalApiV1) destroy() error {
logrus.Debugf("pal destroy() called") logrus.Debugf("pal destroy() called")
......
...@@ -50,6 +50,11 @@ static int palExecV2(void *sym, int pid, int *exit_code) ...@@ -50,6 +50,11 @@ static int palExecV2(void *sym, int pid, int *exit_code)
return ((int (*)(pal_exec_args *))sym) return ((int (*)(pal_exec_args *))sym)
(&args); (&args);
} }
static int palKillV2(void *sym, int pid, int sig)
{
return ((int (*)(int, int))sym)(pid, sig);
}
*/ */
import "C" import "C"
...@@ -115,3 +120,18 @@ func (pal *enclaveRuntimePalApiV2) exec(cmd []string, envs []string, stdio [3]*o ...@@ -115,3 +120,18 @@ func (pal *enclaveRuntimePalApiV2) exec(cmd []string, envs []string, stdio [3]*o
} }
return exitCode, nil 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
}
...@@ -45,12 +45,13 @@ func (pal *enclaveRuntimePal) Exec(cmd []string, envp []string, stdio [3]*os.Fil ...@@ -45,12 +45,13 @@ func (pal *enclaveRuntimePal) Exec(cmd []string, envp []string, stdio [3]*os.Fil
return api.exec(cmd, envp, stdio) return api.exec(cmd, envp, stdio)
} }
func (pal *enclaveRuntimePal) Kill(sig int, pid int) error { func (pal *enclaveRuntimePal) Kill(pid int, sig int) error {
if pal.version >= 2 { if pal.version == 1 {
api := &enclaveRuntimePalApiV1{} return nil
return api.kill(sig, pid)
} }
return nil
api := &enclaveRuntimePalApiV2{}
return api.kill(pid, sig)
} }
func (pal *enclaveRuntimePal) Destroy() error { func (pal *enclaveRuntimePal) Destroy() error {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册