• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __UVWASI_SERDES_H__
2 #define __UVWASI_SERDES_H__
3 
4 #include "wasi_types.h"
5 
6 /* Basic uint{8,16,32,64}_t read/write functions. */
7 
8 #define BASIC_TYPE(name, type)                                                \
9   void uvwasi_serdes_write_##name(void* ptr, size_t offset, type value);      \
10   type uvwasi_serdes_read_##name(const void* ptr, size_t offset);             \
11 
12 #define BASIC_TYPE_UVWASI(type) BASIC_TYPE(type, uvwasi_##type)
13 
14 #define UVWASI_SERDES_SIZE_uint8_t sizeof(uint8_t)
15 BASIC_TYPE(uint8_t, uint8_t)
16 #define UVWASI_SERDES_SIZE_uint16_t sizeof(uint16_t)
17 BASIC_TYPE(uint16_t, uint16_t)
18 #define UVWASI_SERDES_SIZE_uint32_t sizeof(uint32_t)
19 BASIC_TYPE(uint32_t, uint32_t)
20 #define UVWASI_SERDES_SIZE_uint64_t sizeof(uint64_t)
21 BASIC_TYPE(uint64_t, uint64_t)
22 
23 #define UVWASI_SERDES_SIZE_advice_t sizeof(uvwasi_advice_t)
24 BASIC_TYPE_UVWASI(advice_t)
25 #define UVWASI_SERDES_SIZE_clockid_t sizeof(uvwasi_clockid_t)
26 BASIC_TYPE_UVWASI(clockid_t)
27 #define UVWASI_SERDES_SIZE_device_t sizeof(uvwasi_device_t)
28 BASIC_TYPE_UVWASI(device_t)
29 #define UVWASI_SERDES_SIZE_dircookie_t sizeof(uvwasi_dircookie_t)
30 BASIC_TYPE_UVWASI(dircookie_t)
31 #define UVWASI_SERDES_SIZE_eventrwflags_t sizeof(uvwasi_eventrwflags_t)
32 BASIC_TYPE_UVWASI(eventrwflags_t)
33 #define UVWASI_SERDES_SIZE_eventtype_t sizeof(uvwasi_eventtype_t)
34 BASIC_TYPE_UVWASI(eventtype_t)
35 #define UVWASI_SERDES_SIZE_exitcode_t sizeof(uvwasi_exitcode_t)
36 BASIC_TYPE_UVWASI(exitcode_t)
37 #define UVWASI_SERDES_SIZE_fd_t sizeof(uvwasi_fd_t)
38 BASIC_TYPE_UVWASI(fd_t)
39 #define UVWASI_SERDES_SIZE_fdflags_t sizeof(uvwasi_fdflags_t)
40 BASIC_TYPE_UVWASI(fdflags_t)
41 #define UVWASI_SERDES_SIZE_filesize_t sizeof(uvwasi_filesize_t)
42 BASIC_TYPE_UVWASI(filesize_t)
43 #define UVWASI_SERDES_SIZE_fstflags_t sizeof(uvwasi_fstflags_t)
44 BASIC_TYPE_UVWASI(fstflags_t)
45 #define UVWASI_SERDES_SIZE_inode_t sizeof(uvwasi_inode_t)
46 BASIC_TYPE_UVWASI(inode_t)
47 #define UVWASI_SERDES_SIZE_linkcount_t sizeof(uvwasi_linkcount_t)
48 BASIC_TYPE_UVWASI(linkcount_t)
49 #define UVWASI_SERDES_SIZE_lookupflags_t sizeof(uvwasi_lookupflags_t)
50 BASIC_TYPE_UVWASI(lookupflags_t)
51 #define UVWASI_SERDES_SIZE_oflags_t sizeof(uvwasi_oflags_t)
52 BASIC_TYPE_UVWASI(oflags_t)
53 #define UVWASI_SERDES_SIZE_preopentype_t sizeof(uvwasi_preopentype_t)
54 BASIC_TYPE_UVWASI(preopentype_t)
55 #define UVWASI_SERDES_SIZE_riflags_t sizeof(uvwasi_riflags_t)
56 BASIC_TYPE_UVWASI(riflags_t)
57 #define UVWASI_SERDES_SIZE_rights_t sizeof(uvwasi_rights_t)
58 BASIC_TYPE_UVWASI(rights_t)
59 #define UVWASI_SERDES_SIZE_roflags_t sizeof(uvwasi_roflags_t)
60 BASIC_TYPE_UVWASI(roflags_t)
61 #define UVWASI_SERDES_SIZE_sdflags_t sizeof(uvwasi_sdflags_t)
62 BASIC_TYPE_UVWASI(sdflags_t)
63 #define UVWASI_SERDES_SIZE_siflags_t sizeof(uvwasi_siflags_t)
64 BASIC_TYPE_UVWASI(siflags_t)
65 #define UVWASI_SERDES_SIZE_size_t sizeof(uvwasi_size_t)
66 BASIC_TYPE_UVWASI(size_t)
67 #define UVWASI_SERDES_SIZE_inode_t sizeof(uvwasi_inode_t)
68 BASIC_TYPE_UVWASI(inode_t)
69 #define UVWASI_SERDES_SIZE_signal_t sizeof(uvwasi_signal_t)
70 BASIC_TYPE_UVWASI(signal_t)
71 #define UVWASI_SERDES_SIZE_subclockflags_t sizeof(uvwasi_subclockflags_t)
72 BASIC_TYPE_UVWASI(subclockflags_t)
73 #define UVWASI_SERDES_SIZE_timestamp_t sizeof(uvwasi_timestamp_t)
74 BASIC_TYPE_UVWASI(timestamp_t)
75 #define UVWASI_SERDES_SIZE_userdata_t sizeof(uvwasi_userdata_t)
76 BASIC_TYPE_UVWASI(userdata_t)
77 #define UVWASI_SERDES_SIZE_whence_t sizeof(uvwasi_whence_t)
78 BASIC_TYPE_UVWASI(whence_t)
79 
80 #undef BASIC_TYPE_UVWASI
81 #undef BASIC_TYPE
82 
83 /* WASI structure read/write functions. */
84 
85 #define STRUCT(name)                                                          \
86   void uvwasi_serdes_write_##name(void* ptr,                                  \
87                                   size_t offset,                              \
88                                   const uvwasi_##name* value);                \
89   void uvwasi_serdes_read_##name(const void* ptr,                             \
90                                  size_t offset,                               \
91                                  uvwasi_##name* value);
92 
93 /* iovs currently only need to be read from WASM memory. */
94 #define IOVS_STRUCT(name)                                                     \
95   uvwasi_errno_t uvwasi_serdes_read_##name(const void* ptr,                   \
96                                            size_t end,                        \
97                                            size_t offset,                     \
98                                            uvwasi_##name* value);
99 
100 #define UVWASI_SERDES_SIZE_ciovec_t 8
101 IOVS_STRUCT(ciovec_t)
102 
103 #define UVWASI_SERDES_SIZE_iovec_t 8
104 IOVS_STRUCT(iovec_t)
105 
106 #define UVWASI_SERDES_SIZE_dirent_t 24
107 STRUCT(dirent_t)
108 
109 #define UVWASI_SERDES_SIZE_fdstat_t 24
110 STRUCT(fdstat_t)
111 
112 #define UVWASI_SERDES_SIZE_filestat_t 64
113 STRUCT(filestat_t)
114 
115 #define UVWASI_SERDES_SIZE_prestat_t 8
116 STRUCT(prestat_t)
117 
118 #define UVWASI_SERDES_SIZE_event_t 32
119 STRUCT(event_t)
120 
121 #define UVWASI_SERDES_SIZE_subscription_t 48
122 STRUCT(subscription_t)
123 
124 #undef STRUCT
125 #undef IOVS_STRUCT
126 
127 uvwasi_errno_t uvwasi_serdes_readv_ciovec_t(const void* ptr,
128                                             size_t end,
129                                             size_t offset,
130                                             uvwasi_ciovec_t* iovs,
131                                             uvwasi_size_t iovs_len);
132 
133 uvwasi_errno_t uvwasi_serdes_readv_iovec_t(const void* ptr,
134                                            size_t end,
135                                            size_t offset,
136                                            uvwasi_iovec_t* iovs,
137                                            uvwasi_size_t iovs_len);
138 
139 /* Helper functions for memory bounds checking. */
140 int uvwasi_serdes_check_bounds(size_t offset, size_t end, size_t size);
141 int uvwasi_serdes_check_array_bounds(size_t offset,
142                                      size_t end,
143                                      size_t size,
144                                      size_t count);
145 
146 #endif /* __UVWASI_SERDES_H__ */
147