Skip to content

Commit dda1c96

Browse files
authored
Merge pull request #704 from bytecodealliance/main
Merge bytecodelliance:main into wenyongh:main
2 parents 48f8469 + 89c11c5 commit dda1c96

File tree

16 files changed

+231
-47
lines changed

16 files changed

+231
-47
lines changed

.github/workflows/build_llvm_libraries.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ jobs:
2626
- name: checkout
2727
uses: actions/checkout@v3
2828

29+
- name: install dependencies
30+
run: /usr/bin/env python3 -m pip install -r requirements.txt
31+
working-directory: build-scripts
32+
2933
- name: retrive the last commit ID
3034
id: get_last_commit
31-
run: echo "last_commit=$(/usr/bin/env python3 ./build_llvm.py --llvm-ver)" >> $GITHUB_OUTPUT
35+
run: echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py --llvm-ver)" >> $GITHUB_OUTPUT
3236
working-directory: build-scripts
3337

3438
# Bump the prefix number to evict all previous caches and
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
jobs:
18-
complinace_job:
18+
compliance_job:
1919
runs-on: ubuntu-latest
2020
steps:
2121
- name: checkout

.github/workflows/compilation_on_nuttx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ jobs:
115115

116116
- name: Enable WAMR for NuttX
117117
run: |
118-
find nuttx/boards -name defconfig | xargs sed -i '$a\CONFIG_EOL_IS_LF=y\n${{ matrix.wamr_config_option }}'
118+
find nuttx/boards -name defconfig | xargs sed -i '$a\CONFIG_EOL_IS_LF=y\nCONFIG_PSEUDOFS_SOFTLINKS=y\n${{ matrix.wamr_config_option }}'
119119
find nuttx/boards/sim -name defconfig | xargs sed -i '$a\CONFIG_LIBM=y\n'
120120
121121
- name: Build

build-scripts/build_llvm.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import argparse
88
import os
99
import pathlib
10+
import requests
1011
import shlex
1112
import shutil
1213
import subprocess
@@ -27,11 +28,23 @@ def clone_llvm(dst_dir, llvm_repo, llvm_branch):
2728
return llvm_dir
2829

2930

30-
def query_llvm_version(llvm_dir):
31-
GIT_LOG_CMD = f"git log --format=format:'%h' -1"
32-
return subprocess.check_output(
33-
shlex.split(GIT_LOG_CMD), cwd=llvm_dir, universal_newlines=True, text=True
34-
)
31+
def query_llvm_version(llvm_info):
32+
github_token = os.environ['GH_TOKEN']
33+
owner_project = llvm_info['repo'].replace("https://github.com/", "").replace(".git", "")
34+
url = f"https://api.github.com/repos/{owner_project}/commits/{llvm_info['branch']}"
35+
headers = {
36+
'Authorization': f"Bearer {github_token}"
37+
}
38+
39+
try:
40+
response = requests.request("GET", url, headers=headers, data={})
41+
response.raise_for_status()
42+
except requests.exceptions.HTTPError as error:
43+
print (error) # for debugging purpose
44+
return None
45+
46+
response = response.json()
47+
return response['sha']
3548

3649

3750
def build_llvm(llvm_dir, platform, backends, projects, use_clang=False):
@@ -253,13 +266,13 @@ def main():
253266

254267
try:
255268
llvm_info = llvm_repo_and_branch.get(platform, llvm_repo_and_branch["default"])
256-
llvm_dir = clone_llvm(deps_dir, llvm_info["repo"], llvm_info["branch"])
257269

