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

@ -5,9 +5,11 @@
#include "stdio.h"
void print_line(char* str);
void
print_line(char *str);
int main()
int
main()
{
print_line("Hello World!");
print_line("Wasm Micro Runtime");

View File

@ -6,7 +6,8 @@
#include "stdio.h"
#include "string.h"
void print_line(char* str)
void
print_line(char *str)
{
printf("%s\n", str);
}

View File

@ -6,7 +6,8 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
char *buf;

View File

@ -24,10 +24,10 @@ static char **app_argv;
* @return true if the main function is called, false otherwise.
*/
bool
wasm_application_execute_main(wasm_module_inst_t module_inst,
int32_t argc, char *argv[]);
wasm_application_execute_main(wasm_module_inst_t module_inst, int32_t argc,
char *argv[]);
static void*
static void *
app_instance_main(wasm_module_inst_t module_inst)
{
const char *exception;
@ -40,7 +40,8 @@ app_instance_main(wasm_module_inst_t module_inst)
static char global_heap_buf[256 * 1024] = { 0 };
void iwasm_main(void *arg1)
void
iwasm_main(void *arg1)
{
uint8 *wasm_file_buf = NULL;
uint32 wasm_file_size;
@ -52,7 +53,7 @@ void iwasm_main(void *arg1)
int log_verbose_level = 2;
#endif
(void) arg1;
(void)arg1;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
@ -71,22 +72,19 @@ void iwasm_main(void *arg1)
#endif
/* load WASM byte buffer from byte buffer of include file */
wasm_file_buf = (uint8*) wasm_test_file;
wasm_file_buf = (uint8 *)wasm_test_file;
wasm_file_size = sizeof(wasm_test_file);
/* load WASM module */
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
error_buf, sizeof(error_buf)))) {
error_buf, sizeof(error_buf)))) {
printf("%s\n", error_buf);
goto fail1;
}
/* instantiate the module */
if (!(wasm_module_inst = wasm_runtime_instantiate(wasm_module,
8 * 1024,
8 * 1024,
error_buf,
sizeof(error_buf)))) {
if (!(wasm_module_inst = wasm_runtime_instantiate(
wasm_module, 8 * 1024, 8 * 1024, error_buf, sizeof(error_buf)))) {
printf("%s\n", error_buf);
goto fail2;
}
@ -108,10 +106,10 @@ fail1:
#define DEFAULT_THREAD_STACKSIZE (6 * 1024)
#define DEFAULT_THREAD_PRIORITY 50
bool iwasm_init(void)
bool
iwasm_init(void)
{
int ret = aos_task_new("wasm-main", iwasm_main, NULL,
DEFAULT_THREAD_STACKSIZE);
int ret =
aos_task_new("wasm-main", iwasm_main, NULL, DEFAULT_THREAD_STACKSIZE);
return ret == 0 ? true : false;
}

View File

@ -7,10 +7,11 @@
#include <wasm_export.h>
#define LOGI(...) \
((void)__android_log_print(ANDROID_LOG_INFO, "wasm_jni::", __VA_ARGS__))
((void)__android_log_print(ANDROID_LOG_INFO, "wasm_jni::", __VA_ARGS__))
static void *
app_instance_main(wasm_module_inst_t module_inst) {
app_instance_main(wasm_module_inst_t module_inst)
{
const char *exception;
wasm_application_execute_main(module_inst, 0, NULL);
@ -58,20 +59,21 @@ static unsigned char wasm_test_file[] = {
};
extern "C" JNIEXPORT void JNICALL
Java_com_intel_wasm_api_Runtime_run(JNIEnv *env, jclass thiz) {
Java_com_intel_wasm_api_Runtime_run(JNIEnv *env, jclass thiz)
{
wasm_module_t wasm_module = NULL;
wasm_module_inst_t wasm_module_inst = NULL;
RuntimeInitArgs init_args;
uint wasm_file_size = 0;
uint8_t *wasm_file_buf = NULL;
char error_buf[128] = {0};
char error_buf[128] = { 0 };
memset(&init_args, 0, sizeof(RuntimeInitArgs));
init_args.mem_alloc_type = Alloc_With_Allocator;
init_args.mem_alloc_option.allocator.malloc_func = (void*)malloc;
init_args.mem_alloc_option.allocator.realloc_func = (void*)realloc;
init_args.mem_alloc_option.allocator.free_func = (void*)free;
init_args.mem_alloc_option.allocator.malloc_func = (void *)malloc;
init_args.mem_alloc_option.allocator.realloc_func = (void *)realloc;
init_args.mem_alloc_option.allocator.free_func = (void *)free;
LOGI("wasm_runtime_full_init");
/* initialize runtime environment */
@ -82,7 +84,7 @@ Java_com_intel_wasm_api_Runtime_run(JNIEnv *env, jclass thiz) {
/* load WASM byte buffer from a preinstall WASM bin file */
LOGI("use an internal test file, gona to output Hello World in logcat\n");
wasm_file_buf = (uint8_t*) wasm_test_file;
wasm_file_buf = (uint8_t *)wasm_test_file;
wasm_file_size = sizeof(wasm_test_file);
/* load WASM module */
@ -96,11 +98,10 @@ Java_com_intel_wasm_api_Runtime_run(JNIEnv *env, jclass thiz) {
/* instantiate the module */
LOGI("wasm_runtime_instantiate");
if (!(wasm_module_inst = wasm_runtime_instantiate(wasm_module,
64 * 1024, /* stack size */
64 * 1024, /* heap size */
error_buf,
sizeof(error_buf)))) {
if (!(wasm_module_inst =
wasm_runtime_instantiate(wasm_module, 64 * 1024, /* stack size */
64 * 1024, /* heap size */
error_buf, sizeof(error_buf)))) {
LOGI("%s\n", error_buf);
LOGI("goto fail2\n");
goto fail2;
@ -121,7 +122,7 @@ fail2:
fail1:
// in our case, we don't need a free, but it is not a typical one
/* free the file buffer */
//bh_free((void *) wasm_file_buf);
// bh_free((void *) wasm_file_buf);
/* destroy runtime environment */
LOGI("wasm_runtime_destroy");

View File

@ -14,7 +14,7 @@
static int app_argc;
static char **app_argv;
static void*
static void *
app_instance_main(wasm_module_inst_t module_inst)
{
const char *exception;
@ -27,7 +27,8 @@ app_instance_main(wasm_module_inst_t module_inst)
static char global_heap_buf[CONFIG_GLOBAL_HEAP_BUF_SIZE] = { 0 };
void iwasm_main(void)
void
iwasm_main(void)
{
uint8 *wasm_file_buf = NULL;
uint32 wasm_file_size;
@ -60,7 +61,7 @@ void iwasm_main(void)
#endif
/* load WASM byte buffer from byte buffer of include file */
wasm_file_buf = (uint8*)wasm_test_file;
wasm_file_buf = (uint8 *)wasm_test_file;
wasm_file_size = sizeof(wasm_test_file);
/* load WASM module */
@ -73,11 +74,9 @@ void iwasm_main(void)
os_printf("### wasm runtime load module success.\n");
/* instantiate the module */
if (!(wasm_module_inst = wasm_runtime_instantiate(wasm_module,
CONFIG_APP_STACK_SIZE,
CONFIG_APP_HEAP_SIZE,
error_buf,
sizeof(error_buf)))) {
if (!(wasm_module_inst = wasm_runtime_instantiate(
wasm_module, CONFIG_APP_STACK_SIZE, CONFIG_APP_HEAP_SIZE,
error_buf, sizeof(error_buf)))) {
os_printf("%s\n", error_buf);
goto fail2;
}

View File

@ -26,7 +26,7 @@
#define FALSE 0
#endif
#define TOKEN_FILENAME "enclave.token"
#define TOKEN_FILENAME "enclave.token"
#define ENCLAVE_FILENAME "enclave.signed.so"
#define MAX_PATH 1024
@ -41,7 +41,7 @@ pal_get_enclave_id(void)
}
void
ocall_print(const char* str)
ocall_print(const char *str)
{
printf("%s", str);
}
@ -50,8 +50,7 @@ static char *
get_exe_path(char *path_buf, unsigned path_buf_size)
{
ssize_t i;
ssize_t size = readlink("/proc/self/exe",
path_buf, path_buf_size - 1);
ssize_t size = readlink("/proc/self/exe", path_buf, path_buf_size - 1);
if (size < 0 || (size >= path_buf_size - 1)) {
return NULL;
@ -99,8 +98,9 @@ enclave_init(sgx_enclave_id_t *p_eid)
home_dir = getpwuid(getuid())->pw_dir;
size_t home_dir_len = home_dir ? strlen(home_dir) : 0;
if (home_dir != NULL &&
home_dir_len <= MAX_PATH - 1 - sizeof(TOKEN_FILENAME) - strlen("/")) {
if (home_dir != NULL
&& home_dir_len
<= MAX_PATH - 1 - sizeof(TOKEN_FILENAME) - strlen("/")) {
/* compose the token path */
strncpy(token_path, home_dir, MAX_PATH);
strncat(token_path, "/", strlen("/"));
@ -123,18 +123,19 @@ enclave_init(sgx_enclave_id_t *p_eid)
if (read_num != 0 && read_num != sizeof(sgx_launch_token_t)) {
/* if token is invalid, clear the buffer */
memset(&token, 0x0, sizeof(sgx_launch_token_t));
printf("Warning: Invalid launch token read from \"%s\".\n", token_path);
printf("Warning: Invalid launch token read from \"%s\".\n",
token_path);
}
}
/* Step 2: call sgx_create_enclave to initialize an enclave instance */
/* Debug Support: set 2nd parameter to 1 */
ret = sgx_create_enclave(ENCLAVE_FILENAME, SGX_DEBUG_FLAG,
&token, &updated, p_eid, NULL);
ret = sgx_create_enclave(ENCLAVE_FILENAME, SGX_DEBUG_FLAG, &token, &updated,
p_eid, NULL);
if (ret != SGX_SUCCESS)
/* Try to load enclave.sign.so from the path of exe file */
ret = sgx_create_enclave(enclave_path, SGX_DEBUG_FLAG,
&token, &updated, p_eid, NULL);
ret = sgx_create_enclave(enclave_path, SGX_DEBUG_FLAG, &token, &updated,
p_eid, NULL);
if (ret != SGX_SUCCESS) {
printf("Failed to create enclave from %s, error code: %d\n",
ENCLAVE_FILENAME, ret);
@ -145,8 +146,10 @@ enclave_init(sgx_enclave_id_t *p_eid)
/* Step 3: save the launch token if it is updated */
if (updated == FALSE || fp == NULL) {
/* if the token is not updated, or file handler is invalid, do not perform saving */
if (fp != NULL) fclose(fp);
/* if the token is not updated, or file handler is invalid,
do not perform saving */
if (fp != NULL)
fclose(fp);
return 0;
}
@ -176,8 +179,7 @@ read_file_to_buffer(const char *filename, uint32_t *ret_size)
}
if (!(file = fopen(filename, "r"))) {
printf("Read file to buffer failed: open file %s failed.\n",
filename);
printf("Read file to buffer failed: open file %s failed.\n", filename);
return NULL;
}
@ -185,7 +187,7 @@ read_file_to_buffer(const char *filename, uint32_t *ret_size)
file_size = ftell(file);
fseek(file, 0, SEEK_SET);
if (!(buffer = (unsigned char*)malloc(file_size))) {
if (!(buffer = (unsigned char *)malloc(file_size))) {
printf("Read file to buffer failed: alloc memory failed.\n");
fclose(file);
return NULL;
@ -205,6 +207,7 @@ read_file_to_buffer(const char *filename, uint32_t *ret_size)
return buffer;
}
/* clang-format off */
static int
print_help()
{
@ -227,6 +230,7 @@ print_help()
printf(" --max-threads=n Set maximum thread number per cluster, default is 4\n");
return 1;
}
/* clang-format on */
/**
* Split a space separated strings into an array of strings
@ -287,8 +291,8 @@ typedef enum EcallCmd {
} EcallCmd;
static void
app_instance_func(void *wasm_module_inst, const char *func_name,
int app_argc, char **app_argv);
app_instance_func(void *wasm_module_inst, const char *func_name, int app_argc,
char **app_argv);
static void *
app_instance_repl(void *module_inst, int app_argc, char **app_argv)
@ -315,8 +319,8 @@ app_instance_repl(void *module_inst, int app_argc, char **app_argv)
break;
}
if (app_argc != 0) {
app_instance_func(module_inst, app_argv[0],
app_argc - 1, app_argv + 1);
app_instance_func(module_inst, app_argv[0], app_argc - 1,
app_argv + 1);
}
free(app_argv);
}
@ -349,9 +353,9 @@ set_log_verbose_level(int log_verbose_level)
/* Set log verbose level */
if (log_verbose_level != 2) {
ecall_args[0] = log_verbose_level;
if (SGX_SUCCESS != ecall_handle_command(g_eid, CMD_SET_LOG_LEVEL,
(uint8_t *)ecall_args,
sizeof(uint64_t))) {
if (SGX_SUCCESS
!= ecall_handle_command(g_eid, CMD_SET_LOG_LEVEL,
(uint8_t *)ecall_args, sizeof(uint64_t))) {
printf("Call ecall_handle_command() failed.\n");
return false;
}
@ -366,9 +370,9 @@ init_runtime(bool alloc_with_pool, uint32_t max_thread_num)
ecall_args[0] = alloc_with_pool;
ecall_args[1] = max_thread_num;
if (SGX_SUCCESS != ecall_handle_command(g_eid, CMD_INIT_RUNTIME,
(uint8_t *)ecall_args,
sizeof(uint64_t) * 2)) {
if (SGX_SUCCESS
!= ecall_handle_command(g_eid, CMD_INIT_RUNTIME, (uint8_t *)ecall_args,
sizeof(uint64_t) * 2)) {
printf("Call ecall_handle_command() failed.\n");
return false;
}
@ -382,15 +386,15 @@ init_runtime(bool alloc_with_pool, uint32_t max_thread_num)
static void
destroy_runtime()
{
if (SGX_SUCCESS != ecall_handle_command(g_eid, CMD_DESTROY_RUNTIME,
NULL, 0)) {
if (SGX_SUCCESS
!= ecall_handle_command(g_eid, CMD_DESTROY_RUNTIME, NULL, 0)) {
printf("Call ecall_handle_command() failed.\n");
}
}
static void *
load_module(uint8_t *wasm_file_buf, uint32_t wasm_file_size,
char *error_buf, uint32_t error_buf_size)
load_module(uint8_t *wasm_file_buf, uint32_t wasm_file_size, char *error_buf,
uint32_t error_buf_size)
{
uint64_t ecall_args[4];
@ -398,9 +402,9 @@ load_module(uint8_t *wasm_file_buf, uint32_t wasm_file_size,
ecall_args[1] = wasm_file_size;
ecall_args[2] = (uint64_t)(uintptr_t)error_buf;
ecall_args[3] = error_buf_size;
if (SGX_SUCCESS != ecall_handle_command(g_eid, CMD_LOAD_MODULE,
(uint8_t *)ecall_args,
sizeof(uint64_t) * 4)) {
if (SGX_SUCCESS
!= ecall_handle_command(g_eid, CMD_LOAD_MODULE, (uint8_t *)ecall_args,
sizeof(uint64_t) * 4)) {
printf("Call ecall_handle_command() failed.\n");
return NULL;
}
@ -414,16 +418,15 @@ unload_module(void *wasm_module)
uint64_t ecall_args[1];
ecall_args[0] = (uint64_t)(uintptr_t)wasm_module;
if (SGX_SUCCESS != ecall_handle_command(g_eid, CMD_UNLOAD_MODULE,
(uint8_t *)ecall_args,
sizeof(uint64_t))) {
if (SGX_SUCCESS
!= ecall_handle_command(g_eid, CMD_UNLOAD_MODULE, (uint8_t *)ecall_args,
sizeof(uint64_t))) {
printf("Call ecall_handle_command() failed.\n");
}
}
static void *
instantiate_module(void *wasm_module,
uint32_t stack_size, uint32_t heap_size,
instantiate_module(void *wasm_module, uint32_t stack_size, uint32_t heap_size,
char *error_buf, uint32_t error_buf_size)
{
uint64_t ecall_args[5];
@ -433,9 +436,9 @@ instantiate_module(void *wasm_module,
ecall_args[2] = heap_size;
ecall_args[3] = (uint64_t)(uintptr_t)error_buf;
ecall_args[4] = error_buf_size;
if (SGX_SUCCESS != ecall_handle_command(g_eid, CMD_INSTANTIATE_MODULE,
(uint8_t *)ecall_args,
sizeof(uint64_t) * 5)) {
if (SGX_SUCCESS
!= ecall_handle_command(g_eid, CMD_INSTANTIATE_MODULE,
(uint8_t *)ecall_args, sizeof(uint64_t) * 5)) {
printf("Call ecall_handle_command() failed.\n");
return NULL;
}
@ -449,25 +452,24 @@ deinstantiate_module(void *wasm_module_inst)
uint64_t ecall_args[1];
ecall_args[0] = (uint64_t)(uintptr_t)wasm_module_inst;
if (SGX_SUCCESS != ecall_handle_command(g_eid, CMD_DEINSTANTIATE_MODULE,
(uint8_t *)ecall_args,
sizeof(uint64_t))) {
if (SGX_SUCCESS
!= ecall_handle_command(g_eid, CMD_DEINSTANTIATE_MODULE,
(uint8_t *)ecall_args, sizeof(uint64_t))) {
printf("Call ecall_handle_command() failed.\n");
}
}
static bool
get_exception(void *wasm_module_inst,
char *exception, uint32_t exception_size)
get_exception(void *wasm_module_inst, char *exception, uint32_t exception_size)
{
uint64_t ecall_args[3];
ecall_args[0] = (uint64_t)(uintptr_t)wasm_module_inst;
ecall_args[1] = (uint64_t)(uintptr_t)exception;
ecall_args[2] = exception_size;
if (SGX_SUCCESS != ecall_handle_command(g_eid, CMD_GET_EXCEPTION,
(uint8_t *)ecall_args,
sizeof(uint64_t) * 3)) {
if (SGX_SUCCESS
!= ecall_handle_command(g_eid, CMD_GET_EXCEPTION, (uint8_t *)ecall_args,
sizeof(uint64_t) * 3)) {
printf("Call ecall_handle_command() failed.\n");
}
@ -475,16 +477,15 @@ get_exception(void *wasm_module_inst,
}
static void
app_instance_main(void *wasm_module_inst,
int app_argc, char **app_argv)
app_instance_main(void *wasm_module_inst, int app_argc, char **app_argv)
{
char exception[128];
uint64_t ecall_args_buf[16], *ecall_args = ecall_args_buf;
int i, size;
if (app_argc + 2 > sizeof(ecall_args_buf) / sizeof(uint64_t)) {
if (!(ecall_args = (uint64_t *)
malloc(sizeof(uint64_t) * (app_argc + 2)))) {
if (!(ecall_args =
(uint64_t *)malloc(sizeof(uint64_t) * (app_argc + 2)))) {
printf("Allocate memory failed.\n");
return;
}
@ -497,9 +498,9 @@ app_instance_main(void *wasm_module_inst,
}
size = (uint32_t)sizeof(uint64_t) * (app_argc + 2);
if (SGX_SUCCESS != ecall_handle_command(g_eid, CMD_EXEC_APP_MAIN,
(uint8_t *)ecall_args,
size)) {
if (SGX_SUCCESS
!= ecall_handle_command(g_eid, CMD_EXEC_APP_MAIN, (uint8_t *)ecall_args,
size)) {
printf("Call ecall_handle_command() failed.\n");
}
@ -513,15 +514,15 @@ app_instance_main(void *wasm_module_inst,
}
static void
app_instance_func(void *wasm_module_inst, const char *func_name,
int app_argc, char **app_argv)
app_instance_func(void *wasm_module_inst, const char *func_name, int app_argc,
char **app_argv)
{
uint64_t ecall_args_buf[16], *ecall_args = ecall_args_buf;
int i, size;
if (app_argc + 3 > sizeof(ecall_args_buf) / sizeof(uint64_t)) {
if (!(ecall_args = (uint64_t *)
malloc(sizeof(uint64_t) * (app_argc + 3)))) {
if (!(ecall_args =
(uint64_t *)malloc(sizeof(uint64_t) * (app_argc + 3)))) {
printf("Allocate memory failed.\n");
return;
}
@ -535,9 +536,9 @@ app_instance_func(void *wasm_module_inst, const char *func_name,
}
size = (uint32_t)sizeof(uint64_t) * (app_argc + 3);
if (SGX_SUCCESS != ecall_handle_command(g_eid, CMD_EXEC_APP_FUNC,
(uint8_t *)ecall_args,
size)) {
if (SGX_SUCCESS
!= ecall_handle_command(g_eid, CMD_EXEC_APP_FUNC, (uint8_t *)ecall_args,
size)) {
printf("Call ecall_handle_command() failed.\n");
}
@ -547,11 +548,9 @@ app_instance_func(void *wasm_module_inst, const char *func_name,
}
static bool
set_wasi_args(void *wasm_module,
const char **dir_list, uint32_t dir_list_size,
const char **env_list, uint32_t env_list_size,
int stdinfd, int stdoutfd, int stderrfd,
char **argv, uint32_t argc)
set_wasi_args(void *wasm_module, const char **dir_list, uint32_t dir_list_size,
const char **env_list, uint32_t env_list_size, int stdinfd,
int stdoutfd, int stderrfd, char **argv, uint32_t argc)
{
uint64_t ecall_args[10];
@ -565,9 +564,9 @@ set_wasi_args(void *wasm_module,
ecall_args[7] = stderrfd;
ecall_args[8] = (uint64_t)(uintptr_t)argv;
ecall_args[9] = argc;
if (SGX_SUCCESS != ecall_handle_command(g_eid, CMD_SET_WASI_ARGS,
(uint8_t *)ecall_args,
sizeof(uint64_t) * 10)) {
if (SGX_SUCCESS
!= ecall_handle_command(g_eid, CMD_SET_WASI_ARGS, (uint8_t *)ecall_args,
sizeof(uint64_t) * 10)) {
printf("Call ecall_handle_command() failed.\n");
}
@ -693,29 +692,28 @@ main(int argc, char *argv[])
/* Load WASM byte buffer from WASM bin file */
if (!(wasm_file_buf =
(uint8_t *)read_file_to_buffer(wasm_file, &wasm_file_size))) {
(uint8_t *)read_file_to_buffer(wasm_file, &wasm_file_size))) {
goto fail1;
}
/* Load module */
if (!(wasm_module = load_module(wasm_file_buf, wasm_file_size,
error_buf, sizeof(error_buf)))) {
if (!(wasm_module = load_module(wasm_file_buf, wasm_file_size, error_buf,
sizeof(error_buf)))) {
printf("%s\n", error_buf);
goto fail2;
}
/* Set wasi arguments */
if (!set_wasi_args(wasm_module, dir_list, dir_list_size,
env_list, env_list_size, 0, 1, 2, argv, argc)) {
if (!set_wasi_args(wasm_module, dir_list, dir_list_size, env_list,
env_list_size, 0, 1, 2, argv, argc)) {
printf("%s\n", "set wasi arguments failed.\n");
goto fail3;
}
/* Instantiate module */
if (!(wasm_module_inst = instantiate_module(wasm_module,
stack_size, heap_size,
error_buf,
sizeof(error_buf)))) {
if (!(wasm_module_inst =
instantiate_module(wasm_module, stack_size, heap_size, error_buf,
sizeof(error_buf)))) {
printf("%s\n", error_buf);
goto fail3;
}
@ -723,8 +721,7 @@ main(int argc, char *argv[])
if (is_repl_mode)
app_instance_repl(wasm_module_inst, argc, argv);
else if (func_name)
app_instance_func(wasm_module_inst, func_name,
argc - 1, argv + 1);
app_instance_func(wasm_module_inst, func_name, argc - 1, argv + 1);
else
app_instance_main(wasm_module_inst, argc, argv);
@ -782,19 +779,19 @@ wamr_pal_create_process(struct wamr_pal_create_process_args *args)
int stderrfd = -1;
int argc = 2;
char *argv[argc] = { (char*)"./iwasm", (char *)args->argv[0] };
char *argv[argc] = { (char *)"./iwasm", (char *)args->argv[0] };
uint8_t *wasm_files_buf = NULL;
void *wasm_modules = NULL;
int len = 0, i;
char *temp = (char *)args->argv[0];
while(temp) {
while (temp) {
len++;
temp=(char *)args->argv[len];
temp = (char *)args->argv[len];
}
if (len > sizeof(wasm_files)/sizeof(char *)) {
if (len > sizeof(wasm_files) / sizeof(char *)) {
printf("Number of input files is out of range\n");
return -1;
}
@ -829,8 +826,8 @@ wamr_pal_create_process(struct wamr_pal_create_process_args *args)
char error_buf[128] = { 0 };
/* Load WASM byte buffer from WASM bin file */
if (!(wasm_file_buf = (uint8_t *)read_file_to_buffer
(wasm_files[i], &wasm_file_size))) {
if (!(wasm_file_buf = (uint8_t *)read_file_to_buffer(
wasm_files[i], &wasm_file_size))) {
printf("Failed to read file to buffer\n");
destroy_runtime();
return -1;
@ -846,10 +843,9 @@ wamr_pal_create_process(struct wamr_pal_create_process_args *args)
}
/* Set wasi arguments */
if (!set_wasi_args(wasm_module, dir_list, dir_list_size,
env_list, env_list_size,
stdinfd, stdoutfd, stderrfd,
argv, argc)) {
if (!set_wasi_args(wasm_module, dir_list, dir_list_size, env_list,
env_list_size, stdinfd, stdoutfd, stderrfd, argv,
argc)) {
printf("%s\n", "set wasi arguments failed.\n");
unload_module(wasm_module);
free(wasm_file_buf);
@ -858,10 +854,9 @@ wamr_pal_create_process(struct wamr_pal_create_process_args *args)
}
/* Instantiate module */
if (!(wasm_module_inst[i] = instantiate_module(wasm_module,
stack_size, heap_size,
error_buf,
sizeof(error_buf)))) {
if (!(wasm_module_inst[i] =
instantiate_module(wasm_module, stack_size, heap_size,
error_buf, sizeof(error_buf)))) {
printf("%s\n", error_buf);
unload_module(wasm_module);
free(wasm_file_buf);
@ -884,37 +879,43 @@ wamr_pal_create_process(struct wamr_pal_create_process_args *args)
int
wamr_pal_destroy(void)
{
//sgx_destroy_enclave(g_eid);
// sgx_destroy_enclave(g_eid);
return 0;
}
int
wamr_pal_exec(struct wamr_pal_exec_args *args)
{
//app_instance_main(wasm_module_inst[i], argc, argv);
// app_instance_main(wasm_module_inst[i], argc, argv);
return 0;
}
int
wamr_pal_kill(int pid, int sig)
{
//deinstantiate_module(wasm_module_inst[i]);
//unload_module(wasm_module);
//free(wasm_file_buf);
// deinstantiate_module(wasm_module_inst[i]);
// unload_module(wasm_module);
// free(wasm_file_buf);
return 0;
}
int pal_get_version(void) __attribute__((weak, alias ("wamr_pal_get_version")));
int
pal_get_version(void) __attribute__((weak, alias("wamr_pal_get_version")));
int pal_init(const struct wamr_pal_attr *attr)\
__attribute__ ((weak, alias ("wamr_pal_init")));
int
pal_init(const struct wamr_pal_attr *attr)
__attribute__((weak, alias("wamr_pal_init")));
int pal_create_process(struct wamr_pal_create_process_args *args)\
__attribute__ ((weak, alias ("wamr_pal_create_process")));
int
pal_create_process(struct wamr_pal_create_process_args *args)
__attribute__((weak, alias("wamr_pal_create_process")));
int pal_exec(struct wamr_pal_exec_args *args)\
__attribute__ ((weak, alias ("wamr_pal_exec")));
int
pal_exec(struct wamr_pal_exec_args *args)
__attribute__((weak, alias("wamr_pal_exec")));
int pal_kill(int pid, int sig) __attribute__ ((weak, alias ("wamr_pal_kill")));
int
pal_kill(int pid, int sig) __attribute__((weak, alias("wamr_pal_kill")));
int pal_destroy(void) __attribute__ ((weak, alias ("wamr_pal_destroy")));
int
pal_destroy(void) __attribute__((weak, alias("wamr_pal_destroy")));

View File

@ -20,7 +20,8 @@ extern "C" {
*
* @retval If > 0, then success; otherwise, it is an invalid version.
*/
int wamr_pal_get_version(void);
int
wamr_pal_get_version(void);
/*
* WAMR PAL attributes
@ -29,19 +30,21 @@ typedef struct wamr_pal_attr {
// WAMR instance directory.
//
// The default value is "."; that is, the current working directory
const char *instance_dir;
const char *instance_dir;
// Log level.
//
// Specifies the log verbose level (0 to 5, default is 2)
// large level with more log
//
const char *log_level;
const char *log_level;
} wamr_pal_attr_t;
/* clang-format off */
#define WAMR_PAL_ATTR_INITVAL { \
.instance_dir = ".", \
.log_level = 2 \
}
/* clang-format on */
/*
* The struct which consists of file descriptors of standard I/O
@ -66,21 +69,23 @@ struct wamr_pal_create_process_args {
// Argments array pass to new process.
//
// The arguments to the command. By convention, the argv[0] should be the program name.
// And the last element of the array must be NULL to indicate the length of array.
// The arguments to the command. By convention, the argv[0] should be the
// program name. And the last element of the array must be NULL to indicate
// the length of array.
//
// Mandatory field. Must not be NULL.
const char **argv;
// Untrusted environment variable array pass to new process.
//
// The untrusted env vars to the command. And the last element of the array must be
// NULL to indicate the length of array.
// The untrusted env vars to the command. And the last element of the array
// must be NULL to indicate the length of array.
//
// Optional field.
const char **env;
// File descriptors of the redirected standard I/O (i.e., stdin, stdout, stderr)
// File descriptors of the redirected standard I/O (i.e., stdin, stdout,
// stderr)
//
// If set to NULL, will use the original standard I/O file descriptors.
//
@ -115,32 +120,41 @@ struct wamr_pal_exec_args {
int *exit_value;
};
int wamr_pal_init(const struct wamr_pal_attr *args);
int
wamr_pal_init(const struct wamr_pal_attr *args);
int wamr_pal_create_process(struct wamr_pal_create_process_args *args);
int
wamr_pal_create_process(struct wamr_pal_create_process_args *args);
int wamr_pal_destroy(void);
int
wamr_pal_destroy(void);
int wamr_pal_exec(struct wamr_pal_exec_args *args);
int
wamr_pal_exec(struct wamr_pal_exec_args *args);
int wamr_pal_kill(int pid, int sig);
int
wamr_pal_kill(int pid, int sig);
int pal_get_version(void);
int
pal_get_version(void);
int pal_init(const struct wamr_pal_attr *attr);
int
pal_init(const struct wamr_pal_attr *attr);
int pal_create_process(struct wamr_pal_create_process_args *args);
int
pal_create_process(struct wamr_pal_create_process_args *args);
int pal_exec(struct wamr_pal_exec_args *args);
int
pal_exec(struct wamr_pal_exec_args *args);
int pal_kill(int pid, int sig);
int pal_destroy(void);
int
pal_kill(int pid, int sig);
int
pal_destroy(void);
#ifdef __cplusplus
}
#endif
#endif /* __WAMR_PAL_API_H__ */

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();

View File

@ -18,6 +18,7 @@ static char **app_argv;
#define MODULE_PATH ("--module-path=")
/* clang-format off */
static int
print_help()
{
@ -55,6 +56,7 @@ print_help()
#endif
return 1;
}
/* clang-format on */
static void *
app_instance_main(wasm_module_inst_t module_inst)
@ -194,8 +196,8 @@ module_reader_callback(const char *module_name, uint8 **p_buffer,
uint32 *p_size)
{
const char *format = "%s/%s.wasm";
int sz = strlen(module_search_path) + strlen("/") + strlen(module_name) +
strlen(".wasm") + 1;
int sz = strlen(module_search_path) + strlen("/") + strlen(module_name)
+ strlen(".wasm") + 1;
char *wasm_file_name = BH_MALLOC(sz);
if (!wasm_file_name) {
return false;
@ -245,12 +247,12 @@ main(int argc, char *argv[])
uint32 env_list_size = 0;
#endif
#if WASM_ENABLE_DEBUG_INTERP != 0
char * ip_addr = NULL;
//int platform_port = 0;
char *ip_addr = NULL;
/* int platform_port = 0; */
int instance_port = 0;
#endif
/* Process options. */
/* Process options. */
for (argc--, argv++; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
if (!strcmp(argv[0], "-f") || !strcmp(argv[0], "--function")) {
argc--, argv++;
@ -332,7 +334,7 @@ main(int argc, char *argv[])
#endif
#if WASM_ENABLE_DEBUG_INTERP != 0
else if (!strncmp(argv[0], "-g=", 3)) {
char * port_str = strchr(argv[0] + 3, ':');
char *port_str = strchr(argv[0] + 3, ':');
char *port_end;
if (port_str == NULL)
return print_help();
@ -386,7 +388,7 @@ main(int argc, char *argv[])
/* load WASM byte buffer from WASM bin file */
if (!(wasm_file_buf =
(uint8 *)bh_read_file_to_buffer(wasm_file, &wasm_file_size)))
(uint8 *)bh_read_file_to_buffer(wasm_file, &wasm_file_size)))
goto fail1;
if (is_xip_mode) {
@ -394,15 +396,15 @@ main(int argc, char *argv[])
int map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC;
int map_flags = MMAP_MAP_NONE;
if (!(wasm_file_mapped = os_mmap(NULL, (uint32)wasm_file_size,
map_prot, map_flags))) {
if (!(wasm_file_mapped =
os_mmap(NULL, (uint32)wasm_file_size, map_prot, map_flags))) {
printf("mmap memory failed\n");
wasm_runtime_free(wasm_file_buf);
goto fail1;
}
bh_memcpy_s(wasm_file_mapped, wasm_file_size,
wasm_file_buf, wasm_file_size);
bh_memcpy_s(wasm_file_mapped, wasm_file_size, wasm_file_buf,
wasm_file_size);
wasm_runtime_free(wasm_file_buf);
wasm_file_buf = wasm_file_mapped;
}
@ -425,8 +427,8 @@ main(int argc, char *argv[])
/* instantiate the module */
if (!(wasm_module_inst =
wasm_runtime_instantiate(wasm_module, stack_size, heap_size,
error_buf, sizeof(error_buf)))) {
wasm_runtime_instantiate(wasm_module, stack_size, heap_size,
error_buf, sizeof(error_buf)))) {
printf("%s\n", error_buf);
goto fail3;
}

View File

@ -4,19 +4,17 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
//
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
// #include "platform_api_extension.h"
#include "wasm_export.h"
#include <thread.h>
/*provide some test program*/
/* provide some test program */
#include "test_wasm.h"
#define DEFAULT_THREAD_STACKSIZE (6 * 1024)
@ -25,31 +23,31 @@
static int app_argc;
static char **app_argv;
static void*
static void *
app_instance_main(wasm_module_inst_t module_inst)
{
const char *exception;
wasm_application_execute_main(module_inst, app_argc, app_argv);
if ((exception = wasm_runtime_get_exception(module_inst))){
if ((exception = wasm_runtime_get_exception(module_inst))) {
puts(exception);
}
return NULL;
}
void *
iwasm_t(void *arg1)
{
wasm_module_t wasm_module = (wasm_module_t) arg1;
wasm_module_t wasm_module = (wasm_module_t)arg1;
wasm_module_inst_t wasm_module_inst = NULL;
char error_buf[128];
/* instantiate the module */
if (!(wasm_module_inst = wasm_runtime_instantiate(wasm_module, 8 * 1024,
8 * 1024, error_buf, sizeof(error_buf)))) {
if (!(wasm_module_inst = wasm_runtime_instantiate(
wasm_module, 8 * 1024, 8 * 1024, error_buf, sizeof(error_buf)))) {
puts(error_buf);
}else{
}
else {
app_instance_main(wasm_module_inst);
/* destroy the module instance */
wasm_runtime_deinstantiate(wasm_module_inst);
@ -57,10 +55,14 @@ iwasm_t(void *arg1)
return NULL;
}
/* choose allocator */
#define FUNC_ALLOC
/* #define POOL_ALLOC */
void *
iwasm_main(void *arg1)
{
(void) arg1; /*unused*/
(void)arg1; /* unused */
uint8_t *wasm_file_buf = NULL;
unsigned wasm_file_buf_size = 0;
wasm_module_t wasm_module = NULL;
@ -68,13 +70,9 @@ iwasm_main(void *arg1)
RuntimeInitArgs init_args;
//chose allocator
#define FUNC_ALLOC
//#define POOL_ALLOC
memset(&init_args, 0, sizeof(RuntimeInitArgs));
#ifdef POOL_ALLOC
static char global_heap_buf[256 * 1024] = { 0 };//(256 kB)
static char global_heap_buf[256 * 1024] = { 0 }; /* 256 kB */
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
@ -94,17 +92,16 @@ iwasm_main(void *arg1)
return NULL;
}
/* load WASM byte buffer from byte buffer of include file */
wasm_file_buf = (uint8_t *) wasm_test_file;
wasm_file_buf = (uint8_t *)wasm_test_file;
wasm_file_buf_size = sizeof(wasm_test_file);
/* load WASM module */
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_buf_size,
error_buf, sizeof(error_buf)))) {
puts(error_buf);
}else{
}
else {
iwasm_t(wasm_module);
wasm_runtime_unload(wasm_module);
}
@ -116,14 +113,15 @@ iwasm_main(void *arg1)
bool
iwasm_init(void)
{
struct{
char * stack;
int stacksize;
uint8_t priority;
int flags;
/* clang-format off */
struct {
char *stack;
int stacksize;
uint8_t priority;
int flags;
thread_task_func_t task_func;
void * arg;
const char * name;
void *arg;
const char *name;
} b = {
.stacksize = DEFAULT_THREAD_STACKSIZE,
.priority = 8,
@ -132,17 +130,20 @@ iwasm_init(void)
.arg = NULL,
.name = "simple_wamr"
};
/* clang-format on */
b.stack=malloc(b.stacksize);
kernel_pid_t tpid = thread_create (b.stack, b.stacksize, b.priority, b.flags, b.task_func, b.arg, b.name);
b.stack = malloc(b.stacksize);
kernel_pid_t tpid = thread_create(b.stack, b.stacksize, b.priority, b.flags,
b.task_func, b.arg, b.name);
return tpid != 0 ? true : false;;
return tpid != 0 ? true : false;
;
}
#define telltruth(X) ((X) ? "true" : "false")
#define telltruth(X) ((X) ? "true" : "false")
int
main(void)
{
printf("iwasm_initilised: %s\n",telltruth(iwasm_init()));
printf("iwasm_initilised: %s\n", telltruth(iwasm_init()));
}

View File

@ -15,17 +15,21 @@
#ifdef WAMR_ENABLE_RTT_EXPORT
#ifdef WAMR_RTT_EXPORT_VPRINTF
static int wasm_vprintf(wasm_exec_env_t env, const char* fmt, va_list va)
static int
wasm_vprintf(wasm_exec_env_t env, const char *fmt, va_list va)
{
return vprintf(fmt, va);
}
static int wasm_vsprintf(wasm_exec_env_t env, char* buf, const char* fmt, va_list va)
static int
wasm_vsprintf(wasm_exec_env_t env, char *buf, const char *fmt, va_list va)
{
return vsprintf(buf, fmt, va);
}
static int wasm_vsnprintf(wasm_exec_env_t env, char *buf, int n, const char *fmt, va_list va)
static int
wasm_vsnprintf(wasm_exec_env_t env, char *buf, int n, const char *fmt,
va_list va)
{
return vsnprintf(buf, n, fmt, va);
}
@ -33,118 +37,127 @@ static int wasm_vsnprintf(wasm_exec_env_t env, char *buf, int n, const char *fmt
#endif /* WAMR_RTT_EXPORT_VPRINTF */
#ifdef WAMR_RTT_EXPORT_DEVICE_OPS
static rt_device_t wasm_rt_device_find(wasm_exec_env_t env, const char *name)
static rt_device_t
wasm_rt_device_find(wasm_exec_env_t env, const char *name)
{
return rt_device_find(name);
}
static rt_err_t wasm_rt_device_open(wasm_exec_env_t env, rt_device_t dev, rt_uint16_t o_flag)
static rt_err_t
wasm_rt_device_open(wasm_exec_env_t env, rt_device_t dev, rt_uint16_t o_flag)
{
return rt_device_open(dev , o_flag);
return rt_device_open(dev, o_flag);
}
static rt_size_t wasm_rt_device_write(wasm_exec_env_t env, rt_device_t dev, rt_off_t offset, const void*buf, rt_size_t size)
static rt_size_t
wasm_rt_device_write(wasm_exec_env_t env, rt_device_t dev, rt_off_t offset,
const void *buf, rt_size_t size)
{
return rt_device_write(dev, offset, buf, size);
}
static rt_size_t wasm_rt_device_read(wasm_exec_env_t env, rt_device_t dev, rt_off_t offset, void *buf, rt_size_t size)
static rt_size_t
wasm_rt_device_read(wasm_exec_env_t env, rt_device_t dev, rt_off_t offset,
void *buf, rt_size_t size)
{
return rt_device_read(dev, offset, buf, size);
}
static rt_err_t wasm_rt_device_close(wasm_exec_env_t env, rt_device_t dev)
static rt_err_t
wasm_rt_device_close(wasm_exec_env_t env, rt_device_t dev)
{
return rt_device_close(dev);
}
static rt_err_t wasm_rt_device_control(wasm_exec_env_t env, rt_device_t dev, int cmd, void *arg)
static rt_err_t
wasm_rt_device_control(wasm_exec_env_t env, rt_device_t dev, int cmd, void *arg)
{
return rt_device_control(dev, cmd, arg);
}
#endif /* WAMR_RTT_EXPORT_DEVICE_OPS */
/* clang-format off */
static NativeSymbol native_export_symbols[] = {
#ifdef WAMR_RTT_EXPORT_VPRINTF
{
"vprintf",
wasm_vprintf,
"($*)i"
},
{
"vsprintf",
wasm_vsprintf,
"($$*)i"
},
{
"vsnprintf",
wasm_vsnprintf,
"($i$*)i"
},
{
"vprintf",
wasm_vprintf,
"($*)i"
},
{
"vsprintf",
wasm_vsprintf,
"($$*)i"
},
{
"vsnprintf",
wasm_vsnprintf,
"($i$*)i"
},
#endif /* WAMR_RTT_EXPORT_VPRINTF */
#ifdef WAMR_RTT_EXPORT_DEVICE_OPS
{
"rt_device_find",
wasm_rt_device_find,
"($)i"
},
{
"rt_device_open",
wasm_rt_device_open,
"(ii)i"
},
{
"rt_device_write",
wasm_rt_device_write,
"(ii*~)i"
},
{
"rt_device_read",
wasm_rt_device_read,
"(ii*~)i"
},
{
"rt_device_close",
wasm_rt_device_close,
"(i)i"
},
{
"rt_device_control",
wasm_rt_device_control,
"(ii*)i"
},
{
"rt_device_find",
wasm_rt_device_find,
"($)i"
},
{
"rt_device_open",
wasm_rt_device_open,
"(ii)i"
},
{
"rt_device_write",
wasm_rt_device_write,
"(ii*~)i"
},
{
"rt_device_read",
wasm_rt_device_read,
"(ii*~)i"
},
{
"rt_device_close",
wasm_rt_device_close,
"(i)i"
},
{
"rt_device_control",
wasm_rt_device_control,
"(ii*)i"
},
#ifdef WAMR_RTT_EXPORT_DEVICE_OPS_CPP
{
"_Z15rt_device_closeP9rt_device",
wasm_rt_device_close,
"(i)i"
},
{
"_Z14rt_device_readP9rt_devicejPvj",
wasm_rt_device_read,
"(ii*~)i"
},
{
"_Z15rt_device_writeP9rt_devicejPKvj",
wasm_rt_device_write,
"(ii*~)i"
},
{
"_Z14rt_device_openP9rt_devicet",
wasm_rt_device_open,
"(ii)i"
},
{
"_Z14rt_device_findPKc",
wasm_rt_device_find,
"($)i"
},
{
"_Z15rt_device_closeP9rt_device",
wasm_rt_device_close,
"(i)i"
},
{
"_Z14rt_device_readP9rt_devicejPvj",
wasm_rt_device_read,
"(ii*~)i"
},
{
"_Z15rt_device_writeP9rt_devicejPKvj",
wasm_rt_device_write,
"(ii*~)i"
},
{
"_Z14rt_device_openP9rt_devicet",
wasm_rt_device_open,
"(ii)i"
},
{
"_Z14rt_device_findPKc",
wasm_rt_device_find,
"($)i"
},
#endif /* WAMR_RTT_EXPORT_DEVICE_OPS_CPP */
#endif /* WAMR_RTT_EXPORT_DEVICE_OPS */
};
/* clang-format on */
#endif /* WAMR_ENABLE_RTT_EXPORT */
@ -166,23 +179,22 @@ app_instance_main(wasm_module_inst_t module_inst, int app_argc, char **app_argv)
return NULL;
}
rt_uint8_t *my_read_file_to_buffer(char* filename, rt_uint32_t *size)
rt_uint8_t *
my_read_file_to_buffer(char *filename, rt_uint32_t *size)
{
struct stat f_stat;
dfs_file_stat(filename, &f_stat);
struct dfs_fd fd;
rt_uint8_t* buff = rt_malloc(f_stat.st_size);
rt_uint8_t *buff = rt_malloc(f_stat.st_size);
*size = 0;
if (!buff)
{
if (!buff) {
rt_set_errno(-ENOMEM);
return RT_NULL;
}
int ret = dfs_file_open(&fd, filename, O_RDONLY);
if (ret)
{
if (ret) {
rt_free(buff);
rt_set_errno(ret);
return RT_NULL;
@ -192,8 +204,7 @@ rt_uint8_t *my_read_file_to_buffer(char* filename, rt_uint32_t *size)
dfs_file_close(&fd);
if (*size != f_stat.st_size)
{
if (*size != f_stat.st_size) {
rt_free(buff);
rt_set_errno(-EBADF);
return RT_NULL;
@ -202,20 +213,23 @@ rt_uint8_t *my_read_file_to_buffer(char* filename, rt_uint32_t *size)
return buff;
}
void iwasm_help(void)
void
iwasm_help(void)
{
#ifdef WAMR_ENABLE_IWASM_PARAMS
rt_kputs("wrong input: iwasm [-t] [-m] [-s] <*.wasm> <wasm_args ...>\n iwasm [-h]\n");
rt_kputs("wrong input: iwasm [-t] [-m] [-s] <*.wasm> <wasm_args ...>\n"
" iwasm [-h]\n");
rt_kputs("\t -h: show this tips.\n");
rt_kputs("\t -t: show time taking to run this app.\n");
rt_kputs("\t -m: show memory taking to run this app\n");
rt_kputs("\t wasm file name and exec params must behind of all vm-param\n");
#else
rt_kputs("wrong input: iwasm <*.wasm> <wasm_args ...>\n");
#endif /* WAMR_ENABLE_PARAMS */
#endif /* WAMR_ENABLE_PARAMS */
}
int iwasm(int argc, char **argv)
int
iwasm(int argc, char **argv)
{
rt_uint8_t *wasm_file_buf = NULL;
rt_uint32_t wasm_file_size;
@ -224,52 +238,43 @@ int iwasm(int argc, char **argv)
wasm_module_inst_t wasm_module_inst = NULL;
RuntimeInitArgs init_args;
static char error_buf[128] = { 0 };
// avoid stack overflow
/* avoid stack overflow */
#ifdef WAMR_ENABLE_IWASM_PARAMS
int i_arg_begin;
bool show_mem = false;
bool show_stack = false;
bool show_time_exec = false;
for(i_arg_begin=1; i_arg_begin < argc; i_arg_begin++)
{
if (argv[i_arg_begin][0] != '-')
{
for (i_arg_begin = 1; i_arg_begin < argc; i_arg_begin++) {
if (argv[i_arg_begin][0] != '-') {
break;
}
if (argv[i_arg_begin][1] == 'm')
{
if (argv[i_arg_begin][1] == 'm') {
show_mem = true;
}
else if (argv[i_arg_begin][1] == 's')
{
else if (argv[i_arg_begin][1] == 's') {
show_stack = true;
}
else if (argv[i_arg_begin][1] == 't')
{
else if (argv[i_arg_begin][1] == 't') {
show_time_exec = true;
}
else if (argv[i_arg_begin][1] == 'h')
{
else if (argv[i_arg_begin][1] == 'h') {
iwasm_help();
return 0;
}
else if (argv[i_arg_begin][1] == 0x00)
{
else if (argv[i_arg_begin][1] == 0x00) {
continue;
}
else
{
else {
rt_kprintf("[iwasm] unknown param: %s\n", argv[i_arg_begin]);
}
}
#else /* WAMR_ENABLE_PARAMS */
#else /* WAMR_ENABLE_PARAMS */
#define i_arg_begin 1
#endif /* WAMR_ENABLE_PARAMS */
#endif /* WAMR_ENABLE_PARAMS */
if (argc - i_arg_begin < 1)
{
if (argc - i_arg_begin < 1) {
iwasm_help();
return -1;
}
@ -281,56 +286,53 @@ int iwasm(int argc, char **argv)
init_args.mem_alloc_option.allocator.free_func = os_free;
#ifdef WAMR_ENABLE_RTT_EXPORT
init_args.native_symbols = native_export_symbols;
init_args.n_native_symbols = sizeof(native_export_symbols) / sizeof(NativeSymbol);
init_args.n_native_symbols =
sizeof(native_export_symbols) / sizeof(NativeSymbol);
init_args.native_module_name = "env";
#endif /* WAMR_ENABLE_RTT_EXPORT */
#ifdef WAMR_ENABLE_IWASM_PARAMS
#if defined(RT_USING_HEAP) && defined(RT_USING_MEMHEAP_AS_HEAP)
extern long list_memheap(void);
if (show_mem)
{
if (show_mem) {
list_memheap();
}
#else
rt_uint32_t total, max, used;
if (show_mem)
{
if (show_mem) {
rt_memory_info(&total, &used, &max);
}
#endif
rt_thread_t tid;
if (show_stack)
{
if (show_stack) {
tid = rt_thread_self();
printf("thread stack addr: %p, size: %u, sp: %p\n", tid->stack_addr, tid->stack_size, tid->sp);
printf("thread stack addr: %p, size: %u, sp: %p\n", tid->stack_addr,
tid->stack_size, tid->sp);
}
#endif /* WAMR_ENABLE_PARAMS */
#endif /* WAMR_ENABLE_PARAMS */
if (wasm_runtime_full_init(&init_args) == false)
{
if (wasm_runtime_full_init(&init_args) == false) {
rt_kprintf("Init WASM runtime environment failed.\n");
return -1;
}
wasm_file_buf = my_read_file_to_buffer (argv[i_arg_begin], &wasm_file_size);
if (!wasm_file_buf)
{
wasm_file_buf = my_read_file_to_buffer(argv[i_arg_begin], &wasm_file_size);
if (!wasm_file_buf) {
rt_err_t err = rt_get_errno();
rt_kprintf("WASM load file to RAM failed: %d\n", err);
goto fail1;
}
rt_memset(error_buf, 0x00, sizeof(error_buf));
wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size, error_buf, sizeof(error_buf));
if (!wasm_module)
{
wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size, error_buf,
sizeof(error_buf));
if (!wasm_module) {
rt_kprintf("%s\n", error_buf);
goto fail2;
}
rt_memset(error_buf, 0x00, sizeof(error_buf));
wasm_module_inst = wasm_runtime_instantiate(wasm_module, stack_size, heap_size, error_buf, sizeof(error_buf));
if (!wasm_module_inst)
{
wasm_module_inst = wasm_runtime_instantiate(
wasm_module, stack_size, heap_size, error_buf, sizeof(error_buf));
if (!wasm_module_inst) {
rt_kprintf("%s\n", error_buf);
goto fail3;
}
@ -340,35 +342,33 @@ int iwasm(int argc, char **argv)
if (show_time_exec) {
ticks_exec = rt_tick_get();
}
#endif /* WAMR_ENABLE_PARAMS */
#endif /* WAMR_ENABLE_PARAMS */
app_instance_main(wasm_module_inst, argc - i_arg_begin, &argv[i_arg_begin]);
#ifdef WAMR_ENABLE_IWASM_PARAMS
if (show_time_exec)
{
if (show_time_exec) {
ticks_exec = rt_tick_get() - ticks_exec;
printf("[iwasm] execute ticks took: %u [ticks/s = %u]\n", ticks_exec, RT_TICK_PER_SECOND);
printf("[iwasm] execute ticks took: %u [ticks/s = %u]\n", ticks_exec,
RT_TICK_PER_SECOND);
}
#if defined(RT_USING_HEAP) && defined(RT_USING_MEMHEAP_AS_HEAP)
if (show_mem)
{
if (show_mem) {
list_memheap();
}
#else
rt_uint32_t total_after, max_after, used_after;
if (show_mem)
{
if (show_mem) {
rt_memory_info(&total_after, &used_after, &max_after);
rt_kprintf("[iwasm] memory took: %u\n", used_after - used);
}
#endif
if (show_stack)
{
printf("[iwasm] thread stack addr: %p, size: %u, sp: %p\n", tid->stack_addr, tid->stack_size, tid->sp);
if (show_stack) {
printf("[iwasm] thread stack addr: %p, size: %u, sp: %p\n",
tid->stack_addr, tid->stack_size, tid->sp);
}
#endif /* WAMR_ENABLE_PARAMS */
#endif /* WAMR_ENABLE_PARAMS */
/* destroy the module instance */
wasm_runtime_deinstantiate(wasm_module_inst);

View File

@ -15,6 +15,7 @@ static char **app_argv;
#define MODULE_PATH ("--module-path=")
/* clang-format off */
static int
print_help()
{
@ -47,6 +48,7 @@ print_help()
#endif
return 1;
}
/* clang-format on */
static void *
app_instance_main(wasm_module_inst_t module_inst)
@ -113,37 +115,37 @@ split_string(char *str, int *count)
static void *
app_instance_repl(wasm_module_inst_t module_inst)
{
char buffer[4096];
char *cmd;
size_t n;
char buffer[4096];
char *cmd;
size_t n;
while ((printf("webassembly> "),
cmd = fgets(buffer, sizeof(buffer), stdin)) != NULL) {
bh_assert(cmd);
n = strlen(cmd);
if (cmd[n - 1] == '\n') {
if (n == 1)
continue;
else
cmd[n - 1] = '\0';
}
if (!strcmp(cmd, "__exit__")) {
printf("exit repl mode\n");
break;
}
app_argv = split_string(cmd, &app_argc);
if (app_argv == NULL) {
LOG_ERROR("Wasm prepare param failed: split string failed.\n");
break;
}
if (app_argc != 0) {
wasm_application_execute_func(module_inst, app_argv[0],
app_argc - 1, app_argv + 1);
}
free(app_argv);
}
while ((printf("webassembly> "), cmd = fgets(buffer, sizeof(buffer), stdin))
!= NULL) {
bh_assert(cmd);
n = strlen(cmd);
if (cmd[n - 1] == '\n') {
if (n == 1)
continue;
else
cmd[n - 1] = '\0';
}
if (!strcmp(cmd, "__exit__")) {
printf("exit repl mode\n");
break;
}
app_argv = split_string(cmd, &app_argc);
if (app_argv == NULL) {
LOG_ERROR("Wasm prepare param failed: split string failed.\n");
break;
}
if (app_argc != 0) {
wasm_application_execute_func(module_inst, app_argv[0],
app_argc - 1, app_argv + 1);
}
free(app_argv);
}
return NULL;
return NULL;
}
#if WASM_ENABLE_LIBC_WASI != 0
@ -175,7 +177,7 @@ static char global_heap_buf[10 * 1024 * 1024] = { 0 };
static char *
handle_module_path(const char *module_path)
{
// next character after =
/* next character after '=' */
return (strchr(module_path, '=')) + 1;
}
@ -235,7 +237,7 @@ main(int argc, char *argv[])
uint32 env_list_size = 0;
#endif
/* Process options. */
/* Process options. */
for (argc--, argv++; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
if (!strcmp(argv[0], "-f") || !strcmp(argv[0], "--function")) {
argc--, argv++;
@ -348,7 +350,7 @@ main(int argc, char *argv[])
/* load WASM byte buffer from WASM bin file */
if (!(wasm_file_buf =
(uint8 *)bh_read_file_to_buffer(wasm_file, &wasm_file_size)))
(uint8 *)bh_read_file_to_buffer(wasm_file, &wasm_file_size)))
goto fail1;
#if WASM_ENABLE_MULTI_MODULE != 0
@ -369,8 +371,8 @@ main(int argc, char *argv[])
/* instantiate the module */
if (!(wasm_module_inst =
wasm_runtime_instantiate(wasm_module, stack_size, heap_size,
error_buf, sizeof(error_buf)))) {
wasm_runtime_instantiate(wasm_module, stack_size, heap_size,
error_buf, sizeof(error_buf)))) {
printf("%s\n", error_buf);
goto fail3;
}

View File

@ -57,10 +57,10 @@ static char **app_argv;
* @return true if the main function is called, false otherwise.
*/
bool
wasm_application_execute_main(wasm_module_inst_t module_inst,
int argc, char *argv[]);
wasm_application_execute_main(wasm_module_inst_t module_inst, int argc,
char *argv[]);
static void*
static void *
app_instance_main(wasm_module_inst_t module_inst)
{
const char *exception;
@ -69,15 +69,15 @@ app_instance_main(wasm_module_inst_t module_inst)
unsigned argv[2] = { 0 };
if (wasm_runtime_lookup_function(module_inst, "main", NULL)
|| wasm_runtime_lookup_function(module_inst,
"__main_argc_argv", NULL)) {
|| wasm_runtime_lookup_function(module_inst, "__main_argc_argv",
NULL)) {
LOG_VERBOSE("Calling main funciton\n");
wasm_application_execute_main(module_inst, app_argc, app_argv);
}
else if ((func = wasm_runtime_lookup_function(module_inst,
"app_main", NULL))) {
exec_env = wasm_runtime_create_exec_env(module_inst,
CONFIG_APP_HEAP_SIZE);
else if ((func = wasm_runtime_lookup_function(module_inst, "app_main",
NULL))) {
exec_env =
wasm_runtime_create_exec_env(module_inst, CONFIG_APP_HEAP_SIZE);
if (!exec_env) {
os_printf("Create exec env failed\n");
return NULL;
@ -110,15 +110,17 @@ static char global_heap_buf[CONFIG_GLOBAL_HEAP_BUF_SIZE] = { 0 };
/*
esp32_technical_reference_manual:
"
The capacity of Internal SRAM 1 is 128 KB. Either CPU can read and write this memory at addresses
0x3FFE_0000 ~ 0x3FFF_FFFF of the data bus, and also at addresses 0x400A_0000 ~ 0x400B_FFFF of the
instruction bus.
The capacity of Internal SRAM 1 is 128 KB. Either CPU can read and write this
memory at addresses 0x3FFE_0000 ~ 0x3FFF_FFFF of the data bus, and also at
addresses 0x400A_0000 ~ 0x400B_FFFF of the instruction bus.
"
The custom linker script defines dram0_1_seg and map it to 0x400A_0000 ~ 0x400B_FFFF for instruction bus access.
Here we define the buffer that will be placed to dram0_1_seg.
The custom linker script defines dram0_1_seg and map it to 0x400A_0000 ~
0x400B_FFFF for instruction bus access. Here we define the buffer that will be
placed to dram0_1_seg.
*/
static char esp32_executable_memory_buf[100 * 1024] __attribute__((section (".aot_code_buf"))) = { 0 };
static char esp32_executable_memory_buf[100 * 1024]
__attribute__((section(".aot_code_buf"))) = { 0 };
/* the poll allocator for executable memory */
static mem_allocator_t esp32_exec_mem_pool_allocator;
@ -127,8 +129,8 @@ static int
esp32_exec_mem_init()
{
if (!(esp32_exec_mem_pool_allocator =
mem_allocator_create(esp32_executable_memory_buf,
sizeof(esp32_executable_memory_buf))))
mem_allocator_create(esp32_executable_memory_buf,
sizeof(esp32_executable_memory_buf))))
return -1;
return 0;
@ -153,7 +155,8 @@ esp32_exec_mem_free(void *addr)
}
#endif /* end of #ifdef CONFIG_BOARD_ESP32 */
void iwasm_main(void *arg1, void *arg2, void *arg3)
void
iwasm_main(void *arg1, void *arg2, void *arg3)
{
int start, end;
start = k_uptime_get_32();
@ -167,9 +170,9 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
int log_verbose_level = 2;
#endif
(void) arg1;
(void) arg2;
(void) arg3;
(void)arg1;
(void)arg2;
(void)arg3;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
@ -198,7 +201,7 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
#endif
/* load WASM byte buffer from byte buffer of include file */
wasm_file_buf = (uint8*) wasm_test_file;
wasm_file_buf = (uint8 *)wasm_test_file;
wasm_file_size = sizeof(wasm_test_file);
/* load WASM module */
@ -213,11 +216,9 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
}
/* instantiate the module */
if (!(wasm_module_inst = wasm_runtime_instantiate(wasm_module,
CONFIG_APP_STACK_SIZE,
CONFIG_APP_HEAP_SIZE,
error_buf,
sizeof(error_buf)))) {
if (!(wasm_module_inst = wasm_runtime_instantiate(
wasm_module, CONFIG_APP_STACK_SIZE, CONFIG_APP_HEAP_SIZE,
error_buf, sizeof(error_buf)))) {
printf("%s\n", error_buf);
goto fail2;
}
@ -253,16 +254,16 @@ fail1:
K_THREAD_STACK_DEFINE(iwasm_main_thread_stack, MAIN_THREAD_STACK_SIZE);
static struct k_thread iwasm_main_thread;
bool iwasm_init(void)
bool
iwasm_init(void)
{
k_tid_t tid = k_thread_create(&iwasm_main_thread, iwasm_main_thread_stack,
MAIN_THREAD_STACK_SIZE,
iwasm_main, NULL, NULL, NULL,
MAIN_THREAD_PRIORITY, 0, K_NO_WAIT);
k_tid_t tid = k_thread_create(
&iwasm_main_thread, iwasm_main_thread_stack, MAIN_THREAD_STACK_SIZE,
iwasm_main, NULL, NULL, NULL, MAIN_THREAD_PRIORITY, 0, K_NO_WAIT);
return tid ? true : false;
}
void main(void)
void
main(void)
{
iwasm_init();
}

View File

@ -4,38 +4,38 @@
*/
unsigned char __aligned(4) wasm_test_file[] = {
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x10, 0x03, 0x60,
0x01, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x01,
0x7F, 0x00, 0x02, 0x31, 0x04, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x70, 0x75,
0x74, 0x73, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x61, 0x6C,
0x6C, 0x6F, 0x63, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x70, 0x72,
0x69, 0x6E, 0x74, 0x66, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x66,
0x72, 0x65, 0x65, 0x00, 0x02, 0x03, 0x02, 0x01, 0x01, 0x04, 0x05, 0x01,
0x70, 0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x12, 0x03,
0x7F, 0x01, 0x41, 0xC0, 0x01, 0x0B, 0x7F, 0x00, 0x41, 0x3A, 0x0B, 0x7F,
0x00, 0x41, 0xC0, 0x01, 0x0B, 0x07, 0x2C, 0x04, 0x06, 0x6D, 0x65, 0x6D,
0x6F, 0x72, 0x79, 0x02, 0x00, 0x04, 0x6D, 0x61, 0x69, 0x6E, 0x00, 0x04,
0x0A, 0x5F, 0x5F, 0x64, 0x61, 0x74, 0x61, 0x5F, 0x65, 0x6E, 0x64, 0x03,
0x01, 0x0B, 0x5F, 0x5F, 0x68, 0x65, 0x61, 0x70, 0x5F, 0x62, 0x61, 0x73,
0x65, 0x03, 0x02, 0x0A, 0xB1, 0x01, 0x01, 0xAE, 0x01, 0x01, 0x03, 0x7F,
0x23, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x20, 0x6B, 0x22, 0x02, 0x24,
0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x9B, 0x80, 0x80, 0x80, 0x00, 0x10,
0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x02, 0x40, 0x02, 0x40, 0x41, 0x10,
0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x22, 0x03, 0x0D, 0x00, 0x41, 0xA8,
0x80, 0x80, 0x80, 0x00, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41,
0x7F, 0x21, 0x04, 0x0C, 0x01, 0x0B, 0x20, 0x02, 0x20, 0x03, 0x36, 0x02,
0x10, 0x41, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x02, 0x41, 0x10, 0x6A,
0x10, 0x82, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41, 0x00, 0x21, 0x04, 0x20,
0x03, 0x41, 0x04, 0x6A, 0x41, 0x00, 0x2F, 0x00, 0x91, 0x80, 0x80, 0x80,
0x00, 0x3B, 0x00, 0x00, 0x20, 0x03, 0x41, 0x00, 0x28, 0x00, 0x8D, 0x80,
0x80, 0x80, 0x00, 0x36, 0x00, 0x00, 0x20, 0x02, 0x20, 0x03, 0x36, 0x02,
0x00, 0x41, 0x93, 0x80, 0x80, 0x80, 0x00, 0x20, 0x02, 0x10, 0x82, 0x80,
0x80, 0x80, 0x00, 0x1A, 0x20, 0x03, 0x10, 0x83, 0x80, 0x80, 0x80, 0x00,
0x0B, 0x20, 0x02, 0x41, 0x20, 0x6A, 0x24, 0x80, 0x80, 0x80, 0x80, 0x00,
0x20, 0x04, 0x0B, 0x0B, 0x40, 0x01, 0x00, 0x41, 0x00, 0x0B, 0x3A, 0x62,
0x75, 0x66, 0x20, 0x70, 0x74, 0x72, 0x3A, 0x20, 0x25, 0x70, 0x0A, 0x00,
0x31, 0x32, 0x33, 0x34, 0x0A, 0x00, 0x62, 0x75, 0x66, 0x3A, 0x20, 0x25,
0x73, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C,
0x64, 0x21, 0x00, 0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x20, 0x62, 0x75,
0x66, 0x20, 0x66, 0x61, 0x69, 0x6C, 0x65, 0x64, 0x00
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x10, 0x03, 0x60,
0x01, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x01,
0x7F, 0x00, 0x02, 0x31, 0x04, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x70, 0x75,
0x74, 0x73, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x61, 0x6C,
0x6C, 0x6F, 0x63, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x70, 0x72,
0x69, 0x6E, 0x74, 0x66, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x66,
0x72, 0x65, 0x65, 0x00, 0x02, 0x03, 0x02, 0x01, 0x01, 0x04, 0x05, 0x01,
0x70, 0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x12, 0x03,
0x7F, 0x01, 0x41, 0xC0, 0x01, 0x0B, 0x7F, 0x00, 0x41, 0x3A, 0x0B, 0x7F,
0x00, 0x41, 0xC0, 0x01, 0x0B, 0x07, 0x2C, 0x04, 0x06, 0x6D, 0x65, 0x6D,
0x6F, 0x72, 0x79, 0x02, 0x00, 0x04, 0x6D, 0x61, 0x69, 0x6E, 0x00, 0x04,
0x0A, 0x5F, 0x5F, 0x64, 0x61, 0x74, 0x61, 0x5F, 0x65, 0x6E, 0x64, 0x03,
0x01, 0x0B, 0x5F, 0x5F, 0x68, 0x65, 0x61, 0x70, 0x5F, 0x62, 0x61, 0x73,
0x65, 0x03, 0x02, 0x0A, 0xB1, 0x01, 0x01, 0xAE, 0x01, 0x01, 0x03, 0x7F,
0x23, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x20, 0x6B, 0x22, 0x02, 0x24,
0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x9B, 0x80, 0x80, 0x80, 0x00, 0x10,
0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x02, 0x40, 0x02, 0x40, 0x41, 0x10,
0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x22, 0x03, 0x0D, 0x00, 0x41, 0xA8,
0x80, 0x80, 0x80, 0x00, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41,
0x7F, 0x21, 0x04, 0x0C, 0x01, 0x0B, 0x20, 0x02, 0x20, 0x03, 0x36, 0x02,
0x10, 0x41, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x02, 0x41, 0x10, 0x6A,
0x10, 0x82, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41, 0x00, 0x21, 0x04, 0x20,
0x03, 0x41, 0x04, 0x6A, 0x41, 0x00, 0x2F, 0x00, 0x91, 0x80, 0x80, 0x80,
0x00, 0x3B, 0x00, 0x00, 0x20, 0x03, 0x41, 0x00, 0x28, 0x00, 0x8D, 0x80,
0x80, 0x80, 0x00, 0x36, 0x00, 0x00, 0x20, 0x02, 0x20, 0x03, 0x36, 0x02,
0x00, 0x41, 0x93, 0x80, 0x80, 0x80, 0x00, 0x20, 0x02, 0x10, 0x82, 0x80,
0x80, 0x80, 0x00, 0x1A, 0x20, 0x03, 0x10, 0x83, 0x80, 0x80, 0x80, 0x00,
0x0B, 0x20, 0x02, 0x41, 0x20, 0x6A, 0x24, 0x80, 0x80, 0x80, 0x80, 0x00,
0x20, 0x04, 0x0B, 0x0B, 0x40, 0x01, 0x00, 0x41, 0x00, 0x0B, 0x3A, 0x62,
0x75, 0x66, 0x20, 0x70, 0x74, 0x72, 0x3A, 0x20, 0x25, 0x70, 0x0A, 0x00,
0x31, 0x32, 0x33, 0x34, 0x0A, 0x00, 0x62, 0x75, 0x66, 0x3A, 0x20, 0x25,
0x73, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C,
0x64, 0x21, 0x00, 0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x20, 0x62, 0x75,
0x66, 0x20, 0x66, 0x61, 0x69, 0x6C, 0x65, 0x64, 0x00
};

View File

@ -6,7 +6,8 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
char *buf;