Skip to content

Commit 28f1040

Browse files
authored
Fix some compile warnings and update document (#670)
And implement clock_gettime wrapper for libc-built.
1 parent 04e7afe commit 28f1040

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

core/app-mgr/app-manager/module_wasm_app.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ wasm_set_wasi_root_dir(const char *root_dir)
16741674
if (!(path = realpath(root_dir, resolved_path)))
16751675
return false;
16761676

1677-
strncpy(wasi_root_dir, path, sizeof(wasi_root_dir));
1677+
snprintf(wasi_root_dir, sizeof(wasi_root_dir), "%s", path);
16781678
return true;
16791679
}
16801680

core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,28 @@ __cxa_throw_wrapper(wasm_exec_env_t exec_env,
10681068
wasm_runtime_set_exception(module_inst, buf);
10691069
}
10701070

1071+
struct timespec_app {
1072+
int64 tv_sec;
1073+
int32 tv_nsec;
1074+
};
1075+
1076+
static uint32
1077+
clock_gettime_wrapper(wasm_exec_env_t exec_env,
1078+
uint32 clk_id, struct timespec_app *ts_app)
1079+
{
1080+
wasm_module_inst_t module_inst = get_module_inst(exec_env);
1081+
uint64 time;
1082+
1083+
if (!validate_native_addr(ts_app, sizeof(struct timespec_app)))
1084+
return (uint32)-1;
1085+
1086+
time = os_time_get_boot_microsecond();
1087+
ts_app->tv_sec = time / 1000000;
1088+
ts_app->tv_nsec = (time % 1000000) * 1000;
1089+
1090+
return (uint32)0;
1091+
}
1092+
10711093
#if WASM_ENABLE_SPEC_TEST != 0
10721094
static void
10731095
print_wrapper(wasm_exec_env_t exec_env)
@@ -1167,6 +1189,7 @@ static NativeSymbol native_symbols_libc_builtin[] = {
11671189
REG_NATIVE_FUNC(__cxa_allocate_exception, "(i)i"),
11681190
REG_NATIVE_FUNC(__cxa_begin_catch, "(*)"),
11691191
REG_NATIVE_FUNC(__cxa_throw, "(**i)"),
1192+
REG_NATIVE_FUNC(clock_gettime, "(i*)i"),
11701193
};
11711194

11721195
#if WASM_ENABLE_SPEC_TEST != 0

doc/build_wamr.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ The script `runtime_lib.cmake` defines a number of variables for configuring the
2020
- **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).
2121

2222
- **WAMR_BUILD_TARGET**: set the target CPU architecture. Current supported targets are: X86_64, X86_32, AARCH64, ARM, THUMB, XTENSA, RISCV64 and MIPS.
23-
- 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.
23+
- 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.
24+
- 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.
2425
- 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).
2526
- 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).
2627

@@ -465,4 +466,4 @@ $ ls ../build_out/
465466
*build_wamr.sh* will generate *linux* compatible libraries ( libiwasm.so and
466467
libvmlib.a ) and an executable binary (*iwasm*) and copy *iwasm* to
467468
*build_out*. All original generated files are still under
468-
*product-mini/platforms/linux/build*.
469+
*product-mini/platforms/linux/build*.

product-mini/platforms/linux/CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ if (COLLECT_CODE_COVERAGE EQUAL 1)
9494
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
9595
endif ()
9696

97-
# UNDEFINED BEHAVIOR
98-
# refer to https://en.cppreference.com/w/cpp/language/ub
99-
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
100-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover")
101-
endif()
102-
10397
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
10498

10599
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")
114108
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
115109
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
116110
endif ()
111+
# UNDEFINED BEHAVIOR, refer to https://en.cppreference.com/w/cpp/language/ub
112+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
113+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover")
114+
endif()
117115
endif ()
118116

119117
# The following flags are to enhance security, but it may impact performance,

samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@ extern int aee_host_msg_callback(void *msg, uint32_t msg_len);
2727

2828
int uart_char_cnt = 0;
2929

30-
static void uart_irq_callback(struct device *dev)
30+
static void uart_irq_callback(const struct device *dev,
31+
void *user_data)
3132
{
3233
unsigned char ch;
3334

3435
while (uart_poll_in(dev, &ch) == 0) {
3536
uart_char_cnt++;
3637
aee_host_msg_callback(&ch, 1);
3738
}
39+
(void)user_data;
3840
}
3941

40-
struct device *uart_dev = NULL;
42+
const struct device *uart_dev = NULL;
4143

4244
static bool host_init()
4345
{

0 commit comments

Comments
 (0)