Skip to content

Commit 5e19625

Browse files
Fix function type not set issue of aot_call_indirect (#229)
Add registration of libc-wasi to 'wasi_snapshot_preview1' to support cargo-wasi change zephyr build method from cmake to west fix problem when preserve space for local vars fix wasi authority problem
1 parent 374e687 commit 5e19625

File tree

26 files changed

+513
-144
lines changed

26 files changed

+513
-144
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ core/deps/llvm
55
core/deps/lvgl
66
core/shared/mem-alloc/tlsf
77

8+
wamr-sdk/out/
9+
wamr-sdk/runtime/build_runtime_sdk/
10+
test-tools/host-tool/bin/

_clang-format

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
BasedOnStyle: Mozilla
3+
IndentWidth: 4
4+
5+
---
6+
Language: Cpp
7+
AlignConsecutiveMacros: true
8+
AllowShortBlocksOnASingleLine: true
9+
BinPackArguments: true
10+
BinPackParameters: true
11+
BreakBeforeBraces: Custom
12+
BraceWrapping:
13+
AfterCaseLabel: false
14+
AfterClass: true
15+
AfterControlStatement: false
16+
AfterEnum: true
17+
AfterFunction: true
18+
AfterNamespace: false
19+
AfterObjCDeclaration: false
20+
AfterStruct: true
21+
AfterUnion: false
22+
AfterExternBlock: true
23+
BeforeCatch: false
24+
BeforeElse: false
25+
IndentBraces: false
26+
SplitEmptyFunction: true
27+
SplitEmptyRecord: false
28+
SplitEmptyNamespace: true
29+
ColumnLimit: 79
30+
DerivePointerAlignment: false
31+
IncludeBlocks: Regroup
32+
IncludeCategories:
33+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
34+
Priority: 2
35+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
36+
Priority: 1
37+
- Regex: ".*"
38+
Priority: 3
39+
PointerAlignment: Right
40+
ReflowComments: false
41+
Standard: Cpp03
42+
StatementMacros:
43+
- Q_UNUSED
44+
- QT_REQUIRE_VERSION
45+
# AccessModifierOffset: -2
46+
# AlignAfterOpenBracket: Align
47+
# AlignConsecutiveAssignments: false
48+
# AlignConsecutiveDeclarations: false
49+
# AlignEscapedNewlines: Right
50+
# AlignOperands: true
51+
# AlignTrailingComments: true
52+
# AllowAllArgumentsOnNextLine: true
53+
# AllowAllConstructorInitializersOnNextLine: true
54+
# AllowAllParametersOfDeclarationOnNextLine: false
55+
# AllowShortCaseLabelsOnASingleLine: false
56+
# AllowShortFunctionsOnASingleLine: Inline
57+
# AllowShortLambdasOnASingleLine: All
58+
# AllowShortIfStatementsOnASingleLine: Never
59+
# AllowShortLoopsOnASingleLine: false
60+
# AlwaysBreakAfterDefinitionReturnType: TopLevel
61+
# AlwaysBreakAfterReturnType: TopLevel
62+
# AlwaysBreakBeforeMultilineStrings: false
63+
# AlwaysBreakTemplateDeclarations: Yes
64+
# BreakBeforeBinaryOperators: None
65+
# BreakBeforeInheritanceComma: false
66+
# BreakInheritanceList: BeforeComma
67+
# BreakBeforeTernaryOperators: true
68+
# BreakConstructorInitializersBeforeComma: false
69+
# BreakConstructorInitializers: BeforeComma
70+
# BreakAfterJavaFieldAnnotations: false
71+
# BreakStringLiterals: true
72+
# CommentPragmas: '^ IWYU pragma:'
73+
# CompactNamespaces: false
74+
# ConstructorInitializerAllOnOneLineOrOnePerLine: false
75+
# ConstructorInitializerIndentWidth: 2
76+
# ContinuationIndentWidth: 2
77+
# Cpp11BracedListStyle: false
78+
# DisableFormat: false
79+
# ExperimentalAutoDetectBinPacking: false
80+
# FixNamespaceComments: false
81+
# ForEachMacros:
82+
# - foreach
83+
# - Q_FOREACH
84+
# - BOOST_FOREACH
85+
# IncludeIsMainRegex: '(Test)?$'
86+
# IndentCaseLabels: true
87+
# IndentPPDirectives: None
88+
# IndentWrappedFunctionNames: false
89+
# JavaScriptQuotes: Leave
90+
# JavaScriptWrapImports: true
91+
# KeepEmptyLinesAtTheStartOfBlocks: true
92+
# MacroBlockBegin: ''
93+
# MacroBlockEnd: ''
94+
# MaxEmptyLinesToKeep: 1
95+
# NamespaceIndentation: None
96+
# ObjCBinPackProtocolList: Auto
97+
# ObjCBlockIndentWidth: 2
98+
# ObjCSpaceAfterProperty: true
99+
# ObjCSpaceBeforeProtocolList: false
100+
# PenaltyBreakAssignment: 2
101+
# PenaltyBreakBeforeFirstCallParameter: 19
102+
# PenaltyBreakComment: 300
103+
# PenaltyBreakFirstLessLess: 120
104+
# PenaltyBreakString: 1000
105+
# PenaltyBreakTemplateDeclaration: 10
106+
# PenaltyExcessCharacter: 1000000
107+
# PenaltyReturnTypeOnItsOwnLine: 200
108+
# SortIncludes: true
109+
# SortUsingDeclarations: true
110+
# SpaceAfterCStyleCast: false
111+
# SpaceAfterLogicalNot: false
112+
# SpaceAfterTemplateKeyword: false
113+
# SpaceBeforeAssignmentOperators: true
114+
# SpaceBeforeCpp11BracedList: false
115+
# SpaceBeforeCtorInitializerColon: true
116+
# SpaceBeforeInheritanceColon: true
117+
# SpaceBeforeParens: ControlStatements
118+
# SpaceBeforeRangeBasedForLoopColon: true
119+
# SpaceInEmptyParentheses: false
120+
# SpacesBeforeTrailingComments: 1
121+
# SpacesInAngles: false
122+
# SpacesInContainerLiterals: true
123+
# SpacesInCStyleCastParentheses: false
124+
# SpacesInParentheses: false
125+
# SpacesInSquareBrackets: false
126+
# TabWidth: 4
127+
# UseTab: Never
128+
# ...
129+

build-scripts/config_common.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,33 +94,33 @@ message (" CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
9494
if (WAMR_BUILD_INTERP EQUAL 1)
9595
message (" WAMR Interpreter enabled")
9696
else ()
97-
message (" WAMR Interpreter disbled")
97+
message (" WAMR Interpreter disabled")
9898
endif ()
9999
if (WAMR_BUILD_AOT EQUAL 1)
100100
message (" WAMR AOT enabled")
101101
else ()
102-
message (" WAMR AOT disbled")
102+
message (" WAMR AOT disabled")
103103
endif ()
104104
if (WAMR_BUILD_JIT EQUAL 1)
105105
message (" WAMR JIT enabled")
106106
else ()
107-
message (" WAMR JIT disbled")
107+
message (" WAMR JIT disabled")
108108
endif ()
109109
if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
110110
message (" Libc builtin enabled")
111111
else ()
112-
message (" Libc builtin disbled")
112+
message (" Libc builtin disabled")
113113
endif ()
114114
if (WAMR_BUILD_LIBC_WASI EQUAL 1)
115115
message (" Libc WASI enabled")
116116
else ()
117-
message (" Libc WASI disbled")
117+
message (" Libc WASI disabled")
118118
endif ()
119119
if (WAMR_BUILD_FAST_INTERP EQUAL 1)
120120
add_definitions (-DWASM_ENABLE_FAST_INTERP=1)
121121
message (" Fast interpreter enabled")
122122
else ()
123123
add_definitions (-DWASM_ENABLE_FAST_INTERP=0)
124-
message (" Fast interpreter disbled")
124+
message (" Fast interpreter disabled")
125125
endif ()
126126

core/iwasm/aot/aot_loader.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,8 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end,
794794
}
795795

796796
#if WASM_ENABLE_LIBC_WASI != 0
797-
if (!strcmp(import_funcs[i].module_name, "wasi_unstable"))
797+
if (!strcmp(import_funcs[i].module_name, "wasi_unstable")
798+
|| !strcmp(import_funcs[i].module_name, "wasi_snapshot_preview1"))
798799
module->is_wasi_module = true;
799800
#endif
800801
}

