[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Minios-devel] [UNIKRAFT/LIBWAMR PATCH v4 4/4] Add various patches to (a) make wamr build against pthread-embedded, (b) use wasm's log and (c) patch into wamr's linux's main loop.
Reviewed-by: Jia He <justin.he@xxxxxxx> --- Cheers, Justin (Jia He) On 2019/10/11 17:06, Felipe Huici wrote: Signed-off-by: Felipe Huici <felipe.huici@xxxxxxxxx> --- ...-fix-pthread-embedded-pthread-t-type.patch | 15 +++ ...-fix-pthread-embedded-pthread-t-type.patch | 16 +++ ...thread-use-wasm-log-insteadof-bh-log.patch | 11 ++ patches/0004-add-math-h.patch | 11 ++ patches/0005-adapt-main-c-to-unikraft.patch | 116 ++++++++++++++++++ 5 files changed, 169 insertions(+) create mode 100644 patches/0001-wasm-log-fix-pthread-embedded-pthread-t-type.patch create mode 100644 patches/0002-bh-thread-fix-pthread-embedded-pthread-t-type.patch create mode 100644 patches/0003-bh-thread-use-wasm-log-insteadof-bh-log.patch create mode 100644 patches/0004-add-math-h.patch create mode 100644 patches/0005-adapt-main-c-to-unikraft.patch diff --git a/patches/0001-wasm-log-fix-pthread-embedded-pthread-t-type.patch b/patches/0001-wasm-log-fix-pthread-embedded-pthread-t-type.patch new file mode 100644 index 0000000..8630539 --- /dev/null +++ b/patches/0001-wasm-log-fix-pthread-embedded-pthread-t-type.patch @@ -0,0 +1,15 @@ +--- /core/iwasm/runtime/utils/wasm_log.c.orig 2019-07-30 10:01:46.715217329 +0200 ++++ /core/iwasm/runtime/utils/wasm_log.c 2019-07-30 10:07:26.891746359 +0200 +@@ -57,8 +57,11 @@ + /* Try to own the log stream and start the log output. */ + ws_mutex_lock (&log_stream_lock); + self = ws_self_thread (); ++#ifdef CONFIG_LIBPTHREAD_EMBEDDED ++ wasm_printf ("[%X]: ", (int)self.p); ++#else + wasm_printf ("[%X]: ", (int)self); +- ++#endif + return true; + } + diff --git a/patches/0002-bh-thread-fix-pthread-embedded-pthread-t-type.patch b/patches/0002-bh-thread-fix-pthread-embedded-pthread-t-type.patch new file mode 100644 index 0000000..7101ce2 --- /dev/null +++ b/patches/0002-bh-thread-fix-pthread-embedded-pthread-t-type.patch @@ -0,0 +1,16 @@ +--- /core/shared-lib/platform/linux/bh_thread.c.orig 2019-07-30 10:08:21.243191688 +0200 ++++ /core/shared-lib/platform/linux/bh_thread.c 2019-07-30 10:08:55.110846278 +0200 +@@ -93,8 +93,12 @@ + bh_assert(tid); + bh_assert(start); + ++#ifdef CONFIG_LIBPTHREAD_EMBEDDED ++ tid->p = INVALID_THREAD_ID; ++#else + *tid = INVALID_THREAD_ID; +- ++#endif ++ + pthread_attr_init(&tattr); + pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); + if (pthread_attr_setstacksize(&tattr, stack_size) != 0) { diff --git a/patches/0003-bh-thread-use-wasm-log-insteadof-bh-log.patch b/patches/0003-bh-thread-use-wasm-log-insteadof-bh-log.patch new file mode 100644 index 0000000..6a5e923 --- /dev/null +++ b/patches/0003-bh-thread-use-wasm-log-insteadof-bh-log.patch @@ -0,0 +1,11 @@ +--- /core/shared-lib/platform/linux/bh_thread.c.orig 2019-07-30 11:10:57.884821508 +0200 ++++ /core/shared-lib/platform/linux/bh_thread.c 2019-07-30 11:11:54.492244787 +0200 +@@ -16,7 +16,7 @@ + + #include "bh_thread.h" + #include "bh_assert.h" +-#include "bh_log.h" ++#include "wasm_log.h" + #include "bh_memory.h" + #include <stdio.h> + #include <stdlib.h> diff --git a/patches/0004-add-math-h.patch b/patches/0004-add-math-h.patch new file mode 100644 index 0000000..4a01bbc --- /dev/null +++ b/patches/0004-add-math-h.patch @@ -0,0 +1,11 @@ +--- a/core/iwasm/runtime/vmcore-wasm/wasm_interp.c 2019-10-04 19:29:40.818609262 +0200 ++++ b/core/iwasm/runtime/vmcore-wasm/wasm_interp.c 2019-10-04 19:29:52.050488455 +0200 +@@ -22,6 +22,8 @@ + #include "wasm_log.h" + #include "wasm_memory.h" + ++#include <math.h> ++ + typedef int32 CellType_I32; + typedef int64 CellType_I64; + typedef float32 CellType_F32; diff --git a/patches/0005-adapt-main-c-to-unikraft.patch b/patches/0005-adapt-main-c-to-unikraft.patch new file mode 100644 index 0000000..c8f73e5 --- /dev/null +++ b/patches/0005-adapt-main-c-to-unikraft.patch @@ -0,0 +1,116 @@ +--- a/core/iwasm/products/linux/main.c 2019-09-09 14:51:40.000000000 +0200 ++++ b/core/iwasm/products/linux/main.c 2019-10-11 10:57:38.858381930 +0200 +@@ -28,6 +28,8 @@ + #include "wasm_memory.h" + #include "bh_memory.h" + ++#include <uk/plat/memory.h> ++ + static int app_argc; + static char **app_argv; + +@@ -158,7 +160,7 @@ + return NULL; + } + +-#define USE_GLOBAL_HEAP_BUF 0 ++#define USE_GLOBAL_HEAP_BUF 1 + + #if USE_GLOBAL_HEAP_BUF != 0 + static char global_heap_buf[10 * 1024 * 1024] = { 0 }; +@@ -177,15 +179,11 @@ + int log_verbose_level = 1; + #endif + bool is_repl_mode = false; +- ++ + /* Process options. */ + for (argc--, argv++; argc > 0 && argv[0][0] == '-'; argc--, argv++) { + if (!strcmp(argv[0], "-f") || !strcmp(argv[0], "--function")) { + argc--, argv++; +- if (argc < 2) { +- print_help(); +- return 0; +- } + func_name = argv[0]; + } + #if WASM_ENABLE_LOG != 0 +@@ -197,13 +195,8 @@ + #endif + else if (!strcmp(argv[0], "--repl")) + is_repl_mode = true; +- else +- return print_help(); + } + +- if (argc == 0) +- return print_help(); +- + wasm_file = argv[0]; + app_argc = argc; + app_argv = argv; +@@ -227,35 +220,39 @@ + + wasm_log_set_verbose_level(log_verbose_level); + +- /* load WASM byte buffer from WASM bin file */ +- if (!(wasm_file_buf = (uint8*) bh_read_file_to_buffer(wasm_file, +- &wasm_file_size))) +- goto fail2; +- +- /* load WASM module */ +- if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size, +- error_buf, sizeof(error_buf)))) { +- wasm_printf("%s\n", error_buf); +- goto fail3; +- } +- +- /* instantiate the module */ +- if (!(wasm_module_inst = wasm_runtime_instantiate(wasm_module, +- 64 * 1024, /* stack size */ +- 64 * 1024, /* heap size */ +- error_buf, +- sizeof(error_buf)))) { +- wasm_printf("%s\n", error_buf); +- goto fail4; ++ /* load from initrd */ ++ struct ukplat_memregion_desc img; ++ if (ukplat_memregion_find_initrd0(&img) >= 0) { ++ wasm_file_buf = (uint8*)img.base; ++ wasm_file_size = img.len; ++ ++ /* load WASM module */ ++ if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size, ++ error_buf, sizeof(error_buf)))) { ++ wasm_printf("%s\n", error_buf); ++ goto fail3; ++ } ++ ++ /* instantiate the module */ ++ if (!(wasm_module_inst = wasm_runtime_instantiate(wasm_module, ++ 64 * 1024, /* stack size */ ++ 64 * 1024, /* heap size */ ++ error_buf, ++ sizeof(error_buf)))) { ++ wasm_printf("%s\n", error_buf); ++ goto fail4; ++ } ++ app_instance_main(wasm_module_inst); ++ } ++ else if (is_repl_mode) { ++ printf("Entering REPL mode...\n"); ++ app_instance_repl(wasm_module_inst); + } +- +- if (is_repl_mode) +- app_instance_repl(wasm_module_inst); + else if (func_name) + app_instance_func(wasm_module_inst, func_name); + else +- app_instance_main(wasm_module_inst); +- ++ printf("warning: did not select --repl nor -initrd mode!\n"); ++ + /* destroy the module instance */ + wasm_runtime_deinstantiate(wasm_module_inst); + -- --- Cheers, Justin (Jia He) _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |