wasi_thread_start.h 848 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (C) 2022 Amazon.com Inc. or its affiliates. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef WASI_THREAD_START_H
  6. #define WASI_THREAD_START_H
  7. #define STACK_SIZE 32 * 1024 // same as the main stack
  8. /* See https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids */
  9. #define ASSERT_VALID_TID(TID) \
  10. (void)TID; \
  11. assert(TID >= 1 && TID <= 0x1FFFFFFF && "Invalid thread ID")
  12. typedef struct {
  13. void *stack;
  14. } start_args_t;
  15. static inline int
  16. start_args_init(start_args_t *start_args)
  17. {
  18. start_args->stack = malloc(STACK_SIZE);
  19. if (!start_args->stack) {
  20. return 0;
  21. }
  22. start_args->stack += STACK_SIZE;
  23. return 1;
  24. }
  25. static inline void
  26. start_args_deinit(start_args_t *start_args)
  27. {
  28. free(start_args->stack - STACK_SIZE);
  29. }
  30. #endif