diff --git a/Pal/src/db_main.c b/Pal/src/db_main.c index d02a0394..07576712 100644 --- a/Pal/src/db_main.c +++ b/Pal/src/db_main.c @@ -207,17 +207,15 @@ static int loader_filter (const char * key, int len) } /* 'pal_main' must be called by the host-specific bootloader */ -noreturn void pal_main ( +noreturn void pal_main( PAL_NUM instance_id, /* current instance id */ PAL_HANDLE manifest_handle, /* manifest handle if opened */ PAL_HANDLE exec_handle, /* executable handle if opened */ PAL_PTR exec_loaded_addr, /* executable addr if loaded */ PAL_HANDLE parent_process, /* parent process if it's a child */ PAL_HANDLE first_thread, /* first thread handle */ - PAL_STR * arguments, /* application arguments */ - PAL_STR * environments /* environment variables */ - ) -{ + PAL_STR* arguments, /* application arguments */ + PAL_STR* environments /* environment variables */) { pal_state.instance_id = instance_id; pal_state.alloc_align = _DkGetAllocationAlignment(); assert(IS_POWER_OF_2(pal_state.alloc_align)); diff --git a/Pal/src/db_streams.c b/Pal/src/db_streams.c index 24290306..a0f4bf17 100644 --- a/Pal/src/db_streams.c +++ b/Pal/src/db_streams.c @@ -150,16 +150,14 @@ static int parse_stream_uri(const char** uri, char** prefix, struct handle_ops** return 0; } -/* _DkStreamOpen for internal use. Open stream based on uri. - access/share/create/options are the same flags defined for - DkStreamOpen. */ +/* _DkStreamOpen for internal use. Open stream based on uri. access/share/create/options are the + * same flags defined for DkStreamOpen. */ int _DkStreamOpen(PAL_HANDLE* handle, const char* uri, int access, int share, int create, int options) { struct handle_ops* ops = NULL; - char* type = NULL; + char* type = NULL; int ret = parse_stream_uri(&uri, &type, &ops); - if (ret < 0) return ret; diff --git a/Pal/src/host/Linux-SGX/db_main.c b/Pal/src/host/Linux-SGX/db_main.c index ffb7a995..73469a29 100644 --- a/Pal/src/host/Linux-SGX/db_main.c +++ b/Pal/src/host/Linux-SGX/db_main.c @@ -144,7 +144,7 @@ static int loader_filter (const char * key, int len) /* * Takes a pointer+size to an untrusted memory region containing a - * NUL-separated list of strings. It builds a argv-style list in trusted memory + * NUL-separated list of strings. It builds an argv-style list in trusted memory * with those strings. * * It is responsible for handling the access to untrusted memory safely @@ -155,44 +155,45 @@ static int loader_filter (const char * key, int len) * to free it (For argv and envp we rely on auto free on termination in * practice). */ -static const char** make_argv_list(void * uptr_src, uint64_t src_size) { - const char **argv; +static const char** make_argv_list(void* uptr_src, size_t src_size) { + const char** argv; if (src_size == 0) { argv = malloc(sizeof(char *)); - argv[0] = NULL; + if (argv) + argv[0] = NULL; return argv; } - char * data = malloc(src_size); + char* data = malloc(src_size); if (!data) { return NULL; } if (!sgx_copy_to_enclave(data, src_size, uptr_src, src_size)) { - goto free_and_err; + goto fail; } data[src_size - 1] = '\0'; - uint64_t argc = 0; - for (uint64_t i = 0; i < src_size; i++) { + size_t argc = 0; + for (size_t i = 0; i < src_size; i++) { if (data[i] == '\0') { argc++; } } size_t argv_size; - if (__builtin_mul_overflow(argc + 1, sizeof(char *), &argv_size)) { - goto free_and_err; + if (__builtin_mul_overflow(argc + 1, sizeof(char*), &argv_size)) { + goto fail; } argv = malloc(argv_size); if (!argv) { - goto free_and_err; + goto fail; } argv[argc] = NULL; - uint64_t data_i = 0; - for (uint64_t arg_i = 0; arg_i < argc; arg_i++) { + size_t data_i = 0; + for (size_t arg_i = 0; arg_i < argc; arg_i++) { argv[arg_i] = &data[data_i]; while (data[data_i] != '\0') { data_i++; @@ -202,7 +203,7 @@ static const char** make_argv_list(void * uptr_src, uint64_t src_size) { return argv; -free_and_err: +fail: free(data); return NULL; } @@ -334,11 +335,11 @@ void pal_linux_main(char * uptr_args, uint64_t args_size, if (args_size > MAX_ARGS_SIZE || env_size > MAX_ENV_SIZE) { return; } - const char ** arguments = make_argv_list(uptr_args, args_size); + const char** arguments = make_argv_list(uptr_args, args_size); if (!arguments) { return; } - const char ** environments = make_argv_list(uptr_env, env_size); + const char** environments = make_argv_list(uptr_env, env_size); if (!environments) { return; } @@ -389,8 +390,7 @@ void pal_linux_main(char * uptr_args, uint64_t args_size, void* manifest_addr = enclave_top - ALIGN_UP_PTR_POW2(manifest_size, g_page_size); /* parse manifest data into config storage */ - struct config_store * root_config = - malloc(sizeof(struct config_store)); + struct config_store* root_config = malloc(sizeof(struct config_store)); root_config->raw_data = manifest_addr; root_config->raw_size = manifest_size; root_config->malloc = malloc; diff --git a/Pal/src/host/Linux/db_process.c b/Pal/src/host/Linux/db_process.c index be82d771..440deebc 100644 --- a/Pal/src/host/Linux/db_process.c +++ b/Pal/src/host/Linux/db_process.c @@ -127,9 +127,7 @@ struct proc_args { * NOTE: more tricks may be needed to prevent unexpected optimization for * future compiler. */ -static int __attribute_noinline -child_process (struct proc_param * proc_param) -{ +static int __attribute_noinline child_process(struct proc_param* proc_param) { int ret = ARCH_VFORK(); if (ret) return ret; @@ -154,9 +152,7 @@ failed: return -PAL_ERROR_DENIED; } -int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args) -{ - +int _DkProcessCreate(PAL_HANDLE* handle, const char* uri, const char** args) { PAL_HANDLE exec = NULL; PAL_HANDLE parent_handle = NULL, child_handle = NULL; int ret; @@ -177,7 +173,7 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args) * tell its address to forked process. */ size_t len; - const char * file_uri = URI_PREFIX_FILE; + const char* file_uri = URI_PREFIX_FILE; if (exec_map && exec_map->l_name && (len = strlen(uri)) >= URI_PREFIX_FILE_LEN && !memcmp(uri, file_uri, URI_PREFIX_FILE_LEN) && /* skip "file:"*/ @@ -187,7 +183,7 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args) exec->file.map_start = (PAL_PTR)exec_map->l_map_start; } - /* step 2: create parant and child process handle */ + /* step 2: create parent and child process handle */ struct proc_param param; ret = create_process_handle(&parent_handle, &child_handle); @@ -198,12 +194,12 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args) param.exec = exec; param.manifest = pal_state.manifest_handle; - /* step 3: compose process parameter */ + /* step 3: compose process parameters */ size_t parent_datasz = 0, exec_datasz = 0, manifest_datasz = 0; - void * parent_data = NULL; - void * exec_data = NULL; - void * manifest_data = NULL; + void* parent_data = NULL; + void* exec_data = NULL; + void* manifest_data = NULL; ret = handle_serialize(parent_handle, &parent_data); if (ret < 0) @@ -230,7 +226,7 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args) } size_t datasz = parent_datasz + exec_datasz + manifest_datasz; - struct proc_args * proc_args = __alloca(sizeof(struct proc_args) + datasz); + struct proc_args* proc_args = __alloca(sizeof(struct proc_args) + datasz); proc_args->parent_process_id = linux_state.parent_process_id; memcpy(&proc_args->pal_sec, &pal_sec, sizeof(struct pal_sec)); @@ -238,7 +234,7 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args) proc_args->pal_sec._r_debug = NULL; proc_args->memory_quota = linux_state.memory_quota; - void * data = (void *) (proc_args + 1); + void* data = (void*)(proc_args + 1); memcpy(data, parent_data, parent_datasz); data += (proc_args->parent_data_size = parent_datasz); @@ -366,7 +362,7 @@ void init_child_process (PAL_HANDLE * parent_handle, PAL_HANDLE parent = NULL; ret = handle_deserialize(&parent, data, proc_args->parent_data_size); if (ret < 0) - INIT_FAIL(-ret, "cannot deseilaize parent process handle"); + INIT_FAIL(-ret, "cannot deserialize parent process handle"); data += proc_args->parent_data_size; *parent_handle = parent; diff --git a/Pal/src/pal_internal.h b/Pal/src/pal_internal.h index e8353dec..16d934bb 100644 --- a/Pal/src/pal_internal.h +++ b/Pal/src/pal_internal.h @@ -309,12 +309,11 @@ int _DkAttestationReport(PAL_PTR user_report_data, PAL_NUM* user_report_data_siz int _DkAttestationQuote(PAL_PTR user_report_data, PAL_NUM user_report_data_size, PAL_PTR quote, PAL_NUM* quote_size); -#define INIT_FAIL(exitcode, reason) \ - do { \ - printf("PAL failed at " __FILE__ ":%s:%u (exitcode = %u, reason=%s)\n", \ - __FUNCTION__, (unsigned int)__LINE__, \ - (unsigned int) (exitcode), (const char *) (reason)); \ - _DkProcessExit(exitcode); \ +#define INIT_FAIL(exitcode, reason) \ + do { \ + printf("PAL failed at " __FILE__ ":%s:%u (exitcode = %u, reason=%s)\n", \ + __FUNCTION__, (unsigned int)__LINE__, (unsigned int)(exitcode), reason); \ + _DkProcessExit(exitcode); \ } while (0) /* function and definition for loading binaries */