Merge branch main into dev/wasi-libc-windows

This commit is contained in:
Wenyong Huang
2023-10-08 15:03:35 +08:00
151 changed files with 5909 additions and 2046 deletions

View File

@ -559,9 +559,6 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
uint32 thread_handle;
uint32 stack_size = 8192;
int32 ret = -1;
#if WASM_ENABLE_LIBC_WASI != 0
WASIContext *wasi_ctx;
#endif
bh_assert(module);
bh_assert(module_inst);
@ -588,11 +585,7 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
wasm_runtime_set_custom_data_internal(
new_module_inst, wasm_runtime_get_custom_data(module_inst));
#if WASM_ENABLE_LIBC_WASI != 0
wasi_ctx = get_wasi_ctx(module_inst);
if (wasi_ctx)
wasm_runtime_set_wasi_ctx(new_module_inst, wasi_ctx);
#endif
wasm_native_inherit_contexts(new_module_inst, module_inst);
if (!(wasm_cluster_dup_c_api_imports(new_module_inst, module_inst)))
goto fail;

View File

@ -23,7 +23,7 @@ include(FetchContent)
set(RATS_BUILD_MODE "sgx"
CACHE INTERNAL "Select build mode for librats(host|occlum|sgxwasm)")
set(RATS_INSTALL_PATH "${CMAKE_BINARY_DIR}/librats" CACHE INTERNAL "")
set(BUILD_SAMPLES OFF)
set(BUILD_SAMPLES OFF CACHE BOOL "Disable de compilation of the librats samples" FORCE)
FetchContent_Declare(
librats

View File

@ -80,9 +80,6 @@ thread_spawn_wrapper(wasm_exec_env_t exec_env, uint32 start_arg)
int32 thread_id;
uint32 stack_size = 8192;
int32 ret = -1;
#if WASM_ENABLE_LIBC_WASI != 0
WASIContext *wasi_ctx;
#endif
bh_assert(module);
bh_assert(module_inst);
@ -99,11 +96,7 @@ thread_spawn_wrapper(wasm_exec_env_t exec_env, uint32 start_arg)
if (!(wasm_cluster_dup_c_api_imports(new_module_inst, module_inst)))
goto thread_preparation_fail;
#if WASM_ENABLE_LIBC_WASI != 0
wasi_ctx = wasm_runtime_get_wasi_ctx(module_inst);
if (wasi_ctx)
wasm_runtime_set_wasi_ctx(new_module_inst, wasi_ctx);
#endif
wasm_native_inherit_contexts(new_module_inst, module_inst);
start_func = wasm_runtime_lookup_function(new_module_inst,
THREAD_START_FUNCTION, NULL);

View File

@ -0,0 +1,66 @@
#!/bin/bash
#
# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
set -eo pipefail
CC=${CC:=/opt/wasi-sdk/bin/clang}
WAMR_DIR=../../../../..
show_usage() {
echo "Usage: $0 [--sysroot PATH_TO_SYSROOT]"
echo "--sysroot PATH_TO_SYSROOT specify to build with custom sysroot for wasi-libc"
}
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--sysroot)
sysroot_path="$2"
shift
shift
;;
--help)
show_usage
exit
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
rm -rf *.wasm
rm -rf *.aot
for test_c in *.c; do
test_wasm="$(basename $test_c .c).wasm"
if [[ -n "$sysroot_path" ]]; then
if [ ! -d "$sysroot_path" ]; then
echo "Directory $sysroot_path doesn't exist. Aborting"
exit 1
fi
sysroot_command="--sysroot $sysroot_path"
fi
echo "Compiling $test_c to $test_wasm"
$CC \
-target wasm32-wasi-threads \
-O2 \
-Wall \
-pthread \
-z stack-size=32768 \
-Wl,--export=__heap_base \
-Wl,--export=__data_end \
-Wl,--shared-memory,--max-memory=1966080 \
-Wl,--export=wasi_thread_start \
-Wl,--export=malloc \
-Wl,--export=free \
-Wl,--export=test \
$sysroot_command \
$test_c -o $test_wasm
done

View File

