2023-01-09 12:36:34 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2023-01-11 01:40:32 +00:00
|
|
|
#define STACK_SIZE 32 * 1024 // same as the main stack
|
2023-01-09 12:36:34 +00:00
|
|
|
|
2023-08-31 12:23:54 +00:00
|
|
|
/* See https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids */
|
|
|
|
#define ASSERT_VALID_TID(TID) \
|
2024-01-17 00:06:02 +00:00
|
|
|
(void)TID; \
|
2023-08-31 12:23:54 +00:00
|
|
|
assert(TID >= 1 && TID <= 0x1FFFFFFF && "Invalid thread ID")
|
|
|
|
|
2023-01-09 12:36:34 +00:00
|
|
|
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
|