/
types.go
1154 lines (876 loc) · 30.9 KB
/
types.go
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
// THIS FILE IS AUTO-GENERATED from the following files:
//
// wasi_snapshot_preview1.witx
//
// To regenerate this file execute:
//
// cargo run --manifest-path gen-wasi/Cargo.toml generate-api
//
// Modifications to this file will cause CI to fail, the code generator tool
// must be modified to change this file.
//
// This file describes the [WASI] interface, consisting of functions, types,
// and defined values (macros).
//
// The interface described here is greatly inspired by [CloudABI]'s clean,
// thoughtfully-designed, capability-oriented, POSIX-style API.
//
// [CloudABI]: https://github.com/NuxiNL/cloudlibc
// [WASI]: https://github.com/WebAssembly/WASI/
package wasi
import (
"github.com/pgavlin/warp/exec"
)
type wasiSize = uint32
// Non-negative file size or length of a region within a file.
type wasiFilesize = uint64
// Timestamp in nanoseconds.
type wasiTimestamp = uint64
// Identifiers for clocks.
type wasiClockid = uint32
// The clock measuring real time. Time value zero corresponds with
// 1970-01-01T00:00:00Z.
const wasiClockidRealtime = 0
// The store-wide monotonic clock, which is defined as a clock measuring
// real time, whose value cannot be adjusted and which cannot have negative
// clock jumps. The epoch of this clock is undefined. The absolute time
// value of this clock therefore has no meaning.
const wasiClockidMonotonic = 1
// The CPU-time clock associated with the current process.
const wasiClockidProcessCputimeId = 2
// The CPU-time clock associated with the current thread.
const wasiClockidThreadCputimeId = 3
// Error codes returned by functions.
// Not all of these error codes are returned by the functions provided by this
// API; some are used in higher-level library layers, and others are provided
// merely for alignment with POSIX.
type wasiErrno = uint16
// No error occurred. System call completed successfully.
const wasiErrnoSuccess = 0
// Argument list too long.
const wasiErrno2big = 1
// Permission denied.
const wasiErrnoAcces = 2
// Address in use.
const wasiErrnoAddrinuse = 3
// Address not available.
const wasiErrnoAddrnotavail = 4
// Address family not supported.
const wasiErrnoAfnosupport = 5
// Resource unavailable, or operation would block.
const wasiErrnoAgain = 6
// Connection already in progress.
const wasiErrnoAlready = 7
// Bad file descriptor.
const wasiErrnoBadf = 8
// Bad message.
const wasiErrnoBadmsg = 9
// Device or resource busy.
const wasiErrnoBusy = 10
// Operation canceled.
const wasiErrnoCanceled = 11
// No child processes.
const wasiErrnoChild = 12
// Connection aborted.
const wasiErrnoConnaborted = 13
// Connection refused.
const wasiErrnoConnrefused = 14
// Connection reset.
const wasiErrnoConnreset = 15
// Resource deadlock would occur.
const wasiErrnoDeadlk = 16
// Destination address required.
const wasiErrnoDestaddrreq = 17
// Mathematics argument out of domain of function.
const wasiErrnoDom = 18
// Reserved.
const wasiErrnoDquot = 19
// File exists.
const wasiErrnoExist = 20
// Bad address.
const wasiErrnoFault = 21
// File too large.
const wasiErrnoFbig = 22
// Host is unreachable.
const wasiErrnoHostunreach = 23
// Identifier removed.
const wasiErrnoIdrm = 24
// Illegal byte sequence.
const wasiErrnoIlseq = 25
// Operation in progress.
const wasiErrnoInprogress = 26
// Interrupted function.
const wasiErrnoIntr = 27
// Invalid argument.
const wasiErrnoInval = 28
// I/O error.
const wasiErrnoIo = 29
// Socket is connected.
const wasiErrnoIsconn = 30
// Is a directory.
const wasiErrnoIsdir = 31
// Too many levels of symbolic links.
const wasiErrnoLoop = 32
// File descriptor value too large.
const wasiErrnoMfile = 33
// Too many links.
const wasiErrnoMlink = 34
// Message too large.
const wasiErrnoMsgsize = 35
// Reserved.
const wasiErrnoMultihop = 36
// Filename too long.
const wasiErrnoNametoolong = 37
// Network is down.
const wasiErrnoNetdown = 38
// Connection aborted by network.
const wasiErrnoNetreset = 39
// Network unreachable.
const wasiErrnoNetunreach = 40
// Too many files open in system.
const wasiErrnoNfile = 41
// No buffer space available.
const wasiErrnoNobufs = 42
// No such device.
const wasiErrnoNodev = 43
// No such file or directory.
const wasiErrnoNoent = 44
// Executable file format error.
const wasiErrnoNoexec = 45
// No locks available.
const wasiErrnoNolck = 46
// Reserved.
const wasiErrnoNolink = 47
// Not enough space.
const wasiErrnoNomem = 48
// No message of the desired type.
const wasiErrnoNomsg = 49
// Protocol not available.
const wasiErrnoNoprotoopt = 50
// No space left on device.
const wasiErrnoNospc = 51
// Function not supported.
const wasiErrnoNosys = 52
// The socket is not connected.
const wasiErrnoNotconn = 53
// Not a directory or a symbolic link to a directory.
const wasiErrnoNotdir = 54
// Directory not empty.
const wasiErrnoNotempty = 55
// State not recoverable.
const wasiErrnoNotrecoverable = 56
// Not a socket.
const wasiErrnoNotsock = 57
// Not supported, or operation not supported on socket.
const wasiErrnoNotsup = 58
// Inappropriate I/O control operation.
const wasiErrnoNotty = 59
// No such device or address.
const wasiErrnoNxio = 60
// Value too large to be stored in data type.
const wasiErrnoOverflow = 61
// Previous owner died.
const wasiErrnoOwnerdead = 62
// Operation not permitted.
const wasiErrnoPerm = 63
// Broken pipe.
const wasiErrnoPipe = 64
// Protocol error.
const wasiErrnoProto = 65
// Protocol not supported.
const wasiErrnoProtonosupport = 66
// Protocol wrong type for socket.
const wasiErrnoPrototype = 67
// Result too large.
const wasiErrnoRange = 68
// Read-only file system.
const wasiErrnoRofs = 69
// Invalid seek.
const wasiErrnoSpipe = 70
// No such process.
const wasiErrnoSrch = 71
// Reserved.
const wasiErrnoStale = 72
// Connection timed out.
const wasiErrnoTimedout = 73
// Text file busy.
const wasiErrnoTxtbsy = 74
// Cross-device link.
const wasiErrnoXdev = 75
// Extension: Capabilities insufficient.
const wasiErrnoNotcapable = 76
// File descriptor rights, determining which actions may be performed.
type wasiRights = uint64
// The right to invoke `fd_datasync`.
// If `path_open` is set, includes the right to invoke
// `path_open` with `fdflags::dsync`.
const wasiRightsFdDatasync = 1 << 0
// The right to invoke `fd_read` and `sock_recv`.
// If `rights::fd_seek` is set, includes the right to invoke `fd_pread`.
const wasiRightsFdRead = 1 << 1
// The right to invoke `fd_seek`. This flag implies `rights::fd_tell`.
const wasiRightsFdSeek = 1 << 2
// The right to invoke `fd_fdstat_set_flags`.
const wasiRightsFdFdstatSetFlags = 1 << 3
// The right to invoke `fd_sync`.
// If `path_open` is set, includes the right to invoke
// `path_open` with `fdflags::rsync` and `fdflags::dsync`.
const wasiRightsFdSync = 1 << 4
// The right to invoke `fd_seek` in such a way that the file offset
// remains unaltered (i.e., `whence::cur` with offset zero), or to
// invoke `fd_tell`.
const wasiRightsFdTell = 1 << 5
// The right to invoke `fd_write` and `sock_send`.
// If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`.
const wasiRightsFdWrite = 1 << 6
// The right to invoke `fd_advise`.
const wasiRightsFdAdvise = 1 << 7
// The right to invoke `fd_allocate`.
const wasiRightsFdAllocate = 1 << 8
// The right to invoke `path_create_directory`.
const wasiRightsPathCreateDirectory = 1 << 9
// If `path_open` is set, the right to invoke `path_open` with `oflags::creat`.
const wasiRightsPathCreateFile = 1 << 10
// The right to invoke `path_link` with the file descriptor as the
// source directory.
const wasiRightsPathLinkSource = 1 << 11
// The right to invoke `path_link` with the file descriptor as the
// target directory.
const wasiRightsPathLinkTarget = 1 << 12
// The right to invoke `path_open`.
const wasiRightsPathOpen = 1 << 13
// The right to invoke `fd_readdir`.
const wasiRightsFdReaddir = 1 << 14
// The right to invoke `path_readlink`.
const wasiRightsPathReadlink = 1 << 15
// The right to invoke `path_rename` with the file descriptor as the source directory.
const wasiRightsPathRenameSource = 1 << 16
// The right to invoke `path_rename` with the file descriptor as the target directory.
const wasiRightsPathRenameTarget = 1 << 17
// The right to invoke `path_filestat_get`.
const wasiRightsPathFilestatGet = 1 << 18
// The right to change a file's size (there is no `path_filestat_set_size`).
// If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`.
const wasiRightsPathFilestatSetSize = 1 << 19
// The right to invoke `path_filestat_set_times`.
const wasiRightsPathFilestatSetTimes = 1 << 20
// The right to invoke `fd_filestat_get`.
const wasiRightsFdFilestatGet = 1 << 21
// The right to invoke `fd_filestat_set_size`.
const wasiRightsFdFilestatSetSize = 1 << 22
// The right to invoke `fd_filestat_set_times`.
const wasiRightsFdFilestatSetTimes = 1 << 23
// The right to invoke `path_symlink`.
const wasiRightsPathSymlink = 1 << 24
// The right to invoke `path_remove_directory`.
const wasiRightsPathRemoveDirectory = 1 << 25
// The right to invoke `path_unlink_file`.
const wasiRightsPathUnlinkFile = 1 << 26
// If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`.
// If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`.
const wasiRightsPollFdReadwrite = 1 << 27
// The right to invoke `sock_shutdown`.
const wasiRightsSockShutdown = 1 << 28
// A file descriptor handle.
type wasiFd = handle
// A region of memory for scatter/gather reads.
type wasiIovec struct {
// The address of the buffer to be filled.
buf pointer
// The length of the buffer to be filled.
bufLen wasiSize
}
func (v *wasiIovec) layout() (uint32, uint32) {
return 8, 4
}
func (v *wasiIovec) store(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
mem.PutUint32(uint32(v.buf), uint32(base), 0)
mem.PutUint32(uint32(v.bufLen), uint32(base), 4)
}
func (v *wasiIovec) load(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
v.buf = pointer(mem.Uint32(uint32(base), 0))
v.bufLen = wasiSize(mem.Uint32(uint32(base), 4))
}
// A region of memory for scatter/gather writes.
type wasiCiovec struct {
// The address of the buffer to be written.
buf pointer
// The length of the buffer to be written.
bufLen wasiSize
}
func (v *wasiCiovec) layout() (uint32, uint32) {
return 8, 4
}
func (v *wasiCiovec) store(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
mem.PutUint32(uint32(v.buf), uint32(base), 0)
mem.PutUint32(uint32(v.bufLen), uint32(base), 4)
}
func (v *wasiCiovec) load(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
v.buf = pointer(mem.Uint32(uint32(base), 0))
v.bufLen = wasiSize(mem.Uint32(uint32(base), 4))
}
type wasiIovecArray list
func (v *wasiIovecArray) elementSize() uint32 {
return 8
}
func (l *wasiIovecArray) storeIndex(mem *exec.Memory, index int, value wasiIovec) {
addr := uint32(l.pointer) + 8*uint32(index)
value.store(mem, uint32(addr), 0)
}
func (l *wasiIovecArray) loadIndex(mem *exec.Memory, index int) wasiIovec {
var value wasiIovec
addr := uint32(l.pointer) + uint32(index)*8
value.load(mem, uint32(addr), 0)
return value
}
type wasiCiovecArray list
func (v *wasiCiovecArray) elementSize() uint32 {
return 8
}
func (l *wasiCiovecArray) storeIndex(mem *exec.Memory, index int, value wasiCiovec) {
addr := uint32(l.pointer) + 8*uint32(index)
value.store(mem, uint32(addr), 0)
}
func (l *wasiCiovecArray) loadIndex(mem *exec.Memory, index int) wasiCiovec {
var value wasiCiovec
addr := uint32(l.pointer) + uint32(index)*8
value.load(mem, uint32(addr), 0)
return value
}
// Relative offset within a file.
type wasiFiledelta = int64
// The position relative to which to set the offset of the file descriptor.
type wasiWhence = uint8
// Seek relative to start-of-file.
const wasiWhenceSet = 0
// Seek relative to current position.
const wasiWhenceCur = 1
// Seek relative to end-of-file.
const wasiWhenceEnd = 2
// A reference to the offset of a directory entry.
//
// The value 0 signifies the start of the directory.
type wasiDircookie = uint64
// The type for the `dirent::d_namlen` field of `dirent` struct.
type wasiDirnamlen = uint32
// File serial number that is unique within its file system.
type wasiInode = uint64
// The type of a file descriptor or file.
type wasiFiletype = uint8
// The type of the file descriptor or file is unknown or is different from any of the other types specified.
const wasiFiletypeUnknown = 0
// The file descriptor or file refers to a block device inode.
const wasiFiletypeBlockDevice = 1
// The file descriptor or file refers to a character device inode.
const wasiFiletypeCharacterDevice = 2
// The file descriptor or file refers to a directory inode.
const wasiFiletypeDirectory = 3
// The file descriptor or file refers to a regular file inode.
const wasiFiletypeRegularFile = 4
// The file descriptor or file refers to a datagram socket.
const wasiFiletypeSocketDgram = 5
// The file descriptor or file refers to a byte-stream socket.
const wasiFiletypeSocketStream = 6
// The file refers to a symbolic link inode.
const wasiFiletypeSymbolicLink = 7
// A directory entry.
type wasiDirent struct {
// The offset of the next directory entry stored in this directory.
dNext wasiDircookie
// The serial number of the file referred to by this directory entry.
dIno wasiInode
// The length of the name of the directory entry.
dNamlen wasiDirnamlen
// The type of the file referred to by this directory entry.
dType wasiFiletype
}
func (v *wasiDirent) layout() (uint32, uint32) {
return 24, 8
}
func (v *wasiDirent) store(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
mem.PutUint64(uint64(v.dNext), uint32(base), 0)
mem.PutUint64(uint64(v.dIno), uint32(base), 8)
mem.PutUint32(uint32(v.dNamlen), uint32(base), 16)
mem.PutByte(byte(v.dType), uint32(base), 20)
}
func (v *wasiDirent) load(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
v.dNext = wasiDircookie(mem.Uint64(uint32(base), 0))
v.dIno = wasiInode(mem.Uint64(uint32(base), 8))
v.dNamlen = wasiDirnamlen(mem.Uint32(uint32(base), 16))
v.dType = wasiFiletype(mem.Byte(uint32(base), 20))
}
// File or memory access pattern advisory information.
type wasiAdvice = uint8
// The application has no advice to give on its behavior with respect to the specified data.
const wasiAdviceNormal = 0
// The application expects to access the specified data sequentially from lower offsets to higher offsets.
const wasiAdviceSequential = 1
// The application expects to access the specified data in a random order.
const wasiAdviceRandom = 2
// The application expects to access the specified data in the near future.
const wasiAdviceWillneed = 3
// The application expects that it will not access the specified data in the near future.
const wasiAdviceDontneed = 4
// The application expects to access the specified data once and then not reuse it thereafter.
const wasiAdviceNoreuse = 5
// File descriptor flags.
type wasiFdflags = uint16
// Append mode: Data written to the file is always appended to the file's end.
const wasiFdflagsAppend = 1 << 0
// Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
const wasiFdflagsDsync = 1 << 1
// Non-blocking mode.
const wasiFdflagsNonblock = 1 << 2
// Synchronized read I/O operations.
const wasiFdflagsRsync = 1 << 3
// Write according to synchronized I/O file integrity completion. In
// addition to synchronizing the data stored in the file, the implementation
// may also synchronously update the file's metadata.
const wasiFdflagsSync = 1 << 4
// File descriptor attributes.
type wasiFdstat struct {
// File type.
fsFiletype wasiFiletype
// File descriptor flags.
fsFlags wasiFdflags
// Rights that apply to this file descriptor.
fsRightsBase wasiRights
// Maximum set of rights that may be installed on new file descriptors that
// are created through this file descriptor, e.g., through `path_open`.
fsRightsInheriting wasiRights
}
func (v *wasiFdstat) layout() (uint32, uint32) {
return 24, 8
}
func (v *wasiFdstat) store(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
mem.PutByte(byte(v.fsFiletype), uint32(base), 0)
mem.PutUint16(uint16(v.fsFlags), uint32(base), 2)
mem.PutUint64(uint64(v.fsRightsBase), uint32(base), 8)
mem.PutUint64(uint64(v.fsRightsInheriting), uint32(base), 16)
}
func (v *wasiFdstat) load(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
v.fsFiletype = wasiFiletype(mem.Byte(uint32(base), 0))
v.fsFlags = wasiFdflags(mem.Uint16(uint32(base), 2))
v.fsRightsBase = wasiRights(mem.Uint64(uint32(base), 8))
v.fsRightsInheriting = wasiRights(mem.Uint64(uint32(base), 16))
}
// Identifier for a device containing a file system. Can be used in combination
// with `inode` to uniquely identify a file or directory in the filesystem.
type wasiDevice = uint64
// Which file time attributes to adjust.
type wasiFstflags = uint16
// Adjust the last data access timestamp to the value stored in `filestat::atim`.
const wasiFstflagsAtim = 1 << 0
// Adjust the last data access timestamp to the time of clock `clockid::realtime`.
const wasiFstflagsAtimNow = 1 << 1
// Adjust the last data modification timestamp to the value stored in `filestat::mtim`.
const wasiFstflagsMtim = 1 << 2
// Adjust the last data modification timestamp to the time of clock `clockid::realtime`.
const wasiFstflagsMtimNow = 1 << 3
// Flags determining the method of how paths are resolved.
type wasiLookupflags = uint32
// As long as the resolved path corresponds to a symbolic link, it is expanded.
const wasiLookupflagsSymlinkFollow = 1 << 0
// Open flags used by `path_open`.
type wasiOflags = uint16
// Create file if it does not exist.
const wasiOflagsCreat = 1 << 0
// Fail if not a directory.
const wasiOflagsDirectory = 1 << 1
// Fail if file already exists.
const wasiOflagsExcl = 1 << 2
// Truncate file to size 0.
const wasiOflagsTrunc = 1 << 3
// Number of hard links to an inode.
type wasiLinkcount = uint64
// File attributes.
type wasiFilestat struct {
// Device ID of device containing the file.
dev wasiDevice
// File serial number.
ino wasiInode
// File type.
filetype wasiFiletype
// Number of hard links to the file.
nlink wasiLinkcount
// For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
size wasiFilesize
// Last data access timestamp.
atim wasiTimestamp
// Last data modification timestamp.
mtim wasiTimestamp
// Last file status change timestamp.
ctim wasiTimestamp
}
func (v *wasiFilestat) layout() (uint32, uint32) {
return 64, 8
}
func (v *wasiFilestat) store(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
mem.PutUint64(uint64(v.dev), uint32(base), 0)
mem.PutUint64(uint64(v.ino), uint32(base), 8)
mem.PutByte(byte(v.filetype), uint32(base), 16)
mem.PutUint64(uint64(v.nlink), uint32(base), 24)
mem.PutUint64(uint64(v.size), uint32(base), 32)
mem.PutUint64(uint64(v.atim), uint32(base), 40)
mem.PutUint64(uint64(v.mtim), uint32(base), 48)
mem.PutUint64(uint64(v.ctim), uint32(base), 56)
}
func (v *wasiFilestat) load(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
v.dev = wasiDevice(mem.Uint64(uint32(base), 0))
v.ino = wasiInode(mem.Uint64(uint32(base), 8))
v.filetype = wasiFiletype(mem.Byte(uint32(base), 16))
v.nlink = wasiLinkcount(mem.Uint64(uint32(base), 24))
v.size = wasiFilesize(mem.Uint64(uint32(base), 32))
v.atim = wasiTimestamp(mem.Uint64(uint32(base), 40))
v.mtim = wasiTimestamp(mem.Uint64(uint32(base), 48))
v.ctim = wasiTimestamp(mem.Uint64(uint32(base), 56))
}
// User-provided value that may be attached to objects that is retained when
// extracted from the implementation.
type wasiUserdata = uint64
// Type of a subscription to an event or its occurrence.
type wasiEventtype = uint8
// The time value of clock `subscription_clock::id` has
// reached timestamp `subscription_clock::timeout`.
const wasiEventtypeClock = 0
// File descriptor `subscription_fd_readwrite::file_descriptor` has data
// available for reading. This event always triggers for regular files.
const wasiEventtypeFdRead = 1
// File descriptor `subscription_fd_readwrite::file_descriptor` has capacity
// available for writing. This event always triggers for regular files.
const wasiEventtypeFdWrite = 2
// The state of the file descriptor subscribed to with
// `eventtype::fd_read` or `eventtype::fd_write`.
type wasiEventrwflags = uint16
// The peer of this socket has closed or disconnected.
const wasiEventrwflagsFdReadwriteHangup = 1 << 0
// The contents of an `event` when type is `eventtype::fd_read` or
// `eventtype::fd_write`.
type wasiEventFdReadwrite struct {
// The number of bytes available for reading or writing.
nbytes wasiFilesize
// The state of the file descriptor.
flags wasiEventrwflags
}
func (v *wasiEventFdReadwrite) layout() (uint32, uint32) {
return 16, 8
}
func (v *wasiEventFdReadwrite) store(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
mem.PutUint64(uint64(v.nbytes), uint32(base), 0)
mem.PutUint16(uint16(v.flags), uint32(base), 8)
}
func (v *wasiEventFdReadwrite) load(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
v.nbytes = wasiFilesize(mem.Uint64(uint32(base), 0))
v.flags = wasiEventrwflags(mem.Uint16(uint32(base), 8))
}
// An event that occurred.
type wasiEvent struct {
// User-provided value that got attached to `subscription::userdata`.
userdata wasiUserdata
// If non-zero, an error that occurred while processing the subscription request.
error wasiErrno
// The type of event that occured
type_ wasiEventtype
// The contents of the event, if it is an `eventtype::fd_read` or
// `eventtype::fd_write`. `eventtype::clock` events ignore this field.
fdReadwrite wasiEventFdReadwrite
}
func (v *wasiEvent) layout() (uint32, uint32) {
return 32, 8
}
func (v *wasiEvent) store(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
mem.PutUint64(uint64(v.userdata), uint32(base), 0)
mem.PutUint16(uint16(v.error), uint32(base), 8)
mem.PutByte(byte(v.type_), uint32(base), 10)
v.fdReadwrite.store(mem, uint32(base), 16)
}
func (v *wasiEvent) load(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
v.userdata = wasiUserdata(mem.Uint64(uint32(base), 0))
v.error = wasiErrno(mem.Uint16(uint32(base), 8))
v.type_ = wasiEventtype(mem.Byte(uint32(base), 10))
v.fdReadwrite.load(mem, uint32(base), 16)
}
// Flags determining how to interpret the timestamp provided in
// `subscription_clock::timeout`.
type wasiSubclockflags = uint16
// If set, treat the timestamp provided in
// `subscription_clock::timeout` as an absolute timestamp of clock
// `subscription_clock::id`. If clear, treat the timestamp
// provided in `subscription_clock::timeout` relative to the
// current time value of clock `subscription_clock::id`.
const wasiSubclockflagsSubscriptionClockAbstime = 1 << 0
// The contents of a `subscription` when type is `eventtype::clock`.
type wasiSubscriptionClock struct {
// The clock against which to compare the timestamp.
id wasiClockid
// The absolute or relative timestamp.
timeout wasiTimestamp
// The amount of time that the implementation may wait additionally
// to coalesce with other events.
precision wasiTimestamp
// Flags specifying whether the timeout is absolute or relative
flags wasiSubclockflags
}
func (v *wasiSubscriptionClock) layout() (uint32, uint32) {
return 32, 8
}
func (v *wasiSubscriptionClock) store(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
mem.PutUint32(uint32(v.id), uint32(base), 0)
mem.PutUint64(uint64(v.timeout), uint32(base), 8)
mem.PutUint64(uint64(v.precision), uint32(base), 16)
mem.PutUint16(uint16(v.flags), uint32(base), 24)
}
func (v *wasiSubscriptionClock) load(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
v.id = wasiClockid(mem.Uint32(uint32(base), 0))
v.timeout = wasiTimestamp(mem.Uint64(uint32(base), 8))
v.precision = wasiTimestamp(mem.Uint64(uint32(base), 16))
v.flags = wasiSubclockflags(mem.Uint16(uint32(base), 24))
}
// The contents of a `subscription` when type is type is
// `eventtype::fd_read` or `eventtype::fd_write`.
type wasiSubscriptionFdReadwrite struct {
// The file descriptor on which to wait for it to become ready for reading or writing.
fileDescriptor wasiFd
}
func (v *wasiSubscriptionFdReadwrite) layout() (uint32, uint32) {
return 4, 4
}
func (v *wasiSubscriptionFdReadwrite) store(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
mem.PutUint32(uint32(v.fileDescriptor), uint32(base), 0)
}
func (v *wasiSubscriptionFdReadwrite) load(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
v.fileDescriptor = wasiFd(mem.Uint32(uint32(base), 0))
}
// The contents of a `subscription`.
type wasiSubscriptionU struct {
tag uint8
clock wasiSubscriptionClock
fdRead wasiSubscriptionFdReadwrite
fdWrite wasiSubscriptionFdReadwrite
}
func (v *wasiSubscriptionU) layout() (uint32, uint32) {
return 40, 8
}
func (v *wasiSubscriptionU) store(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
mem.PutByte(byte(v.tag), uint32(base), 0)
switch v.tag {
case 0:
v.clock.store(mem, uint32(base), 8)
case 1:
v.fdRead.store(mem, uint32(base), 4)
case 2:
v.fdWrite.store(mem, uint32(base), 4)
}
}
func (v *wasiSubscriptionU) load(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
v.tag = uint8(mem.Byte(uint32(base), 0))
switch v.tag {
case 0:
v.clock.load(mem, uint32(base), 8)
case 1:
v.fdRead.load(mem, uint32(base), 4)
case 2:
v.fdWrite.load(mem, uint32(base), 4)
}
}
// Subscription to an event.
type wasiSubscription struct {
// User-provided value that is attached to the subscription in the
// implementation and returned through `event::userdata`.
userdata wasiUserdata
// The type of the event to which to subscribe, and its contents
u wasiSubscriptionU
}
func (v *wasiSubscription) layout() (uint32, uint32) {
return 48, 8
}
func (v *wasiSubscription) store(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
mem.PutUint64(uint64(v.userdata), uint32(base), 0)
v.u.store(mem, uint32(base), 8)
}
func (v *wasiSubscription) load(mem *exec.Memory, addr, offset uint32) {
base := addr + offset
v.userdata = wasiUserdata(mem.Uint64(uint32(base), 0))
v.u.load(mem, uint32(base), 8)
}
// Exit code generated by a process when exiting.
type wasiExitcode = uint32
// Signal condition.
type wasiSignal = uint8
// No signal. Note that POSIX has special semantics for `kill(pid, 0)`,
// so this value is reserved.
const wasiSignalNone = 0
// Hangup.
// Action: Terminates the process.
const wasiSignalHup = 1
// Terminate interrupt signal.
// Action: Terminates the process.
const wasiSignalInt = 2
// Terminal quit signal.
// Action: Terminates the process.
const wasiSignalQuit = 3
// Illegal instruction.
// Action: Terminates the process.
const wasiSignalIll = 4
// Trace/breakpoint trap.
// Action: Terminates the process.
const wasiSignalTrap = 5
// Process abort signal.
// Action: Terminates the process.
const wasiSignalAbrt = 6
// Access to an undefined portion of a memory object.
// Action: Terminates the process.
const wasiSignalBus = 7
// Erroneous arithmetic operation.
// Action: Terminates the process.
const wasiSignalFpe = 8
// Kill.
// Action: Terminates the process.
const wasiSignalKill = 9
// User-defined signal 1.
// Action: Terminates the process.
const wasiSignalUsr1 = 10
// Invalid memory reference.
// Action: Terminates the process.
const wasiSignalSegv = 11
// User-defined signal 2.
// Action: Terminates the process.
const wasiSignalUsr2 = 12