@ -0,0 +1,34 @@
/*
* Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <pthread.h>
#include <errno.h>
#include "mutex_common.h"
void
test()
{
pthread_mutex_t mutex;
// Set mutex type to errorcheck. This type provides some additional checks
// (for example returns EDEADLK instead of deadlocking in some cases)
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
run_common_tests(&mutex);
fprintf(stderr, "Errorcheck mutex test is completed\n");
pthread_mutex_destroy(&mutex);
}
int
main()
{
test();
return 0;
}

View File

@ -0,0 +1,3 @@
{
"name": "lib-wasi-threads stress tests"
}

View File

@ -0,0 +1,229 @@
/*
* Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef MUTEX_COMMON_H
#define MUTEX_COMMON_H
#include <pthread.h>
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <stdbool.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
enum Constants {
NUM_ITER = 250000,
NUM_THREADS = 12,
NUM_RETRY = 8,
RETRY_SLEEP_TIME_US = 1000,
};
// We're counting how many times each thread was called using this array
// Main thread is also counted here so we need to make arrays bigger
typedef struct {
int tids[NUM_THREADS + 1];
int calls[NUM_THREADS + 1];
} StatCollector;
typedef struct {
pthread_mutex_t *mutex;
StatCollector stat;
int counter;
bool is_sleeping;
} MutexCounter;
// This enum defines whether thread should sleep to increase contention
enum SleepState {
NON_SLEEP = 0,
SLEEP = 1,
};
void
mutex_counter_init(MutexCounter *mutex_counter, pthread_mutex_t *mutex,
enum SleepState is_sleeping)
{
memset(mutex_counter, 0, sizeof(*mutex_counter));
mutex_counter->mutex = mutex;
mutex_counter->is_sleeping = is_sleeping;
}
// This function spawns the thread using exponential retries if it receives
// EAGAIN
static inline void
spawn_thread(pthread_t *tid, void *func, void *arg)
{
int status_code = -1;
int timeout_us = RETRY_SLEEP_TIME_US;
for (int tries = 0; status_code != 0 && tries < NUM_RETRY; ++tries) {
status_code = pthread_create(tid, NULL, (void *(*)(void *))func, arg);
assert(status_code == 0 || status_code == EAGAIN);
if (status_code == EAGAIN) {
usleep(timeout_us);
timeout_us *= 2;
}
}
assert(status_code == 0 && "Thread creation should succeed");
}
// This function adds tid to our stat
static inline void
add_to_stat(StatCollector *stat, int tid)
{
int tid_num = 0;
for (; tid_num < NUM_THREADS + 1 && stat->tids[tid_num] != 0; ++tid_num) {
if (stat->tids[tid_num] == tid) {
stat->calls[tid_num]++;
return;
}
}
assert(tid_num < NUM_THREADS + 1);
stat->tids[tid_num] = tid;
stat->calls[tid_num] = 1;
}
// This function prints number of calls by TID
static inline void
print_stat(StatCollector *stat)
{
fprintf(stderr, "Thread calls count by TID\n");
for (int i = 0; i < NUM_THREADS + 1; ++i) {
if (stat->tids[i] != 0) {
fprintf(stderr, "TID: %d; Calls: %d\n", stat->tids[i],
stat->calls[i]);
}
}
}
// This function is run by the threads, it increases counter in a loop and then
// sleeps after unlocking the mutex to provide better contention
static inline void *
inc_shared_variable(void *arg)
{
MutexCounter *mutex_counter = (MutexCounter *)(arg);
int sleep_us = 0;
while (!pthread_mutex_lock(mutex_counter->mutex)
&& mutex_counter->counter < NUM_ITER) {
mutex_counter->counter++;
add_to_stat(&mutex_counter->stat, (int)(pthread_self()));
if (mutex_counter->is_sleeping) {
sleep_us = rand() % 1000;
}
assert(pthread_mutex_unlock(mutex_counter->mutex) == 0
&& "Should be able to unlock a mutex");
if (mutex_counter->is_sleeping) {
usleep(sleep_us);
}
}
assert(mutex_counter->counter == NUM_ITER);
assert(pthread_mutex_unlock(mutex_counter->mutex) == 0
&& "Should be able to unlock the mutex after test execution");
return NULL;
}
// Locking and unlocking a mutex in a single thread.
static inline void *
same_thread_lock_unlock_test(void *mutex)
{
for (int i = 0; i < NUM_ITER; ++i) {
assert(pthread_mutex_lock(mutex) == 0
&& "Main thread should be able to lock a mutex");
assert(pthread_mutex_unlock(mutex) == 0
&& "Main thread should be able to unlock a mutex");
}
return NULL;
}
// This function spawns a thread that locks and unlocks a mutex `NUM_ITER` times
// in a row
static inline void
same_non_main_thread_lock_unlock_test(pthread_mutex_t *mutex)
{
pthread_t tid = 0;
spawn_thread(&tid, same_thread_lock_unlock_test, mutex);
assert(tid != 0 && "TID can't be 0 after successful thread creation");
assert(pthread_join(tid, NULL) == 0
&& "Thread should be joined successfully");
}
// This function checks basic contention between main and non-main thread
// increasing the shared variable
static inline void
two_threads_inc_test(pthread_mutex_t *mutex)
{
MutexCounter mutex_counter;
mutex_counter_init(&mutex_counter, mutex, false);
pthread_t tid = 0;
spawn_thread(&tid, inc_shared_variable, &mutex_counter);
assert(tid != 0 && "TID can't be 0 after successful thread creation");
inc_shared_variable(&mutex_counter);
assert(pthread_join(tid, NULL) == 0
&& "Thread should be joined without errors");
assert(mutex_counter.counter == NUM_ITER);
}
// This function creates number of threads specified by NUM_THREADS and run
// concurrent increasing of shared variable
static inline void
max_threads_inc_test(pthread_mutex_t *mutex, int threads_num,
enum SleepState is_sleeping)
{
MutexCounter mutex_counter;
mutex_counter_init(&mutex_counter, mutex, is_sleeping);
pthread_t tids[threads_num];
for (int i = 0; i < threads_num; ++i) {
spawn_thread(&tids[i], inc_shared_variable, &mutex_counter);
}
inc_shared_variable(&mutex_counter);
for (int i = 0; i < threads_num; ++i) {
assert(pthread_join(tids[i], NULL) == 0
&& "Thread should be joined without errors");
}
print_stat(&mutex_counter.stat);
}
// This function just runs all the tests described above
static inline void
run_common_tests(pthread_mutex_t *mutex)
{
srand(time(NULL));
fprintf(stderr, "Starting same_thread_lock_unlock_test test\n");
same_thread_lock_unlock_test(mutex);
fprintf(stderr, "Finished same_thread_lock_unlock_test test\n");
fprintf(stderr, "Starting same_non_main_thread_lock_unlock_test test\n");
same_non_main_thread_lock_unlock_test(mutex);
fprintf(stderr, "Finished same_non_main_thread_lock_unlock_test test\n");
fprintf(stderr, "Starting two_threads_inc_test test\n");
two_threads_inc_test(mutex);
fprintf(stderr, "Finished two_threads_inc_test test\n");
fprintf(stderr, "Starting max_threads_inc_test_sleep test\n");
max_threads_inc_test(mutex, NUM_THREADS, SLEEP);
fprintf(stderr, "Finished concurrent_inc sleep test\n");
fprintf(stderr, "Starting max_threads_inc_test_non_sleep test\n");
max_threads_inc_test(mutex, NUM_THREADS, NON_SLEEP);
fprintf(stderr, "Finished max_threads_inc_test test\n");
}
#endif // MUTEX_COMMON_H

View File

@ -0,0 +1,27 @@
/*
* Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <pthread.h>
#include <errno.h>
#include "mutex_common.h"
void
test()
{
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, NULL);
run_common_tests(&mutex);
fprintf(stderr, "Normal mutex test is completed\n");
pthread_mutex_destroy(&mutex);
}
int
main()
{
test();
return 0;
}

View File

@ -0,0 +1,72 @@
/*
* Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <pthread.h>
#include <errno.h>
#include "mutex_common.h"
void
multiple_same_thread_lock(void *mutex)
{
for (int i = 0; i < 100; ++i) {
assert(pthread_mutex_lock(mutex) == 0
&& "Recursive mutex should allow multiple locking");
}
for (int i = 0; i < 100; ++i) {
assert(pthread_mutex_unlock(mutex) == 0
&& "Recursive mutex should allow multiple unlocking");
}
}
void *
same_thread_multiple_rec_mutex_lock(void *mutex)
{
for (int i = 0; i < NUM_ITER; ++i) {
multiple_same_thread_lock(mutex);
}
return NULL;
}
void
test()
{
pthread_mutex_t mutex;
// Set mutex type to recursive. This type allows multiple locking and
// unlocking within the same thread
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
run_common_tests(&mutex);
fprintf(stderr, "Starting same_thread_multiple_rec_mutex_lock test\n");
same_thread_multiple_rec_mutex_lock(&mutex);
fprintf(stderr, "Finished same_thread_multiple_rec_mutex_lock test\n");
fprintf(stderr, "Starting same_thread_multiple_rec_mutex_lock test in "
"non-main thread\n");
pthread_t tid;
spawn_thread(&tid, same_thread_multiple_rec_mutex_lock, &mutex);
assert(pthread_join(tid, NULL) == 0
&& "Non-main thread should be joined successfully");
fprintf(stderr, "Finished same_thread_multiple_rec_mutex_lock test in "
"non-main thread\n");
fprintf(stderr, "Recursive mutex test is completed\n");
pthread_mutex_destroy(&mutex);
}
int
main()
{
test();
return 0;
}

View File

@ -16,13 +16,6 @@
#include <stdlib.h>
#include <unistd.h>
enum CONSTANTS {
NUM_ITER = 100000,
NUM_RETRY = 8,
MAX_NUM_THREADS = 8,
RETRY_SLEEP_TIME_US = 2000,
};
unsigned prime_numbers_count = 0;
bool
@ -49,10 +42,10 @@ check_if_prime(void *value)
}
unsigned int
validate()
validate(int iter_num)
{
unsigned int counter = 0;
for (unsigned int i = 2; i <= NUM_ITER; ++i) {
for (unsigned int i = 2; i <= iter_num; ++i) {
counter += is_prime(i);
}
@ -60,11 +53,12 @@ validate()
}
void
spawn_thread(pthread_t *thread, unsigned int *arg)
spawn_thread(pthread_t *thread, int retry_time_us, int retry_num,
unsigned int *arg)
{
int status_code = -1;
int timeout_us = RETRY_SLEEP_TIME_US;
for (int tries = 0; status_code != 0 && tries < NUM_RETRY; ++tries) {
int timeout_us = retry_time_us;
for (int tries = 0; status_code != 0 && tries < retry_num; ++tries) {
status_code = pthread_create(thread, NULL, &check_if_prime, arg);
assert(status_code == 0 || status_code == EAGAIN);
if (status_code == EAGAIN) {
@ -76,42 +70,56 @@ spawn_thread(pthread_t *thread, unsigned int *arg)
assert(status_code == 0 && "Thread creation should succeed");
}
int
main(int argc, char **argv)
void
test(int iter_num, int retry_num, int max_threads_num, int retry_time_us)
{
pthread_t threads[MAX_NUM_THREADS];
unsigned int args[MAX_NUM_THREADS];
pthread_t threads[max_threads_num];
unsigned int args[max_threads_num];
double percentage = 0.1;
for (unsigned int factorised_number = 2; factorised_number < NUM_ITER;
for (unsigned int factorised_number = 2; factorised_number < iter_num;
++factorised_number) {
if (factorised_number > NUM_ITER * percentage) {
if (factorised_number > iter_num * percentage) {
fprintf(stderr, "Stress test is %d%% finished\n",
(unsigned int)(percentage * 100));
percentage += 0.1;
}
unsigned int thread_num = factorised_number % MAX_NUM_THREADS;
unsigned int thread_num = factorised_number % max_threads_num;
if (threads[thread_num] != 0) {
assert(pthread_join(threads[thread_num], NULL) == 0);
}
args[thread_num] = factorised_number;
usleep(RETRY_SLEEP_TIME_US);
spawn_thread(&threads[thread_num], &args[thread_num]);
usleep(retry_time_us);
spawn_thread(&threads[thread_num], retry_time_us, retry_num,
&args[thread_num]);
assert(threads[thread_num] != 0);
}
for (int i = 0; i < MAX_NUM_THREADS; ++i) {
for (int i = 0; i < max_threads_num; ++i) {
assert(threads[i] == 0 || pthread_join(threads[i], NULL) == 0);
}
// Check the test results
assert(
prime_numbers_count == validate()
prime_numbers_count == validate(iter_num)
&& "Answer mismatch between tested code and reference implementation");
fprintf(stderr, "Stress test finished successfully\n");
}
enum DEFAULT_PARAMETERS {
ITER_NUM = 20000,
RETRY_NUM = 8,
MAX_THREADS_NUM = 12,
RETRY_SLEEP_TIME_US = 2000,
};
int
main(int argc, char **argv)
{
test(ITER_NUM, RETRY_NUM, MAX_THREADS_NUM, RETRY_SLEEP_TIME_US);
return 0;
}

View File

@ -9,14 +9,6 @@
#include <stdio.h>
#include <unistd.h>
enum CONSTANTS {
NUM_ITER = 200000,
NUM_RETRY = 8,
MAX_NUM_THREADS = 8,
RETRY_SLEEP_TIME_US = 4000,
SECOND = 1000 * 1000 * 1000
};
int threads_executed = 0;
unsigned int threads_creation_tried = 0;
unsigned int threads_in_use = 0;
@ -31,11 +23,11 @@ thread_func(void *arg)
}
void
spawn_thread(pthread_t *thread)
spawn_thread(pthread_t *thread, int retry_time, int iter_num)
{
int status_code = -1;
int timeout_us = RETRY_SLEEP_TIME_US;
for (int tries = 0; status_code != 0 && tries < NUM_RETRY; ++tries) {
int timeout_us = retry_time;
for (int tries = 0; status_code != 0 && tries < iter_num; ++tries) {
status_code = pthread_create(thread, NULL, &thread_func, NULL);
__atomic_fetch_add(&threads_creation_tried, 1, __ATOMIC_RELAXED);
@ -49,30 +41,33 @@ spawn_thread(pthread_t *thread)
assert(status_code == 0 && "Thread creation should succeed");
}
int
main(int argc, char **argv)
void
test(int iter_num, int max_threads_num, int retry_num, int retry_time_us)
{
double percentage = 0.1;
int second_us = 1000 * 1000 * 1000; // 1 second in us
for (int iter = 0; iter < NUM_ITER; ++iter) {
if (iter > NUM_ITER * percentage) {
for (int iter = 0; iter < iter_num; ++iter) {
if (iter > iter_num * percentage) {
fprintf(stderr, "Spawning stress test is %d%% finished\n",
(unsigned int)(percentage * 100));
percentage += 0.1;
}
while (__atomic_load_n(&threads_in_use, __ATOMIC_SEQ_CST)
== MAX_NUM_THREADS) {
== max_threads_num) {
usleep(100);
}
__atomic_fetch_add(&threads_in_use, 1, __ATOMIC_SEQ_CST);
pthread_t tmp;
spawn_thread(&tmp);
spawn_thread(&tmp, retry_time_us, iter_num);
pthread_detach(tmp);
}
while ((__atomic_load_n(&threads_in_use, __ATOMIC_SEQ_CST) != 0)) {
__builtin_wasm_memory_atomic_wait32(&threads_in_use, 0, SECOND);
// Casting to int* to supress compiler warning
__builtin_wasm_memory_atomic_wait32((int *)(&threads_in_use), 0,
second_us);
}
assert(__atomic_load_n(&threads_in_use, __ATOMIC_SEQ_CST) == 0);
@ -89,5 +84,18 @@ main(int argc, char **argv)
"with retry ratio %f\n",
threads_creation_tried,
(1. * threads_creation_tried) / threads_executed);
}
enum DEFAULT_PARAMETERS {
ITER_NUM = 50000,
RETRY_NUM = 8,
MAX_NUM_THREADS = 12,
RETRY_SLEEP_TIME_US = 4000,
};
int
main(int argc, char **argv)
{
test(ITER_NUM, MAX_NUM_THREADS, RETRY_NUM, RETRY_SLEEP_TIME_US);
return 0;
}

View File

@ -34,7 +34,10 @@ while [[ $# -gt 0 ]]; do
done
# Stress tests names
thread_start_file_exclusions=("spawn_stress_test.wasm" "linear_memory_size_update.wasm" "stress_test_threads_creation.wasm")
thread_start_file_exclusions=("linear_memory_size_update.wasm")
rm -rf *.wasm
rm -rf *.aot
for test_c in *.c; do
test_wasm="$(basename $test_c .c).wasm"

View File

@ -65,7 +65,7 @@ main(int argc, char **argv)
assert(start_args_init(&data[i].base));
thread_ids[i] = __wasi_thread_spawn(&data[i]);
printf("Thread created with id=%d\n", thread_ids[i]);
assert(thread_ids[i] > 0 && "Thread creation failed");
ASSERT_VALID_TID(thread_ids[i]);
for (int j = 0; j < i; j++) {
assert(thread_ids[i] != thread_ids[j] && "Duplicated TIDs");

View File

@ -49,7 +49,7 @@ main(int argc, char **argv)
for (int i = 0; i < NUM_THREADS; i++) {
assert(start_args_init(&data[i].base));
thread_ids[i] = __wasi_thread_spawn(&data[i]);
assert(thread_ids[i] > 0 && "Thread creation failed");
ASSERT_VALID_TID(thread_ids[i]);
}
printf("Wait for threads to finish\n");

View File

@ -61,7 +61,7 @@ main(int argc, char **argv)
for (int i = 0; i < NUM_THREADS; i++) {
assert(start_args_init(&data[i].base));
thread_ids[i] = __wasi_thread_spawn(&data[i]);
assert(thread_ids[i] > 0 && "Thread creation failed");
ASSERT_VALID_TID(thread_ids[i]);
}
printf("Wait for threads to finish\n");

View File

@ -1,6 +0,0 @@
{
"lib-wasi-threads tests": {
"spawn_stress_test": "Stress tests are incompatible with the other part and executed differently",
"stress_test_threads_creation": "Stress tests are incompatible with the other part and executed differently"
}
}

View File

@ -38,7 +38,7 @@ main(int argc, char **argv)
assert(start_args_init(&data.base));
int thread_id = __wasi_thread_spawn(&data);
assert(thread_id > 0 && "Thread creation failed");
ASSERT_VALID_TID(thread_id);
return EXIT_SUCCESS;
}

View File

@ -69,7 +69,7 @@ main(int argc, char **argv)
data[i].iteration = i;
thread_ids[i] = __wasi_thread_spawn(&data[i]);
assert(thread_ids[i] > 0 && "Thread creation failed");
ASSERT_VALID_TID(thread_ids[i]);
}
printf("Wait for threads to finish\n");

View File

@ -8,8 +8,14 @@
#include "platform_common.h"
#ifdef __cplusplus
extern "C" {
#endif
#define TID_ALLOCATOR_INIT_SIZE CLUSTER_MAX_THREAD_NUM
enum {
/* Keep it in sync with
https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids */
TID_MIN = 1,
TID_MAX = 0x1FFFFFFF
}; // Reserved TIDs (WASI specification)
@ -33,4 +39,8 @@ tid_allocator_get_tid(TidAllocator *tid_allocator);
void
tid_allocator_release_tid(TidAllocator *tid_allocator, int32 thread_id);
#ifdef __cplusplus
}
#endif
#endif /* _TID_ALLOCATOR_H */

