wasi 0.7.0

Experimental WASI API bindings for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
From 62f535fa4e1a259aabd5f22449af01e32aeb6f47 Mon Sep 17 00:00:00 2001
From: Dan Gohman <sunfish@mozilla.com>
Date: Tue, 23 Jul 2019 10:23:06 -0700
Subject: [PATCH] maybe

---
 src/wasi_unstable/constants.rs    | 188 +++++++++++++
 src/wasi_unstable/minimal_safe.rs | 336 +++++++++++++++++++++++
 src/wasi_unstable/mod.rs          | 431 ++++--------------------------
 src/wasi_unstable/types.rs        |  41 +++
 4 files changed, 623 insertions(+), 373 deletions(-)
 create mode 100644 src/wasi_unstable/constants.rs
 create mode 100644 src/wasi_unstable/minimal_safe.rs
 create mode 100644 src/wasi_unstable/types.rs

diff --git a/src/wasi_unstable/constants.rs b/src/wasi_unstable/constants.rs
new file mode 100644
index 0000000..0af896b
--- /dev/null
+++ b/src/wasi_unstable/constants.rs
@@ -0,0 +1,188 @@
+//! This file defines idiomatic Rust names for constants.
+
+use crate::wasi_unstable::raw::*;
+use crate::wasi_unstable::types::*;
+
+pub const ADVICE_NORMAL: Advice = __WASI_ADVICE_NORMAL;
+pub const ADVICE_SEQUENTIAL: Advice = __WASI_ADVICE_SEQUENTIAL;
+pub const ADVICE_RANDOM: Advice = __WASI_ADVICE_RANDOM;
+pub const ADVICE_WILLNEED: Advice = __WASI_ADVICE_WILLNEED;
+pub const ADVICE_DONTNEED: Advice = __WASI_ADVICE_DONTNEED;
+pub const ADVICE_NOREUSE: Advice = __WASI_ADVICE_NOREUSE;
+pub const CLOCK_REALTIME: ClockId = __WASI_CLOCK_REALTIME;
+pub const CLOCK_MONOTONIC: ClockId = __WASI_CLOCK_MONOTONIC;
+pub const CLOCK_PROCESS_CPUTIME_ID: ClockId = __WASI_CLOCK_PROCESS_CPUTIME_ID;
+pub const CLOCK_THREAD_CPUTIME_ID: ClockId = __WASI_CLOCK_THREAD_CPUTIME_ID;
+pub const DIRCOOKIE_START: DirCookie = __WASI_DIRCOOKIE_START;
+pub const ESUCCESS: Errno = __WASI_ESUCCESS;
+pub const E2BIG: Errno = __WASI_E2BIG;
+pub const EACCES: Errno = __WASI_EACCES;
+pub const EADDRINUSE: Errno = __WASI_EADDRINUSE;
+pub const EADDRNOTAVAIL: Errno = __WASI_EADDRNOTAVAIL;
+pub const EAFNOSUPPORT: Errno = __WASI_EAFNOSUPPORT;
+pub const EAGAIN: Errno = __WASI_EAGAIN;
+pub const EALREADY: Errno = __WASI_EALREADY;
+pub const EBADF: Errno = __WASI_EBADF;
+pub const EBADMSG: Errno = __WASI_EBADMSG;
+pub const EBUSY: Errno = __WASI_EBUSY;
+pub const ECANCELED: Errno = __WASI_ECANCELED;
+pub const ECHILD: Errno = __WASI_ECHILD;
+pub const ECONNABORTED: Errno = __WASI_ECONNABORTED;
+pub const ECONNREFUSED: Errno = __WASI_ECONNREFUSED;
+pub const ECONNRESET: Errno = __WASI_ECONNRESET;
+pub const EDEADLK: Errno = __WASI_EDEADLK;
+pub const EDESTADDRREQ: Errno = __WASI_EDESTADDRREQ;
+pub const EDOM: Errno = __WASI_EDOM;
+pub const EDQUOT: Errno = __WASI_EDQUOT;
+pub const EEXIST: Errno = __WASI_EEXIST;
+pub const EFAULT: Errno = __WASI_EFAULT;
+pub const EFBIG: Errno = __WASI_EFBIG;
+pub const EHOSTUNREACH: Errno = __WASI_EHOSTUNREACH;
+pub const EIDRM: Errno = __WASI_EIDRM;
+pub const EILSEQ: Errno = __WASI_EILSEQ;
+pub const EINPROGRESS: Errno = __WASI_EINPROGRESS;
+pub const EINTR: Errno = __WASI_EINTR;
+pub const EINVAL: Errno = __WASI_EINVAL;
+pub const EIO: Errno = __WASI_EIO;
+pub const EISCONN: Errno = __WASI_EISCONN;
+pub const EISDIR: Errno = __WASI_EISDIR;
+pub const ELOOP: Errno = __WASI_ELOOP;
+pub const EMFILE: Errno = __WASI_EMFILE;
+pub const EMLINK: Errno = __WASI_EMLINK;
+pub const EMSGSIZE: Errno = __WASI_EMSGSIZE;
+pub const EMULTIHOP: Errno = __WASI_EMULTIHOP;
+pub const ENAMETOOLONG: Errno = __WASI_ENAMETOOLONG;
+pub const ENETDOWN: Errno = __WASI_ENETDOWN;
+pub const ENETRESET: Errno = __WASI_ENETRESET;
+pub const ENETUNREACH: Errno = __WASI_ENETUNREACH;
+pub const ENFILE: Errno = __WASI_ENFILE;
+pub const ENOBUFS: Errno = __WASI_ENOBUFS;
+pub const ENODEV: Errno = __WASI_ENODEV;
+pub const ENOENT: Errno = __WASI_ENOENT;
+pub const ENOEXEC: Errno = __WASI_ENOEXEC;
+pub const ENOLCK: Errno = __WASI_ENOLCK;
+pub const ENOLINK: Errno = __WASI_ENOLINK;
+pub const ENOMEM: Errno = __WASI_ENOMEM;
+pub const ENOMSG: Errno = __WASI_ENOMSG;
+pub const ENOPROTOOPT: Errno = __WASI_ENOPROTOOPT;
+pub const ENOSPC: Errno = __WASI_ENOSPC;
+pub const ENOSYS: Errno = __WASI_ENOSYS;
+pub const ENOTCONN: Errno = __WASI_ENOTCONN;
+pub const ENOTDIR: Errno = __WASI_ENOTDIR;
+pub const ENOTEMPTY: Errno = __WASI_ENOTEMPTY;
+pub const ENOTRECOVERABLE: Errno = __WASI_ENOTRECOVERABLE;
+pub const ENOTSOCK: Errno = __WASI_ENOTSOCK;
+pub const ENOTSUP: Errno = __WASI_ENOTSUP;
+pub const ENOTTY: Errno = __WASI_ENOTTY;
+pub const ENXIO: Errno = __WASI_ENXIO;
+pub const EOVERFLOW: Errno = __WASI_EOVERFLOW;
+pub const EOWNERDEAD: Errno = __WASI_EOWNERDEAD;
+pub const EPERM: Errno = __WASI_EPERM;
+pub const EPIPE: Errno = __WASI_EPIPE;
+pub const EPROTO: Errno = __WASI_EPROTO;
+pub const EPROTONOSUPPORT: Errno = __WASI_EPROTONOSUPPORT;
+pub const EPROTOTYPE: Errno = __WASI_EPROTOTYPE;
+pub const ERANGE: Errno = __WASI_ERANGE;
+pub const EROFS: Errno = __WASI_EROFS;
+pub const ESPIPE: Errno = __WASI_ESPIPE;
+pub const ESRCH: Errno = __WASI_ESRCH;
+pub const ESTALE: Errno = __WASI_ESTALE;
+pub const ETIMEDOUT: Errno = __WASI_ETIMEDOUT;
+pub const ETXTBSY: Errno = __WASI_ETXTBSY;
+pub const EXDEV: Errno = __WASI_EXDEV;
+pub const ENOTCAPABLE: Errno = __WASI_ENOTCAPABLE;
+pub const EVENT_FD_READWRITE_HANGUP: EventRwFlags = __WASI_EVENT_FD_READWRITE_HANGUP;
+pub const EVENTTYPE_CLOCK: EventType = __WASI_EVENTTYPE_CLOCK;
+pub const EVENTTYPE_FD_READ: EventType = __WASI_EVENTTYPE_FD_READ;
+pub const EVENTTYPE_FD_WRITE: EventType = __WASI_EVENTTYPE_FD_WRITE;
+pub const FDFLAG_APPEND: FdFlags = __WASI_FDFLAG_APPEND;
+pub const FDFLAG_DSYNC: FdFlags = __WASI_FDFLAG_DSYNC;
+pub const FDFLAG_NONBLOCK: FdFlags = __WASI_FDFLAG_NONBLOCK;
+pub const FDFLAG_RSYNC: FdFlags = __WASI_FDFLAG_RSYNC;
+pub const FDFLAG_SYNC: FdFlags = __WASI_FDFLAG_SYNC;
+pub const FILETYPE_UNKNOWN: FileType = __WASI_FILETYPE_UNKNOWN;
+pub const FILETYPE_BLOCK_DEVICE: FileType = __WASI_FILETYPE_BLOCK_DEVICE;
+pub const FILETYPE_CHARACTER_DEVICE: FileType = __WASI_FILETYPE_CHARACTER_DEVICE;
+pub const FILETYPE_DIRECTORY: FileType = __WASI_FILETYPE_DIRECTORY;
+pub const FILETYPE_REGULAR_FILE: FileType = __WASI_FILETYPE_REGULAR_FILE;
+pub const FILETYPE_SOCKET_DGRAM: FileType = __WASI_FILETYPE_SOCKET_DGRAM;
+pub const FILETYPE_SOCKET_STREAM: FileType = __WASI_FILETYPE_SOCKET_STREAM;
+pub const FILETYPE_SYMBOLIC_LINK: FileType = __WASI_FILETYPE_SYMBOLIC_LINK;
+pub const FILESTAT_SET_ATIM: FstFlags = __WASI_FILESTAT_SET_ATIM;
+pub const FILESTAT_SET_ATIM_NOW: FstFlags = __WASI_FILESTAT_SET_ATIM_NOW;
+pub const FILESTAT_SET_MTIM: FstFlags = __WASI_FILESTAT_SET_MTIM;
+pub const FILESTAT_SET_MTIM_NOW: FstFlags = __WASI_FILESTAT_SET_MTIM_NOW;
+pub const LOOKUP_SYMLINK_FOLLOW: LookupFlags = __WASI_LOOKUP_SYMLINK_FOLLOW;
+pub const O_CREAT: OFlags = __WASI_O_CREAT;
+pub const O_DIRECTORY: OFlags = __WASI_O_DIRECTORY;
+pub const O_EXCL: OFlags = __WASI_O_EXCL;
+pub const O_TRUNC: OFlags = __WASI_O_TRUNC;
+pub const PREOPENTYPE_DIR: PreopenType = __WASI_PREOPENTYPE_DIR;
+pub const SOCK_RECV_PEEK: RiFlags = __WASI_SOCK_RECV_PEEK;
+pub const SOCK_RECV_WAITALL: RiFlags = __WASI_SOCK_RECV_WAITALL;
+pub const RIGHT_FD_DATASYNC: Rights = __WASI_RIGHT_FD_DATASYNC;
+pub const RIGHT_FD_READ: Rights = __WASI_RIGHT_FD_READ;
+pub const RIGHT_FD_SEEK: Rights = __WASI_RIGHT_FD_SEEK;
+pub const RIGHT_FD_FDSTAT_SET_FLAGS: Rights = __WASI_RIGHT_FD_FDSTAT_SET_FLAGS;
+pub const RIGHT_FD_SYNC: Rights = __WASI_RIGHT_FD_SYNC;
+pub const RIGHT_FD_TELL: Rights = __WASI_RIGHT_FD_TELL;
+pub const RIGHT_FD_WRITE: Rights = __WASI_RIGHT_FD_WRITE;
+pub const RIGHT_FD_ADVISE: Rights = __WASI_RIGHT_FD_ADVISE;
+pub const RIGHT_FD_ALLOCATE: Rights = __WASI_RIGHT_FD_ALLOCATE;
+pub const RIGHT_PATH_CREATE_DIRECTORY: Rights = __WASI_RIGHT_PATH_CREATE_DIRECTORY;
+pub const RIGHT_PATH_CREATE_FILE: Rights = __WASI_RIGHT_PATH_CREATE_FILE;
+pub const RIGHT_PATH_LINK_SOURCE: Rights = __WASI_RIGHT_PATH_LINK_SOURCE;
+pub const RIGHT_PATH_LINK_TARGET: Rights = __WASI_RIGHT_PATH_LINK_TARGET;
+pub const RIGHT_PATH_OPEN: Rights = __WASI_RIGHT_PATH_OPEN;
+pub const RIGHT_FD_READDIR: Rights = __WASI_RIGHT_FD_READDIR;
+pub const RIGHT_PATH_READLINK: Rights = __WASI_RIGHT_PATH_READLINK;
+pub const RIGHT_PATH_RENAME_SOURCE: Rights = __WASI_RIGHT_PATH_RENAME_SOURCE;
+pub const RIGHT_PATH_RENAME_TARGET: Rights = __WASI_RIGHT_PATH_RENAME_TARGET;
+pub const RIGHT_PATH_FILESTAT_GET: Rights = __WASI_RIGHT_PATH_FILESTAT_GET;
+pub const RIGHT_PATH_FILESTAT_SET_SIZE: Rights = __WASI_RIGHT_PATH_FILESTAT_SET_SIZE;
+pub const RIGHT_PATH_FILESTAT_SET_TIMES: Rights = __WASI_RIGHT_PATH_FILESTAT_SET_TIMES;
+pub const RIGHT_FD_FILESTAT_GET: Rights = __WASI_RIGHT_FD_FILESTAT_GET;
+pub const RIGHT_FD_FILESTAT_SET_SIZE: Rights = __WASI_RIGHT_FD_FILESTAT_SET_SIZE;
+pub const RIGHT_FD_FILESTAT_SET_TIMES: Rights = __WASI_RIGHT_FD_FILESTAT_SET_TIMES;
+pub const RIGHT_PATH_SYMLINK: Rights = __WASI_RIGHT_PATH_SYMLINK;
+pub const RIGHT_PATH_REMOVE_DIRECTORY: Rights = __WASI_RIGHT_PATH_REMOVE_DIRECTORY;
+pub const RIGHT_PATH_UNLINK_FILE: Rights = __WASI_RIGHT_PATH_UNLINK_FILE;
+pub const RIGHT_POLL_FD_READWRITE: Rights = __WASI_RIGHT_POLL_FD_READWRITE;
+pub const RIGHT_SOCK_SHUTDOWN: Rights = __WASI_RIGHT_SOCK_SHUTDOWN;
+pub const SOCK_RECV_DATA_TRUNCATED: RoFlags = __WASI_SOCK_RECV_DATA_TRUNCATED;
+pub const SHUT_RD: SdFlags = __WASI_SHUT_RD;
+pub const SHUT_WR: SdFlags = __WASI_SHUT_WR;
+pub const SIGHUP: Signal = __WASI_SIGHUP;
+pub const SIGINT: Signal = __WASI_SIGINT;
+pub const SIGQUIT: Signal = __WASI_SIGQUIT;
+pub const SIGILL: Signal = __WASI_SIGILL;
+pub const SIGTRAP: Signal = __WASI_SIGTRAP;
+pub const SIGABRT: Signal = __WASI_SIGABRT;
+pub const SIGBUS: Signal = __WASI_SIGBUS;
+pub const SIGFPE: Signal = __WASI_SIGFPE;
+pub const SIGKILL: Signal = __WASI_SIGKILL;
+pub const SIGUSR1: Signal = __WASI_SIGUSR1;
+pub const SIGSEGV: Signal = __WASI_SIGSEGV;
+pub const SIGUSR2: Signal = __WASI_SIGUSR2;
+pub const SIGPIPE: Signal = __WASI_SIGPIPE;
+pub const SIGALRM: Signal = __WASI_SIGALRM;
+pub const SIGTERM: Signal = __WASI_SIGTERM;
+pub const SIGCHLD: Signal = __WASI_SIGCHLD;
+pub const SIGCONT: Signal = __WASI_SIGCONT;
+pub const SIGSTOP: Signal = __WASI_SIGSTOP;
+pub const SIGTSTP: Signal = __WASI_SIGTSTP;
+pub const SIGTTIN: Signal = __WASI_SIGTTIN;
+pub const SIGTTOU: Signal = __WASI_SIGTTOU;
+pub const SIGURG: Signal = __WASI_SIGURG;
+pub const SIGXCPU: Signal = __WASI_SIGXCPU;
+pub const SIGXFSZ: Signal = __WASI_SIGXFSZ;
+pub const SIGVTALRM: Signal = __WASI_SIGVTALRM;
+pub const SIGPROF: Signal = __WASI_SIGPROF;
+pub const SIGWINCH: Signal = __WASI_SIGWINCH;
+pub const SIGPOLL: Signal = __WASI_SIGPOLL;
+pub const SIGPWR: Signal = __WASI_SIGPWR;
+pub const SIGSYS: Signal = __WASI_SIGSYS;
+pub const SUBSCRIPTION_CLOCK_ABSTIME: SubclockFlags = __WASI_SUBSCRIPTION_CLOCK_ABSTIME;
+pub const WHENCE_CUR: Whence = __WASI_WHENCE_CUR;
+pub const WHENCE_END: Whence = __WASI_WHENCE_END;
+pub const WHENCE_SET: Whence = __WASI_WHENCE_SET;
diff --git a/src/wasi_unstable/minimal_safe.rs b/src/wasi_unstable/minimal_safe.rs
new file mode 100644
index 0000000..91a1ef1
--- /dev/null
+++ b/src/wasi_unstable/minimal_safe.rs
@@ -0,0 +1,336 @@
+//! This file defines minimally safe wrappers around the raw functions.
+//! Pointer-length pairs are translated to Rust slice, and output pointer
+//! parameters are translated to output reference parameters.
+//!
+//! These are primarily useful for writing low-level API tests. For most
+//! other use cases, the interfaces defined in the top-level `wasi_unstable`
+//! module will be easier to use.
+
+use crate::wasi_unstable::raw::*;
+use core::ffi::c_void;
+
+pub use crate::wasi_unstable::constants::*;
+pub use crate::wasi_unstable::types::*;
+
+#[inline]
+pub fn clock_res_get(clock_id: ClockId, resolution: &mut Timestamp) -> Errno {
+    unsafe { __wasi_clock_res_get(clock_id, resolution) }
+}
+
+#[inline]
+pub fn clock_time_get(clock_id: ClockId, precision: Timestamp, time: &mut Timestamp) -> Errno {
+    unsafe { __wasi_clock_time_get(clock_id, precision, time) }
+}
+
+#[inline]
+pub fn fd_pread(fd: Fd, iovs: &[IoVec], offset: FileSize, nread: &mut usize) -> Errno {
+    unsafe { __wasi_fd_pread(fd, iovs.as_ptr(), iovs.len(), offset, nread) }
+}
+
+#[inline]
+pub fn fd_pwrite(fd: Fd, iovs: &[CIoVec], offset: FileSize, nwritten: &mut usize) -> Errno {
+    unsafe { __wasi_fd_pwrite(fd, iovs.as_ptr(), iovs.len(), offset, nwritten) }
+}
+
+#[inline]
+pub fn random_get(buf: &mut [u8]) -> Errno {
+    unsafe { __wasi_random_get(buf.as_mut_ptr() as *mut c_void, buf.len()) }
+}
+
+#[inline]
+pub fn fd_close(fd: Fd) -> Errno {
+    unsafe { __wasi_fd_close(fd) }
+}
+
+#[inline]
+pub fn fd_datasync(fd: Fd) -> Errno {
+    unsafe { __wasi_fd_datasync(fd) }
+}
+
+#[inline]
+pub fn fd_read(fd: Fd, iovs: &[IoVec], nread: &mut usize) -> Errno {
+    unsafe { __wasi_fd_read(fd, iovs.as_ptr(), iovs.len(), nread) }
+}
+
+#[inline]
+pub fn fd_renumber(from: Fd, to: Fd) -> Errno {
+    unsafe { __wasi_fd_renumber(from, to) }
+}
+
+#[inline]
+pub fn fd_seek(fd: Fd, offset: FileDelta, whence: Whence, newoffset: &mut FileSize) -> Errno {
+    unsafe { __wasi_fd_seek(fd, offset, whence, newoffset) }
+}
+
+#[inline]
+pub fn fd_tell(fd: Fd, newoffset: &mut FileSize) -> Errno {
+    unsafe { __wasi_fd_tell(fd, newoffset) }
+}
+
+#[inline]
+pub fn fd_fdstat_get(fd: Fd, buf: &mut FdStat) -> Errno {
+    unsafe { __wasi_fd_fdstat_get(fd, buf) }
+}
+
+#[inline]
+pub fn fd_fdstat_set_flags(fd: Fd, flags: FdFlags) -> Errno {
+    unsafe { __wasi_fd_fdstat_set_flags(fd, flags) }
+}
+
+#[inline]
+pub fn fd_fdstat_set_rights(fd: Fd, fs_rights_base: Rights, fs_rights_inheriting: Rights) -> Errno {
+    unsafe { __wasi_fd_fdstat_set_rights(fd, fs_rights_base, fs_rights_inheriting) }
+}
+
+#[inline]
+pub fn fd_sync(fd: Fd) -> Errno {
+    unsafe { __wasi_fd_sync(fd) }
+}
+
+#[inline]
+pub fn fd_write(fd: Fd, iovs: &[CIoVec], nwritten: &mut usize) -> Errno {
+    unsafe { __wasi_fd_write(fd, iovs.as_ptr(), iovs.len(), nwritten) }
+}
+
+#[inline]
+pub fn fd_advise(fd: Fd, offset: FileSize, len: FileSize, advice: Advice) -> Errno {
+    unsafe { __wasi_fd_advise(fd, offset, len, advice) }
+}
+
+#[inline]
+pub fn fd_allocate(fd: Fd, offset: FileSize, len: FileSize) -> Errno {
+    unsafe { __wasi_fd_allocate(fd, offset, len) }
+}
+
+#[inline]
+pub fn path_create_directory(fd: Fd, path: &[u8]) -> Errno {
+    unsafe { __wasi_path_create_directory(fd, path.as_ptr(), path.len()) }
+}
+
+#[inline]
+pub fn path_link(
+    old_fd: Fd,
+    old_flags: LookupFlags,
+    old_path: &[u8],
+    new_fd: Fd,
+    new_path: &[u8],
+) -> Errno {
+    unsafe {
+        __wasi_path_link(
+            old_fd,
+            old_flags,
+            old_path.as_ptr(),
+            old_path.len(),
+            new_fd,
+            new_path.as_ptr(),
+            new_path.len(),
+        )
+    }
+}
+
+#[inline]
+#[allow(clippy::too_many_arguments)]
+pub fn path_open(
+    dirfd: Fd,
+    dirflags: LookupFlags,
+    path: &[u8],
+    oflags: OFlags,
+    fs_rights_base: Rights,
+    fs_rights_inheriting: Rights,
+    fs_flags: FdFlags,
+    fd: &mut Fd,
+) -> Errno {
+    unsafe {
+        __wasi_path_open(
+            dirfd,
+            dirflags,
+            path.as_ptr(),
+            path.len(),
+            oflags,
+            fs_rights_base,
+            fs_rights_inheriting,
+            fs_flags,
+            fd,
+        )
+    }
+}
+
+#[inline]
+pub fn fd_readdir(fd: Fd, buf: &mut [u8], cookie: DirCookie, bufused: &mut usize) -> Errno {
+    unsafe {
+        __wasi_fd_readdir(
+            fd,
+            buf.as_mut_ptr() as *mut c_void,
+            buf.len(),
+            cookie,
+            bufused,
+        )
+    }
+}
+
+#[inline]
+pub fn path_readlink(fd: Fd, path: &[u8], buf: &mut [u8], bufused: &mut usize) -> Errno {
+    unsafe {
+        __wasi_path_readlink(
+            fd,
+            path.as_ptr(),
+            path.len(),
+            buf.as_mut_ptr(),
+            buf.len(),
+            bufused,
+        )
+    }
+}
+
+#[inline]
+pub fn path_rename(old_fd: Fd, old_path: &[u8], new_fd: Fd, new_path: &[u8]) -> Errno {
+    unsafe {
+        __wasi_path_rename(
+            old_fd,
+            old_path.as_ptr(),
+            old_path.len(),
+            new_fd,
+            new_path.as_ptr(),
+            new_path.len(),
+        )
+    }
+}
+
+#[inline]
+pub fn fd_filestat_get(fd: Fd, buf: &mut FileStat) -> Errno {
+    unsafe { __wasi_fd_filestat_get(fd, buf) }
+}
+
+#[inline]
+pub fn fd_filestat_set_times(
+    fd: Fd,
+    st_atim: Timestamp,
+    st_mtim: Timestamp,
+    fstflags: FstFlags,
+) -> Errno {
+    unsafe { __wasi_fd_filestat_set_times(fd, st_atim, st_mtim, fstflags) }
+}
+
+#[inline]
+pub fn fd_filestat_set_size(fd: Fd, st_size: FileSize) -> Errno {
+    unsafe { __wasi_fd_filestat_set_size(fd, st_size) }
+}
+
+#[inline]
+pub fn path_filestat_get(fd: Fd, flags: LookupFlags, path: &[u8], buf: &mut FileStat) -> Errno {
+    unsafe { __wasi_path_filestat_get(fd, flags, path.as_ptr(), path.len(), buf) }
+}
+
+#[inline]
+pub fn path_filestat_set_times(
+    fd: Fd,
+    flags: LookupFlags,
+    path: &[u8],
+    st_atim: Timestamp,
+    st_mtim: Timestamp,
+    fstflags: FstFlags,
+) -> Errno {
+    unsafe {
+        __wasi_path_filestat_set_times(
+            fd,
+            flags,
+            path.as_ptr(),
+            path.len(),
+            st_atim,
+            st_mtim,
+            fstflags,
+        )
+    }
+}
+
+#[inline]
+pub fn path_symlink(old_path: &[u8], fd: Fd, new_path: &[u8]) -> Errno {
+    unsafe {
+        __wasi_path_symlink(
+            old_path.as_ptr(),
+            old_path.len(),
+            fd,
+            new_path.as_ptr(),
+            new_path.len(),
+        )
+    }
+}
+
+#[inline]
+pub fn path_unlink_file(fd: Fd, path: &[u8]) -> Errno {
+    unsafe { __wasi_path_unlink_file(fd, path.as_ptr(), path.len()) }
+}
+
+#[inline]
+pub fn path_remove_directory(fd: Fd, path: &[u8]) -> Errno {
+    unsafe { __wasi_path_remove_directory(fd, path.as_ptr(), path.len()) }
+}
+
+#[inline]
+pub fn poll_oneoff(in_: &[Subscription], out: &mut [Event], nevents: &mut usize) -> Errno {
+    assert!(out.len() >= in_.len());
+    unsafe { __wasi_poll_oneoff(in_.as_ptr(), out.as_mut_ptr(), in_.len(), nevents) }
+}
+
+#[inline]
+pub fn proc_exit(rval: ExitCode) {
+    unsafe { __wasi_proc_exit(rval) }
+}
+
+#[inline]
+pub fn proc_raise(sig: Signal) -> Errno {
+    unsafe { __wasi_proc_raise(sig) }
+}
+
+#[inline]
+pub fn sock_recv(
+    sock: Fd,
+    ri_data: &[IoVec],
+    ri_flags: RiFlags,
+    ro_datalen: &mut usize,
+    ro_flags: &mut RoFlags,
+) -> Errno {
+    unsafe {
+        __wasi_sock_recv(
+            sock,
+            ri_data.as_ptr(),
+            ri_data.len(),
+            ri_flags,
+            ro_datalen,
+            ro_flags,
+        )
+    }
+}
+
+#[inline]
+pub fn sock_send(sock: Fd, si_data: &[CIoVec], si_flags: SiFlags, so_datalen: &mut usize) -> Errno {
+    unsafe { __wasi_sock_send(sock, si_data.as_ptr(), si_data.len(), si_flags, so_datalen) }
+}
+
+#[inline]
+pub fn sock_shutdown(sock: Fd, how: SdFlags) -> Errno {
+    unsafe { __wasi_sock_shutdown(sock, how) }
+}
+
+#[inline]
+pub fn sched_yield() -> Errno {
+    unsafe { __wasi_sched_yield() }
+}
+
+#[inline]
+pub fn fd_prestat_get(fd: Fd, buf: &mut Prestat) -> Errno {
+    unsafe { __wasi_fd_prestat_get(fd, buf) }
+}
+
+#[inline]
+pub fn fd_prestat_dir_name(fd: Fd, path: &mut [u8]) -> Errno {
+    unsafe { __wasi_fd_prestat_dir_name(fd, path.as_mut_ptr(), path.len()) }
+}
+
+// TODO: Safe interfaces to the args and environ functions
+/*
+pub fn args_get(argv: *mut *mut u8, argv_buf: *mut u8) -> Errno {}
+pub fn args_sizes_get(argc: *mut usize, argv_buf_size: *mut usize) -> Errno {}
+pub fn environ_get(environ: *mut *mut u8, environ_buf: *mut u8) -> Errno {}
+pub fn environ_sizes_get(environ_count: *mut usize, environ_buf_size: *mut usize) -> Errno {}
+*/
diff --git a/src/wasi_unstable/mod.rs b/src/wasi_unstable/mod.rs
index 37bec24..893f59a 100644
--- a/src/wasi_unstable/mod.rs
+++ b/src/wasi_unstable/mod.rs
@@ -1,241 +1,56 @@
 //! This module declares the Rust bindings to the `wasi_unstable` API.
 //!
 //! The raw bindings are in the `raw` submodule. They use raw pointers and
