Use one libc wrapper copy for sgx and other platforms (#107)

And remove bh_printf macro for other platform header files
This commit is contained in:
wenyongh 2019-08-28 15:19:52 +08:00 committed by GitHub
parent 5c69543c54
commit 5257dd8a48
13 changed files with 26 additions and 1077 deletions

View File

@ -414,7 +414,7 @@ sprintf_out(int c, struct str_context *ctx)
static int static int
printf_out(int c, struct str_context *ctx) printf_out(int c, struct str_context *ctx)
{ {
printf("%c", c); bh_printf("%c", c);
ctx->count++; ctx->count++;
return c; return c;
} }
@ -542,13 +542,13 @@ _puts_wrapper(int32 str_offset)
return 0; return 0;
str = addr_app_to_native(str_offset); str = addr_app_to_native(str_offset);
return printf("%s\n", str); return bh_printf("%s\n", str);
} }
static int static int
_putchar_wrapper(int c) _putchar_wrapper(int c)
{ {
printf("%c", c); bh_printf("%c", c);
return 1; return 1;
} }
@ -699,7 +699,10 @@ _strcpy_wrapper(int32 dst_offset, int32 src_offset)
dst = addr_app_to_native(dst_offset); dst = addr_app_to_native(dst_offset);
src = addr_app_to_native(src_offset); src = addr_app_to_native(src_offset);
strcpy(dst, src); while (*src != '\0')
*dst++ = *src++;
*dst = '\0';
return dst_offset; return dst_offset;
} }
@ -842,7 +845,7 @@ static void
_llvm_stackrestore_wrapper(uint32 llvm_stack) _llvm_stackrestore_wrapper(uint32 llvm_stack)
{ {
wasm_module_inst_t module_inst = get_module_inst(); wasm_module_inst_t module_inst = get_module_inst();
printf("_llvm_stackrestore called!\n"); bh_printf("_llvm_stackrestore called!\n");
wasm_runtime_set_llvm_stack(module_inst, llvm_stack); wasm_runtime_set_llvm_stack(module_inst, llvm_stack);
} }
@ -850,7 +853,7 @@ static uint32
_llvm_stacksave_wrapper() _llvm_stacksave_wrapper()
{ {
wasm_module_inst_t module_inst = get_module_inst(); wasm_module_inst_t module_inst = get_module_inst();
printf("_llvm_stacksave called!\n"); bh_printf("_llvm_stacksave called!\n");
return wasm_runtime_get_llvm_stack(module_inst); return wasm_runtime_get_llvm_stack(module_inst);
} }
@ -905,13 +908,13 @@ nullFunc_X_wrapper(int32 code)
static void static void
print_i32_wrapper(int i32) print_i32_wrapper(int i32)
{ {
printf("%d\n", i32); bh_printf("%d\n", i32);
} }
static void static void
print_wrapper(int i32) print_wrapper(int i32)
{ {
printf("%d\n", i32); bh_printf("%d\n", i32);
} }
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@ set (WASM_LIBC_DIR ${CMAKE_CURRENT_LIST_DIR})
include_directories(${WASM_LIBC_DIR}) include_directories(${WASM_LIBC_DIR})
file (GLOB_RECURSE source_all ${WASM_LIBC_DIR}/libc_wrapper.c) file (GLOB_RECURSE source_all ${WASM_LIBC_DIR}/*.c)
set (WASM_LIBC_SOURCE ${source_all}) set (WASM_LIBC_SOURCE ${source_all})

View File

@ -1,23 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set (WASM_LIBC_DIR ${CMAKE_CURRENT_LIST_DIR})
include_directories(${WASM_LIBC_DIR})
file (GLOB_RECURSE source_all ${WASM_LIBC_DIR}/libc_wrapper_sgx.c)
set (WASM_LIBC_SOURCE ${source_all})

View File

@ -26,6 +26,7 @@ add_definitions(-DUSE_SGX=1)
add_definitions(-DOPS_INPUT_OUTPUT=1) add_definitions(-DOPS_INPUT_OUTPUT=1)
add_definitions(-DOPS_UNSAFE_BUFFERS=0) add_definitions(-DOPS_UNSAFE_BUFFERS=0)
add_definitions(-DWASM_ENABLE_LOG=0) add_definitions(-DWASM_ENABLE_LOG=0)
add_definitions(-Dbh_printf=bh_printf_sgx)
# Enable repl mode if want to test spec cases # Enable repl mode if want to test spec cases
# add_definitions(-DWASM_ENABLE_REPL) # add_definitions(-DWASM_ENABLE_REPL)
@ -71,19 +72,19 @@ include (../../runtime/platform/${PLATFORM}/platform.cmake)
include (../../runtime/utils/utils.cmake) include (../../runtime/utils/utils.cmake)
include (../../runtime/vmcore-wasm/vmcore.cmake) include (../../runtime/vmcore-wasm/vmcore.cmake)
include (../../lib/native/base/wasm_lib_base.cmake) include (../../lib/native/base/wasm_lib_base.cmake)
include (../../lib/native/libc/wasm_libc_sgx.cmake) include (../../lib/native/libc/wasm_libc.cmake)
include (${SHARED_LIB_DIR}/platform/${PLATFORM}/shared_platform.cmake) include (${SHARED_LIB_DIR}/platform/${PLATFORM}/shared_platform.cmake)
include (${SHARED_LIB_DIR}/mem-alloc/mem_alloc.cmake) include (${SHARED_LIB_DIR}/mem-alloc/mem_alloc.cmake)
include (${SHARED_LIB_DIR}/utils/shared_utils.cmake)
#add_executable (iwasm main.c ext_lib_export.c)
add_library (vmlib add_library (vmlib
ext_lib_export.c
${WASM_PLATFORM_LIB_SOURCE} ${WASM_PLATFORM_LIB_SOURCE}
${WASM_UTILS_LIB_SOURCE} ${WASM_UTILS_LIB_SOURCE}
${VMCORE_LIB_SOURCE} ${VMCORE_LIB_SOURCE}
${WASM_LIB_BASE_DIR}/base_lib_export.c ${WASM_LIB_BASE_DIR}/base_lib_export.c
${WASM_LIBC_SOURCE} ${WASM_LIBC_SOURCE}
${PLATFORM_SHARED_SOURCE} ${PLATFORM_SHARED_SOURCE}
${MEM_ALLOC_SHARED_SOURCE}) ${MEM_ALLOC_SHARED_SOURCE}
${UTILS_SHARED_SOURCE})
add_library (extlib ext_lib_export.c)

View File

@ -26,9 +26,7 @@
#define DEFAULT_MEM_ALLOCATOR MEM_ALLOCATOR_EMS #define DEFAULT_MEM_ALLOCATOR MEM_ALLOCATOR_EMS
/* Beihai log system */ /* Beihai log system */
#ifndef BEIHAI_ENABLE_LOG
#define BEIHAI_ENABLE_LOG 1 #define BEIHAI_ENABLE_LOG 1
#endif
/* Beihai debugger support */ /* Beihai debugger support */
#define BEIHAI_ENABLE_TOOL_AGENT 1 #define BEIHAI_ENABLE_TOOL_AGENT 1
@ -129,3 +127,7 @@
/* Default base offset of external memory space */ /* Default base offset of external memory space */
#define DEFAULT_EXT_MEM_BASE_OFFSET (-2 * BH_GB) #define DEFAULT_EXT_MEM_BASE_OFFSET (-2 * BH_GB)
#ifndef bh_printf
#define bh_printf printf
#endif

View File

@ -52,8 +52,6 @@ typedef int64_t int64;
#define wa_free bh_free #define wa_free bh_free
#define wa_strdup bh_strdup #define wa_strdup bh_strdup
#define bh_printf printf
typedef aos_task_t korp_thread; typedef aos_task_t korp_thread;
typedef korp_thread *korp_tid; typedef korp_thread *korp_tid;
typedef aos_task_t *aos_tid_t; typedef aos_task_t *aos_tid_t;

View File

@ -52,7 +52,7 @@ void bh_set_print_function(bh_print_function_t pf)
print_function = pf; print_function = pf;
} }
int bh_printf(const char *message, ...) int bh_printf_sgx(const char *message, ...)
{ {
if (print_function != NULL) { if (print_function != NULL) {
char msg[FIXED_BUFFER_SIZE] = { '\0' }; char msg[FIXED_BUFFER_SIZE] = { '\0' };

View File

@ -38,7 +38,7 @@
extern "C" { extern "C" {
#endif #endif
extern int bh_printf(const char *message, ...); extern int bh_printf_sgx(const char *message, ...);
typedef uint64_t uint64; typedef uint64_t uint64;
typedef int64_t int64; typedef int64_t int64;

View File

@ -77,8 +77,6 @@ typedef void* (*thread_start_routine_t)(void*);
#define wa_free bh_free #define wa_free bh_free
#define wa_strdup bh_strdup #define wa_strdup bh_strdup
#define bh_printf printf
int snprintf(char *buffer, size_t count, const char *format, ...); int snprintf(char *buffer, size_t count, const char *format, ...);
double fmod(double x, double y); double fmod(double x, double y);
float fmodf(float x, float y); float fmodf(float x, float y);

View File

@ -75,8 +75,6 @@ typedef void* (*thread_start_routine_t)(void*);
#define wa_free bh_free #define wa_free bh_free
#define wa_strdup bh_strdup #define wa_strdup bh_strdup
#define bh_printf printf
int snprintf(char *buffer, size_t count, const char *format, ...); int snprintf(char *buffer, size_t count, const char *format, ...);
double fmod(double x, double y); double fmod(double x, double y);
float fmodf(float x, float y); float fmodf(float x, float y);

View File

@ -78,8 +78,6 @@ typedef void* (*thread_start_routine_t)(void*);
#define wa_malloc bh_malloc #define wa_malloc bh_malloc
#define wa_free bh_free #define wa_free bh_free
#define bh_printf printf
/* Unit test framework is based on C++, where the declaration of /* Unit test framework is based on C++, where the declaration of
snprintf is different. */ snprintf is different. */
#ifndef __cplusplus #ifndef __cplusplus