提交 074e35b2 编写于 作者: Y YiLin.Li 提交者: jia zhang

rune/libenclave/skeleton: sink the implementation of PAL V2 APIs.

Move the implementation of skeleton PAL V2 APIs from liberpal-skeleton-v2.c
to liberpal-skeleton.c
Signed-off-by: NYilin Li <YiLin.Li@linux.alibaba.com>
上级 6c4714c6
......@@ -23,45 +23,17 @@ int pal_init(pal_attr_t *attr)
int pal_create_process(pal_create_process_args *args)
{
if (args == NULL || args->path == NULL || args->argv == NULL || args->pid == NULL || args->stdio == NULL) {
errno = EINVAL;
return -1;
}
int pid;
if ((pid = fork()) < 0)
return -1;
else if (pid == 0) {
int exit_code, ret;
ret = __pal_exec(args->path, args->argv, args->stdio, &exit_code);
exit(ret ? ret : exit_code);
} else
*args->pid = pid;
return 0;
return __pal_create_process(args);
}
int pal_exec(pal_exec_args *attr)
{
if (attr == NULL || attr->exit_value == NULL) {
errno = EINVAL;
return -1;
}
int status;
waitpid(attr->pid, &status, 0);
if (WIFEXITED(status) || WIFSIGNALED(status))
*attr->exit_value = WEXITSTATUS(status);
return 0;
return wait4child(attr);
}
int pal_kill(int pid, int sig)
{
/* No implementation */
return 0;
return __pal_kill(pid, sig);
}
int pal_destroy(void)
......
......@@ -13,6 +13,7 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 25
#include <sys/types.h>
#else
......@@ -467,6 +468,49 @@ int __pal_exec(char *path, char *argv[], pal_stdio_fds *stdio, int *exit_code)
return 0;
}
int __pal_create_process(pal_create_process_args *args)
{
int pid;
if (args == NULL || args->path == NULL || args->argv == NULL || args->pid == NULL || args->stdio == NULL) {
return -1;
}
if ((pid = fork()) < 0)
return -1;
else if (pid == 0) {
int exit_code, ret;
ret = __pal_exec(args->path, args->argv, args->stdio, &exit_code);
exit(ret ? ret : exit_code);
} else
*args->pid = pid;
return 0;
}
int wait4child(pal_exec_args *attr)
{
int status;
if (attr == NULL || attr->exit_value == NULL) {
return -1;
}
waitpid(attr->pid, &status, 0);
if (WIFEXITED(status) || WIFSIGNALED(status))
*attr->exit_value = WEXITSTATUS(status);
return 0;
}
int __pal_kill(int pid, int sig)
{
/* No implementation */
return 0;
}
int __pal_destory(void)
{
if (!initialized) {
......
......@@ -29,6 +29,9 @@ typedef struct {
int __pal_init(pal_attr_t *attr);
int __pal_exec(char *path, char *argv[], pal_stdio_fds *stdio, int *exit_code);
int __pal_create_process(pal_create_process_args *args);
int wait4child(pal_exec_args *attr);
int __pal_kill(int pid, int sig);
int __pal_destory(void);
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册