258270
if options.llvm_ver:
259-
commit_hash = query_llvm_version(llvm_dir)
271+
commit_hash = query_llvm_version(llvm_info)
260272
print(commit_hash)
261273
return commit_hash is not None
262-
274+
275+
llvm_dir = clone_llvm(deps_dir, llvm_info["repo"], llvm_info["branch"])
263276
if (
264277
build_llvm(
265278
llvm_dir, platform, options.arch, options.project, options.use_clang

build-scripts/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests==2.28.2

build-scripts/runtime_lib.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ endif ()
1919
if (NOT DEFINED DEPS_DIR)
2020
set (DEPS_DIR ${WAMR_ROOT_DIR}/core/deps)
2121
endif ()
22+
if (NOT DEFINED SHARED_PLATFORM_CONFIG)
23+
# CMake file for platform configuration. The PLATFORM_SHARED_SOURCE varable
24+
# should point to a list of platform-specfic source files to compile.
25+
set (SHARED_PLATFORM_CONFIG ${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake)
26+
endif ()
2227

2328
if (DEFINED EXTRA_SDK_INCLUDE_PATH)
2429
message(STATUS, "EXTRA_SDK_INCLUDE_PATH = ${EXTRA_SDK_INCLUDE_PATH} ")
@@ -165,7 +170,7 @@ LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header})
165170

166171
enable_language (ASM)
167172

168-
include (${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake)
173+
include (${SHARED_PLATFORM_CONFIG})
169174
include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
170175
include (${IWASM_DIR}/common/iwasm_common.cmake)
171176
include (${SHARED_DIR}/utils/shared_utils.cmake)

core/iwasm/common/arch/invokeNative_ia32.s

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ _invokeNative:
1616
push %ebp
1717
movl %esp, %ebp
1818
movl 16(%ebp), %ecx /* ecx = argc */
19-
movl 12(%ebp), %edx /* edx = argv */
19+
leal 2(%ecx), %edx /* edx = ecx + 2 (count return address and saved ebp) */
20+
andl $3, %edx /* edx = edx % 4 */
21+
jz stack_aligned /* if edx == 0, stack is already 16 bytes aligned */
22+
leal -16(%esp, %edx, 4), %esp /* esp = esp - 16 + edx * 4 */
23+
stack_aligned:
2024
test %ecx, %ecx
2125
jz skip_push_args /* if ecx == 0, skip pushing arguments */
26+
movl 12(%ebp), %edx /* edx = argv */
2227
leal -4(%edx,%ecx,4), %edx /* edx = edx + ecx * 4 - 4 */
2328
subl %esp, %edx /* edx = edx - esp */
2429
1:

core/iwasm/common/wasm_runtime_common.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,12 @@ wasm_set_exception(WASMModuleInstance *module_inst, const char *exception)
23172317
if (exec_env) {
23182318
wasm_cluster_spread_exception(exec_env, exception ? false : true);
23192319
}
2320+
#if WASM_ENABLE_SHARED_MEMORY
2321+
if (exception) {
2322+
notify_stale_threads_on_exception(
2323+
(WASMModuleInstanceCommon *)module_inst);
2324+
}
2325+
#endif
23202326
#else
23212327
(void)exec_env;
23222328
#endif

core/iwasm/common/wasm_shared_memory.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ typedef struct AtomicWaitNode {
3030
korp_cond wait_cond;
3131
} AtomicWaitNode;
3232

33+
typedef struct AtomicWaitAddressArgs {
34+
uint32 index;
35+
void **addr;
36+
} AtomicWaitAddressArgs;
37+
3338
/* Atomic wait map */
3439
static HashMap *wait_map;
3540

@@ -87,6 +92,53 @@ search_module(WASMModuleCommon *module)
8792
return NULL;
8893
}
8994

95+
static void
96+
wait_map_address_count_callback(void *key, void *value,
97+
void *p_total_elem_count)
98+
{
99+
*(uint32 *)p_total_elem_count = *(uint32 *)p_total_elem_count + 1;
100+
}
101+
102+
static void
103+
create_list_of_waiter_addresses(void *key, void *value, void *user_data)
104+
{
105+
AtomicWaitAddressArgs *data = (AtomicWaitAddressArgs *)user_data;
106+
data->addr[data->index++] = key;
107+
}
108+
109+
void
110+
notify_stale_threads_on_exception(WASMModuleInstanceCommon *module_inst)
111+
{
112+
AtomicWaitAddressArgs args = { 0 };
113+
uint32 i = 0, total_elem_count = 0;
114+
115+
os_mutex_lock(&shared_memory_list_lock);
116+
117+
/* count number of addresses in wait_map */
118+
bh_hash_map_traverse(wait_map, wait_map_address_count_callback,
119+
(void *)&total_elem_count);
120+
121+
/* allocate memory */
122+
if (!(args.addr = wasm_runtime_malloc(sizeof(void *) * total_elem_count))) {
123+
LOG_ERROR(
124+
"failed to allocate memory for list of atomic wait addresses");
125+
os_mutex_unlock(&shared_memory_list_lock);
126+
return;
127+
}
128+
129+
/* set values in list of addresses */
130+
bh_hash_map_traverse(wait_map, create_list_of_waiter_addresses, &args);
131+
os_mutex_unlock(&shared_memory_list_lock);
132+
133+
/* notify */
134+
for (i = 0; i < args.index; i++) {
135+
wasm_runtime_atomic_notify(module_inst, args.addr[i], UINT32_MAX);
136+
}
137+
138+
/* free memory allocated to args data */
139+
wasm_runtime_free(args.addr);
140+
}
141+
90142
WASMSharedMemNode *
91143
wasm_module_get_shared_memory(WASMModuleCommon *module)
92144
{
@@ -322,6 +374,10 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
322374
bh_assert(module->module_type == Wasm_Module_Bytecode
323375
|| module->module_type == Wasm_Module_AoT);
324376

377+
if (wasm_get_exception(module_inst)) {
378+
return -1;
379+
}
380+
325381
/* Currently we have only one memory instance */
326382
if (!module_inst->memories[0]->is_shared) {
327383
wasm_runtime_set_exception(module, "expected shared memory");

core/iwasm/common/wasm_shared_memory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ wasm_shared_memory_init();
3737
void
3838
wasm_shared_memory_destroy();
3939

40+
void
41+
notify_stale_threads_on_exception(WASMModuleInstanceCommon *module);
42+
4043
WASMSharedMemNode *
4144
wasm_module_get_shared_memory(WASMModuleCommon *module);
4245

0 commit comments

Comments
 (0)