core/iwasm/aot/aot_runtime.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,15 +855,16 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
855855

856856
bool
857857
aot_call_indirect(WASMExecEnv *exec_env,
858-
uint32 func_type_idx, uint32 table_elem_idx,
858+
bool check_func_type, uint32 func_type_idx,
859+
uint32 table_elem_idx,
859860
uint32 *frame_lp, uint32 argc, uint32 *argv_ret)
860861
{
861862
AOTModuleInstance *module_inst = (AOTModuleInstance*)
862863
wasm_runtime_get_module_inst(exec_env);
863864
AOTModule *aot_module = (AOTModule*)module_inst->aot_module.ptr;
864865
uint32 *func_type_indexes = (uint32*)module_inst->func_type_indexes.ptr;
865866
uint32 *table_data = (uint32*)module_inst->table_data.ptr;
866-
AOTFuncType *func_type = aot_module->func_types[func_type_idx];;
867+
AOTFuncType *func_type;
867868
void **func_ptrs = (void**)module_inst->func_ptrs.ptr, *func_ptr;
868869
uint32 table_size = module_inst->table_size;
869870
uint32 func_idx, func_type_idx1;
@@ -884,10 +885,14 @@ aot_call_indirect(WASMExecEnv *exec_env,
884885
}
885886

886887
func_type_idx1 = func_type_indexes[func_idx];
887-
if (!aot_is_wasm_type_equal(module_inst, func_type_idx, func_type_idx1)) {
888-
aot_set_exception_with_id(module_inst, EXCE_INVALID_FUNCTION_TYPE_INDEX);
888+
if (check_func_type
889+
&& !aot_is_wasm_type_equal(module_inst, func_type_idx,
890+
func_type_idx1)) {
891+
aot_set_exception_with_id(module_inst,
892+
EXCE_INVALID_FUNCTION_TYPE_INDEX);
889893
return false;
890894
}
895+
func_type = aot_module->func_types[func_type_idx1];
891896

892897
if (!(func_ptr = func_ptrs[func_idx])) {
893898
bh_assert(func_idx < aot_module->import_func_count);
@@ -906,7 +911,8 @@ aot_call_indirect(WASMExecEnv *exec_env,
906911
if (import_func->call_conv_raw) {
907912
attachment = import_func->attachment;
908913
return wasm_runtime_invoke_native_raw(exec_env, func_ptr,
909-
func_type, signature, attachment,
914+
func_type, signature,
915+
attachment,
910916
frame_lp, argc, argv_ret);
911917
}
912918
}
@@ -915,4 +921,3 @@ aot_call_indirect(WASMExecEnv *exec_env,
915921
func_type, signature, attachment,
916922
frame_lp, argc, argv_ret);
917923
}
918-

core/iwasm/aot/aot_runtime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,8 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
445445

446446
bool
447447
aot_call_indirect(WASMExecEnv *exec_env,
448-
uint32 func_type_idx, uint32 table_elem_idx,
448+
bool check_func_type, uint32 func_type_idx,
449+
uint32 table_elem_idx,
449450
uint32 *frame_lp, uint32 argc, uint32 *argv_ret);
450451

451452
uint32

core/iwasm/aot/iwasm_aot.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ include_directories (${IWASM_AOT_DIR})
99

1010
file (GLOB c_source_all ${IWASM_AOT_DIR}/*.c)
1111

12-
if (${WAMR_BUILD_TARGET} STREQUAL "X86_64" OR ${WAMR_BUILD_TARGET} STREQUAL "AMD_64")
12+
if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
1313
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_64.c)
14-
elseif (${WAMR_BUILD_TARGET} STREQUAL "X86_32")
14+
elseif (WAMR_BUILD_TARGET STREQUAL "X86_32")
1515
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_32.c)
16-
elseif (${WAMR_BUILD_TARGET} MATCHES "AARCH64.*")
16+
elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*")
1717
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_aarch64.c)
18-
elseif (${WAMR_BUILD_TARGET} MATCHES "ARM.*")
18+
elseif (WAMR_BUILD_TARGET MATCHES "ARM.*")
1919
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_arm.c)
20-
elseif (${WAMR_BUILD_TARGET} MATCHES "THUMB.*")
20+
elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
2121
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_thumb.c)
22-
elseif (${WAMR_BUILD_TARGET} STREQUAL "MIPS")
22+
elseif (WAMR_BUILD_TARGET STREQUAL "MIPS")
2323
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_mips.c)
24-
elseif (${WAMR_BUILD_TARGET} STREQUAL "XTENSA")
24+
elseif (WAMR_BUILD_TARGET STREQUAL "XTENSA")
2525
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_xtensa.c)
2626
else ()
2727
message (FATAL_ERROR "Build target isn't set")

core/iwasm/common/iwasm_common.cmake

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ add_definitions(-DBH_FREE=wasm_runtime_free)
1010

1111
file (GLOB c_source_all ${IWASM_COMMON_DIR}/*.c)
1212

13-
if (${WAMR_BUILD_TARGET} STREQUAL "X86_64" OR ${WAMR_BUILD_TARGET} STREQUAL "AMD_64")
13+
if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
1414
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_em64.s)
15-
elseif (${WAMR_BUILD_TARGET} STREQUAL "X86_32")
15+
elseif (WAMR_BUILD_TARGET STREQUAL "X86_32")
1616
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_ia32.s)
17-
elseif (${WAMR_BUILD_TARGET} MATCHES "ARM.*")
18-
if (${WAMR_BUILD_TARGET} MATCHES "ARM.*_VFP")
17+
elseif (WAMR_BUILD_TARGET MATCHES "ARM.*")
18+
if (WAMR_BUILD_TARGET MATCHES "ARM.*_VFP")
1919
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_arm_vfp.s)
2020
else ()
2121
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_arm.s)
2222
endif ()
23-
elseif (${WAMR_BUILD_TARGET} MATCHES "THUMB.*")
24-
if (${WAMR_BUILD_TARGET} MATCHES "THUMB.*_VFP")
23+
elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
24+
if (WAMR_BUILD_TARGET MATCHES "THUMB.*_VFP")
2525
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_thumb_vfp.s)
2626
else ()
2727
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_thumb.s)
2828
endif ()
29-
elseif (${WAMR_BUILD_TARGET} MATCHES "AARCH64.*")
29+
elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*")
3030
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_aarch64.s)
31-
elseif (${WAMR_BUILD_TARGET} STREQUAL "MIPS")
31+
elseif (WAMR_BUILD_TARGET STREQUAL "MIPS")
3232
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_mips.s)
33-
elseif (${WAMR_BUILD_TARGET} STREQUAL "XTENSA")
33+
elseif (WAMR_BUILD_TARGET STREQUAL "XTENSA")
3434
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_xtensa.s)
35-
elseif (${WAMR_BUILD_TARGET} STREQUAL "GENERAL")
35+
elseif (WAMR_BUILD_TARGET STREQUAL "GENERAL")
3636
# Use invokeNative_general.c instead of assembly code,
3737
# but the maximum number of native arguments is limited to 20,
3838
# and there are possible issues when passing arguments to

core/iwasm/common/wasm_native.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ wasm_native_init()
251251
if (!wasm_native_register_natives("wasi_unstable",
252252
native_symbols, n_native_symbols))
253253
return false;
254+
if (!wasm_native_register_natives("wasi_snapshot_preview1",
255+
native_symbols, n_native_symbols))
256+
return false;
254257
#endif
255258

256259
#if WASM_ENABLE_BASE_LIB != 0

0 commit comments

Comments
 (0)