forked from bytecodealliance/wasm-micro-runtime
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable aux stack allocations for threads spawned by wasi_thread_start (
bytecodealliance#1867) This syscall doesn't need allocating stack or TLS and it's expected from the application to do that instead. E.g. WASI-libc already does this for `pthread_create`. Also fix some of the examples to allocate memory for stack and not use stack before the stack pointer is set to a correct value.
- Loading branch information
Showing
12 changed files
with
159 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# A slightly modified copy of the wasi-libc implementation | ||
# https://github.com/WebAssembly/wasi-libc/pull/376/ | ||
.globaltype __stack_pointer, i32 | ||
.functype __wasi_thread_start_C (i32, i32) -> () | ||
|
||
.globl wasi_thread_start | ||
|
||
wasi_thread_start: | ||
.functype wasi_thread_start (i32, i32) -> () | ||
|
||
# Set up the minimum C environment. | ||
# Note: offsetof(start_arg, stack) == 0 | ||
local.get 1 # start_arg | ||
i32.load 0 # stack | ||
global.set __stack_pointer | ||
|
||
# Make the C function do the rest of work. | ||
local.get 0 # tid | ||
local.get 1 # start_arg | ||
call __wasi_thread_start_C | ||
|
||
end_function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2022 Amazon.com Inc. or its affiliates. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
*/ | ||
#ifndef WASI_THREAD_START_H | ||
#define WASI_THREAD_START_H | ||
|
||
#define STACK_SIZE 1024 | ||
|
||
typedef struct { | ||
void *stack; | ||
} start_args_t; | ||
|
||
static inline int | ||
start_args_init(start_args_t *start_args) | ||
{ | ||
start_args->stack = malloc(STACK_SIZE); | ||
if (!start_args->stack) { | ||
return 0; | ||
} | ||
|
||
start_args->stack += STACK_SIZE; | ||
return 1; | ||
} | ||
|
||
static inline void | ||
start_args_deinit(start_args_t *start_args) | ||
{ | ||
free(start_args->stack - STACK_SIZE); | ||
} | ||
|
||
#endif |