|
1 | 1 | --- REL_17_5_WASM/src/include/port/wasi.h |
2 | 2 | +++ pglite-REL_17_5_WASM/src/include/port/wasi.h |
3 | | -@@ -1,17 +1,336 @@ |
| 3 | +@@ -1,17 +1,229 @@ |
4 | 4 | -/* src/include/port/{wasi/emscripten}.h */ |
5 | 5 | +#pragma once |
6 | 6 |
|
|
54 | 54 | + return -1; |
55 | 55 | +} |
56 | 56 | + |
57 | | -+/* |
58 | | -+struct __wasi_addrinfo_t{ |
59 | | -+ int32_t ai_flags; |
60 | | -+ int32_t ai_family; |
61 | | -+ int32_t ai_socktype; |
62 | | -+ int32_t ai_protocol; |
63 | | -+ __wasi_size_t ai_addrlen; |
64 | | -+ __wasi_address_t* ai_addr; |
65 | | -+ //__wasi_size_t ai_canonname_len; |
66 | | -+ uint32_t ai_canonname; |
67 | | -+ struct __wasi_addrinfo_t** ai_next; |
68 | | -+}; |
69 | | -+*/ |
70 | | -+ |
71 | | -+#include <arpa/inet.h> // for inet_pton |
72 | | -+#include <sys/types.h> |
73 | | -+#include <sys/socket.h> |
74 | | -+#include <netdb.h> |
75 | | -+ |
76 | | -+/* extern one is not valid in wasip2 |
77 | | -+extern int getaddrinfo(const char *restrict node, |
78 | | -+ const char *restrict service, |
79 | | -+ const struct addrinfo *restrict hints, |
80 | | -+ struct addrinfo **restrict res); |
81 | | -+*/ |
82 | | -+ |
83 | | -+ |
84 | | -+/* |
85 | | -+static int getaddrinfo(const char *hostname, const char *service, |
86 | | -+ const struct addrinfo *hints, struct addrinfo **res) { |
87 | | -+ struct addrinfo *result = malloc(sizeof(struct addrinfo)); |
88 | | -+ if (!result) return EAI_MEMORY; |
89 | | -+ |
90 | | -+ memset(result, 0, sizeof(struct addrinfo)); |
91 | | -+ result->ai_family = AF_INET; |
92 | | -+ result->ai_socktype = SOCK_STREAM; |
93 | | -+ result->ai_protocol = IPPROTO_TCP; |
94 | | -+ |
95 | | -+ struct sockaddr_in *addr = malloc(sizeof(struct sockaddr_in)); |
96 | | -+ if (!addr) { |
97 | | -+ free(result); |
98 | | -+ return EAI_MEMORY; |
99 | | -+ } |
100 | | -+ |
101 | | -+ addr->sin_family = AF_INET; |
102 | | -+ addr->sin_port = htons(atoi(service)); |
103 | | -+ if (inet_pton(AF_INET, hostname, &(addr->sin_addr)) <= 0) { |
104 | | -+ free(result); |
105 | | -+ free(addr); |
106 | | -+ return EAI_FAIL; |
107 | | -+ } |
108 | | -+ |
109 | | -+ result->ai_addr = (struct sockaddr *)addr; |
110 | | -+ result->ai_addrlen = sizeof(struct sockaddr_in); |
111 | | -+ result->ai_next = NULL; |
112 | | -+ |
113 | | -+ *res = result; |
114 | | -+ return 0; |
115 | | -+} |
116 | | -+ |
117 | | -+*/ |
118 | | -+ |
119 | | -+ |
120 | | -+ |
121 | 57 | +// ============= signal ============== |
122 | 58 | + |
123 | 59 | +#define SA_RESTART 4 |
|
157 | 93 | +} |
158 | 94 | + |
159 | 95 | + |
160 | | -+ |
161 | | -+ |
162 | 96 | +// WIP: semaphores |
163 | 97 | +// https://github.com/bytecodealliance/wasm-micro-runtime/issues/3054 |
164 | 98 | +#include <sys/sem.h> |
|
245 | 179 | + |
246 | 180 | +// ==================================================== |
247 | 181 | + |
248 | | -+/* |
249 | | -+#include <setjmp.h> |
250 | | -+ |
251 | | -+static int |
252 | | -+sigsetjmp(sigjmp_buf env, int savesigs) { |
253 | | -+// puts("# 201: sigsetjmp"); |
254 | | -+ return 0; |
255 | | -+} |
256 | | -+ |
257 | | -+static void |
258 | | -+siglongjmp(sigjmp_buf env, int val) { |
259 | | -+ puts("# 207: siglongjmp"); |
260 | | -+} |
261 | | -+*/ |
262 | | -+ |
263 | | -+ |
264 | 182 | +// WIP : |
265 | 183 | + |
266 | 184 | +#include <sys/mman.h> |
| 185 | ++ |
267 | 186 | +#if defined(PYDK) |
268 | 187 | +extern int shm_open(const char *name, int oflag, mode_t mode); |
269 | 188 | +extern int shm_unlink(const char *name); |
|
274 | 193 | + int fd; |
275 | 194 | + snprintf(tmpnam, 128, "/tmp%s", name); |
276 | 195 | + fd=fileno(fopen(tmpnam, "w+")); |
277 | | -+ fprintf(stderr, "# 212: shm_open(%s) => %d\n", tmpnam, fd); |
| 196 | ++ fprintf(stderr, "# 186: shm_open(%s) => %d\n", tmpnam, fd); |
278 | 197 | + return fd; |
279 | 198 | +} |
280 | 199 | + |
281 | 200 | +static int |
282 | 201 | +shm_unlink(const char *name) { |
283 | 202 | + char tmpnam[128]; |
284 | 203 | + snprintf(tmpnam, 128, "/tmp%s", name); |
285 | | -+ fprintf(stderr, "# 220: shm_unlink(%s) STUB\n", tmpnam); |
| 204 | ++ fprintf(stderr, "# 194: shm_unlink(%s) STUB\n", tmpnam); |
286 | 205 | + return remove(tmpnam); // -1 |
287 | 206 | +} |
288 | 207 | + |
|
293 | 212 | + |
294 | 213 | +static void |
295 | 214 | +tzset(void) { |
296 | | -+ puts("# 241: tzset(void) STUB"); |
| 215 | ++ puts("# 205: tzset(void) STUB"); |
297 | 216 | +} |
298 | 217 | + |
299 | 218 | +#if defined(PG_INITDB) || defined(FE_UTILS_PRINT) || defined(PG_DUMP_PARALLEL) |
|
303 | 222 | +#endif |
304 | 223 | + |
305 | 224 | + |
306 | | -+ |
307 | | -+ |
308 | | -+// TODO: socket here |
309 | | -+// ================================================================== |
310 | | -+ |
311 | | -+#include <sys/socket.h> |
312 | | -+ |
313 | | -+//extern ssize_t sdk_recv(int sockfd, void *buf, size_t len, int flags); |
314 | | -+//extern ssize_t recvfrom(int socket, void *buffer, size_t length, int flags, void *address, socklen_t *address_len); |
315 | | -+ |
316 | | -+//extern ssize_t sdk_send(int sockfd, const void *buf, size_t len, int flags); |
317 | | -+//extern ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, void *dest_addr, socklen_t addrlen); |
318 | | -+ |
319 | | -+ |
320 | | -+ |
321 | | -+ |
322 | 225 | +static int |
323 | 226 | +listen(int sockfd, int backlog) { |
324 | 227 | + return 0; |
|
329 | 232 | + return NULL; |
330 | 233 | +} |
331 | 234 | + |
332 | | -+//#define pthread_mutex_lock(mut) sdk_pthread_mutex_lock(mut) |
333 | | -+//extern int sdk_pthread_mutex_lock(void *mutex); |
334 | | -+ |
335 | | -+/* |
336 | | -+ int pthread_mutex_lock(pthread_mutex_t *mutex); |
337 | | -+ int pthread_mutex_trylock(pthread_mutex_t *mutex); |
338 | | -+ int pthread_mutex_unlock(pthread_mutex_t *mutex); |
339 | | -+*/ |
340 | | -+ |
341 | 235 | +#endif // __wasi__p2 |
342 | 236 | + |
343 | 237 | +#endif // I_WASI |
344 | | -+ |
345 | 238 |
|
346 | 239 |
|
347 | 240 | -#endif // I_WASM |
0 commit comments