From 0bb1cbfbb5ea985c8cecd7232496cb5f16ac3433 Mon Sep 17 00:00:00 2001 From: "Hui, Chunyang" Date: Thu, 14 May 2020 02:46:33 +0000 Subject: [PATCH] Add PAL version api --- src/pal/include/occlum_pal_api.h | 12 ++++++++++++ src/pal/pal.lds | 1 + src/pal/src/pal_api.c | 4 ++++ src/run/main.c | 6 ++++++ 4 files changed, 23 insertions(+) diff --git a/src/pal/include/occlum_pal_api.h b/src/pal/include/occlum_pal_api.h index 26679b1e..cc4882d5 100644 --- a/src/pal/include/occlum_pal_api.h +++ b/src/pal/include/occlum_pal_api.h @@ -5,6 +5,18 @@ extern "C" { #endif +/* + * Occlum PAL API version number + */ +#define OCCLUM_PAL_VERSION 1 + +/* + * @brief Get version of Occlum PAL API + * + * @retval If > 0, then success; otherwise, it is an invalid version. + */ +int occlum_pal_get_version(void); + /* * Occlum PAL attributes */ diff --git a/src/pal/pal.lds b/src/pal/pal.lds index d3383aa2..2557be77 100644 --- a/src/pal/pal.lds +++ b/src/pal/pal.lds @@ -1,5 +1,6 @@ { global: + occlum_pal_get_version; occlum_pal_init; occlum_pal_exec; occlum_pal_destroy; diff --git a/src/pal/src/pal_api.c b/src/pal/src/pal_api.c index 1199f720..b3893244 100644 --- a/src/pal/src/pal_api.c +++ b/src/pal/src/pal_api.c @@ -6,6 +6,10 @@ #include "pal_syscall.h" #include "errno2str.h" +int occlum_pal_get_version(void) { + return OCCLUM_PAL_VERSION; +} + int occlum_pal_init(const struct occlum_pal_attr* attr) { errno = 0; diff --git a/src/run/main.c b/src/run/main.c index 5f149ed4..2176b99e 100644 --- a/src/run/main.c +++ b/src/run/main.c @@ -26,6 +26,12 @@ int main(int argc, char* argv[]) { const char* cmd_path = (const char*) argv[1]; const char** cmd_args = (const char**) &argv[2]; + // Check Occlum PAL version + int pal_version = occlum_pal_get_version(); + if (pal_version <= 0) { + return EXIT_FAILURE; + } + // Init Occlum PAL struct occlum_pal_attr attr = OCCLUM_PAL_ATTR_INITVAL; attr.instance_dir = get_instance_dir();