Debian Codegraph @

runtime/platform/wasi.h

raw symbols SCIP
1 #define _GNU_SOURCE
2
3 #include <dirent.h>
4 #include <fcntl.h>
5 #include <fenv.h>
6 #include <inttypes.h>
7 #include <netinet/in.h>
8 #include <netinet/tcp.h>
9 #include <poll.h>
10 #include <sys/ioctl.h>
11 #include <sys/resource.h>
12 #include <sys/socket.h>
13 #include <sys/stat.h>
14 #include <sys/sysinfo.h>
15 #include <sys/time.h>
16 #include <sys/types.h>
17 #include <unistd.h>
18 #include <utime.h>
19
20 #define HAS_FEROUND TRUE
21 #define HAS_MSG_DONTWAIT TRUE
22 #define HAS_REMAP FALSE
23 #define HAS_SHRINK_HEAP FALSE
24 #define HAS_SIGALTSTACK FALSE
25 #define NEEDS_SIGALTSTACK_EXEC FALSE
26 #define HAS_SPAWN FALSE
27 #define HAS_TIME_PROFILING FALSE
28
29 #define MLton_Platform_OS_host "wasi"
30
31 /*
32 * The definitions below are missing from WASI but are required by the runtime.
33 *
34 * In a small number of cases, these are implemented in wasi.c, but most of them
35 * are not. See wasi.c for a discussion.
36 *
37 * These are not guarded by ifdefs so that we can easily detect when functionality
38 * is added to WASI.
39 *
40 * This file is roughly based on the mingw implementation.
41 */
42
43 /* ------------------------------------------------- */
44 /* Itimer */
45 /* ------------------------------------------------- */
46
47 #define ITIMER_REAL 0
48 #define ITIMER_VIRTUAL 1
49 #define ITIMER_PROF 2
50
51 struct itimerval {
52 struct timeval it_interval;
53 struct timeval it_value;
54 };
55
56 int setitimer (int, const struct itimerval *, struct itimerval *);
57
58 /* ------------------------------------------------- */
59 /* Rlimit */
60 /* ------------------------------------------------- */
61
62 #define RLIMIT_CPU 0
63 #define RLIMIT_FSIZE 1
64 #define RLIMIT_DATA 2
65 #define RLIMIT_STACK 3
66 #define RLIMIT_CORE 4
67 #define RLIMIT_NOFILE 5
68 #define RLIMIT_AS 6
69 #define RLIMIT_NLIMITS 7
70
71 #define RLIM_INFINITY (0xffffffffUL)
72
73 typedef unsigned long rlim_t;
74
75 struct rlimit {
76 rlim_t rlim_cur;
77 rlim_t rlim_max;
78 };
79
80 int getrlimit (int resource, struct rlimit *);
81 int setrlimit (int resource, const struct rlimit *);
82
83 /* ------------------------------------------------- */
84 /* Networking */
85 /* ------------------------------------------------- */
86
87 struct servent {
88 char *s_name;
89 char **s_aliases;
90 int s_port;
91 char *s_proto;
92 };
93
94 struct servent *getservbyname (const char *, const char *);
95 extern struct servent *getservbyport (int, const char *);
96
97 struct hostent {
98 char *h_name;
99 char **h_aliases;
100 int h_addrtype;
101 int h_length;
102 char **h_addr_list;
103 };
104
105 struct hostent *gethostbyaddr (const void *, socklen_t, int);
106 struct hostent *gethostbyname (const char *);
107
108 int socket (int, int, int);
109 int socketpair (int, int, int, int [2]);
110 int bind (int, const struct sockaddr *, socklen_t);
111 int connect (int, const struct sockaddr *, socklen_t);
112 int listen (int, int);
113 ssize_t recvfrom (int, void *, size_t, int, struct sockaddr *, socklen_t *);
114 ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t);
115 int setsockopt (int, int, int, const void *, socklen_t);
116 int getpeername (int, struct sockaddr *, socklen_t *);
117 int gethostname(char *, size_t);
118 int getsockname (int, struct sockaddr *, socklen_t *);
119
120 #define SIOCATMARK 0x8905
121
122 #define SO_DEBUG 1
123 #define SO_REUSEADDR 2
124 #define SO_TYPE 3
125 #define SO_ERROR 4
126 #define SO_DONTROUTE 5
127 #define SO_BROADCAST 6
128 #define SO_SNDBUF 7
129 #define SO_RCVBUF 8
130 #define SO_KEEPALIVE 9
131 #define SO_OOBINLINE 10
132 #define SO_NO_CHECK 11
133 #define SO_PRIORITY 12
134 #define SO_LINGER 13
135 #define SO_BSDCOMPAT 14
136 #define SO_REUSEPORT 15
137 #define SO_PASSCRED 16
138 #define SO_PEERCRED 17
139 #define SO_RCVLOWAT 18
140 #define SO_SNDLOWAT 19
141 #define SO_ACCEPTCONN 30
142 #define SO_PEERSEC 31
143 #define SO_SNDBUFFORCE 32
144 #define SO_RCVBUFFORCE 33
145 #define SO_PROTOCOL 38
146 #define SO_DOMAIN 39
147 #define SO_RCVTIMEO 66
148 #define SO_SNDTIMEO 67
149
150 #define SOCK_RAW 3
151 #define SOCK_RDM 4
152 #define SOCK_SEQPACKET 5
153 #define SOCK_DCCP 6
154 #define SOCK_PACKET 10
155
156 struct sockaddr_un {
157 sa_family_t sun_family;
158 char sun_path[108];
159 };
160
161 #define MSG_OOB 0x0001
162 #define MSG_DONTROUTE 0x0004
163 #define MSG_CTRUNC 0x0008
164 #define MSG_PROXY 0x0010
165 #define MSG_DONTWAIT 0x0040
166 #define MSG_EOR 0x0080
167
168 struct protoent {
169 char *p_name;
170 char **p_aliases;
171 int p_proto;
172 };
173
174 struct protoent *getprotobyname (const char *);
175 struct protoent *getprotobynumber (int);
176
177 /* ------------------------------------------------- */
178 /* Files */
179 /* ------------------------------------------------- */
180
181 #define F_DUPFD 0
182 #define F_GETOWN 5
183 #define F_SETOWN 6
184 #define F_GETLK 7
185 #define F_SETLK 8
186
187 #define F_RDLCK 1
188 #define F_WRLCK 2
189 #define F_UNLCK 3
190
191 #define F_SETLKW 9
192
193 int chmod(const char *, mode_t);
194 int chown (const char *, uid_t, gid_t);
195 int fchdir (int);
196 int fchmod (int, mode_t);
197 int fchown (int, uid_t, gid_t);
198 long fpathconf (int, int);
199 int link (const char *, const char *);
200 int lstat (const char *, struct stat *);
201 int mkfifo (const char *, mode_t);
202 int mkstemp (char *);
203 long pathconf (const char *, int);
204 int symlink (const char *, const char *);
205 int truncate (const char *, off_t);
206 mode_t umask(mode_t);
207
208 int dup(int);
209 int dup2(int, int);
210 int fcntl (int, int, ...);
211 int fsync (int);
212 int pipe (int [2]);
213
214 /* ------------------------------------------------- */
215 /* Processes */
216 /* ------------------------------------------------- */
217
218 struct tms {
219 int tms_utime;
220 int tms_stime;
221 int tms_cutime;
222 int tms_cstime;
223 };
224
225 struct utsname {
226 char machine[20];
227 char nodename[256];
228 char release[20];
229 char sysname[30];
230 char version[20];
231 };
232
233 char *getlogin (void);
234 char *ctermid (char *);
235 gid_t getegid (void);
236 uid_t geteuid (void);
237 gid_t getgid (void);
238 int getgroups (int, gid_t []);
239 pid_t getpgid(pid_t);
240 pid_t getpgrp(void);
241 pid_t getppid (void);
242 uid_t getuid (void);
243 int setenv (const char *, const char *, int);
244 int setgid (gid_t);
245 int setgroups (size_t, const gid_t *);
246 int setpgid (pid_t, pid_t);
247 pid_t setsid (void);
248 int setuid (uid_t);
249 clock_t times (struct tms *);
250 char *ttyname (int);
251 int uname (struct utsname *);
252
253 #define POLLPRI 0x002
254
255 #define WNOHANG 1
256 #define WUNTRACED 2
257
258 #define WIFEXITED(w) ((w) & 0)
259 #define WIFSIGNALED(w) ((w) & 0)
260 #define WIFSTOPPED(w) ((w) & 0)
261 #define WTERMSIG(w) ((w) & 0)
262 #define WEXITSTATUS(w) ((w) & 0)
263 #define WSTOPSIG WEXITSTATUS
264
265 int alarm(int);
266 int execve(const char *, char *const [], char *const []);
267 int execvp(const char *, char *const []);
268 pid_t fork(void);
269 int kill(pid_t, int);
270 int pause(void);
271 pid_t waitpid (pid_t, int *, int);
272
273 /* ------------------------------------------------- */
274 /* Signals */
275 /* ------------------------------------------------- */
276
277 #define SIG_BLOCK 0
278 #define SIG_UNBLOCK 1
279 #define SIG_SETMASK 2
280
281 struct sigaction {
282 int sa_flags;
283 sigset_t sa_mask;
284 void (*sa_handler)(int);
285 };
286
287 int sigaction (int, const struct sigaction *, struct sigaction *);
288 int sigaddset (sigset_t *, int);
289 int sigdelset (sigset_t *, int);
290 int sigemptyset (sigset_t *);
291 int sigfillset (sigset_t *);
292 int sigismember (const sigset_t *, int);
293 int sigpending (sigset_t *);
294 int sigprocmask (int, const sigset_t *, sigset_t *);
295 int sigsuspend (const sigset_t *);
296
297 /* ------------------------------------------------- */
298 /* Passwd */
299 /* ------------------------------------------------- */
300
301 struct group {
302 gid_t gr_gid;
303 char **gr_mem;
304 char *gr_name;
305 char *gr_passwd;
306 };
307
308 struct passwd {
309 char *pw_dir;
310 gid_t pw_gid;
311 char *pw_name;
312 char *pw_shell;
313 uid_t pw_uid;
314 };
315
316 struct group *getgrgid (gid_t);
317 struct group *getgrnam (const char *);
318 struct passwd *getpwnam (const char *);
319 struct passwd *getpwuid (uid_t);
320
321 /* ------------------------------------------------- */
322 /* TTY */
323 /* ------------------------------------------------- */
324
325 #define B0 0x00000
326 #define B50 0x00001
327 #define B75 0x00002
328 #define B110 0x00003
329 #define B134 0x00004
330 #define B150 0x00005
331 #define B200 0x00006
332 #define B300 0x00007
333 #define B600 0x00008
334 #define B1200 0x00009
335 #define B1800 0x0000a
336 #define B2400 0x0000b
337 #define B4800 0x0000c
338 #define B9600 0x0000d
339 #define B19200 0x0000e
340 #define B38400 0x0000f
341
342 #define VEOL 2
343 #define VEOL2 3
344 #define VEOF 4
345 #define VERASE 5
346 #define VINTR 6
347 #define VKILL 7
348 #define VLNEXT 8
349 #define VMIN 9
350 #define VQUIT 10
351 #define VREPRINT 11
352 #define VSTART 12
353 #define VSTOP 13
354 #define VSUSP 14
355 #define VSWTC 15
356 #define VTIME 16
357 #define VWERASE 17
358 #define NCCS 18
359
360 #define IGNBRK 0x00001
361 #define BRKINT 0x00002
362 #define IGNPAR 0x00004
363 #define IMAXBEL 0x00008
364 #define INPCK 0x00010
365 #define ISTRIP 0x00020
366 #define INLCR 0x00040
367 #define IGNCR 0x00080
368 #define ICRNL 0x00100
369 #define IXON 0x00400
370 #define IXOFF 0x01000
371 #define IUCLC 0x04000
372 #define IXANY 0x08000
373 #define PARMRK 0x10000
374 #define OPOST 0x00001
375
376 #define CSIZE 0x00030
377 #define CS5 0x00000
378 #define CS6 0x00010
379 #define CS7 0x00020
380 #define CS8 0x00030
381 #define CSTOPB 0x00040
382 #define CREAD 0x00080
383 #define PARENB 0x00100
384 #define PARODD 0x00200
385 #define HUPCL 0x00400
386 #define CLOCAL 0x00800
387 #define CBAUDEX 0x0100f
388 #define B57600 0x01001
389 #define B115200 0x01002
390 #define B128000 0x01003
391 #define B230400 0x01004
392 #define B256000 0x01005
393 #define CRTSXOFF 0x04000
394 #define CRTSCTS 0x08000
395
396 #define ISIG 0x0001
397 #define ICANON 0x0002
398 #define ECHO 0x0004
399 #define ECHOE 0x0008
400 #define ECHOK 0x0010
401 #define ECHONL 0x0020
402 #define NOFLSH 0x0040
403 #define TOSTOP 0x0080
404 #define IEXTEN 0x0100
405 #define FLUSHO 0x0200
406 #define ECHOKE 0x0400
407 #define ECHOCTL 0x0800
408
409 #define TCOOFF 0
410 #define TCOON 1
411 #define TCIOFF 2
412 #define TCION 3
413
414 #define TCIFLUSH 0
415 #define TCOFLUSH 1
416 #define TCIOFLUSH 2
417 #define TCFLSH 3
418
419 #define TCSAFLUSH 1
420 #define TCSANOW 2
421 #define TCSADRAIN 3
422 #define TCSADFLUSH 4
423
424 typedef unsigned char cc_t;
425 typedef unsigned int speed_t;
426 typedef unsigned int tcflag_t;
427
428 struct termios {
429 cc_t c_cc[NCCS];
430 tcflag_t c_cflag;
431 tcflag_t c_iflag;
432 tcflag_t c_lflag;
433 tcflag_t c_oflag;
434 };
435
436 speed_t cfgetispeed (struct termios *);
437 speed_t cfgetospeed (struct termios *);
438 int cfsetispeed (struct termios *, speed_t);
439 int cfsetospeed (struct termios *, speed_t);
440 int tcdrain (int);
441 int tcflow (int, int);
442 int tcflush (int, int);
443 int tcgetattr (int, struct termios *);
444 pid_t tcgetpgrp (int);
445 int tcsendbreak (int, int);
446 int tcsetattr (int, int, struct termios *);
447 int tcsetpgrp (int, pid_t);
448
449 /* ------------------------------------------------- */
450 /* Syslog */
451 /* ------------------------------------------------- */
452
453 #define LOG_DEBUG 0
454 #define LOG_INFO 1
455 #define LOG_NOTICE 2
456 #define LOG_WARNING 3
457 #define LOG_ERR 4
458 #define LOG_CRIT 5
459 #define LOG_ALERT 6
460 #define LOG_EMERG 7
461
462 #define LOG_PID 0x01
463 #define LOG_CONS 0x02
464 #define LOG_ODELAY 0x04
465 #define LOG_NDELAY 0x08
466 #define LOG_NOWAIT 0x10
467 #define LOG_PERROR 0x20
468
469 #define LOG_AUTH 1
470 #define LOG_CRON 2
471 #define LOG_DAEMON 3
472 #define LOG_KERN 4
473 #define LOG_LOCAL0 5
474 #define LOG_LOCAL1 6
475 #define LOG_LOCAL2 7
476 #define LOG_LOCAL3 8
477 #define LOG_LOCAL4 9
478 #define LOG_LOCAL5 10
479 #define LOG_LOCAL6 11
480 #define LOG_LOCAL7 12
481 #define LOG_LPR 13
482 #define LOG_MAIL 14
483 #define LOG_NEWS 15
484 #define LOG_SYSLOG 16
485 #define LOG_USER 17
486 #define LOG_UUCP 18
487
488 void openlog (const char *, int, int);
489 void closelog (void);
490 void syslog (int, const char *, const char *);