Apply clang-format for core/shared and product-mini files (#785)

Apply clang-format for core/shared and product-mini files
This commit is contained in:
Wenyong Huang
2021-10-14 09:12:07 +08:00
committed by GitHub
parent fb4afc7ca4
commit 17f62ad472
107 changed files with 3436 additions and 2898 deletions

View File

@ -13,14 +13,15 @@
#include "bh_platform.h"
extern "C" {
typedef void (*os_print_function_t)(const char* message);
extern void os_set_print_function(os_print_function_t pf);
typedef void (*os_print_function_t)(const char *message);
extern void
os_set_print_function(os_print_function_t pf);
void
enclave_print(const char *message)
{
ocall_print(message);
}
void
enclave_print(const char *message)
{
ocall_print(message);
}
}
typedef enum EcallCmd {
@ -130,8 +131,8 @@ handle_cmd_load_module(uint64 *args, uint32 argc)
bh_assert(argc == 4);
if (total_size >= UINT32_MAX
|| !(enclave_module = (EnclaveModule *)
wasm_runtime_malloc((uint32)total_size))) {
|| !(enclave_module =
(EnclaveModule *)wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"WASM module load failed: "
"allocate memory failed.");
@ -140,14 +141,13 @@ handle_cmd_load_module(uint64 *args, uint32 argc)
}
memset(enclave_module, 0, (uint32)total_size);
enclave_module->wasm_file = (uint8 *)enclave_module
+ sizeof(EnclaveModule);
bh_memcpy_s(enclave_module->wasm_file, wasm_file_size,
wasm_file, wasm_file_size);
enclave_module->wasm_file = (uint8 *)enclave_module + sizeof(EnclaveModule);
bh_memcpy_s(enclave_module->wasm_file, wasm_file_size, wasm_file,
wasm_file_size);
if (!(enclave_module->module =
wasm_runtime_load(enclave_module->wasm_file, wasm_file_size,
error_buf, error_buf_size))) {
wasm_runtime_load(enclave_module->wasm_file, wasm_file_size,
error_buf, error_buf_size))) {
wasm_runtime_free(enclave_module);
*(void **)args_org = NULL;
return;
@ -189,9 +189,8 @@ handle_cmd_instantiate_module(uint64 *args, uint32 argc)
bh_assert(argc == 5);
if (!(module_inst =
wasm_runtime_instantiate(enclave_module->module,
stack_size, heap_size,
error_buf, error_buf_size))) {
wasm_runtime_instantiate(enclave_module->module, stack_size,
heap_size, error_buf, error_buf_size))) {
*(void **)args_org = NULL;
return;
}
@ -225,8 +224,7 @@ handle_cmd_get_exception(uint64 *args, uint32 argc)
bh_assert(argc == 3);
if ((exception1 = wasm_runtime_get_exception(module_inst))) {
snprintf(exception, exception_size,
"%s", exception1);
snprintf(exception, exception_size, "%s", exception1);
args_org[0] = true;
}
else {
@ -339,15 +337,14 @@ handle_cmd_set_wasi_args(uint64 *args, int32 argc)
}
if (total_size >= UINT32_MAX
|| !(enclave_module->wasi_arg_buf = p = (char *)
wasm_runtime_malloc((uint32)total_size))) {
|| !(enclave_module->wasi_arg_buf = p =
(char *)wasm_runtime_malloc((uint32)total_size))) {
*args_org = false;
return;
}
p1 = p + sizeof(char *) * dir_list_size
+ sizeof(char *) * env_list_size
+ sizeof(char *) * wasi_argc;
p1 = p + sizeof(char *) * dir_list_size + sizeof(char *) * env_list_size
+ sizeof(char *) * wasi_argc;
if (dir_list_size > 0) {
enclave_module->wasi_dir_list = (char **)p;
@ -385,17 +382,12 @@ handle_cmd_set_wasi_args(uint64 *args, int32 argc)
p += sizeof(char *) * wasi_argc;
}
wasm_runtime_set_wasi_args_ex(enclave_module->module,
(const char **)enclave_module->wasi_dir_list,
dir_list_size,
NULL, 0,
(const char **)enclave_module->wasi_env_list,
env_list_size,
enclave_module->wasi_argv,
enclave_module->wasi_argc,
(stdinfd != -1) ? stdinfd : 0,
(stdoutfd != -1) ? stdoutfd : 1,
(stderrfd != -1) ? stderrfd : 2);
wasm_runtime_set_wasi_args_ex(
enclave_module->module, (const char **)enclave_module->wasi_dir_list,
dir_list_size, NULL, 0, (const char **)enclave_module->wasi_env_list,
env_list_size, enclave_module->wasi_argv, enclave_module->wasi_argc,
(stdinfd != -1) ? stdinfd : 0, (stdoutfd != -1) ? stdoutfd : 1,
(stderrfd != -1) ? stderrfd : 2);
*args_org = true;
}
@ -408,8 +400,7 @@ handle_cmd_set_wasi_args(uint64 *args, int32 argc)
#endif /* end of SGX_DISABLE_WASI */
void
ecall_handle_command(unsigned cmd,
unsigned char *cmd_buf,
ecall_handle_command(unsigned cmd, unsigned char *cmd_buf,
unsigned cmd_buf_size)
{
uint64 *args = (uint64 *)cmd_buf;
@ -494,11 +485,9 @@ ecall_iwasm_main(uint8_t *wasm_file_buf, uint32_t wasm_file_size)
}
/* instantiate the module */
if (!(wasm_module_inst = wasm_runtime_instantiate(wasm_module,
16 * 1024,
16 * 1024,
error_buf,
sizeof(error_buf)))) {
if (!(wasm_module_inst =
wasm_runtime_instantiate(wasm_module, 16 * 1024, 16 * 1024,
error_buf, sizeof(error_buf)))) {
ocall_print(error_buf);
ocall_print("\n");
goto fail2;

View File

@ -8,7 +8,8 @@
#include "wasm_export.h"
#include "bh_platform.h"
void ecall_iwasm_test()
void
ecall_iwasm_test()
{
ocall_print(" Prepare to invoke sgx_open ... ==>\n\n");
@ -76,7 +77,7 @@ void ecall_iwasm_test()
02 : - O_RDWR */
/** 1. open **/
fd = open(file, O_RDWR);
if (fd !=-1) {
if (fd != -1) {
ocall_print("\tOperation open test_open.txt success.\n");
}
@ -107,7 +108,7 @@ void ecall_iwasm_test()
ocall_print("\tOperation fdatasync success.\n");
}
/** isatty **/
/** isatty **/
ret = isatty(fd);
if (ret == 0) {
ocall_print("\tOperation fisatty success.\n");
@ -140,7 +141,7 @@ void ecall_iwasm_test()
p_dirent = readdir(dirp);
if (p_dirent != NULL) {
ocall_print("\tOperation readdir success.\t");
ocall_print(p_dirent -> d_name);
ocall_print(p_dirent->d_name);
ocall_print("\n");
}
@ -158,7 +159,7 @@ void ecall_iwasm_test()
/** closedir **/
ret = closedir(dirp);
if (ret == 0 ) {
if (ret == 0) {
ocall_print("\tOperation closedir success. \n");
}
/* 2. close */
@ -192,7 +193,7 @@ void ecall_iwasm_test()
ret = renameat(AT_FDCWD, rlt_dir_path, AT_FDCWD, rlt_dir_path_new);
if (ret == 0) {
ocall_print("\tOperation renameat ./tmp to "
"./tmp_new success. \n");
"./tmp_new success. \n");
}
renameat(AT_FDCWD, rlt_dir_path_new, AT_FDCWD, rlt_dir_path);
@ -220,7 +221,7 @@ void ecall_iwasm_test()
ret = symlinkat(file, AT_FDCWD, file_sf_ln);
if (ret == 0) {
ocall_print("\tOperation symlinkat from test.txt "
"to text_sf_ln.txt success. \n");
"to text_sf_ln.txt success. \n");
}
/** readlinkat **/
total_size = readlinkat(AT_FDCWD, file_sf_ln, buf, sizeof(buf));
@ -336,22 +337,23 @@ void ecall_iwasm_test()
close(fd);
/** getopt **/
while((ret = getopt(argc, argv, "f:abc")) != -1){ //get option from the getopt() method
switch(ret){
//For option i, r, l, print that these are options
case 'a':
case 'b':
case 'c':
ocall_print("\tGiven Option operation success. \n");
break;
case 'f': //here f is used for some file name
ocall_print("\tGiven File operation success.\n");
break;
case '?': //used for some unknown options
ocall_print("\tunknown option trigger success.\n");
break;
}
}
while ((ret = getopt(argc, argv, "f:abc"))
!= -1) { // get option from the getopt() method
switch (ret) {
// For option i, r, l, print that these are options
case 'a':
case 'b':
case 'c':
ocall_print("\tGiven Option operation success. \n");
break;
case 'f': // here f is used for some file name
ocall_print("\tGiven File operation success.\n");
break;
case '?': // used for some unknown options
ocall_print("\tunknown option trigger success.\n");
break;
}
}
/** sched_yield **/
ret = sched_yield();