Fix some compile warnings and update document (#670)

And implement clock_gettime wrapper for libc-built.
This commit is contained in:
Wenyong Huang 2021-07-22 19:39:53 +08:00 committed by GitHub
parent 04e7afe55d
commit 28f104036c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 11 deletions

View File

@ -1674,7 +1674,7 @@ wasm_set_wasi_root_dir(const char *root_dir)
if (!(path = realpath(root_dir, resolved_path)))
return false;
strncpy(wasi_root_dir, path, sizeof(wasi_root_dir));
snprintf(wasi_root_dir, sizeof(wasi_root_dir), "%s", path);
return true;
}

View File

@ -1068,6 +1068,28 @@ __cxa_throw_wrapper(wasm_exec_env_t exec_env,
wasm_runtime_set_exception(module_inst, buf);
}
struct timespec_app {
int64 tv_sec;
int32 tv_nsec;
};
static uint32
clock_gettime_wrapper(wasm_exec_env_t exec_env,
uint32 clk_id, struct timespec_app *ts_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
uint64 time;
if (!validate_native_addr(ts_app, sizeof(struct timespec_app)))
return (uint32)-1;
time = os_time_get_boot_microsecond();
ts_app->tv_sec = time / 1000000;
ts_app->tv_nsec = (time % 1000000) * 1000;
return (uint32)0;
}
#if WASM_ENABLE_SPEC_TEST != 0
static void
print_wrapper(wasm_exec_env_t exec_env)
@ -1167,6 +1189,7 @@ static NativeSymbol native_symbols_libc_builtin[] = {
REG_NATIVE_FUNC(__cxa_allocate_exception, "(i)i"),
REG_NATIVE_FUNC(__cxa_begin_catch, "(*)"),
REG_NATIVE_FUNC(__cxa_throw, "(**i)"),
REG_NATIVE_FUNC(clock_gettime, "(i*)i"),
};
#if WASM_ENABLE_SPEC_TEST != 0

View File

@ -20,7 +20,8 @@ The script `runtime_lib.cmake` defines a number of variables for configuring the
- **WAMR_BUILD_PLATFORM**: set the target platform. It can be set to any platform name (folder name) under folder [core/shared/platform](../core/shared/platform).
- **WAMR_BUILD_TARGET**: set the target CPU architecture. Current supported targets are: X86_64, X86_32, AARCH64, ARM, THUMB, XTENSA, RISCV64 and MIPS.
- For ARM and THUMB, the format is \<arch>\[\<sub-arch>]\[_VFP], where \<sub-arch> is the ARM sub-architecture and the "_VFP" suffix means using VFP coprocessor registers s0-s15 (d0-d7) for passing arguments or returning results in standard procedure-call. For AARCH64, the format is\<arch>[\<sub-arch>], VFP is enabled by default. Both \<sub-arch> and "_VFP" are optional, e.g. AARCH64, AARCH64V8, AARCHV8.1, ARMV7, ARMV7_VFP, THUMBV7, THUMBV7_VFP and so on.
- For ARM and THUMB, the format is \<arch>\[\<sub-arch>]\[_VFP], where \<sub-arch> is the ARM sub-architecture and the "_VFP" suffix means using VFP coprocessor registers s0-s15 (d0-d7) for passing arguments or returning results in standard procedure-call. Both \<sub-arch> and "_VFP" are optional, e.g. ARMV7, ARMV7_VFP, THUMBV7, THUMBV7_VFP and so on.
- For AARCH64, the format is\<arch>[\<sub-arch>], VFP is enabled by default. \<sub-arch> is optional, e.g. AARCH64, AARCH64V8, AARCH64V8.1 and so on.
- For RISCV64, the format is \<arch\>[_abi], where "_abi" is optional, currently the supported formats are RISCV64, RISCV64_LP64D and RISCV64_LP64: RISCV64 and RISCV64_LP64D are identical, using [LP64D](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#-named-abis) as abi (LP64 with hardware floating-point calling convention for FLEN=64). And RISCV64_LP64 uses [LP64](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#-named-abis) as abi (Integer calling-convention only, and hardware floating-point calling convention is not used).
- For RISCV32, the format is \<arch\>[_abi], where "_abi" is optional, currently the supported formats are RISCV32, RISCV32_ILP32D and RISCV32_ILP32: RISCV32 and RISCV32_ILP32D are identical, using [ILP32D](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#-named-abis) as abi (ILP32 with hardware floating-point calling convention for FLEN=64). And RISCV32_ILP32 uses [ILP32](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#-named-abis) as abi (Integer calling-convention only, and hardware floating-point calling convention is not used).
@ -465,4 +466,4 @@ $ ls ../build_out/
*build_wamr.sh* will generate *linux* compatible libraries ( libiwasm.so and
libvmlib.a ) and an executable binary (*iwasm*) and copy *iwasm* to
*build_out*. All original generated files are still under
*product-mini/platforms/linux/build*.
*product-mini/platforms/linux/build*.

View File

@ -94,12 +94,6 @@ if (COLLECT_CODE_COVERAGE EQUAL 1)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
endif ()
# UNDEFINED BEHAVIOR
# refer to https://en.cppreference.com/w/cpp/language/ub
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover")
endif()
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
@ -114,6 +108,10 @@ if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
endif ()
# UNDEFINED BEHAVIOR, refer to https://en.cppreference.com/w/cpp/language/ub
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover")
endif()
endif ()
# The following flags are to enhance security, but it may impact performance,

View File

@ -27,7 +27,8 @@ extern int aee_host_msg_callback(void *msg, uint32_t msg_len);
int uart_char_cnt = 0;
static void uart_irq_callback(struct device *dev)
static void uart_irq_callback(const struct device *dev,
void *user_data)
{
unsigned char ch;
@ -35,9 +36,10 @@ static void uart_irq_callback(struct device *dev)
uart_char_cnt++;
aee_host_msg_callback(&ch, 1);
}
(void)user_data;
}
struct device *uart_dev = NULL;
const struct device *uart_dev = NULL;
static bool host_init()
{