libc_wasi_wrapper.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _LIBC_WASI_WRAPPER_H
  6. #define _LIBC_WASI_WRAPPER_H
  7. #include "posix.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. typedef __wasi_address_family_t wasi_address_family_t;
  12. typedef __wasi_addr_t wasi_addr_t;
  13. typedef __wasi_advice_t wasi_advice_t;
  14. typedef __wasi_ciovec_t wasi_ciovec_t;
  15. typedef __wasi_clockid_t wasi_clockid_t;
  16. typedef __wasi_dircookie_t wasi_dircookie_t;
  17. // __wasi_errno_t is typedef'd to uint16 which is correct according to the ABI
  18. // specification. However, in WASM, the smallest integer type is int32. If we
  19. // return uint16, we would rely on language SDKs to implement the correct
  20. // behaviour of casting to uint16 before checking the value or using it any way.
  21. // Failure to do so can cause tricky bugs as the upper 16 bits of the error
  22. // result are not guaranteed to be zero'ed by us so the result essentially
  23. // contains garbage from the WASM app perspective. To prevent this, we return
  24. // uint32 directly instead so as not to be reliant on the correct behaviour of
  25. // any current/future WASI SDK implementations.
  26. typedef uint32_t wasi_errno_t;
  27. typedef __wasi_event_t wasi_event_t;
  28. typedef __wasi_exitcode_t wasi_exitcode_t;
  29. typedef __wasi_fdflags_t wasi_fdflags_t;
  30. typedef __wasi_fdstat_t wasi_fdstat_t;
  31. typedef __wasi_fd_t wasi_fd_t;
  32. typedef __wasi_filedelta_t wasi_filedelta_t;
  33. typedef __wasi_filesize_t wasi_filesize_t;
  34. typedef __wasi_filestat_t wasi_filestat_t;
  35. typedef __wasi_filetype_t wasi_filetype_t;
  36. typedef __wasi_fstflags_t wasi_fstflags_t;
  37. typedef __wasi_iovec_t wasi_iovec_t;
  38. typedef __wasi_ip_port_t wasi_ip_port_t;
  39. typedef __wasi_lookupflags_t wasi_lookupflags_t;
  40. typedef __wasi_oflags_t wasi_oflags_t;
  41. typedef __wasi_preopentype_t wasi_preopentype_t;
  42. typedef __wasi_prestat_t wasi_prestat_t;
  43. typedef __wasi_riflags_t wasi_riflags_t;
  44. typedef __wasi_rights_t wasi_rights_t;
  45. typedef __wasi_roflags_t wasi_roflags_t;
  46. typedef __wasi_sdflags_t wasi_sdflags_t;
  47. typedef __wasi_siflags_t wasi_siflags_t;
  48. typedef __wasi_signal_t wasi_signal_t;
  49. typedef __wasi_size_t wasi_size_t;
  50. typedef __wasi_sock_type_t wasi_sock_type_t;
  51. typedef __wasi_subscription_t wasi_subscription_t;
  52. typedef __wasi_timestamp_t wasi_timestamp_t;
  53. typedef __wasi_whence_t wasi_whence_t;
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57. #endif /* end of _LIBC_WASI_WRAPPER_H */