View File

@ -0,0 +1,6 @@
# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
create_wamr_unit_test(wasi_threads
${CMAKE_CURRENT_LIST_DIR}/test_tid_allocator.cpp
)

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <gtest/gtest.h>
#include "tid_allocator.h"
#include <stdint.h>
class TidAllocatorTest : public ::testing::Test
{
protected:
void SetUp() override { ASSERT_TRUE(tid_allocator_init(&_allocator)); }
void TearDown() override { tid_allocator_deinit(&_allocator); }
TidAllocator _allocator;
};
static bool
is_tid_valid(int32 tid)
{
/* See: https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids
*/
return tid >= TID_MIN && tid <= TID_MAX;
}
TEST_F(TidAllocatorTest, BasicTest)
{
int32 tid = tid_allocator_get_tid(&_allocator);
ASSERT_TRUE(is_tid_valid(tid));
}
TEST_F(TidAllocatorTest, ShouldFailOnAllocatingMoreThanAllowedThreadIDs)
{
int32 last_tid = 0;
for (int32 i = 0; i < TID_MAX + 1; i++) {
last_tid = tid_allocator_get_tid(&_allocator);
if (last_tid < 0) {
break;
}
ASSERT_TRUE(is_tid_valid(last_tid));
}
ASSERT_LT(last_tid, 0);
}
TEST_F(TidAllocatorTest, ShouldAllocateMoreThanAllowedTIDsIfOldTIDsAreReleased)
{
int32 last_tid = 0;
for (int32 i = 0; i < TID_MAX + 1; i++) {
if (last_tid != 0) {
tid_allocator_release_tid(&_allocator, last_tid);
}
last_tid = tid_allocator_get_tid(&_allocator);
ASSERT_TRUE(is_tid_valid(last_tid));
}
}

View File

