From 074e35b28ad4e2d4a7660c00812abde7f61eb4de Mon Sep 17 00:00:00 2001 From: "YiLin.Li" Date: Mon, 17 Aug 2020 09:40:27 +0000 Subject: [PATCH] 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: Yilin Li --- .../pal/skeleton/liberpal-skeleton-v2.c | 34 ++------------ .../runtime/pal/skeleton/liberpal-skeleton.c | 44 +++++++++++++++++++ .../runtime/pal/skeleton/liberpal-skeleton.h | 3 ++ 3 files changed, 50 insertions(+), 31 deletions(-) diff --git a/rune/libenclave/internal/runtime/pal/skeleton/liberpal-skeleton-v2.c b/rune/libenclave/internal/runtime/pal/skeleton/liberpal-skeleton-v2.c index abb8838..c6a7847 100644 --- a/rune/libenclave/internal/runtime/pal/skeleton/liberpal-skeleton-v2.c +++ b/rune/libenclave/internal/runtime/pal/skeleton/liberpal-skeleton-v2.c @@ -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) diff --git a/rune/libenclave/internal/runtime/pal/skeleton/liberpal-skeleton.c b/rune/libenclave/internal/runtime/pal/skeleton/liberpal-skeleton.c index 5856cbd..b0198c9 100644 --- a/rune/libenclave/internal/runtime/pal/skeleton/liberpal-skeleton.c +++ b/rune/libenclave/internal/runtime/pal/skeleton/liberpal-skeleton.c @@ -13,6 +13,7 @@ #include #include #include +#include #if __GLIBC__ == 2 && __GLIBC_MINOR__ < 25 #include #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) { diff --git a/rune/libenclave/internal/runtime/pal/skeleton/liberpal-skeleton.h b/rune/libenclave/internal/runtime/pal/skeleton/liberpal-skeleton.h index 540428b..a7d5bdf 100644 --- a/rune/libenclave/internal/runtime/pal/skeleton/liberpal-skeleton.h +++ b/rune/libenclave/internal/runtime/pal/skeleton/liberpal-skeleton.h @@ -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 -- GitLab