wasi_thread_start.h 816 B

123456789101112131415161718192021222324252627282930313233343536
  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. assert(TID >= 1 && TID <= 0x1FFFFFFF && "Invalid thread ID")
  11. typedef struct {
  12. void *stack;
  13. } start_args_t;
  14. static inline int
  15. start_args_init(start_args_t *start_args)
  16. {
  17. start_args->stack = malloc(STACK_SIZE);
  18. if (!start_args->stack) {
  19. return 0;
  20. }
  21. start_args->stack += STACK_SIZE;
  22. return 1;
  23. }
  24. static inline void
  25. start_args_deinit(start_args_t *start_args)
  26. {
  27. free(start_args->stack - STACK_SIZE);
  28. }
  29. #endif