-//! are unsafe. In the the top-level module, raw pointer-length pairs are
-//! replaced by Rust slice types, output parameters are converted to normal
+//! are unsafe. Minimally safe versions which replace raw pointers with
+//! slices and references are in the `minimal_safe` module.
+//!
+//! In the the top-level module, output parameters are converted to normal
 //! return values, names are translated to be more Rust-idiomatic, and the
 //! functions are safe.
-//!
-//! TODO: Not all functions are covered yet; implement the rest of the API.
 
+mod constants;
+mod types;
+
+pub mod minimal_safe;
 pub mod raw;
 
 use core::ffi::c_void;
 use core::mem::MaybeUninit;
 use raw::*;
 
-pub type Advice = __wasi_advice_t;
-pub type ClockId = __wasi_clockid_t;
-pub type Device = __wasi_device_t;
-pub type DirCookie = __wasi_dircookie_t;
-pub type Errno = __wasi_errno_t;
-pub type EventRwFlags = __wasi_eventrwflags_t;
-pub type EventType = __wasi_eventtype_t;
-pub type ExitCode = __wasi_exitcode_t;
-pub type Fd = __wasi_fd_t;
-pub type FdFlags = __wasi_fdflags_t;
-pub type FileDelta = __wasi_filedelta_t;
-pub type FileSize = __wasi_filesize_t;
-pub type FileType = __wasi_filetype_t;
-pub type FstFlags = __wasi_fstflags_t;
-pub type Inode = __wasi_inode_t;
-pub type LinkCount = __wasi_linkcount_t;
-pub type LookupFlags = __wasi_lookupflags_t;
-pub type OFlags = __wasi_oflags_t;
-pub type PreopenType = __wasi_preopentype_t;
-pub type RiFlags = __wasi_riflags_t;
-pub type Rights = __wasi_rights_t;
-pub type RoFlags = __wasi_roflags_t;
-pub type SdFlags = __wasi_sdflags_t;
-pub type SiFlags = __wasi_siflags_t;
-pub type Signal = __wasi_signal_t;
-pub type SubclockFlags = __wasi_subclockflags_t;
-pub type Timestamp = __wasi_timestamp_t;
-pub type Userdata = __wasi_userdata_t;
-pub type Whence = __wasi_whence_t;
-pub type Dirent = __wasi_dirent_t;
-pub type FdStat = __wasi_fdstat_t;
-pub type FileStat = __wasi_filestat_t;
-pub type CIoVec = __wasi_ciovec_t;
-pub type IoVec = __wasi_iovec_t;
-pub type Subscription = __wasi_subscription_t;
-pub type Event = __wasi_event_t;
-pub type Prestat = __wasi_prestat_t;
-
-pub const ADVICE_NORMAL: Advice = __WASI_ADVICE_NORMAL;
-pub const ADVICE_SEQUENTIAL: Advice = __WASI_ADVICE_SEQUENTIAL;
-pub const ADVICE_RANDOM: Advice = __WASI_ADVICE_RANDOM;
-pub const ADVICE_WILLNEED: Advice = __WASI_ADVICE_WILLNEED;
-pub const ADVICE_DONTNEED: Advice = __WASI_ADVICE_DONTNEED;
-pub const ADVICE_NOREUSE: Advice = __WASI_ADVICE_NOREUSE;
-pub const CLOCK_REALTIME: ClockId = __WASI_CLOCK_REALTIME;
-pub const CLOCK_MONOTONIC: ClockId = __WASI_CLOCK_MONOTONIC;
-pub const CLOCK_PROCESS_CPUTIME_ID: ClockId = __WASI_CLOCK_PROCESS_CPUTIME_ID;
-pub const CLOCK_THREAD_CPUTIME_ID: ClockId = __WASI_CLOCK_THREAD_CPUTIME_ID;
-pub const DIRCOOKIE_START: DirCookie = __WASI_DIRCOOKIE_START;
-pub const ESUCCESS: Errno = __WASI_ESUCCESS;
-pub const E2BIG: Errno = __WASI_E2BIG;
-pub const EACCES: Errno = __WASI_EACCES;
-pub const EADDRINUSE: Errno = __WASI_EADDRINUSE;
-pub const EADDRNOTAVAIL: Errno = __WASI_EADDRNOTAVAIL;
-pub const EAFNOSUPPORT: Errno = __WASI_EAFNOSUPPORT;
-pub const EAGAIN: Errno = __WASI_EAGAIN;
-pub const EALREADY: Errno = __WASI_EALREADY;
-pub const EBADF: Errno = __WASI_EBADF;
-pub const EBADMSG: Errno = __WASI_EBADMSG;
-pub const EBUSY: Errno = __WASI_EBUSY;
-pub const ECANCELED: Errno = __WASI_ECANCELED;
-pub const ECHILD: Errno = __WASI_ECHILD;
-pub const ECONNABORTED: Errno = __WASI_ECONNABORTED;
-pub const ECONNREFUSED: Errno = __WASI_ECONNREFUSED;
-pub const ECONNRESET: Errno = __WASI_ECONNRESET;
-pub const EDEADLK: Errno = __WASI_EDEADLK;
-pub const EDESTADDRREQ: Errno = __WASI_EDESTADDRREQ;
-pub const EDOM: Errno = __WASI_EDOM;
-pub const EDQUOT: Errno = __WASI_EDQUOT;
-pub const EEXIST: Errno = __WASI_EEXIST;
-pub const EFAULT: Errno = __WASI_EFAULT;
-pub const EFBIG: Errno = __WASI_EFBIG;
-pub const EHOSTUNREACH: Errno = __WASI_EHOSTUNREACH;
-pub const EIDRM: Errno = __WASI_EIDRM;
-pub const EILSEQ: Errno = __WASI_EILSEQ;
-pub const EINPROGRESS: Errno = __WASI_EINPROGRESS;
-pub const EINTR: Errno = __WASI_EINTR;
-pub const EINVAL: Errno = __WASI_EINVAL;
-pub const EIO: Errno = __WASI_EIO;
-pub const EISCONN: Errno = __WASI_EISCONN;
-pub const EISDIR: Errno = __WASI_EISDIR;
-pub const ELOOP: Errno = __WASI_ELOOP;
-pub const EMFILE: Errno = __WASI_EMFILE;
-pub const EMLINK: Errno = __WASI_EMLINK;
-pub const EMSGSIZE: Errno = __WASI_EMSGSIZE;
-pub const EMULTIHOP: Errno = __WASI_EMULTIHOP;
-pub const ENAMETOOLONG: Errno = __WASI_ENAMETOOLONG;
-pub const ENETDOWN: Errno = __WASI_ENETDOWN;
-pub const ENETRESET: Errno = __WASI_ENETRESET;
-pub const ENETUNREACH: Errno = __WASI_ENETUNREACH;
-pub const ENFILE: Errno = __WASI_ENFILE;
-pub const ENOBUFS: Errno = __WASI_ENOBUFS;
-pub const ENODEV: Errno = __WASI_ENODEV;
-pub const ENOENT: Errno = __WASI_ENOENT;
-pub const ENOEXEC: Errno = __WASI_ENOEXEC;
-pub const ENOLCK: Errno = __WASI_ENOLCK;
-pub const ENOLINK: Errno = __WASI_ENOLINK;
-pub const ENOMEM: Errno = __WASI_ENOMEM;
-pub const ENOMSG: Errno = __WASI_ENOMSG;
-pub const ENOPROTOOPT: Errno = __WASI_ENOPROTOOPT;
-pub const ENOSPC: Errno = __WASI_ENOSPC;
-pub const ENOSYS: Errno = __WASI_ENOSYS;
-pub const ENOTCONN: Errno = __WASI_ENOTCONN;
-pub const ENOTDIR: Errno = __WASI_ENOTDIR;
-pub const ENOTEMPTY: Errno = __WASI_ENOTEMPTY;
-pub const ENOTRECOVERABLE: Errno = __WASI_ENOTRECOVERABLE;
-pub const ENOTSOCK: Errno = __WASI_ENOTSOCK;
-pub const ENOTSUP: Errno = __WASI_ENOTSUP;
-pub const ENOTTY: Errno = __WASI_ENOTTY;
-pub const ENXIO: Errno = __WASI_ENXIO;
-pub const EOVERFLOW: Errno = __WASI_EOVERFLOW;
-pub const EOWNERDEAD: Errno = __WASI_EOWNERDEAD;
-pub const EPERM: Errno = __WASI_EPERM;
-pub const EPIPE: Errno = __WASI_EPIPE;
-pub const EPROTO: Errno = __WASI_EPROTO;
-pub const EPROTONOSUPPORT: Errno = __WASI_EPROTONOSUPPORT;
-pub const EPROTOTYPE: Errno = __WASI_EPROTOTYPE;
-pub const ERANGE: Errno = __WASI_ERANGE;
-pub const EROFS: Errno = __WASI_EROFS;
-pub const ESPIPE: Errno = __WASI_ESPIPE;
-pub const ESRCH: Errno = __WASI_ESRCH;
-pub const ESTALE: Errno = __WASI_ESTALE;
-pub const ETIMEDOUT: Errno = __WASI_ETIMEDOUT;
-pub const ETXTBSY: Errno = __WASI_ETXTBSY;
-pub const EXDEV: Errno = __WASI_EXDEV;
-pub const ENOTCAPABLE: Errno = __WASI_ENOTCAPABLE;
-pub const EVENT_FD_READWRITE_HANGUP: EventRwFlags = __WASI_EVENT_FD_READWRITE_HANGUP;
-pub const EVENTTYPE_CLOCK: EventType = __WASI_EVENTTYPE_CLOCK;
-pub const EVENTTYPE_FD_READ: EventType = __WASI_EVENTTYPE_FD_READ;
-pub const EVENTTYPE_FD_WRITE: EventType = __WASI_EVENTTYPE_FD_WRITE;
-pub const FDFLAG_APPEND: FdFlags = __WASI_FDFLAG_APPEND;
-pub const FDFLAG_DSYNC: FdFlags = __WASI_FDFLAG_DSYNC;
-pub const FDFLAG_NONBLOCK: FdFlags = __WASI_FDFLAG_NONBLOCK;
-pub const FDFLAG_RSYNC: FdFlags = __WASI_FDFLAG_RSYNC;
-pub const FDFLAG_SYNC: FdFlags = __WASI_FDFLAG_SYNC;
-pub const FILETYPE_UNKNOWN: FileType = __WASI_FILETYPE_UNKNOWN;
-pub const FILETYPE_BLOCK_DEVICE: FileType = __WASI_FILETYPE_BLOCK_DEVICE;
-pub const FILETYPE_CHARACTER_DEVICE: FileType = __WASI_FILETYPE_CHARACTER_DEVICE;
-pub const FILETYPE_DIRECTORY: FileType = __WASI_FILETYPE_DIRECTORY;
-pub const FILETYPE_REGULAR_FILE: FileType = __WASI_FILETYPE_REGULAR_FILE;
-pub const FILETYPE_SOCKET_DGRAM: FileType = __WASI_FILETYPE_SOCKET_DGRAM;
-pub const FILETYPE_SOCKET_STREAM: FileType = __WASI_FILETYPE_SOCKET_STREAM;
-pub const FILETYPE_SYMBOLIC_LINK: FileType = __WASI_FILETYPE_SYMBOLIC_LINK;
-pub const FILESTAT_SET_ATIM: FstFlags = __WASI_FILESTAT_SET_ATIM;
-pub const FILESTAT_SET_ATIM_NOW: FstFlags = __WASI_FILESTAT_SET_ATIM_NOW;
-pub const FILESTAT_SET_MTIM: FstFlags = __WASI_FILESTAT_SET_MTIM;
-pub const FILESTAT_SET_MTIM_NOW: FstFlags = __WASI_FILESTAT_SET_MTIM_NOW;
-pub const LOOKUP_SYMLINK_FOLLOW: LookupFlags = __WASI_LOOKUP_SYMLINK_FOLLOW;
-pub const O_CREAT: OFlags = __WASI_O_CREAT;
-pub const O_DIRECTORY: OFlags = __WASI_O_DIRECTORY;
-pub const O_EXCL: OFlags = __WASI_O_EXCL;
-pub const O_TRUNC: OFlags = __WASI_O_TRUNC;
-pub const PREOPENTYPE_DIR: PreopenType = __WASI_PREOPENTYPE_DIR;
-pub const SOCK_RECV_PEEK: RiFlags = __WASI_SOCK_RECV_PEEK;
-pub const SOCK_RECV_WAITALL: RiFlags = __WASI_SOCK_RECV_WAITALL;
-pub const RIGHT_FD_DATASYNC: Rights = __WASI_RIGHT_FD_DATASYNC;
-pub const RIGHT_FD_READ: Rights = __WASI_RIGHT_FD_READ;
-pub const RIGHT_FD_SEEK: Rights = __WASI_RIGHT_FD_SEEK;
-pub const RIGHT_FD_FDSTAT_SET_FLAGS: Rights = __WASI_RIGHT_FD_FDSTAT_SET_FLAGS;
-pub const RIGHT_FD_SYNC: Rights = __WASI_RIGHT_FD_SYNC;
-pub const RIGHT_FD_TELL: Rights = __WASI_RIGHT_FD_TELL;
-pub const RIGHT_FD_WRITE: Rights = __WASI_RIGHT_FD_WRITE;
-pub const RIGHT_FD_ADVISE: Rights = __WASI_RIGHT_FD_ADVISE;
-pub const RIGHT_FD_ALLOCATE: Rights = __WASI_RIGHT_FD_ALLOCATE;
-pub const RIGHT_PATH_CREATE_DIRECTORY: Rights = __WASI_RIGHT_PATH_CREATE_DIRECTORY;
-pub const RIGHT_PATH_CREATE_FILE: Rights = __WASI_RIGHT_PATH_CREATE_FILE;
-pub const RIGHT_PATH_LINK_SOURCE: Rights = __WASI_RIGHT_PATH_LINK_SOURCE;
-pub const RIGHT_PATH_LINK_TARGET: Rights = __WASI_RIGHT_PATH_LINK_TARGET;
-pub const RIGHT_PATH_OPEN: Rights = __WASI_RIGHT_PATH_OPEN;
-pub const RIGHT_FD_READDIR: Rights = __WASI_RIGHT_FD_READDIR;
-pub const RIGHT_PATH_READLINK: Rights = __WASI_RIGHT_PATH_READLINK;
-pub const RIGHT_PATH_RENAME_SOURCE: Rights = __WASI_RIGHT_PATH_RENAME_SOURCE;
-pub const RIGHT_PATH_RENAME_TARGET: Rights = __WASI_RIGHT_PATH_RENAME_TARGET;
-pub const RIGHT_PATH_FILESTAT_GET: Rights = __WASI_RIGHT_PATH_FILESTAT_GET;
-pub const RIGHT_PATH_FILESTAT_SET_SIZE: Rights = __WASI_RIGHT_PATH_FILESTAT_SET_SIZE;
-pub const RIGHT_PATH_FILESTAT_SET_TIMES: Rights = __WASI_RIGHT_PATH_FILESTAT_SET_TIMES;
-pub const RIGHT_FD_FILESTAT_GET: Rights = __WASI_RIGHT_FD_FILESTAT_GET;
-pub const RIGHT_FD_FILESTAT_SET_SIZE: Rights = __WASI_RIGHT_FD_FILESTAT_SET_SIZE;
-pub const RIGHT_FD_FILESTAT_SET_TIMES: Rights = __WASI_RIGHT_FD_FILESTAT_SET_TIMES;
-pub const RIGHT_PATH_SYMLINK: Rights = __WASI_RIGHT_PATH_SYMLINK;
-pub const RIGHT_PATH_REMOVE_DIRECTORY: Rights = __WASI_RIGHT_PATH_REMOVE_DIRECTORY;
-pub const RIGHT_PATH_UNLINK_FILE: Rights = __WASI_RIGHT_PATH_UNLINK_FILE;
-pub const RIGHT_POLL_FD_READWRITE: Rights = __WASI_RIGHT_POLL_FD_READWRITE;
-pub const RIGHT_SOCK_SHUTDOWN: Rights = __WASI_RIGHT_SOCK_SHUTDOWN;
-pub const SOCK_RECV_DATA_TRUNCATED: RoFlags = __WASI_SOCK_RECV_DATA_TRUNCATED;
-pub const SHUT_RD: SdFlags = __WASI_SHUT_RD;
-pub const SHUT_WR: SdFlags = __WASI_SHUT_WR;
-pub const SIGHUP: Signal = __WASI_SIGHUP;
-pub const SIGINT: Signal = __WASI_SIGINT;
-pub const SIGQUIT: Signal = __WASI_SIGQUIT;
-pub const SIGILL: Signal = __WASI_SIGILL;
-pub const SIGTRAP: Signal = __WASI_SIGTRAP;
-pub const SIGABRT: Signal = __WASI_SIGABRT;
-pub const SIGBUS: Signal = __WASI_SIGBUS;
-pub const SIGFPE: Signal = __WASI_SIGFPE;
-pub const SIGKILL: Signal = __WASI_SIGKILL;
-pub const SIGUSR1: Signal = __WASI_SIGUSR1;
-pub const SIGSEGV: Signal = __WASI_SIGSEGV;
-pub const SIGUSR2: Signal = __WASI_SIGUSR2;
-pub const SIGPIPE: Signal = __WASI_SIGPIPE;
-pub const SIGALRM: Signal = __WASI_SIGALRM;
-pub const SIGTERM: Signal = __WASI_SIGTERM;
-pub const SIGCHLD: Signal = __WASI_SIGCHLD;
-pub const SIGCONT: Signal = __WASI_SIGCONT;
-pub const SIGSTOP: Signal = __WASI_SIGSTOP;
-pub const SIGTSTP: Signal = __WASI_SIGTSTP;
-pub const SIGTTIN: Signal = __WASI_SIGTTIN;
-pub const SIGTTOU: Signal = __WASI_SIGTTOU;
-pub const SIGURG: Signal = __WASI_SIGURG;
-pub const SIGXCPU: Signal = __WASI_SIGXCPU;
-pub const SIGXFSZ: Signal = __WASI_SIGXFSZ;
-pub const SIGVTALRM: Signal = __WASI_SIGVTALRM;
-pub const SIGPROF: Signal = __WASI_SIGPROF;
-pub const SIGWINCH: Signal = __WASI_SIGWINCH;
-pub const SIGPOLL: Signal = __WASI_SIGPOLL;
-pub const SIGPWR: Signal = __WASI_SIGPWR;
-pub const SIGSYS: Signal = __WASI_SIGSYS;
-pub const SUBSCRIPTION_CLOCK_ABSTIME: SubclockFlags = __WASI_SUBSCRIPTION_CLOCK_ABSTIME;
-pub const WHENCE_CUR: Whence = __WASI_WHENCE_CUR;
-pub const WHENCE_END: Whence = __WASI_WHENCE_END;
-pub const WHENCE_SET: Whence = __WASI_WHENCE_SET;
-
+pub use constants::*;
+pub use types::*;
+
+// These are for WASI functions which don't use output parameters, so we can
+// just export the minimal_safe versions.
+pub use minimal_safe::fd_advise;
+pub use minimal_safe::fd_allocate;
+pub use minimal_safe::fd_close;
+pub use minimal_safe::fd_datasync;
+pub use minimal_safe::fd_fdstat_set_flags;
+pub use minimal_safe::fd_fdstat_set_rights;
+pub use minimal_safe::fd_filestat_set_size;
+pub use minimal_safe::fd_filestat_set_times;
+pub use minimal_safe::fd_prestat_dir_name;
+pub use minimal_safe::fd_renumber;
+pub use minimal_safe::fd_sync;
+pub use minimal_safe::path_create_directory;
+pub use minimal_safe::path_filestat_set_times;
+pub use minimal_safe::path_link;
+pub use minimal_safe::path_remove_directory;
+pub use minimal_safe::path_rename;
+pub use minimal_safe::path_symlink;
+pub use minimal_safe::path_unlink_file;
+pub use minimal_safe::proc_exit;
+pub use minimal_safe::proc_raise;
+pub use minimal_safe::random_get;
+pub use minimal_safe::sched_yield;
+pub use minimal_safe::sock_shutdown;
+
+// The following are for WASI functions which do use output parameters. We
+// wrap them separately to avoid creating references to uninitialized data.
+
+#[inline]
 pub fn clock_res_get(clock_id: ClockId) -> (Errno, Timestamp) {
     let mut resolution = MaybeUninit::<Timestamp>::uninit();
     unsafe {
@@ -246,6 +61,7 @@ pub fn clock_res_get(clock_id: ClockId) -> (Errno, Timestamp) {
     }
 }
 
+#[inline]
 pub fn clock_time_get(clock_id: ClockId, precision: Timestamp) -> (Errno, Timestamp) {
     let mut time = MaybeUninit::<Timestamp>::uninit();
     unsafe {
@@ -256,6 +72,7 @@ pub fn clock_time_get(clock_id: ClockId, precision: Timestamp) -> (Errno, Timest
     }
 }
 
+#[inline]
 pub fn fd_pread(fd: Fd, iovs: &[IoVec], offset: FileSize) -> (Errno, usize) {
     let mut nread = MaybeUninit::<usize>::uninit();
     unsafe {
@@ -266,6 +83,7 @@ pub fn fd_pread(fd: Fd, iovs: &[IoVec], offset: FileSize) -> (Errno, usize) {
     }
 }
 
+#[inline]
 pub fn fd_pwrite(fd: Fd, iovs: &[CIoVec], offset: FileSize) -> (Errno, usize) {
     let mut nwritten = MaybeUninit::<usize>::uninit();
     unsafe {
@@ -276,18 +94,7 @@ pub fn fd_pwrite(fd: Fd, iovs: &[CIoVec], offset: FileSize) -> (Errno, usize) {
     }
 }
 
-pub fn random_get(buf: &mut [u8]) -> Errno {
-    unsafe { __wasi_random_get(buf.as_mut_ptr() as *mut c_void, buf.len()) }
-}
-
-pub fn fd_close(fd: Fd) -> Errno {
-    unsafe { __wasi_fd_close(fd) }
-}
-
-pub fn fd_datasync(fd: Fd) -> Errno {
-    unsafe { __wasi_fd_datasync(fd) }
-}
-
+#[inline]
 pub fn fd_read(fd: Fd, iovs: &[IoVec]) -> (Errno, usize) {
     let mut nread = MaybeUninit::<usize>::uninit();
     unsafe {
@@ -298,10 +105,7 @@ pub fn fd_read(fd: Fd, iovs: &[IoVec]) -> (Errno, usize) {
     }
 }
 
-pub fn fd_renumber(from: Fd, to: Fd) -> Errno {
-    unsafe { __wasi_fd_renumber(from, to) }
-}
-
+#[inline]
 pub fn fd_seek(fd: Fd, offset: FileDelta, whence: Whence) -> (Errno, FileSize) {
     let mut newoffset = MaybeUninit::<FileSize>::uninit();
     unsafe {
@@ -312,6 +116,7 @@ pub fn fd_seek(fd: Fd, offset: FileDelta, whence: Whence) -> (Errno, FileSize) {
     }
 }
 
+#[inline]
 pub fn fd_tell(fd: Fd) -> (Errno, FileSize) {
     let mut newoffset = MaybeUninit::<FileSize>::uninit();
     unsafe {
@@ -322,6 +127,7 @@ pub fn fd_tell(fd: Fd) -> (Errno, FileSize) {
     }
 }
 
+#[inline]
 pub fn fd_fdstat_get(fd: Fd) -> (Errno, FdStat) {
     let mut buf = MaybeUninit::<FdStat>::uninit();
     unsafe {
@@ -332,18 +138,7 @@ pub fn fd_fdstat_get(fd: Fd) -> (Errno, FdStat) {
     }
 }
 
-pub fn fd_fdstat_set_flags(fd: Fd, flags: FdFlags) -> Errno {
-    unsafe { __wasi_fd_fdstat_set_flags(fd, flags) }
-}
-
-pub fn fd_fdstat_set_rights(fd: Fd, fs_rights_base: Rights, fs_rights_inheriting: Rights) -> Errno {
-    unsafe { __wasi_fd_fdstat_set_rights(fd, fs_rights_base, fs_rights_inheriting) }
-}
-
-pub fn fd_sync(fd: Fd) -> Errno {
-    unsafe { __wasi_fd_sync(fd) }
-}
-
+#[inline]
 pub fn fd_write(fd: Fd, iovs: &[CIoVec]) -> (Errno, usize) {
     let mut nwritten = MaybeUninit::<usize>::uninit();
     unsafe {
@@ -354,38 +149,7 @@ pub fn fd_write(fd: Fd, iovs: &[CIoVec]) -> (Errno, usize) {
     }
 }
 
-pub fn fd_advise(fd: Fd, offset: FileSize, len: FileSize, advice: Advice) -> Errno {
-    unsafe { __wasi_fd_advise(fd, offset, len, advice) }
-}
-
-pub fn fd_allocate(fd: Fd, offset: FileSize, len: FileSize) -> Errno {
-    unsafe { __wasi_fd_allocate(fd, offset, len) }
-}
-
-pub fn path_create_directory(fd: Fd, path: &[u8]) -> Errno {
-    unsafe { __wasi_path_create_directory(fd, path.as_ptr(), path.len()) }
-}
-
-pub fn path_link(
-    old_fd: Fd,
-    old_flags: LookupFlags,
-    old_path: &[u8],
-    new_fd: Fd,
-    new_path: &[u8],
-) -> Errno {
-    unsafe {
-        __wasi_path_link(
-            old_fd,
-            old_flags,
-            old_path.as_ptr(),
-            old_path.len(),
-            new_fd,
-            new_path.as_ptr(),
-            new_path.len(),
-        )
-    }
-}
-
+#[inline]
 pub fn path_open(
     dirfd: Fd,
     dirflags: LookupFlags,
@@ -414,6 +178,7 @@ pub fn path_open(
     }
 }
 
+#[inline]
 pub fn fd_readdir(fd: Fd, buf: &mut [u8], cookie: DirCookie) -> (Errno, usize) {
     let mut bufused = MaybeUninit::<usize>::uninit();
     unsafe {
@@ -430,6 +195,7 @@ pub fn fd_readdir(fd: Fd, buf: &mut [u8], cookie: DirCookie) -> (Errno, usize) {
     }
 }
 
+#[inline]
 pub fn path_readlink(fd: Fd, path: &[u8], buf: &mut [u8]) -> (Errno, usize) {
     let mut bufused = MaybeUninit::<usize>::uninit();
     unsafe {
@@ -447,19 +213,7 @@ pub fn path_readlink(fd: Fd, path: &[u8], buf: &mut [u8]) -> (Errno, usize) {
     }
 }
 
-pub fn path_rename(old_fd: Fd, old_path: &[u8], new_fd: Fd, new_path: &[u8]) -> Errno {
-    unsafe {
-        __wasi_path_rename(
-            old_fd,
-            old_path.as_ptr(),
-            old_path.len(),
-            new_fd,
-            new_path.as_ptr(),
-            new_path.len(),
-        )
-    }
-}
-
+#[inline]
 pub fn fd_filestat_get(fd: Fd) -> (Errno, FileStat) {
     let mut buf = MaybeUninit::<FileStat>::uninit();
     unsafe {
@@ -470,19 +224,7 @@ pub fn fd_filestat_get(fd: Fd) -> (Errno, FileStat) {
     }
 }
 
-pub fn fd_filestat_set_times(
-    fd: Fd,
-    st_atim: Timestamp,
-    st_mtim: Timestamp,
-    fstflags: FstFlags,
-) -> Errno {
-    unsafe { __wasi_fd_filestat_set_times(fd, st_atim, st_mtim, fstflags) }
-}
-
-pub fn fd_filestat_set_size(fd: Fd, st_size: FileSize) -> Errno {
-    unsafe { __wasi_fd_filestat_set_size(fd, st_size) }
-}
-
+#[inline]
 pub fn path_filestat_get(fd: Fd, flags: LookupFlags, path: &[u8]) -> (Errno, FileStat) {
     let mut buf = MaybeUninit::<FileStat>::uninit();
     unsafe {
@@ -493,47 +235,7 @@ pub fn path_filestat_get(fd: Fd, flags: LookupFlags, path: &[u8]) -> (Errno, Fil
     }
 }
 
-pub fn path_filestat_set_times(
-    fd: Fd,
-    flags: LookupFlags,
-    path: &[u8],
-    st_atim: Timestamp,
-    st_mtim: Timestamp,
-    fstflags: FstFlags,
-) -> Errno {
-    unsafe {
-        __wasi_path_filestat_set_times(
-            fd,
-            flags,
-            path.as_ptr(),
-            path.len(),
-            st_atim,
-            st_mtim,
-            fstflags,
-        )
-    }
-}
-
-pub fn path_symlink(old_path: &[u8], fd: Fd, new_path: &[u8]) -> Errno {
-    unsafe {
-        __wasi_path_symlink(
-            old_path.as_ptr(),
-            old_path.len(),
-            fd,
-            new_path.as_ptr(),
-            new_path.len(),
-        )
-    }
-}
-
-pub fn path_unlink_file(fd: Fd, path: &[u8]) -> Errno {
-    unsafe { __wasi_path_unlink_file(fd, path.as_ptr(), path.len()) }
-}
-
-pub fn path_remove_directory(fd: Fd, path: &[u8]) -> Errno {
-    unsafe { __wasi_path_remove_directory(fd, path.as_ptr(), path.len()) }
-}
-
+#[inline]
 pub fn poll_oneoff(in_: &[Subscription], out: &mut [Event]) -> (Errno, usize) {
     assert!(out.len() >= in_.len());
     let mut nevents = MaybeUninit::<usize>::uninit();
@@ -550,14 +252,7 @@ pub fn poll_oneoff(in_: &[Subscription], out: &mut [Event]) -> (Errno, usize) {
     }
 }
 
-pub fn proc_exit(rval: ExitCode) {
-    unsafe { __wasi_proc_exit(rval) }
-}
-
-pub fn proc_raise(sig: Signal) -> Errno {
-    unsafe { __wasi_proc_raise(sig) }
-}
-
+#[inline]
 pub fn sock_recv(sock: Fd, ri_data: &[IoVec], ri_flags: RiFlags) -> (Errno, usize, RoFlags) {
     let mut ro_datalen = MaybeUninit::<usize>::uninit();
     let mut ro_flags = MaybeUninit::<RoFlags>::uninit();
@@ -577,6 +272,7 @@ pub fn sock_recv(sock: Fd, ri_data: &[IoVec], ri_flags: RiFlags) -> (Errno, usiz
     }
 }
 
+#[inline]
 pub fn sock_send(sock: Fd, si_data: &[CIoVec], si_flags: SiFlags) -> (Errno, usize) {
     let mut so_datalen = MaybeUninit::<usize>::uninit();
     unsafe {
@@ -593,14 +289,7 @@ pub fn sock_send(sock: Fd, si_data: &[CIoVec], si_flags: SiFlags) -> (Errno, usi
     }
 }
 
-pub fn sock_shutdown(sock: Fd, how: SdFlags) -> Errno {
-    unsafe { __wasi_sock_shutdown(sock, how) }
-}
-
-pub fn sched_yield() -> Errno {
-    unsafe { __wasi_sched_yield() }
-}
-
+#[inline]
 pub fn fd_prestat_get(fd: Fd) -> (Errno, Prestat) {
     let mut buf = MaybeUninit::<Prestat>::uninit();
     unsafe {
@@ -611,10 +300,6 @@ pub fn fd_prestat_get(fd: Fd) -> (Errno, Prestat) {
     }
 }
 
-pub fn fd_prestat_dir_name(fd: Fd, path: &mut [u8]) -> Errno {
-    unsafe { __wasi_fd_prestat_dir_name(fd, path.as_mut_ptr(), path.len()) }
-}
-
 // TODO: Safe interfaces to the args and environ functions
 /*
 pub fn args_get(argv: *mut *mut u8, argv_buf: *mut u8) -> Errno {}
diff --git a/src/wasi_unstable/types.rs b/src/wasi_unstable/types.rs
new file mode 100644
index 0000000..dd744c9
--- /dev/null
+++ b/src/wasi_unstable/types.rs
@@ -0,0 +1,41 @@
+//! This file defines idiomatic Rust names for types.
+
+use crate::wasi_unstable::raw::*;
+
+pub type Advice = __wasi_advice_t;
+pub type ClockId = __wasi_clockid_t;
+pub type Device = __wasi_device_t;
+pub type DirCookie = __wasi_dircookie_t;
+pub type Errno = __wasi_errno_t;
+pub type EventRwFlags = __wasi_eventrwflags_t;
+pub type EventType = __wasi_eventtype_t;
+pub type ExitCode = __wasi_exitcode_t;
+pub type Fd = __wasi_fd_t;
+pub type FdFlags = __wasi_fdflags_t;
+pub type FileDelta = __wasi_filedelta_t;
+pub type FileSize = __wasi_filesize_t;
+pub type FileType = __wasi_filetype_t;
+pub type FstFlags = __wasi_fstflags_t;
+pub type Inode = __wasi_inode_t;
+pub type LinkCount = __wasi_linkcount_t;
+pub type LookupFlags = __wasi_lookupflags_t;
+pub type OFlags = __wasi_oflags_t;
+pub type PreopenType = __wasi_preopentype_t;
+pub type RiFlags = __wasi_riflags_t;
+pub type Rights = __wasi_rights_t;
+pub type RoFlags = __wasi_roflags_t;
+pub type SdFlags = __wasi_sdflags_t;
+pub type SiFlags = __wasi_siflags_t;
+pub type Signal = __wasi_signal_t;
+pub type SubclockFlags = __wasi_subclockflags_t;
+pub type Timestamp = __wasi_timestamp_t;
+pub type Userdata = __wasi_userdata_t;
+pub type Whence = __wasi_whence_t;
+pub type Dirent = __wasi_dirent_t;
+pub type FdStat = __wasi_fdstat_t;
+pub type FileStat = __wasi_filestat_t;
+pub type CIoVec = __wasi_ciovec_t;
+pub type IoVec = __wasi_iovec_t;
+pub type Subscription = __wasi_subscription_t;
+pub type Event = __wasi_event_t;
+pub type Prestat = __wasi_prestat_t;
-- 
2.17.1