wasm-micro-runtime/samples/wasi-threads/wasm-apps/wasi_thread_start.h
Marcin Kolny 0e2382a959
Disable aux stack allocations for threads spawned by wasi_thread_start (#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.
2023-01-09 20:36:34 +08:00

32 lines
608 B
C

/*
* 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