@ -335,7 +335,7 @@ wasi_fd_close(wasm_exec_env_t exec_env, wasi_fd_t fd)
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_close(curfds, prestats, fd);
return wasmtime_ssp_fd_close(exec_env, curfds, prestats, fd);
}
static wasi_errno_t
@ -348,7 +348,7 @@ wasi_fd_datasync(wasm_exec_env_t exec_env, wasi_fd_t fd)
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_datasync(curfds, fd);
return wasmtime_ssp_fd_datasync(exec_env, curfds, fd);
}
static wasi_errno_t
@ -389,8 +389,8 @@ wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app,
iovec->buf_len = iovec_app->buf_len;
}
err = wasmtime_ssp_fd_pread(curfds, fd, iovec_begin, iovs_len, offset,
&nread);
err = wasmtime_ssp_fd_pread(exec_env, curfds, fd, iovec_begin, iovs_len,
offset, &nread);
if (err)
goto fail;
@ -443,8 +443,8 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd,
ciovec->buf_len = iovec_app->buf_len;
}
err = wasmtime_ssp_fd_pwrite(curfds, fd, ciovec_begin, iovs_len, offset,
&nwritten);
err = wasmtime_ssp_fd_pwrite(exec_env, curfds, fd, ciovec_begin, iovs_len,
offset, &nwritten);
if (err)
goto fail;
@ -496,7 +496,8 @@ wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd,
iovec->buf_len = iovec_app->buf_len;
}
err = wasmtime_ssp_fd_read(curfds, fd, iovec_begin, iovs_len, &nread);
err = wasmtime_ssp_fd_read(exec_env, curfds, fd, iovec_begin, iovs_len,
&nread);
if (err)
goto fail;
@ -521,7 +522,7 @@ wasi_fd_renumber(wasm_exec_env_t exec_env, wasi_fd_t from, wasi_fd_t to)
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_renumber(curfds, prestats, from, to);
return wasmtime_ssp_fd_renumber(exec_env, curfds, prestats, from, to);
}
static wasi_errno_t
@ -538,7 +539,8 @@ wasi_fd_seek(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filedelta_t offset,
if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t)))
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_seek(curfds, fd, offset, whence, newoffset);
return wasmtime_ssp_fd_seek(exec_env, curfds, fd, offset, whence,
newoffset);
}
static wasi_errno_t
@ -554,7 +556,7 @@ wasi_fd_tell(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t *newoffset)
if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t)))
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_tell(curfds, fd, newoffset);
return wasmtime_ssp_fd_tell(exec_env, curfds, fd, newoffset);
}
static wasi_errno_t
@ -573,7 +575,7 @@ wasi_fd_fdstat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(fdstat_app, sizeof(wasi_fdstat_t)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_fd_fdstat_get(curfds, fd, &fdstat);
err = wasmtime_ssp_fd_fdstat_get(exec_env, curfds, fd, &fdstat);
if (err)
return err;
@ -592,7 +594,7 @@ wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_fdstat_set_flags(curfds, fd, flags);
return wasmtime_ssp_fd_fdstat_set_flags(exec_env, curfds, fd, flags);
}
static wasi_errno_t
@ -607,8 +609,8 @@ wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_fdstat_set_rights(curfds, fd, fs_rights_base,
fs_rights_inheriting);
return wasmtime_ssp_fd_fdstat_set_rights(
exec_env, curfds, fd, fs_rights_base, fs_rights_inheriting);
}
static wasi_errno_t
@ -621,7 +623,7 @@ wasi_fd_sync(wasm_exec_env_t exec_env, wasi_fd_t fd)
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_sync(curfds, fd);
return wasmtime_ssp_fd_sync(exec_env, curfds, fd);
}
static wasi_errno_t
@ -663,7 +665,8 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
ciovec->buf_len = iovec_app->buf_len;
}
err = wasmtime_ssp_fd_write(curfds, fd, ciovec_begin, iovs_len, &nwritten);
err = wasmtime_ssp_fd_write(exec_env, curfds, fd, ciovec_begin, iovs_len,
&nwritten);
if (err)
goto fail;
@ -688,7 +691,7 @@ wasi_fd_advise(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_advise(curfds, fd, offset, len, advice);
return wasmtime_ssp_fd_advise(exec_env, curfds, fd, offset, len, advice);
}
static wasi_errno_t
@ -702,7 +705,7 @@ wasi_fd_allocate(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_allocate(curfds, fd, offset, len);
return wasmtime_ssp_fd_allocate(exec_env, curfds, fd, offset, len);
}
static wasi_errno_t
@ -716,7 +719,8 @@ wasi_path_create_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_path_create_directory(curfds, fd, path, path_len);
return wasmtime_ssp_path_create_directory(exec_env, curfds, fd, path,
path_len);
}
static wasi_errno_t
@ -733,8 +737,9 @@ wasi_path_link(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_path_link(curfds, prestats, old_fd, old_flags, old_path,
old_path_len, new_fd, new_path, new_path_len);
return wasmtime_ssp_path_link(exec_env, curfds, prestats, old_fd, old_flags,
old_path, old_path_len, new_fd, new_path,
new_path_len);
}
static wasi_errno_t
@ -756,9 +761,9 @@ wasi_path_open(wasm_exec_env_t exec_env, wasi_fd_t dirfd,
if (!validate_native_addr(fd_app, sizeof(wasi_fd_t)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_path_open(curfds, dirfd, dirflags, path, path_len,
oflags, fs_rights_base, fs_rights_inheriting,
fs_flags, &fd);
err = wasmtime_ssp_path_open(exec_env, curfds, dirfd, dirflags, path,
path_len, oflags, fs_rights_base,
fs_rights_inheriting, fs_flags, &fd);
*fd_app = fd;
return err;
@ -780,7 +785,8 @@ wasi_fd_readdir(wasm_exec_env_t exec_env, wasi_fd_t fd, void *buf,
if (!validate_native_addr(bufused_app, sizeof(uint32)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_fd_readdir(curfds, fd, buf, buf_len, cookie, &bufused);
err = wasmtime_ssp_fd_readdir(exec_env, curfds, fd, buf, buf_len, cookie,
&bufused);
if (err)
return err;
@ -805,8 +811,8 @@ wasi_path_readlink(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
if (!validate_native_addr(bufused_app, sizeof(uint32)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_path_readlink(curfds, fd, path, path_len, buf, buf_len,
&bufused);
err = wasmtime_ssp_path_readlink(exec_env, curfds, fd, path, path_len, buf,
buf_len, &bufused);
if (err)
return err;
@ -826,8 +832,9 @@ wasi_path_rename(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_path_rename(curfds, old_fd, old_path, old_path_len,
new_fd, new_path, new_path_len);
return wasmtime_ssp_path_rename(exec_env, curfds, old_fd, old_path,
old_path_len, new_fd, new_path,
new_path_len);
}
static wasi_errno_t
@ -844,7 +851,7 @@ wasi_fd_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_filestat_get(curfds, fd, filestat);
return wasmtime_ssp_fd_filestat_get(exec_env, curfds, fd, filestat);
}
static wasi_errno_t
@ -859,8 +866,8 @@ wasi_fd_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_filestat_set_times(curfds, fd, st_atim, st_mtim,
fstflags);
return wasmtime_ssp_fd_filestat_set_times(exec_env, curfds, fd, st_atim,
st_mtim, fstflags);
}
static wasi_errno_t
@ -874,7 +881,7 @@ wasi_fd_filestat_set_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_filestat_set_size(curfds, fd, st_size);
return wasmtime_ssp_fd_filestat_set_size(exec_env, curfds, fd, st_size);
}
static wasi_errno_t
@ -892,8 +899,8 @@ wasi_path_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
return (wasi_errno_t)-1;
return wasmtime_ssp_path_filestat_get(curfds, fd, flags, path, path_len,
filestat);
return wasmtime_ssp_path_filestat_get(exec_env, curfds, fd, flags, path,
path_len, filestat);
}
static wasi_errno_t
@ -909,8 +916,9 @@ wasi_path_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_path_filestat_set_times(
curfds, fd, flags, path, path_len, st_atim, st_mtim, fstflags);
return wasmtime_ssp_path_filestat_set_times(exec_env, curfds, fd, flags,
path, path_len, st_atim,
st_mtim, fstflags);
}
static wasi_errno_t
@ -926,8 +934,8 @@ wasi_path_symlink(wasm_exec_env_t exec_env, const char *old_path,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_path_symlink(curfds, prestats, old_path, old_path_len,
fd, new_path, new_path_len);
return wasmtime_ssp_path_symlink(exec_env, curfds, prestats, old_path,
old_path_len, fd, new_path, new_path_len);
}
static wasi_errno_t
@ -941,7 +949,7 @@ wasi_path_unlink_file(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_path_unlink_file(curfds, fd, path, path_len);
return wasmtime_ssp_path_unlink_file(exec_env, curfds, fd, path, path_len);
}
static wasi_errno_t
@ -955,7 +963,8 @@ wasi_path_remove_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_path_remove_directory(curfds, fd, path, path_len);
return wasmtime_ssp_path_remove_directory(exec_env, curfds, fd, path,
path_len);
}
#if WASM_ENABLE_THREAD_MGR != 0
@ -1026,8 +1035,8 @@ execute_interruptible_poll_oneoff(
/* update timeout for clock subscription events */
update_clock_subscription_data(
in_copy, nsubscriptions, min_uint64(time_quant, timeout - elapsed));
err = wasmtime_ssp_poll_oneoff(curfds, in_copy, out, nsubscriptions,
nevents);
err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in_copy, out,
nsubscriptions, nevents);
elapsed += time_quant;
if (err) {
@ -1079,7 +1088,8 @@ wasi_poll_oneoff(wasm_exec_env_t exec_env, const wasi_subscription_t *in,
return (wasi_errno_t)-1;
#if WASM_ENABLE_THREAD_MGR == 0
err = wasmtime_ssp_poll_oneoff(curfds, in, out, nsubscriptions, &nevents);
err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in, out, nsubscriptions,
&nevents);
#else
err = execute_interruptible_poll_oneoff(curfds, in, out, nsubscriptions,
&nevents, exec_env);
@ -1133,7 +1143,7 @@ wasi_sock_accept(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_fdflags_t flags,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasi_ssp_sock_accept(curfds, fd, flags, fd_new);
return wasi_ssp_sock_accept(exec_env, curfds, fd, flags, fd_new);
}
static wasi_errno_t
@ -1152,7 +1162,7 @@ wasi_sock_addr_local(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasi_ssp_sock_addr_local(curfds, fd, addr);
return wasi_ssp_sock_addr_local(exec_env, curfds, fd, addr);
}
static wasi_errno_t
@ -1171,7 +1181,7 @@ wasi_sock_addr_remote(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasi_ssp_sock_addr_remote(curfds, fd, addr);
return wasi_ssp_sock_addr_remote(exec_env, curfds, fd, addr);
}
static wasi_errno_t
@ -1192,8 +1202,8 @@ wasi_sock_addr_resolve(wasm_exec_env_t exec_env, const char *host,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
ns_lookup_list = wasi_ctx_get_ns_lookup_list(wasi_ctx);
return wasi_ssp_sock_addr_resolve(curfds, ns_lookup_list, host, service,
hints, addr_info, addr_info_size,
return wasi_ssp_sock_addr_resolve(exec_env, curfds, ns_lookup_list, host,
service, hints, addr_info, addr_info_size,
max_info_size);
}
@ -1211,7 +1221,7 @@ wasi_sock_bind(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
addr_pool = wasi_ctx_get_addr_pool(module_inst, wasi_ctx);
return wasi_ssp_sock_bind(curfds, addr_pool, fd, addr);
return wasi_ssp_sock_bind(exec_env, curfds, addr_pool, fd, addr);
}
static wasi_errno_t
@ -1234,7 +1244,7 @@ wasi_sock_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
addr_pool = wasi_ctx_get_addr_pool(module_inst, wasi_ctx);
return wasi_ssp_sock_connect(curfds, addr_pool, fd, addr);
return wasi_ssp_sock_connect(exec_env, curfds, addr_pool, fd, addr);
}
static wasi_errno_t
@ -1253,7 +1263,7 @@ wasi_sock_get_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_broadcast(curfds, fd, is_enabled);
return wasmtime_ssp_sock_get_broadcast(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@ -1272,7 +1282,7 @@ wasi_sock_get_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_keep_alive(curfds, fd, is_enabled);
return wasmtime_ssp_sock_get_keep_alive(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@ -1292,7 +1302,8 @@ wasi_sock_get_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool *is_enabled,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_linger(curfds, fd, is_enabled, linger_s);
return wasmtime_ssp_sock_get_linger(exec_env, curfds, fd, is_enabled,
linger_s);
}
static wasi_errno_t
@ -1311,7 +1322,7 @@ wasi_sock_get_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_recv_buf_size(curfds, fd, size);
return wasmtime_ssp_sock_get_recv_buf_size(exec_env, curfds, fd, size);
}
static wasi_errno_t
@ -1330,7 +1341,7 @@ wasi_sock_get_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_recv_timeout(curfds, fd, timeout_us);
return wasmtime_ssp_sock_get_recv_timeout(exec_env, curfds, fd, timeout_us);
}
static wasi_errno_t
@ -1349,7 +1360,7 @@ wasi_sock_get_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_reuse_addr(curfds, fd, is_enabled);
return wasmtime_ssp_sock_get_reuse_addr(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@ -1368,7 +1379,7 @@ wasi_sock_get_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_reuse_port(curfds, fd, is_enabled);
return wasmtime_ssp_sock_get_reuse_port(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@ -1387,7 +1398,7 @@ wasi_sock_get_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_send_buf_size(curfds, fd, size);
return wasmtime_ssp_sock_get_send_buf_size(exec_env, curfds, fd, size);
}
static wasi_errno_t
@ -1406,7 +1417,7 @@ wasi_sock_get_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_send_timeout(curfds, fd, timeout_us);
return wasmtime_ssp_sock_get_send_timeout(exec_env, curfds, fd, timeout_us);
}
static wasi_errno_t
@ -1425,7 +1436,8 @@ wasi_sock_get_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_tcp_fastopen_connect(curfds, fd, is_enabled);
return wasmtime_ssp_sock_get_tcp_fastopen_connect(exec_env, curfds, fd,
is_enabled);
}
static wasi_errno_t
@ -1444,7 +1456,7 @@ wasi_sock_get_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_tcp_no_delay(curfds, fd, is_enabled);
return wasmtime_ssp_sock_get_tcp_no_delay(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@ -1463,7 +1475,8 @@ wasi_sock_get_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_tcp_quick_ack(curfds, fd, is_enabled);
return wasmtime_ssp_sock_get_tcp_quick_ack(exec_env, curfds, fd,
is_enabled);
}
static wasi_errno_t
@ -1482,7 +1495,7 @@ wasi_sock_get_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_tcp_keep_idle(curfds, fd, time_s);
return wasmtime_ssp_sock_get_tcp_keep_idle(exec_env, curfds, fd, time_s);
}
static wasi_errno_t
@ -1501,7 +1514,7 @@ wasi_sock_get_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_tcp_keep_intvl(curfds, fd, time_s);
return wasmtime_ssp_sock_get_tcp_keep_intvl(exec_env, curfds, fd, time_s);
}
static wasi_errno_t
@ -1520,7 +1533,7 @@ wasi_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_ip_multicast_loop(curfds, fd, ipv6,
return wasmtime_ssp_sock_get_ip_multicast_loop(exec_env, curfds, fd, ipv6,
is_enabled);
}
@ -1539,7 +1552,7 @@ wasi_sock_get_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t *ttl_s)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_ip_ttl(curfds, fd, ttl_s);
return wasmtime_ssp_sock_get_ip_ttl(exec_env, curfds, fd, ttl_s);
}
static wasi_errno_t
@ -1558,7 +1571,7 @@ wasi_sock_get_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_ip_multicast_ttl(curfds, fd, ttl_s);
return wasmtime_ssp_sock_get_ip_multicast_ttl(exec_env, curfds, fd, ttl_s);
}
static wasi_errno_t
@ -1577,7 +1590,7 @@ wasi_sock_get_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_get_ipv6_only(curfds, fd, is_enabled);
return wasmtime_ssp_sock_get_ipv6_only(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@ -1592,7 +1605,7 @@ wasi_sock_listen(wasm_exec_env_t exec_env, wasi_fd_t fd, uint32 backlog)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasi_ssp_sock_listen(curfds, fd, backlog);
return wasi_ssp_sock_listen(exec_env, curfds, fd, backlog);
}
static wasi_errno_t
@ -1609,7 +1622,7 @@ wasi_sock_open(wasm_exec_env_t exec_env, wasi_fd_t poolfd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasi_ssp_sock_open(curfds, poolfd, af, socktype, sockfd);
return wasi_ssp_sock_open(exec_env, curfds, poolfd, af, socktype, sockfd);
}
static wasi_errno_t
@ -1624,7 +1637,7 @@ wasi_sock_set_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_broadcast(curfds, fd, is_enabled);
return wasmtime_ssp_sock_set_broadcast(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@ -1640,7 +1653,7 @@ wasi_sock_set_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_keep_alive(curfds, fd, is_enabled);
return wasmtime_ssp_sock_set_keep_alive(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@ -1656,7 +1669,8 @@ wasi_sock_set_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_linger(curfds, fd, is_enabled, linger_s);
return wasmtime_ssp_sock_set_linger(exec_env, curfds, fd, is_enabled,
linger_s);
}
static wasi_errno_t
@ -1671,7 +1685,7 @@ wasi_sock_set_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, size_t size)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_recv_buf_size(curfds, fd, size);
return wasmtime_ssp_sock_set_recv_buf_size(exec_env, curfds, fd, size);
}
static wasi_errno_t
@ -1687,7 +1701,7 @@ wasi_sock_set_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_recv_timeout(curfds, fd, timeout_us);
return wasmtime_ssp_sock_set_recv_timeout(exec_env, curfds, fd, timeout_us);
}
static wasi_errno_t
@ -1703,7 +1717,7 @@ wasi_sock_set_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_reuse_addr(curfds, fd, is_enabled);
return wasmtime_ssp_sock_set_reuse_addr(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@ -1719,7 +1733,7 @@ wasi_sock_set_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_reuse_port(curfds, fd, is_enabled);
return wasmtime_ssp_sock_set_reuse_port(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@ -1734,7 +1748,7 @@ wasi_sock_set_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, size_t size)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_send_buf_size(curfds, fd, size);
return wasmtime_ssp_sock_set_send_buf_size(exec_env, curfds, fd, size);
}
static wasi_errno_t
@ -1750,7 +1764,7 @@ wasi_sock_set_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_send_timeout(curfds, fd, timeout_us);
return wasmtime_ssp_sock_set_send_timeout(exec_env, curfds, fd, timeout_us);
}
static wasi_errno_t
@ -1766,7 +1780,8 @@ wasi_sock_set_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_tcp_fastopen_connect(curfds, fd, is_enabled);
return wasmtime_ssp_sock_set_tcp_fastopen_connect(exec_env, curfds, fd,
is_enabled);
}
static wasi_errno_t
@ -1782,7 +1797,7 @@ wasi_sock_set_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_tcp_no_delay(curfds, fd, is_enabled);
return wasmtime_ssp_sock_set_tcp_no_delay(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@ -1798,7 +1813,8 @@ wasi_sock_set_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_tcp_quick_ack(curfds, fd, is_enabled);
return wasmtime_ssp_sock_set_tcp_quick_ack(exec_env, curfds, fd,
is_enabled);
}
static wasi_errno_t
@ -1814,7 +1830,7 @@ wasi_sock_set_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_tcp_keep_idle(curfds, fd, time_s);
return wasmtime_ssp_sock_set_tcp_keep_idle(exec_env, curfds, fd, time_s);
}
static wasi_errno_t
@ -1830,7 +1846,7 @@ wasi_sock_set_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_tcp_keep_intvl(curfds, fd, time_s);
return wasmtime_ssp_sock_set_tcp_keep_intvl(exec_env, curfds, fd, time_s);
}
static wasi_errno_t
@ -1846,7 +1862,7 @@ wasi_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_ip_multicast_loop(curfds, fd, ipv6,
return wasmtime_ssp_sock_set_ip_multicast_loop(exec_env, curfds, fd, ipv6,
is_enabled);
}
@ -1867,8 +1883,8 @@ wasi_sock_set_ip_add_membership(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_ip_add_membership(curfds, fd, imr_multiaddr,
imr_interface);
return wasmtime_ssp_sock_set_ip_add_membership(
exec_env, curfds, fd, imr_multiaddr, imr_interface);
}
static wasi_errno_t
@ -1888,8 +1904,8 @@ wasi_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_ip_drop_membership(curfds, fd, imr_multiaddr,
imr_interface);
return wasmtime_ssp_sock_set_ip_drop_membership(
exec_env, curfds, fd, imr_multiaddr, imr_interface);
}
static wasi_errno_t
@ -1904,7 +1920,7 @@ wasi_sock_set_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t ttl_s)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_ip_ttl(curfds, fd, ttl_s);
return wasmtime_ssp_sock_set_ip_ttl(exec_env, curfds, fd, ttl_s);
}
static wasi_errno_t
@ -1920,7 +1936,7 @@ wasi_sock_set_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_ip_multicast_ttl(curfds, fd, ttl_s);
return wasmtime_ssp_sock_set_ip_multicast_ttl(exec_env, curfds, fd, ttl_s);
}
static wasi_errno_t
@ -1935,7 +1951,7 @@ wasi_sock_set_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
return wasmtime_ssp_sock_set_ipv6_only(curfds, fd, is_enabled);
return wasmtime_ssp_sock_set_ipv6_only(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@ -2053,8 +2069,9 @@ wasi_sock_recv_from(wasm_exec_env_t exec_env, wasi_fd_t sock,
memset(buf_begin, 0, total_size);
*ro_data_len = 0;
err = wasmtime_ssp_sock_recv_from(curfds, sock, buf_begin, total_size,
ri_flags, src_addr, &recv_bytes);
err = wasmtime_ssp_sock_recv_from(exec_env, curfds, sock, buf_begin,
total_size, ri_flags, src_addr,
&recv_bytes);
if (err != __WASI_ESUCCESS) {
goto fail;
}
@ -2153,7 +2170,8 @@ wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock,
return err;
*so_data_len = 0;
err = wasmtime_ssp_sock_send(curfds, sock, buf, buf_size, &send_bytes);
err = wasmtime_ssp_sock_send(exec_env, curfds, sock, buf, buf_size,
&send_bytes);
*so_data_len = (uint32)send_bytes;
wasm_runtime_free(buf);
@ -2193,8 +2211,8 @@ wasi_sock_send_to(wasm_exec_env_t exec_env, wasi_fd_t sock,
return err;
*so_data_len = 0;
err = wasmtime_ssp_sock_send_to(curfds, addr_pool, sock, buf, buf_size,
si_flags, dest_addr, &send_bytes);
err = wasmtime_ssp_sock_send_to(exec_env, curfds, addr_pool, sock, buf,
buf_size, si_flags, dest_addr, &send_bytes);
*so_data_len = (uint32)send_bytes;
wasm_runtime_free(buf);
@ -2212,7 +2230,7 @@ wasi_sock_shutdown(wasm_exec_env_t exec_env, wasi_fd_t sock, wasi_sdflags_t how)
if (!wasi_ctx)
return __WASI_EINVAL;
return wasmtime_ssp_sock_shutdown(curfds, sock);
return wasmtime_ssp_sock_shutdown(exec_env, curfds, sock);
}
static wasi_errno_t

View File

@ -22,6 +22,8 @@
#include <stddef.h>
#include <stdint.h>
#include "wasm_export.h"
/* clang-format off */
#ifdef __cplusplus
@ -274,37 +276,6 @@ typedef uint8_t __wasi_sdflags_t;
typedef uint16_t __wasi_siflags_t;
typedef uint8_t __wasi_signal_t;
// 0 is reserved; POSIX has special semantics for kill(pid, 0).
#define __WASI_SIGHUP (1)
#define __WASI_SIGINT (2)
#define __WASI_SIGQUIT (3)
#define __WASI_SIGILL (4)
#define __WASI_SIGTRAP (5)
#define __WASI_SIGABRT (6)
#define __WASI_SIGBUS (7)
#define __WASI_SIGFPE (8)
#define __WASI_SIGKILL (9)
#define __WASI_SIGUSR1 (10)
#define __WASI_SIGSEGV (11)
#define __WASI_SIGUSR2 (12)
#define __WASI_SIGPIPE (13)
#define __WASI_SIGALRM (14)
#define __WASI_SIGTERM (15)
#define __WASI_SIGCHLD (16)
#define __WASI_SIGCONT (17)
#define __WASI_SIGSTOP (18)
#define __WASI_SIGTSTP (19)
#define __WASI_SIGTTIN (20)
#define __WASI_SIGTTOU (21)
#define __WASI_SIGURG (22)
#define __WASI_SIGXCPU (23)
#define __WASI_SIGXFSZ (24)
#define __WASI_SIGVTALRM (25)
#define __WASI_SIGPROF (26)
#define __WASI_SIGWINCH (27)
#define __WASI_SIGPOLL (28)
#define __WASI_SIGPWR (29)
#define __WASI_SIGSYS (30)
typedef uint16_t __wasi_subclockflags_t;
#define __WASI_SUBSCRIPTION_CLOCK_ABSTIME (0x0001)
@ -639,17 +610,13 @@ typedef struct __wasi_addr_info_hints_t {
#endif
__wasi_errno_t wasmtime_ssp_args_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct argv_environ_values *arg_environ,
#endif
char **argv,
char *argv_buf
) WASMTIME_SSP_SYSCALL_NAME(args_get) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_args_sizes_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct argv_environ_values *arg_environ,
#endif
size_t *argc,
size_t *argv_buf_size
) WASMTIME_SSP_SYSCALL_NAME(args_sizes_get) WARN_UNUSED;
@ -666,57 +633,46 @@ __wasi_errno_t wasmtime_ssp_clock_time_get(
) WASMTIME_SSP_SYSCALL_NAME(clock_time_get) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_environ_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct argv_environ_values *arg_environ,
#endif
char **environ,
char *environ_buf
) WASMTIME_SSP_SYSCALL_NAME(environ_get) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_environ_sizes_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct argv_environ_values *arg_environ,
#endif
size_t *environ_count,
size_t *environ_buf_size
) WASMTIME_SSP_SYSCALL_NAME(environ_sizes_get) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_prestat_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_prestats *prestats,
#endif
__wasi_fd_t fd,
__wasi_prestat_t *buf
) WASMTIME_SSP_SYSCALL_NAME(fd_prestat_get) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_prestat_dir_name(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_prestats *prestats,
#endif
__wasi_fd_t fd,
char *path,
size_t path_len
) WASMTIME_SSP_SYSCALL_NAME(fd_prestat_dir_name) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_close(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
struct fd_prestats *prestats,
#endif
__wasi_fd_t fd
) WASMTIME_SSP_SYSCALL_NAME(fd_close) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_datasync(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd
) WASMTIME_SSP_SYSCALL_NAME(fd_datasync) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_pread(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const __wasi_iovec_t *iovs,
size_t iovs_len,
@ -725,9 +681,8 @@ __wasi_errno_t wasmtime_ssp_fd_pread(
) WASMTIME_SSP_SYSCALL_NAME(fd_pread) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_pwrite(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const __wasi_ciovec_t *iovs,
size_t iovs_len,
@ -736,9 +691,8 @@ __wasi_errno_t wasmtime_ssp_fd_pwrite(
) WASMTIME_SSP_SYSCALL_NAME(fd_pwrite) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_read(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const __wasi_iovec_t *iovs,
size_t iovs_len,
@ -746,18 +700,16 @@ __wasi_errno_t wasmtime_ssp_fd_read(
) WASMTIME_SSP_SYSCALL_NAME(fd_read) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_renumber(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
struct fd_prestats *prestats,
#endif
__wasi_fd_t from,
__wasi_fd_t to
) WASMTIME_SSP_SYSCALL_NAME(fd_renumber) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_seek(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_filedelta_t offset,
__wasi_whence_t whence,
@ -765,49 +717,43 @@ __wasi_errno_t wasmtime_ssp_fd_seek(
) WASMTIME_SSP_SYSCALL_NAME(fd_seek) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_tell(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_filesize_t *newoffset
) WASMTIME_SSP_SYSCALL_NAME(fd_tell) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_fdstat_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_fdstat_t *buf
) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_get) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_fdstat_set_flags(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_fdflags_t flags
) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_flags) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_fdstat_set_rights(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_rights_t fs_rights_base,
__wasi_rights_t fs_rights_inheriting
) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_rights) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_sync(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd
) WASMTIME_SSP_SYSCALL_NAME(fd_sync) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_write(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const __wasi_ciovec_t *iovs,
size_t iovs_len,
@ -815,9 +761,8 @@ __wasi_errno_t wasmtime_ssp_fd_write(
) WASMTIME_SSP_SYSCALL_NAME(fd_write) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_advise(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_filesize_t offset,
__wasi_filesize_t len,
@ -825,28 +770,25 @@ __wasi_errno_t wasmtime_ssp_fd_advise(
) WASMTIME_SSP_SYSCALL_NAME(fd_advise) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_allocate(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_filesize_t offset,
__wasi_filesize_t len
) WASMTIME_SSP_SYSCALL_NAME(fd_allocate) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_path_create_directory(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const char *path,
size_t path_len
) WASMTIME_SSP_SYSCALL_NAME(path_create_directory) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_path_link(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
struct fd_prestats *prestats,
#endif
__wasi_fd_t old_fd,
__wasi_lookupflags_t old_flags,
const char *old_path,
@ -857,9 +799,8 @@ __wasi_errno_t wasmtime_ssp_path_link(
) WASMTIME_SSP_SYSCALL_NAME(path_link) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_path_open(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t dirfd,
__wasi_lookupflags_t dirflags,
const char *path,
@ -872,9 +813,8 @@ __wasi_errno_t wasmtime_ssp_path_open(
) WASMTIME_SSP_SYSCALL_NAME(path_open) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_readdir(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
void *buf,
size_t buf_len,
@ -883,9 +823,8 @@ __wasi_errno_t wasmtime_ssp_fd_readdir(
) WASMTIME_SSP_SYSCALL_NAME(fd_readdir) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_path_readlink(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const char *path,
size_t path_len,
@ -895,9 +834,8 @@ __wasi_errno_t wasmtime_ssp_path_readlink(
) WASMTIME_SSP_SYSCALL_NAME(path_readlink) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_path_rename(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t old_fd,
const char *old_path,
size_t old_path_len,
@ -907,17 +845,15 @@ __wasi_errno_t wasmtime_ssp_path_rename(
) WASMTIME_SSP_SYSCALL_NAME(path_rename) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_filestat_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_filestat_t *buf
) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_get) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_filestat_set_times(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_timestamp_t st_atim,
__wasi_timestamp_t st_mtim,
@ -925,17 +861,15 @@ __wasi_errno_t wasmtime_ssp_fd_filestat_set_times(
) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_times) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_fd_filestat_set_size(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_filesize_t st_size
) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_size) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_path_filestat_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_lookupflags_t flags,
const char *path,
@ -944,9 +878,8 @@ __wasi_errno_t wasmtime_ssp_path_filestat_get(
) WASMTIME_SSP_SYSCALL_NAME(path_filestat_get) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_path_filestat_set_times(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_lookupflags_t flags,
const char *path,
@ -957,10 +890,9 @@ __wasi_errno_t wasmtime_ssp_path_filestat_set_times(
) WASMTIME_SSP_SYSCALL_NAME(path_filestat_set_times) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_path_symlink(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
struct fd_prestats *prestats,
#endif
const char *old_path,
size_t old_path_len,
__wasi_fd_t fd,
@ -969,47 +901,30 @@ __wasi_errno_t wasmtime_ssp_path_symlink(
) WASMTIME_SSP_SYSCALL_NAME(path_symlink) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_path_unlink_file(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const char *path,
size_t path_len
) WASMTIME_SSP_SYSCALL_NAME(path_unlink_file) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_path_remove_directory(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const char *path,
size_t path_len
) WASMTIME_SSP_SYSCALL_NAME(path_remove_directory) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_poll_oneoff(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
const __wasi_subscription_t *in,
__wasi_event_t *out,
size_t nsubscriptions,
size_t *nevents
) WASMTIME_SSP_SYSCALL_NAME(poll_oneoff) WARN_UNUSED;
#if 0
/**
* We throw exception in libc-wasi wrapper function wasi_proc_exit()
* but not call this function.
*/
_Noreturn void wasmtime_ssp_proc_exit(
__wasi_exitcode_t rval
) WASMTIME_SSP_SYSCALL_NAME(proc_exit);
#endif
__wasi_errno_t wasmtime_ssp_proc_raise(
__wasi_signal_t sig
) WASMTIME_SSP_SYSCALL_NAME(proc_raise) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_random_get(
void *buf,
size_t buf_len
@ -1017,50 +932,44 @@ __wasi_errno_t wasmtime_ssp_random_get(
__wasi_errno_t
wasi_ssp_sock_accept(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd, __wasi_fdflags_t flags, __wasi_fd_t *fd_new
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_addr_local(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd, __wasi_addr_t *addr
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_addr_remote(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd, __wasi_addr_t *addr
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_open(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t poolfd, __wasi_address_family_t af, __wasi_sock_type_t socktype,
__wasi_fd_t *sockfd
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_bind(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds, struct addr_pool *addr_pool,
#endif
__wasi_fd_t fd, __wasi_addr_t *addr
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_addr_resolve(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds, char **ns_lookup_list,
#endif
const char *host, const char* service,
__wasi_addr_info_hints_t *hints, __wasi_addr_info_t *addr_info,
__wasi_size_t addr_info_size, __wasi_size_t *max_info_size
@ -1068,88 +977,77 @@ wasi_ssp_sock_addr_resolve(
__wasi_errno_t
wasi_ssp_sock_connect(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds, struct addr_pool *addr_pool,
#endif
__wasi_fd_t fd, __wasi_addr_t *addr
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_get_recv_buf_size(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd, __wasi_size_t *size
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_get_reuse_addr(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd, uint8_t *reuse
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_get_reuse_port(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd, uint8_t *reuse
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_get_send_buf_size(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd, __wasi_size_t *size
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_set_recv_buf_size(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd, __wasi_size_t size
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_set_reuse_addr(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd, uint8_t reuse
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_set_reuse_port(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd, uint8_t reuse
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_set_send_buf_size(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd, __wasi_size_t size
) WARN_UNUSED;
__wasi_errno_t
wasi_ssp_sock_listen(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t fd, __wasi_size_t backlog
) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_recv(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
void *buf,
size_t buf_len,
@ -1157,9 +1055,8 @@ __wasi_errno_t wasmtime_ssp_sock_recv(
) WASMTIME_SSP_SYSCALL_NAME(sock_recv) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_recv_from(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
void *buf,
size_t buf_len,
@ -1169,9 +1066,8 @@ __wasi_errno_t wasmtime_ssp_sock_recv_from(
) WASMTIME_SSP_SYSCALL_NAME(sock_recv_from) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_send(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
const void *buf,
size_t buf_len,
@ -1179,9 +1075,8 @@ __wasi_errno_t wasmtime_ssp_sock_send(
) WASMTIME_SSP_SYSCALL_NAME(sock_send) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_send_to(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds, struct addr_pool *addr_pool,
#endif
__wasi_fd_t sock,
const void *buf,
size_t buf_len,
@ -1191,317 +1086,278 @@ __wasi_errno_t wasmtime_ssp_sock_send_to(
) WASMTIME_SSP_SYSCALL_NAME(sock_send_to) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_shutdown(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock
) WASMTIME_SSP_SYSCALL_NAME(sock_shutdown) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_recv_timeout(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
uint64_t timeout_us
) WASMTIME_SSP_SYSCALL_NAME(sock_set_recv_timeout) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_recv_timeout(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
uint64_t *timeout_us
) WASMTIME_SSP_SYSCALL_NAME(sock_get_recv_timeout) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_send_timeout(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
uint64_t timeout_us
) WASMTIME_SSP_SYSCALL_NAME(sock_set_send_timeout) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_send_timeout(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
uint64_t *timeout_us
) WASMTIME_SSP_SYSCALL_NAME(sock_get_send_timeout) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_send_buf_size(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
size_t bufsiz
) WASMTIME_SSP_SYSCALL_NAME(sock_set_send_buf_size) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_send_buf_size(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
size_t *bufsiz
) WASMTIME_SSP_SYSCALL_NAME(sock_get_send_buf_size) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_recv_buf_size(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
size_t bufsiz
) WASMTIME_SSP_SYSCALL_NAME(sock_set_recv_buf_size) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_recv_buf_size(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
size_t *bufsiz
) WASMTIME_SSP_SYSCALL_NAME(sock_get_recv_buf_size) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_keep_alive(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_set_keep_alive) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_keep_alive(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool *is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_get_keep_alive) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_reuse_addr(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_set_reuse_addr) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_reuse_addr(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool *is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_get_reuse_addr) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_reuse_port(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_set_reuse_port) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_reuse_port(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool *is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_get_reuse_port) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_linger(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool is_enabled,
int linger_s
) WASMTIME_SSP_SYSCALL_NAME(sock_set_linger) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_linger(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock, bool *is_enabled, int *linger_s
) WASMTIME_SSP_SYSCALL_NAME(sock_get_linger) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_broadcast(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_set_broadcast) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_broadcast(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool *is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_get_broadcast) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_tcp_no_delay(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_no_delay) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_tcp_no_delay(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool *is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_no_delay) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_tcp_quick_ack(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_quick_ack) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_tcp_quick_ack(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool *is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_quick_ack) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_tcp_keep_idle(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
uint32_t time_s
) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_keep_idle) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_tcp_keep_idle(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
uint32_t *time_s
) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_keep_idle) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_tcp_keep_intvl(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
uint32_t time_s
) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_keep_intvl) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_tcp_keep_intvl(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
uint32_t *time_s
) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_keep_intvl) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_tcp_fastopen_connect(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_fastopen_connect) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_tcp_fastopen_connect(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool *is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_fastopen_connect) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_ip_multicast_loop(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool ipv6,
bool is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_multicast_loop) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_ip_multicast_loop(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool ipv6,
bool *is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_multicast_loop) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_ip_add_membership(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
__wasi_addr_ip_t *imr_multiaddr,
uint32_t imr_interface
) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_add_membership) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_ip_drop_membership(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
__wasi_addr_ip_t *imr_multiaddr,
uint32_t imr_interface
) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_drop_membership) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_ip_ttl(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
uint8_t ttl_s
) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_ttl) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_ip_ttl(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
uint8_t *ttl_s
) WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_ttl) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_ip_multicast_ttl(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
uint8_t ttl_s
) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_multicast_ttl) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_ip_multicast_ttl(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
uint8_t *ttl_s
) WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_multicast_ttl) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_set_ipv6_only(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_set_ipv6_only) WARN_UNUSED;
__wasi_errno_t wasmtime_ssp_sock_get_ipv6_only(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
wasm_exec_env_t exec_env,
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
bool *is_enabled
) WASMTIME_SSP_SYSCALL_NAME(sock_get_ipv6_only) WARN_UNUSED;

View File

@ -0,0 +1,226 @@
/*
* Copyright (C) 2023 Midokura Japan KK. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <errno.h>
#include "ssp_config.h"
#include "blocking_op.h"
int
blocking_op_close(wasm_exec_env_t exec_env, int fd)
{
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
int ret = close(fd);
wasm_runtime_end_blocking_op(exec_env);
return ret;
}
ssize_t
blocking_op_readv(wasm_exec_env_t exec_env, int fd, const struct iovec *iov,
int iovcnt)
{
#ifdef BH_PLATFORM_WINDOWS
errno = ENOTSUP;
return -1;
#else
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
ssize_t ret = readv(fd, iov, iovcnt);
wasm_runtime_end_blocking_op(exec_env);
return ret;
#endif
}
#if CONFIG_HAS_PREADV
ssize_t
blocking_op_preadv(wasm_exec_env_t exec_env, int fd, const struct iovec *iov,
int iovcnt, off_t offset)
{
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
ssize_t ret = preadv(fd, iov, iovcnt, offset);
wasm_runtime_end_blocking_op(exec_env);
return ret;
}
#else /* CONFIG_HAS_PREADV */
ssize_t
blocking_op_pread(wasm_exec_env_t exec_env, int fd, void *p, size_t nb,
off_t offset)
{
#ifdef BH_PLATFORM_WINDOWS
errno = ENOTSUP;
return -1;
#else
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
ssize_t ret = pread(fd, p, nb, offset);
wasm_runtime_end_blocking_op(exec_env);
return ret;
#endif
}
#endif /* CONFIG_HAS_PREADV */
ssize_t
blocking_op_writev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov,
int iovcnt)
{
#ifdef BH_PLATFORM_WINDOWS
errno = ENOTSUP;
return -1;
#else
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
ssize_t ret = writev(fd, iov, iovcnt);
wasm_runtime_end_blocking_op(exec_env);
return ret;
#endif
}
#if CONFIG_HAS_PWRITEV
ssize_t
blocking_op_pwritev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov,
int iovcnt, off_t offset)
{
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
ssize_t ret = pwritev(fd, iov, iovcnt, offset);
wasm_runtime_end_blocking_op(exec_env);
return ret;
}
#else /* CONFIG_HAS_PWRITEV */
ssize_t
blocking_op_pwrite(wasm_exec_env_t exec_env, int fd, const void *p, size_t nb,
off_t offset)
{
#ifdef BH_PLATFORM_WINDOWS
errno = ENOTSUP;
return -1;
#else
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
ssize_t ret = pwrite(fd, p, nb, offset);
wasm_runtime_end_blocking_op(exec_env);
return ret;
#endif
}
#endif /* CONFIG_HAS_PWRITEV */
int
blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock,
bh_socket_t *sockp, void *addr,
unsigned int *addrlenp)
{
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
int ret = os_socket_accept(server_sock, sockp, addr, addrlenp);
wasm_runtime_end_blocking_op(exec_env);
return ret;
}
int
blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock,
const char *addr, int port)
{
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
int ret = os_socket_connect(sock, addr, port);
wasm_runtime_end_blocking_op(exec_env);
return ret;
}
int
blocking_op_socket_recv_from(wasm_exec_env_t exec_env, bh_socket_t sock,
void *buf, unsigned int len, int flags,
bh_sockaddr_t *src_addr)
{
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
int ret = os_socket_recv_from(sock, buf, len, flags, src_addr);
wasm_runtime_end_blocking_op(exec_env);
return ret;
}
int
blocking_op_socket_send_to(wasm_exec_env_t exec_env, bh_socket_t sock,
const void *buf, unsigned int len, int flags,
const bh_sockaddr_t *dest_addr)
{
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
int ret = os_socket_send_to(sock, buf, len, flags, dest_addr);
wasm_runtime_end_blocking_op(exec_env);
return ret;
}
int
blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host,
const char *service, uint8_t *hint_is_tcp,
uint8_t *hint_is_ipv4,
bh_addr_info_t *addr_info,
size_t addr_info_size, size_t *max_info_size)
{
/*
* Note: Unlike others, os_socket_addr_resolve() is not a simple system
* call. It's likely backed by a complex libc function, getaddrinfo().
* Depending on the implementation of getaddrinfo() and underlying
* DNS resolver, it might or might not be possible to make it return
* with os_wakeup_blocking_op().
*
* Unfortunately, many of ISC/bind based resolvers just keep going on
* interrupted system calls. It includes macOS and glibc.
*
* On the other hand, NuttX as of writing this returns EAI_AGAIN
* on EINTR.
*/
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
int ret = os_socket_addr_resolve(host, service, hint_is_tcp, hint_is_ipv4,
addr_info, addr_info_size, max_info_size);
wasm_runtime_end_blocking_op(exec_env);
return ret;
}
int
blocking_op_openat(wasm_exec_env_t exec_env, int fd, const char *path,
int oflags, mode_t mode)
{
#ifdef BH_PLATFORM_WINDOWS
errno = ENOTSUP;
return -1;
#else
if (!wasm_runtime_begin_blocking_op(exec_env)) {
errno = EINTR;
return -1;
}
int ret = openat(fd, path, oflags, mode);
wasm_runtime_end_blocking_op(exec_env);
return ret;
#endif
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2023 Midokura Japan KK. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "bh_platform.h"
#include "wasm_export.h"
int
blocking_op_close(wasm_exec_env_t exec_env, int fd);
ssize_t
blocking_op_readv(wasm_exec_env_t exec_env, int fd, const struct iovec *iov,
int iovcnt);
ssize_t
blocking_op_preadv(wasm_exec_env_t exec_env, int fd, const struct iovec *iov,
int iovcnt, off_t offset);
ssize_t
blocking_op_pread(wasm_exec_env_t exec_env, int fd, void *p, size_t nb,
off_t offset);
ssize_t
blocking_op_writev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov,
int iovcnt);
ssize_t
blocking_op_pwritev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov,
int iovcnt, off_t offset);
ssize_t
blocking_op_pwrite(wasm_exec_env_t exec_env, int fd, const void *p, size_t nb,
off_t offset);
int
blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock,
bh_socket_t *sockp, void *addr,
unsigned int *addrlenp);
int
blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock,
const char *addr, int port);
int
blocking_op_socket_recv_from(wasm_exec_env_t exec_env, bh_socket_t sock,
void *buf, unsigned int len, int flags,
bh_sockaddr_t *src_addr);
int
blocking_op_socket_send_to(wasm_exec_env_t exec_env, bh_socket_t sock,
const void *buf, unsigned int len, int flags,
const bh_sockaddr_t *dest_addr);
int
blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host,
const char *service, uint8_t *hint_is_tcp,
uint8_t *hint_is_ipv4,
bh_addr_info_t *addr_info,
size_t addr_info_size, size_t *max_info_size);
#ifdef BH_PLATFORM_WINDOWS
/* TODO to be (re)moved as part of WASI on windows work */
typedef unsigned mode_t;
#endif
int
blocking_op_openat(wasm_exec_env_t exec_env, int fd, const char *path,
int oflags, mode_t mode);

View File

@ -14,8 +14,8 @@
#ifndef SSP_CONFIG_H
#define SSP_CONFIG_H
#include "bh_platform.h"
#include "gnuc.h"
#include <stdlib.h>
#if defined(__FreeBSD__) || defined(__APPLE__) \
|| (defined(ANDROID) && __ANDROID_API__ < 28)
@ -66,7 +66,8 @@
#endif
#endif
#if !defined(__APPLE__) && !defined(ESP_PLATFORM) && !defined(_WIN32)
#if !defined(__APPLE__) && !defined(ESP_PLATFORM) && !defined(_WIN32) \
&& !defined(__COSMOPOLITAN__)
#define CONFIG_HAS_POSIX_FALLOCATE 1
#else
#define CONFIG_HAS_POSIX_FALLOCATE 0
@ -84,7 +85,8 @@
#define CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 0
#endif
#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX) && !defined(_WIN32)
#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX) && !defined(_WIN32) \
&& !defined(__COSMOPOLITAN__)
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 1
#else
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 0
@ -102,10 +104,18 @@
#define st_mtim st_mtimespec
#endif
#ifdef __APPLE__
#define CONFIG_TLS_USE_GSBASE 1
#else
#define CONFIG_TLS_USE_GSBASE 0
#if defined(O_DSYNC)
#define CONFIG_HAS_O_DSYNC
#endif
// POSIX requires O_RSYNC to be defined, but Linux explicitly doesn't support
// it.
#if defined(O_RSYNC) && !defined(__linux__)
#define CONFIG_HAS_O_RSYNC
#endif
#if defined(O_SYNC)
#define CONFIG_HAS_O_SYNC
#endif
#if !defined(BH_PLATFORM_LINUX_SGX)

View File

@ -16,10 +16,6 @@
#include "debug_engine.h"
#endif
#if WASM_ENABLE_SHARED_MEMORY != 0
#include "wasm_shared_memory.h"
#endif
typedef struct {
bh_list_link l;
void (*destroy_cb)(WASMCluster *);
@ -32,6 +28,8 @@ static bh_list cluster_list_head;
static bh_list *const cluster_list = &cluster_list_head;
static korp_mutex cluster_list_lock;
static korp_mutex _exception_lock;
typedef void (*list_visitor)(void *, void *);
static uint32 cluster_max_thread_num = CLUSTER_MAX_THREAD_NUM;
@ -52,6 +50,10 @@ thread_manager_init()
return false;
if (os_mutex_init(&cluster_list_lock) != 0)
return false;
if (os_mutex_init(&_exception_lock) != 0) {
os_mutex_destroy(&cluster_list_lock);
return false;
}
return true;
}
@ -66,6 +68,7 @@ thread_manager_destroy()
cluster = next;
}
wasm_cluster_cancel_all_callbacks();
os_mutex_destroy(&_exception_lock);
os_mutex_destroy(&cluster_list_lock);
}
@ -477,9 +480,6 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasm_module_t module;
wasm_module_inst_t new_module_inst;
#if WASM_ENABLE_LIBC_WASI != 0
WASIContext *wasi_ctx;
#endif
WASMExecEnv *new_exec_env;
uint32 aux_stack_start, aux_stack_size;
uint32 stack_size = 8192;
@ -517,10 +517,7 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
wasm_runtime_set_custom_data_internal(
new_module_inst, wasm_runtime_get_custom_data(module_inst));
#if WASM_ENABLE_LIBC_WASI != 0
wasi_ctx = wasm_runtime_get_wasi_ctx(module_inst);
wasm_runtime_set_wasi_ctx(new_module_inst, wasi_ctx);
#endif
wasm_native_inherit_contexts(new_module_inst, module_inst);
new_exec_env = wasm_exec_env_create_internal(new_module_inst,
exec_env->wasm_stack_size);
@ -1062,6 +1059,19 @@ set_thread_cancel_flags(WASMExecEnv *exec_env)
WASM_SUSPEND_FLAG_TERMINATE);
os_mutex_unlock(&exec_env->wait_lock);
#ifdef OS_ENABLE_WAKEUP_BLOCKING_OP
wasm_runtime_interrupt_blocking_op(exec_env);
#endif
}
static void
clear_thread_cancel_flags(WASMExecEnv *exec_env)
{
os_mutex_lock(&exec_env->wait_lock);
WASM_SUSPEND_FLAGS_FETCH_AND(exec_env->suspend_flags,
~WASM_SUSPEND_FLAG_TERMINATE);
os_mutex_unlock(&exec_env->wait_lock);
}
int32
@ -1240,72 +1250,55 @@ wasm_cluster_resume_all(WASMCluster *cluster)
os_mutex_unlock(&cluster->lock);
}
struct spread_exception_data {
WASMExecEnv *skip;
const char *exception;
};
static void
set_exception_visitor(void *node, void *user_data)
{
WASMExecEnv *curr_exec_env = (WASMExecEnv *)node;
WASMExecEnv *exec_env = (WASMExecEnv *)user_data;
WASMModuleInstanceCommon *module_inst = get_module_inst(exec_env);
WASMModuleInstance *wasm_inst = (WASMModuleInstance *)module_inst;
const struct spread_exception_data *data = user_data;
WASMExecEnv *exec_env = (WASMExecEnv *)node;
if (curr_exec_env != exec_env) {
WASMModuleInstance *curr_wasm_inst =
(WASMModuleInstance *)get_module_inst(curr_exec_env);
if (exec_env != data->skip) {
WASMModuleInstance *wasm_inst =
(WASMModuleInstance *)get_module_inst(exec_env);
/* Only spread non "wasi proc exit" exception */
#if WASM_ENABLE_SHARED_MEMORY != 0
if (curr_wasm_inst->memory_count > 0)
shared_memory_lock(curr_wasm_inst->memories[0]);
#endif
if (!strstr(wasm_inst->cur_exception, "wasi proc exit")) {
bh_memcpy_s(curr_wasm_inst->cur_exception,
sizeof(curr_wasm_inst->cur_exception),
wasm_inst->cur_exception,
sizeof(wasm_inst->cur_exception));
exception_lock(wasm_inst);
if (data->exception != NULL) {
snprintf(wasm_inst->cur_exception, sizeof(wasm_inst->cur_exception),
"Exception: %s", data->exception);
}
#if WASM_ENABLE_SHARED_MEMORY != 0
if (curr_wasm_inst->memory_count > 0)
shared_memory_unlock(curr_wasm_inst->memories[0]);
#endif
else {
wasm_inst->cur_exception[0] = '\0';
}
exception_unlock(wasm_inst);
/* Terminate the thread so it can exit from dead loops */
set_thread_cancel_flags(curr_exec_env);
}
}
static void
clear_exception_visitor(void *node, void *user_data)
{
WASMExecEnv *exec_env = (WASMExecEnv *)user_data;
WASMExecEnv *curr_exec_env = (WASMExecEnv *)node;
if (curr_exec_env != exec_env) {
WASMModuleInstance *curr_wasm_inst =
(WASMModuleInstance *)get_module_inst(curr_exec_env);
#if WASM_ENABLE_SHARED_MEMORY != 0
if (curr_wasm_inst->memory_count > 0)
shared_memory_lock(curr_wasm_inst->memories[0]);
#endif
curr_wasm_inst->cur_exception[0] = '\0';
#if WASM_ENABLE_SHARED_MEMORY != 0
if (curr_wasm_inst->memory_count > 0)
shared_memory_unlock(curr_wasm_inst->memories[0]);
#endif
if (data->exception != NULL) {
set_thread_cancel_flags(exec_env);
}
else {
clear_thread_cancel_flags(exec_env);
}
}
}
void
wasm_cluster_spread_exception(WASMExecEnv *exec_env, bool clear)
wasm_cluster_set_exception(WASMExecEnv *exec_env, const char *exception)
{
const bool has_exception = exception != NULL;
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
bh_assert(cluster);
struct spread_exception_data data;
data.skip = NULL;
data.exception = exception;
os_mutex_lock(&cluster->lock);
cluster->has_exception = !clear;
traverse_list(&cluster->exec_env_list,
clear ? clear_exception_visitor : set_exception_visitor,
exec_env);
cluster->has_exception = has_exception;
traverse_list(&cluster->exec_env_list, set_exception_visitor, &data);
os_mutex_unlock(&cluster->lock);
}
@ -1341,6 +1334,48 @@ wasm_cluster_spread_custom_data(WASMModuleInstanceCommon *module_inst,
}
}
#if WASM_ENABLE_MODULE_INST_CONTEXT != 0
struct inst_set_context_data {
void *key;
void *ctx;
};
static void
set_context_visitor(void *node, void *user_data)
{
WASMExecEnv *curr_exec_env = (WASMExecEnv *)node;
WASMModuleInstanceCommon *module_inst = get_module_inst(curr_exec_env);
const struct inst_set_context_data *data = user_data;
wasm_runtime_set_context(module_inst, data->key, data->ctx);
}
void
wasm_cluster_set_context(WASMModuleInstanceCommon *module_inst, void *key,
void *ctx)
{
WASMExecEnv *exec_env = wasm_clusters_search_exec_env(module_inst);
if (exec_env == NULL) {
/* Maybe threads have not been started yet. */
wasm_runtime_set_context(module_inst, key, ctx);
}
else {
WASMCluster *cluster;
struct inst_set_context_data data;
data.key = key;
data.ctx = ctx;
cluster = wasm_exec_env_get_cluster(exec_env);
bh_assert(cluster);
os_mutex_lock(&cluster->lock);
traverse_list(&cluster->exec_env_list, set_context_visitor, &data);
os_mutex_unlock(&cluster->lock);
}
}
#endif /* WASM_ENABLE_MODULE_INST_CONTEXT != 0 */
bool
wasm_cluster_is_thread_terminated(WASMExecEnv *exec_env)
{
@ -1353,3 +1388,21 @@ wasm_cluster_is_thread_terminated(WASMExecEnv *exec_env)
return is_thread_terminated;
}
void
exception_lock(WASMModuleInstance *module_inst)
{
/*
* Note: this lock could be per module instance if desirable.
* We can revisit on AOT version bump.
* It probably doesn't matter though because the exception handling
* logic should not be executed too frequently anyway.
*/
os_mutex_lock(&_exception_lock);
}
void
exception_unlock(WASMModuleInstance *module_inst)
{
os_mutex_unlock(&_exception_lock);
}

View File

@ -139,7 +139,7 @@ WASMExecEnv *
wasm_clusters_search_exec_env(WASMModuleInstanceCommon *module_inst);
void
wasm_cluster_spread_exception(WASMExecEnv *exec_env, bool clear);
wasm_cluster_set_exception(WASMExecEnv *exec_env, const char *exception);
WASMExecEnv *
wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env);
@ -151,6 +151,10 @@ void
wasm_cluster_spread_custom_data(WASMModuleInstanceCommon *module_inst,
void *custom_data);
void
wasm_cluster_set_context(WASMModuleInstanceCommon *module_inst, void *key,
void *ctx);
bool
wasm_cluster_is_thread_terminated(WASMExecEnv *exec_env);

View File

@ -163,6 +163,7 @@ void
wasi_nn_destroy(wasm_module_inst_t instance)
{
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
bh_hash_map_remove(hashmap, (void *)instance, NULL, NULL);
wasi_nn_ctx_destroy(wasi_nn_ctx);
}