wasix 0.13.1

WASIX 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
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
// This file is automatically generated, DO NOT EDIT
//
// To regenerate this file run the `crates/witx-bindgen` command

// Inherit from WASI
pub use wasi::*;

use core::fmt;
use core::mem::MaybeUninit;
pub type Pointersize = usize;
pub type Waker = u64;
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct Errno(u16);
/// No error occurred. System call completed successfully.
pub const ERRNO_SUCCESS: Errno = Errno(0);
/// Argument list too long.
pub const ERRNO_2BIG: Errno = Errno(1);
/// Permission denied.
pub const ERRNO_ACCES: Errno = Errno(2);
/// Address in use.
pub const ERRNO_ADDRINUSE: Errno = Errno(3);
/// Address not available.
pub const ERRNO_ADDRNOTAVAIL: Errno = Errno(4);
/// Address family not supported.
pub const ERRNO_AFNOSUPPORT: Errno = Errno(5);
/// Resource unavailable, or operation would block.
pub const ERRNO_AGAIN: Errno = Errno(6);
/// Connection already in progress.
pub const ERRNO_ALREADY: Errno = Errno(7);
/// Bad file descriptor.
pub const ERRNO_BADF: Errno = Errno(8);
/// Bad message.
pub const ERRNO_BADMSG: Errno = Errno(9);
/// Device or resource busy.
pub const ERRNO_BUSY: Errno = Errno(10);
/// Operation canceled.
pub const ERRNO_CANCELED: Errno = Errno(11);
/// No child processes.
pub const ERRNO_CHILD: Errno = Errno(12);
/// Connection aborted.
pub const ERRNO_CONNABORTED: Errno = Errno(13);
/// Connection refused.
pub const ERRNO_CONNREFUSED: Errno = Errno(14);
/// Connection reset.
pub const ERRNO_CONNRESET: Errno = Errno(15);
/// Resource deadlock would occur.
pub const ERRNO_DEADLK: Errno = Errno(16);
/// Destination address required.
pub const ERRNO_DESTADDRREQ: Errno = Errno(17);
/// Mathematics argument out of domain of function.
pub const ERRNO_DOM: Errno = Errno(18);
/// Reserved.
pub const ERRNO_DQUOT: Errno = Errno(19);
/// File exists.
pub const ERRNO_EXIST: Errno = Errno(20);
/// Bad address.
pub const ERRNO_FAULT: Errno = Errno(21);
/// File too large.
pub const ERRNO_FBIG: Errno = Errno(22);
/// Host is unreachable.
pub const ERRNO_HOSTUNREACH: Errno = Errno(23);
/// Identifier removed.
pub const ERRNO_IDRM: Errno = Errno(24);
/// Illegal byte sequence.
pub const ERRNO_ILSEQ: Errno = Errno(25);
/// Operation in progress.
pub const ERRNO_INPROGRESS: Errno = Errno(26);
/// Interrupted function.
pub const ERRNO_INTR: Errno = Errno(27);
/// Invalid argument.
pub const ERRNO_INVAL: Errno = Errno(28);
/// I/O error.
pub const ERRNO_IO: Errno = Errno(29);
/// Socket is connected.
pub const ERRNO_ISCONN: Errno = Errno(30);
/// Is a directory.
pub const ERRNO_ISDIR: Errno = Errno(31);
/// Too many levels of symbolic links.
pub const ERRNO_LOOP: Errno = Errno(32);
/// File descriptor value too large.
pub const ERRNO_MFILE: Errno = Errno(33);
/// Too many links.
pub const ERRNO_MLINK: Errno = Errno(34);
/// Message too large.
pub const ERRNO_MSGSIZE: Errno = Errno(35);
/// Reserved.
pub const ERRNO_MULTIHOP: Errno = Errno(36);
/// Filename too long.
pub const ERRNO_NAMETOOLONG: Errno = Errno(37);
/// Network is down.
pub const ERRNO_NETDOWN: Errno = Errno(38);
/// Connection aborted by network.
pub const ERRNO_NETRESET: Errno = Errno(39);
/// Network unreachable.
pub const ERRNO_NETUNREACH: Errno = Errno(40);
/// Too many files open in system.
pub const ERRNO_NFILE: Errno = Errno(41);
/// No buffer space available.
pub const ERRNO_NOBUFS: Errno = Errno(42);
/// No such device.
pub const ERRNO_NODEV: Errno = Errno(43);
/// No such file or directory.
pub const ERRNO_NOENT: Errno = Errno(44);
/// Executable file format error.
pub const ERRNO_NOEXEC: Errno = Errno(45);
/// No locks available.
pub const ERRNO_NOLCK: Errno = Errno(46);
/// Reserved.
pub const ERRNO_NOLINK: Errno = Errno(47);
/// Not enough space.
pub const ERRNO_NOMEM: Errno = Errno(48);
/// No message of the desired type.
pub const ERRNO_NOMSG: Errno = Errno(49);
/// Protocol not available.
pub const ERRNO_NOPROTOOPT: Errno = Errno(50);
/// No space left on device.
pub const ERRNO_NOSPC: Errno = Errno(51);
/// Function not supported.
pub const ERRNO_NOSYS: Errno = Errno(52);
/// The socket is not connected.
pub const ERRNO_NOTCONN: Errno = Errno(53);
/// Not a directory or a symbolic link to a directory.
pub const ERRNO_NOTDIR: Errno = Errno(54);
/// Directory not empty.
pub const ERRNO_NOTEMPTY: Errno = Errno(55);
/// State not recoverable.
pub const ERRNO_NOTRECOVERABLE: Errno = Errno(56);
/// Not a socket.
pub const ERRNO_NOTSOCK: Errno = Errno(57);
/// Not supported, or operation not supported on socket.
pub const ERRNO_NOTSUP: Errno = Errno(58);
/// Inappropriate I/O control operation.
pub const ERRNO_NOTTY: Errno = Errno(59);
/// No such device or address.
pub const ERRNO_NXIO: Errno = Errno(60);
/// Value too large to be stored in data type.
pub const ERRNO_OVERFLOW: Errno = Errno(61);
/// Previous owner died.
pub const ERRNO_OWNERDEAD: Errno = Errno(62);
/// Operation not permitted.
pub const ERRNO_PERM: Errno = Errno(63);
/// Broken pipe.
pub const ERRNO_PIPE: Errno = Errno(64);
/// Protocol error.
pub const ERRNO_PROTO: Errno = Errno(65);
/// Protocol not supported.
pub const ERRNO_PROTONOSUPPORT: Errno = Errno(66);
/// Protocol wrong type for socket.
pub const ERRNO_PROTOTYPE: Errno = Errno(67);
/// Result too large.
pub const ERRNO_RANGE: Errno = Errno(68);
/// Read-only file system.
pub const ERRNO_ROFS: Errno = Errno(69);
/// Invalid seek.
pub const ERRNO_SPIPE: Errno = Errno(70);
/// No such process.
pub const ERRNO_SRCH: Errno = Errno(71);
/// Reserved.
pub const ERRNO_STALE: Errno = Errno(72);
/// Connection timed out.
pub const ERRNO_TIMEDOUT: Errno = Errno(73);
/// Text file busy.
pub const ERRNO_TXTBSY: Errno = Errno(74);
/// Cross-device link.
pub const ERRNO_XDEV: Errno = Errno(75);
/// Extension: Capabilities insufficient.
pub const ERRNO_NOTCAPABLE: Errno = Errno(76);
/// Cannot send after socket shutdown.
pub const ERRNO_SHUTDOWN: Errno = Errno(77);
/// Memory access violation.
pub const ERRNO_MEMVIOLATION: Errno = Errno(78);
/// Unknown error has occurred.
pub const ERRNO_UNKNOWN: Errno = Errno(79);
/// Pending asynchronous wake.
pub const ERRNO_PENDING: Errno = Errno(80);
impl Errno {
    pub const fn raw(&self) -> u16 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "SUCCESS",
            1 => "2BIG",
            2 => "ACCES",
            3 => "ADDRINUSE",
            4 => "ADDRNOTAVAIL",
            5 => "AFNOSUPPORT",
            6 => "AGAIN",
            7 => "ALREADY",
            8 => "BADF",
            9 => "BADMSG",
            10 => "BUSY",
            11 => "CANCELED",
            12 => "CHILD",
            13 => "CONNABORTED",
            14 => "CONNREFUSED",
            15 => "CONNRESET",
            16 => "DEADLK",
            17 => "DESTADDRREQ",
            18 => "DOM",
            19 => "DQUOT",
            20 => "EXIST",
            21 => "FAULT",
            22 => "FBIG",
            23 => "HOSTUNREACH",
            24 => "IDRM",
            25 => "ILSEQ",
            26 => "INPROGRESS",
            27 => "INTR",
            28 => "INVAL",
            29 => "IO",
            30 => "ISCONN",
            31 => "ISDIR",
            32 => "LOOP",
            33 => "MFILE",
            34 => "MLINK",
            35 => "MSGSIZE",
            36 => "MULTIHOP",
            37 => "NAMETOOLONG",
            38 => "NETDOWN",
            39 => "NETRESET",
            40 => "NETUNREACH",
            41 => "NFILE",
            42 => "NOBUFS",
            43 => "NODEV",
            44 => "NOENT",
            45 => "NOEXEC",
            46 => "NOLCK",
            47 => "NOLINK",
            48 => "NOMEM",
            49 => "NOMSG",
            50 => "NOPROTOOPT",
            51 => "NOSPC",
            52 => "NOSYS",
            53 => "NOTCONN",
            54 => "NOTDIR",
            55 => "NOTEMPTY",
            56 => "NOTRECOVERABLE",
            57 => "NOTSOCK",
            58 => "NOTSUP",
            59 => "NOTTY",
            60 => "NXIO",
            61 => "OVERFLOW",
            62 => "OWNERDEAD",
            63 => "PERM",
            64 => "PIPE",
            65 => "PROTO",
            66 => "PROTONOSUPPORT",
            67 => "PROTOTYPE",
            68 => "RANGE",
            69 => "ROFS",
            70 => "SPIPE",
            71 => "SRCH",
            72 => "STALE",
            73 => "TIMEDOUT",
            74 => "TXTBSY",
            75 => "XDEV",
            76 => "NOTCAPABLE",
            77 => "SHUTDOWN",
            78 => "MEMVIOLATION",
            79 => "UNKNOWN",
            80 => "PENDING",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "No error occurred. System call completed successfully.",
            1 => "Argument list too long.",
            2 => "Permission denied.",
            3 => "Address in use.",
            4 => "Address not available.",
            5 => "Address family not supported.",
            6 => "Resource unavailable, or operation would block.",
            7 => "Connection already in progress.",
            8 => "Bad file descriptor.",
            9 => "Bad message.",
            10 => "Device or resource busy.",
            11 => "Operation canceled.",
            12 => "No child processes.",
            13 => "Connection aborted.",
            14 => "Connection refused.",
            15 => "Connection reset.",
            16 => "Resource deadlock would occur.",
            17 => "Destination address required.",
            18 => "Mathematics argument out of domain of function.",
            19 => "Reserved.",
            20 => "File exists.",
            21 => "Bad address.",
            22 => "File too large.",
            23 => "Host is unreachable.",
            24 => "Identifier removed.",
            25 => "Illegal byte sequence.",
            26 => "Operation in progress.",
            27 => "Interrupted function.",
            28 => "Invalid argument.",
            29 => "I/O error.",
            30 => "Socket is connected.",
            31 => "Is a directory.",
            32 => "Too many levels of symbolic links.",
            33 => "File descriptor value too large.",
            34 => "Too many links.",
            35 => "Message too large.",
            36 => "Reserved.",
            37 => "Filename too long.",
            38 => "Network is down.",
            39 => "Connection aborted by network.",
            40 => "Network unreachable.",
            41 => "Too many files open in system.",
            42 => "No buffer space available.",
            43 => "No such device.",
            44 => "No such file or directory.",
            45 => "Executable file format error.",
            46 => "No locks available.",
            47 => "Reserved.",
            48 => "Not enough space.",
            49 => "No message of the desired type.",
            50 => "Protocol not available.",
            51 => "No space left on device.",
            52 => "Function not supported.",
            53 => "The socket is not connected.",
            54 => "Not a directory or a symbolic link to a directory.",
            55 => "Directory not empty.",
            56 => "State not recoverable.",
            57 => "Not a socket.",
            58 => "Not supported, or operation not supported on socket.",
            59 => "Inappropriate I/O control operation.",
            60 => "No such device or address.",
            61 => "Value too large to be stored in data type.",
            62 => "Previous owner died.",
            63 => "Operation not permitted.",
            64 => "Broken pipe.",
            65 => "Protocol error.",
            66 => "Protocol not supported.",
            67 => "Protocol wrong type for socket.",
            68 => "Result too large.",
            69 => "Read-only file system.",
            70 => "Invalid seek.",
            71 => "No such process.",
            72 => "Reserved.",
            73 => "Connection timed out.",
            74 => "Text file busy.",
            75 => "Cross-device link.",
            76 => "Extension: Capabilities insufficient.",
            77 => "Cannot send after socket shutdown.",
            78 => "Memory access violation.",
            79 => "Unknown error has occurred.",
            80 => "Pending asynchronous wake.",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for Errno {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Errno")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u16> for Errno {
    fn from(a: u16) -> Self {
        Self(a)
    }
}
impl fmt::Display for Errno {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{} (error {})", self.name(), self.0)
    }
}

#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
impl std::error::Error for Errno {}

pub type Rights = u64;
/// The right to invoke `fd_datasync`.
/// If `path_open` is set, includes the right to invoke
/// `path_open` with `fdflags::dsync`.
pub const RIGHTS_FD_DATASYNC: Rights = 1 << 0;
/// The right to invoke `fd_read` and `sock_recv`.
/// If `rights::fd_seek` is set, includes the right to invoke `fd_pread`.
pub const RIGHTS_FD_READ: Rights = 1 << 1;
/// The right to invoke `fd_seek`. This flag implies `rights::fd_tell`.
pub const RIGHTS_FD_SEEK: Rights = 1 << 2;
/// The right to invoke `fd_fdstat_set_flags`.
pub const RIGHTS_FD_FDSTAT_SET_FLAGS: Rights = 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`.
pub const RIGHTS_FD_SYNC: Rights = 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`.
pub const RIGHTS_FD_TELL: Rights = 1 << 5;
/// The right to invoke `fd_write` and `sock_send`.
/// If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`.
pub const RIGHTS_FD_WRITE: Rights = 1 << 6;
/// The right to invoke `fd_advise`.
pub const RIGHTS_FD_ADVISE: Rights = 1 << 7;
/// The right to invoke `fd_allocate`.
pub const RIGHTS_FD_ALLOCATE: Rights = 1 << 8;
/// The right to invoke `path_create_directory`.
pub const RIGHTS_PATH_CREATE_DIRECTORY: Rights = 1 << 9;
/// If `path_open` is set, the right to invoke `path_open` with `oflags::creat`.
pub const RIGHTS_PATH_CREATE_FILE: Rights = 1 << 10;
/// The right to invoke `path_link` with the file descriptor as the
/// source directory.
pub const RIGHTS_PATH_LINK_SOURCE: Rights = 1 << 11;
/// The right to invoke `path_link` with the file descriptor as the
/// target directory.
pub const RIGHTS_PATH_LINK_TARGET: Rights = 1 << 12;
/// The right to invoke `path_open`.
pub const RIGHTS_PATH_OPEN: Rights = 1 << 13;
/// The right to invoke `fd_readdir`.
pub const RIGHTS_FD_READDIR: Rights = 1 << 14;
/// The right to invoke `path_readlink`.
pub const RIGHTS_PATH_READLINK: Rights = 1 << 15;
/// The right to invoke `path_rename` with the file descriptor as the source directory.
pub const RIGHTS_PATH_RENAME_SOURCE: Rights = 1 << 16;
/// The right to invoke `path_rename` with the file descriptor as the target directory.
pub const RIGHTS_PATH_RENAME_TARGET: Rights = 1 << 17;
/// The right to invoke `path_filestat_get`.
pub const RIGHTS_PATH_FILESTAT_GET: Rights = 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`.
pub const RIGHTS_PATH_FILESTAT_SET_SIZE: Rights = 1 << 19;
/// The right to invoke `path_filestat_set_times`.
pub const RIGHTS_PATH_FILESTAT_SET_TIMES: Rights = 1 << 20;
/// The right to invoke `fd_filestat_get`.
pub const RIGHTS_FD_FILESTAT_GET: Rights = 1 << 21;
/// The right to invoke `fd_filestat_set_size`.
pub const RIGHTS_FD_FILESTAT_SET_SIZE: Rights = 1 << 22;
/// The right to invoke `fd_filestat_set_times`.
pub const RIGHTS_FD_FILESTAT_SET_TIMES: Rights = 1 << 23;
/// The right to invoke `path_symlink`.
pub const RIGHTS_PATH_SYMLINK: Rights = 1 << 24;
/// The right to invoke `path_remove_directory`.
pub const RIGHTS_PATH_REMOVE_DIRECTORY: Rights = 1 << 25;
/// The right to invoke `path_unlink_file`.
pub const RIGHTS_PATH_UNLINK_FILE: Rights = 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`.
pub const RIGHTS_POLL_FD_READWRITE: Rights = 1 << 27;
/// The right to invoke `sock_shutdown`.
pub const RIGHTS_SOCK_SHUTDOWN: Rights = 1 << 28;
/// Accept incoming connection
pub const RIGHTS_SOCK_ACCEPT: Rights = 1 << 29;
/// Connect to an address
pub const RIGHTS_SOCK_CONNECT: Rights = 1 << 30;
/// Listen for incoming connection on an address
pub const RIGHTS_SOCK_LISTEN: Rights = 1 << 31;
/// Bind an address to a socket
pub const RIGHTS_SOCK_BIND: Rights = 1 << 32;
/// Receive data on a socket
pub const RIGHTS_SOCK_RECV: Rights = 1 << 33;
/// Send data on a socket
pub const RIGHTS_SOCK_SEND: Rights = 1 << 34;
/// Retrieve locally bound address on a socket
pub const RIGHTS_SOCK_ADDR_LOCAL: Rights = 1 << 35;
/// Retrieve remote address on a socket
pub const RIGHTS_SOCK_ADDR_REMOTE: Rights = 1 << 36;
/// Receive datagram on a socket
pub const RIGHTS_SOCK_RECV_FROM: Rights = 1 << 37;
/// Send datagram on a socket
pub const RIGHTS_SOCK_SEND_TO: Rights = 1 << 38;

#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct Filetype(u8);
/// The type of the file descriptor or file is unknown or is different from any of the other types specified.
pub const FILETYPE_UNKNOWN: Filetype = Filetype(0);
/// The file descriptor or file refers to a block device inode.
pub const FILETYPE_BLOCK_DEVICE: Filetype = Filetype(1);
/// The file descriptor or file refers to a character device inode.
pub const FILETYPE_CHARACTER_DEVICE: Filetype = Filetype(2);
/// The file descriptor or file refers to a directory inode.
pub const FILETYPE_DIRECTORY: Filetype = Filetype(3);
/// The file descriptor or file refers to a regular file inode.
pub const FILETYPE_REGULAR_FILE: Filetype = Filetype(4);
/// The file descriptor or file refers to a datagram socket.
pub const FILETYPE_SOCKET_DGRAM: Filetype = Filetype(5);
/// The file descriptor or file refers to a byte-stream socket.
pub const FILETYPE_SOCKET_STREAM: Filetype = Filetype(6);
/// The file refers to a symbolic link inode.
pub const FILETYPE_SYMBOLIC_LINK: Filetype = Filetype(7);
/// The file descriptor or file refers to a raw socket.
pub const FILETYPE_SOCKET_RAW: Filetype = Filetype(8);
/// The file descriptor or file refers to a sequential packet socket.
pub const FILETYPE_SOCKET_SEQPACKET: Filetype = Filetype(9);
impl Filetype {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "UNKNOWN",
            1 => "BLOCK_DEVICE",
            2 => "CHARACTER_DEVICE",
            3 => "DIRECTORY",
            4 => "REGULAR_FILE",
            5 => "SOCKET_DGRAM",
            6 => "SOCKET_STREAM",
            7 => "SYMBOLIC_LINK",
            8 => "SOCKET_RAW",
            9 => "SOCKET_SEQPACKET",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {0 => "The type of the file descriptor or file is unknown or is different from any of the other types specified.",1 => "The file descriptor or file refers to a block device inode.",2 => "The file descriptor or file refers to a character device inode.",3 => "The file descriptor or file refers to a directory inode.",4 => "The file descriptor or file refers to a regular file inode.",5 => "The file descriptor or file refers to a datagram socket.",6 => "The file descriptor or file refers to a byte-stream socket.",7 => "The file refers to a symbolic link inode.",8 => "The file descriptor or file refers to a raw socket.",9 => "The file descriptor or file refers to a sequential packet socket.",_ => unsafe { core::hint::unreachable_unchecked() },}
    }
}
impl fmt::Debug for Filetype {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Filetype")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for Filetype {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

pub type Riflags = u16;
/// Returns the message without removing it from the socket's receive queue.
pub const RIFLAGS_RECV_PEEK: Riflags = 1 << 0;
/// On byte-stream sockets, block until the full amount of data can be returned.
pub const RIFLAGS_RECV_WAITALL: Riflags = 1 << 1;
/// Indicates if the packet should be truncated to the buffer size
pub const RIFLAGS_RECV_DATA_TRUNCATED: Riflags = 1 << 2;
/// Return immediately if the read would block.
pub const RIFLAGS_RECV_DONT_WAIT: Riflags = 1 << 3;

#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct Signal(u8);
/// No signal. Note that POSIX has special semantics for `kill(pid, 0)`,
/// so this value is reserved.
pub const SIGNAL_NONE: Signal = Signal(0);
/// Hangup.
/// Action: Terminates the process.
pub const SIGNAL_HUP: Signal = Signal(1);
/// Terminate interrupt signal.
/// Action: Terminates the process.
pub const SIGNAL_INT: Signal = Signal(2);
/// Terminal quit signal.
/// Action: Terminates the process.
pub const SIGNAL_QUIT: Signal = Signal(3);
/// Illegal instruction.
/// Action: Terminates the process.
pub const SIGNAL_ILL: Signal = Signal(4);
/// Trace/breakpoint trap.
/// Action: Terminates the process.
pub const SIGNAL_TRAP: Signal = Signal(5);
/// Process abort signal.
/// Action: Terminates the process.
pub const SIGNAL_ABRT: Signal = Signal(6);
/// Access to an undefined portion of a memory object.
/// Action: Terminates the process.
pub const SIGNAL_BUS: Signal = Signal(7);
/// Erroneous arithmetic operation.
/// Action: Terminates the process.
pub const SIGNAL_FPE: Signal = Signal(8);
/// Kill.
/// Action: Terminates the process.
pub const SIGNAL_KILL: Signal = Signal(9);
/// User-defined signal 1.
/// Action: Terminates the process.
pub const SIGNAL_USR1: Signal = Signal(10);
/// Invalid memory reference.
/// Action: Terminates the process.
pub const SIGNAL_SEGV: Signal = Signal(11);
/// User-defined signal 2.
/// Action: Terminates the process.
pub const SIGNAL_USR2: Signal = Signal(12);
/// Write on a pipe with no one to read it.
/// Action: Ignored.
pub const SIGNAL_PIPE: Signal = Signal(13);
/// Alarm clock.
/// Action: Terminates the process.
pub const SIGNAL_ALRM: Signal = Signal(14);
/// Termination signal.
/// Action: Terminates the process.
pub const SIGNAL_TERM: Signal = Signal(15);
/// Stkflt
/// Action: Ignored.
pub const SIGNAL_STKFLT: Signal = Signal(16);
/// Child process terminated, stopped, or continued.
/// Action: Ignored.
pub const SIGNAL_CHLD: Signal = Signal(17);
/// Continue executing, if stopped.
/// Action: Continues executing, if stopped.
pub const SIGNAL_CONT: Signal = Signal(18);
/// Stop executing.
/// Action: Stops executing.
pub const SIGNAL_STOP: Signal = Signal(19);
/// Terminal stop signal.
/// Action: Stops executing.
pub const SIGNAL_TSTP: Signal = Signal(20);
/// Background process attempting read.
/// Action: Stops executing.
pub const SIGNAL_TTIN: Signal = Signal(21);
/// Background process attempting write.
/// Action: Stops executing.
pub const SIGNAL_TTOU: Signal = Signal(22);
/// High bandwidth data is available at a socket.
/// Action: Ignored.
pub const SIGNAL_URG: Signal = Signal(23);
/// CPU time limit exceeded.
/// Action: Terminates the process.
pub const SIGNAL_XCPU: Signal = Signal(24);
/// File size limit exceeded.
/// Action: Terminates the process.
pub const SIGNAL_XFSZ: Signal = Signal(25);
/// Virtual timer expired.
/// Action: Terminates the process.
pub const SIGNAL_VTALRM: Signal = Signal(26);
/// Profiling timer expired.
/// Action: Terminates the process.
pub const SIGNAL_PROF: Signal = Signal(27);
/// Window changed.
/// Action: Ignored.
pub const SIGNAL_WINCH: Signal = Signal(28);
/// I/O possible.
/// Action: Terminates the process.
pub const SIGNAL_POLL: Signal = Signal(29);
/// Power failure.
/// Action: Terminates the process.
pub const SIGNAL_PWR: Signal = Signal(30);
/// Bad system call.
/// Action: Terminates the process.
pub const SIGNAL_SYS: Signal = Signal(31);
impl Signal {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "NONE",
            1 => "HUP",
            2 => "INT",
            3 => "QUIT",
            4 => "ILL",
            5 => "TRAP",
            6 => "ABRT",
            7 => "BUS",
            8 => "FPE",
            9 => "KILL",
            10 => "USR1",
            11 => "SEGV",
            12 => "USR2",
            13 => "PIPE",
            14 => "ALRM",
            15 => "TERM",
            16 => "STKFLT",
            17 => "CHLD",
            18 => "CONT",
            19 => "STOP",
            20 => "TSTP",
            21 => "TTIN",
            22 => "TTOU",
            23 => "URG",
            24 => "XCPU",
            25 => "XFSZ",
            26 => "VTALRM",
            27 => "PROF",
            28 => "WINCH",
            29 => "POLL",
            30 => "PWR",
            31 => "SYS",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => {
                "No signal. Note that POSIX has special semantics for `kill(pid, 0)`,
so this value is reserved."
            }
            1 => {
                "Hangup.
Action: Terminates the process."
            }
            2 => {
                "Terminate interrupt signal.
Action: Terminates the process."
            }
            3 => {
                "Terminal quit signal.
Action: Terminates the process."
            }
            4 => {
                "Illegal instruction.
Action: Terminates the process."
            }
            5 => {
                "Trace/breakpoint trap.
Action: Terminates the process."
            }
            6 => {
                "Process abort signal.
Action: Terminates the process."
            }
            7 => {
                "Access to an undefined portion of a memory object.
Action: Terminates the process."
            }
            8 => {
                "Erroneous arithmetic operation.
Action: Terminates the process."
            }
            9 => {
                "Kill.
Action: Terminates the process."
            }
            10 => {
                "User-defined signal 1.
Action: Terminates the process."
            }
            11 => {
                "Invalid memory reference.
Action: Terminates the process."
            }
            12 => {
                "User-defined signal 2.
Action: Terminates the process."
            }
            13 => {
                "Write on a pipe with no one to read it.
Action: Ignored."
            }
            14 => {
                "Alarm clock.
Action: Terminates the process."
            }
            15 => {
                "Termination signal.
Action: Terminates the process."
            }
            16 => {
                "Stkflt
Action: Ignored."
            }
            17 => {
                "Child process terminated, stopped, or continued.
Action: Ignored."
            }
            18 => {
                "Continue executing, if stopped.
Action: Continues executing, if stopped."
            }
            19 => {
                "Stop executing.
Action: Stops executing."
            }
            20 => {
                "Terminal stop signal.
Action: Stops executing."
            }
            21 => {
                "Background process attempting read.
Action: Stops executing."
            }
            22 => {
                "Background process attempting write.
Action: Stops executing."
            }
            23 => {
                "High bandwidth data is available at a socket.
Action: Ignored."
            }
            24 => {
                "CPU time limit exceeded.
Action: Terminates the process."
            }
            25 => {
                "File size limit exceeded.
Action: Terminates the process."
            }
            26 => {
                "Virtual timer expired.
Action: Terminates the process."
            }
            27 => {
                "Profiling timer expired.
Action: Terminates the process."
            }
            28 => {
                "Window changed.
Action: Ignored."
            }
            29 => {
                "I/O possible.
Action: Terminates the process."
            }
            30 => {
                "Power failure.
Action: Terminates the process."
            }
            31 => {
                "Bad system call.
Action: Terminates the process."
            }
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for Signal {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Signal")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for Signal {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct Disposition(u8);
/// Default action.
pub const DISPOSITION_DEFAULT: Disposition = Disposition(0);
/// Ignore the signal.
pub const DISPOSITION_IGNORE: Disposition = Disposition(1);
impl Disposition {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "DEFAULT",
            1 => "IGNORE",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "Default action.",
            1 => "Ignore the signal.",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for Disposition {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Disposition")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for Disposition {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct SignalDisposition {
    pub sig: Signal,
    pub disp: Disposition,
}
pub type SignalDispositionArray<'a> = &'a [SignalDisposition];

pub type Siflags = u16;
/// Return immediately if the write would block.
pub const SIFLAGS_SEND_DONT_WAIT: Siflags = 1 << 0;

pub type Longsize = u64;
pub type ShortHash = u64;
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct Hugesize {
    /// First set of 64 bits
    pub b0: u64,
    /// second set of 64 bits
    pub b1: u64,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct Hash {
    /// First set of 64 bits
    pub b0: u64,
    /// second set of 64 bits
    pub b1: u64,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct StackSnapshot {
    /// User defined field that can be used by functions
    pub user: u64,
    /// Hash used to identify which stack snapshot to restore
    pub hash: Hash,
}
pub type BufArray<'a> = &'a [u8];
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct Option(u8);
pub const OPTION_NONE: Option = Option(0);
pub const OPTION_SOME: Option = Option(1);
impl Option {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "NONE",
            1 => "SOME",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "",
            1 => "",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for Option {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Option")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for Option {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

#[repr(C)]
#[derive(Copy, Clone)]
pub union OptionTimestampU {
    pub none: u8,
    pub some: Timestamp,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct OptionTimestamp {
    pub tag: u8,
    pub u: OptionTimestampU,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub union OptionHashU {
    pub none: u8,
    pub some: Hash,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct OptionHash {
    pub tag: u8,
    pub u: OptionHashU,
}

pub type Pid = u32;
pub type Tid = u32;
#[repr(C)]
#[derive(Copy, Clone)]
pub union OptionPidU {
    pub none: u8,
    pub some: Pid,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct OptionPid {
    pub tag: u8,
    pub u: OptionPidU,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub union OptionFdU {
    pub none: u8,
    pub some: Fd,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct OptionFd {
    pub tag: u8,
    pub u: OptionFdU,
}

#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct Bool(u8);
pub const BOOL_FALSE: Bool = Bool(0);
pub const BOOL_TRUE: Bool = Bool(1);
impl Bool {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "FALSE",
            1 => "TRUE",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "",
            1 => "",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for Bool {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Bool")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for Bool {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

pub type Eventfdflags = u16;
/// Indicates if this event file description will run as a semaphore
pub const EVENTFDFLAGS_SEMAPHORE: Eventfdflags = 1 << 0;

pub type Fdflagsext = u16;
/// Close this file in the child process when spawning one.
pub const FDFLAGSEXT_CLOEXEC: Fdflagsext = 1 << 0;

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct Tty {
    /// Number of columns
    pub cols: u32,
    /// Number of rows
    pub rows: u32,
    /// Width of the screen in pixels
    pub width: u32,
    /// Height of the screen in pixels
    pub height: u32,
    /// Indicates if stdin is a TTY
    pub stdin_tty: Bool,
    /// Indicates if stdout is a TTY
    pub stdout_tty: Bool,
    /// Indicates if stderr is a TTY
    pub stderr_tty: Bool,
    /// When enabled the TTY will echo input to console
    pub echo: Bool,
    /// When enabled buffers the input until the return key is pressed
    pub line_buffered: Bool,
    /// Indicates if line feeds are ignored on the input
    pub line_feeds: Bool,
}
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct StdioMode(u8);
/// The stdio will be piped
pub const STDIO_MODE_PIPED: StdioMode = StdioMode(0);
/// The stdio will inherit from its parent
pub const STDIO_MODE_INHERIT: StdioMode = StdioMode(1);
/// The stdio will be dumped to null
pub const STDIO_MODE_NULL: StdioMode = StdioMode(2);
/// The stdio will be written to the log file
pub const STDIO_MODE_LOG: StdioMode = StdioMode(3);
impl StdioMode {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "PIPED",
            1 => "INHERIT",
            2 => "NULL",
            3 => "LOG",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "The stdio will be piped",
            1 => "The stdio will inherit from its parent",
            2 => "The stdio will be dumped to null",
            3 => "The stdio will be written to the log file",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for StdioMode {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("StdioMode")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for StdioMode {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct ProcessHandles {
    /// Handle that represents the process
    pub pid: Pid,
    /// File handle for STDIN
    pub stdin: OptionFd,
    /// File handle for STDOUT
    pub stdout: OptionFd,
    /// File handle for STDERR
    pub stderr: OptionFd,
}
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct SockType(u8);
/// Unused enum variant to prevent $socket_dgram value of 0, which
/// conflicts with a macro defined in cpython which is used in a case arm
/// of a switch statement alongside C macros generated from this enum.
///  ref: https://github.com/python/cpython/blob/2f369cafeeb4a4886b00396abd8a5f33e555e1c3/Modules/getaddrinfo.c#L68
///  ref: https://github.com/python/cpython/blob/3f369cafeeb4a4886b00396abd8a5f33e555e1c3/Modules/getaddrinfo.c#L355-L368
pub const SOCK_TYPE_SOCKET_UNUSED: SockType = SockType(0);
/// The file descriptor or file refers to a byte-stream socket.
pub const SOCK_TYPE_SOCKET_STREAM: SockType = SockType(1);
/// The file descriptor or file refers to a datagram socket.
pub const SOCK_TYPE_SOCKET_DGRAM: SockType = SockType(2);
/// The file descriptor or file refers to a raw socket.
pub const SOCK_TYPE_SOCKET_RAW: SockType = SockType(3);
/// The file descriptor or file refers to a sequential packet socket.
pub const SOCK_TYPE_SOCKET_SEQPACKET: SockType = SockType(4);
impl SockType {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "SOCKET_UNUSED",
            1 => "SOCKET_STREAM",
            2 => "SOCKET_DGRAM",
            3 => "SOCKET_RAW",
            4 => "SOCKET_SEQPACKET",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {0 => "Unused enum variant to prevent $socket_dgram value of 0, which
conflicts with a macro defined in cpython which is used in a case arm
of a switch statement alongside C macros generated from this enum.
 ref: https://github.com/python/cpython/blob/2f369cafeeb4a4886b00396abd8a5f33e555e1c3/Modules/getaddrinfo.c#L68
 ref: https://github.com/python/cpython/blob/3f369cafeeb4a4886b00396abd8a5f33e555e1c3/Modules/getaddrinfo.c#L355-L368",1 => "The file descriptor or file refers to a byte-stream socket.",2 => "The file descriptor or file refers to a datagram socket.",3 => "The file descriptor or file refers to a raw socket.",4 => "The file descriptor or file refers to a sequential packet socket.",_ => unsafe { core::hint::unreachable_unchecked() },}
    }
}
impl fmt::Debug for SockType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("SockType")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for SockType {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct SockProto(u16);
pub const SOCK_PROTO_IP: SockProto = SockProto(0);
pub const SOCK_PROTO_ICMP: SockProto = SockProto(1);
pub const SOCK_PROTO_IGMP: SockProto = SockProto(2);
pub const SOCK_PROTO_PROTO_3: SockProto = SockProto(3);
pub const SOCK_PROTO_IPIP: SockProto = SockProto(4);
pub const SOCK_PROTO_PROTO_5: SockProto = SockProto(5);
pub const SOCK_PROTO_TCP: SockProto = SockProto(6);
pub const SOCK_PROTO_PROTO_7: SockProto = SockProto(7);
pub const SOCK_PROTO_EGP: SockProto = SockProto(8);
pub const SOCK_PROTO_PROTO_9: SockProto = SockProto(9);
pub const SOCK_PROTO_PROTO_10: SockProto = SockProto(10);
pub const SOCK_PROTO_PROTO_11: SockProto = SockProto(11);
pub const SOCK_PROTO_PUP: SockProto = SockProto(12);
pub const SOCK_PROTO_PROTO_13: SockProto = SockProto(13);
pub const SOCK_PROTO_PROTO_14: SockProto = SockProto(14);
pub const SOCK_PROTO_PROTO_15: SockProto = SockProto(15);
pub const SOCK_PROTO_PROTO_16: SockProto = SockProto(16);
pub const SOCK_PROTO_UDP: SockProto = SockProto(17);
pub const SOCK_PROTO_PROTO_18: SockProto = SockProto(18);
pub const SOCK_PROTO_PROTO_19: SockProto = SockProto(19);
pub const SOCK_PROTO_PROTO_20: SockProto = SockProto(20);
pub const SOCK_PROTO_PROTO_21: SockProto = SockProto(21);
pub const SOCK_PROTO_IDP: SockProto = SockProto(22);
pub const SOCK_PROTO_PROTO_23: SockProto = SockProto(23);
pub const SOCK_PROTO_PROTO_24: SockProto = SockProto(24);
pub const SOCK_PROTO_PROTO_25: SockProto = SockProto(25);
pub const SOCK_PROTO_PROTO_26: SockProto = SockProto(26);
pub const SOCK_PROTO_PROTO_27: SockProto = SockProto(27);
pub const SOCK_PROTO_PROTO_28: SockProto = SockProto(28);
pub const SOCK_PROTO_PROTO_TP: SockProto = SockProto(29);
pub const SOCK_PROTO_PROTO_30: SockProto = SockProto(30);
pub const SOCK_PROTO_PROTO_31: SockProto = SockProto(31);
pub const SOCK_PROTO_PROTO_32: SockProto = SockProto(32);
pub const SOCK_PROTO_DCCP: SockProto = SockProto(33);
pub const SOCK_PROTO_PROTO_34: SockProto = SockProto(34);
pub const SOCK_PROTO_PROTO_35: SockProto = SockProto(35);
pub const SOCK_PROTO_PROTO_36: SockProto = SockProto(36);
pub const SOCK_PROTO_PROTO_37: SockProto = SockProto(37);
pub const SOCK_PROTO_PROTO_38: SockProto = SockProto(38);
pub const SOCK_PROTO_PROTO_39: SockProto = SockProto(39);
pub const SOCK_PROTO_PROTO_40: SockProto = SockProto(40);
pub const SOCK_PROTO_IPV6: SockProto = SockProto(41);
pub const SOCK_PROTO_PROTO_42: SockProto = SockProto(42);
pub const SOCK_PROTO_ROUTING: SockProto = SockProto(43);
pub const SOCK_PROTO_FRAGMENT: SockProto = SockProto(44);
pub const SOCK_PROTO_PROTO_45: SockProto = SockProto(45);
pub const SOCK_PROTO_RSVP: SockProto = SockProto(46);
pub const SOCK_PROTO_GRE: SockProto = SockProto(47);
pub const SOCK_PROTO_PROTO_48: SockProto = SockProto(48);
pub const SOCK_PROTO_PROTO_49: SockProto = SockProto(49);
pub const SOCK_PROTO_ESP: SockProto = SockProto(50);
pub const SOCK_PROTO_AH: SockProto = SockProto(51);
pub const SOCK_PROTO_PROTO_52: SockProto = SockProto(52);
pub const SOCK_PROTO_PROTO_53: SockProto = SockProto(53);
pub const SOCK_PROTO_PROTO_54: SockProto = SockProto(54);
pub const SOCK_PROTO_PROTO_55: SockProto = SockProto(55);
pub const SOCK_PROTO_PROTO_56: SockProto = SockProto(56);
pub const SOCK_PROTO_PROTO_57: SockProto = SockProto(57);
pub const SOCK_PROTO_ICMPV6: SockProto = SockProto(58);
pub const SOCK_PROTO_NONE: SockProto = SockProto(59);
pub const SOCK_PROTO_DSTOPTS: SockProto = SockProto(60);
pub const SOCK_PROTO_PROTO_61: SockProto = SockProto(61);
pub const SOCK_PROTO_PROTO_62: SockProto = SockProto(62);
pub const SOCK_PROTO_PROTO_63: SockProto = SockProto(63);
pub const SOCK_PROTO_PROTO_64: SockProto = SockProto(64);
pub const SOCK_PROTO_PROTO_65: SockProto = SockProto(65);
pub const SOCK_PROTO_PROTO_66: SockProto = SockProto(66);
pub const SOCK_PROTO_PROTO_67: SockProto = SockProto(67);
pub const SOCK_PROTO_PROTO_68: SockProto = SockProto(68);
pub const SOCK_PROTO_PROTO_69: SockProto = SockProto(69);
pub const SOCK_PROTO_PROTO_70: SockProto = SockProto(70);
pub const SOCK_PROTO_PROTO_71: SockProto = SockProto(71);
pub const SOCK_PROTO_PROTO_72: SockProto = SockProto(72);
pub const SOCK_PROTO_PROTO_73: SockProto = SockProto(73);
pub const SOCK_PROTO_PROTO_74: SockProto = SockProto(74);
pub const SOCK_PROTO_PROTO_75: SockProto = SockProto(75);
pub const SOCK_PROTO_PROTO_76: SockProto = SockProto(76);
pub const SOCK_PROTO_PROTO_77: SockProto = SockProto(77);
pub const SOCK_PROTO_PROTO_78: SockProto = SockProto(78);
pub const SOCK_PROTO_PROTO_79: SockProto = SockProto(79);
pub const SOCK_PROTO_PROTO_80: SockProto = SockProto(80);
pub const SOCK_PROTO_PROTO_81: SockProto = SockProto(81);
pub const SOCK_PROTO_PROTO_82: SockProto = SockProto(82);
pub const SOCK_PROTO_PROTO_83: SockProto = SockProto(83);
pub const SOCK_PROTO_PROTO_84: SockProto = SockProto(84);
pub const SOCK_PROTO_PROTO_85: SockProto = SockProto(85);
pub const SOCK_PROTO_PROTO_86: SockProto = SockProto(86);
pub const SOCK_PROTO_PROTO_87: SockProto = SockProto(87);
pub const SOCK_PROTO_PROTO_88: SockProto = SockProto(88);
pub const SOCK_PROTO_PROTO_89: SockProto = SockProto(89);
pub const SOCK_PROTO_PROTO_90: SockProto = SockProto(90);
pub const SOCK_PROTO_PROTO_91: SockProto = SockProto(91);
pub const SOCK_PROTO_MTP: SockProto = SockProto(92);
pub const SOCK_PROTO_PROTO_93: SockProto = SockProto(93);
pub const SOCK_PROTO_BEETPH: SockProto = SockProto(94);
pub const SOCK_PROTO_PROTO_95: SockProto = SockProto(95);
pub const SOCK_PROTO_PROTO_96: SockProto = SockProto(96);
pub const SOCK_PROTO_PROTO_97: SockProto = SockProto(97);
pub const SOCK_PROTO_ENCAP: SockProto = SockProto(98);
pub const SOCK_PROTO_PROTO_99: SockProto = SockProto(99);
pub const SOCK_PROTO_PROTO_100: SockProto = SockProto(100);
pub const SOCK_PROTO_PROTO_101: SockProto = SockProto(101);
pub const SOCK_PROTO_PROTO_102: SockProto = SockProto(102);
pub const SOCK_PROTO_PIM: SockProto = SockProto(103);
pub const SOCK_PROTO_PROTO_104: SockProto = SockProto(104);
pub const SOCK_PROTO_PROTO_105: SockProto = SockProto(105);
pub const SOCK_PROTO_PROTO_106: SockProto = SockProto(106);
pub const SOCK_PROTO_PROTO_107: SockProto = SockProto(107);
pub const SOCK_PROTO_COMP: SockProto = SockProto(108);
pub const SOCK_PROTO_PROTO_109: SockProto = SockProto(109);
pub const SOCK_PROTO_PROTO_110: SockProto = SockProto(110);
pub const SOCK_PROTO_PROTO_111: SockProto = SockProto(111);
pub const SOCK_PROTO_PROTO_112: SockProto = SockProto(112);
pub const SOCK_PROTO_PROTO_113: SockProto = SockProto(113);
pub const SOCK_PROTO_PROTO_114: SockProto = SockProto(114);
pub const SOCK_PROTO_PROTO_115: SockProto = SockProto(115);
pub const SOCK_PROTO_PROTO_116: SockProto = SockProto(116);
pub const SOCK_PROTO_PROTO_117: SockProto = SockProto(117);
pub const SOCK_PROTO_PROTO_118: SockProto = SockProto(118);
pub const SOCK_PROTO_PROTO_119: SockProto = SockProto(119);
pub const SOCK_PROTO_PROTO_120: SockProto = SockProto(120);
pub const SOCK_PROTO_PROTO_121: SockProto = SockProto(121);
pub const SOCK_PROTO_PROTO_122: SockProto = SockProto(122);
pub const SOCK_PROTO_PROTO_123: SockProto = SockProto(123);
pub const SOCK_PROTO_PROTO_124: SockProto = SockProto(124);
pub const SOCK_PROTO_PROTO_125: SockProto = SockProto(125);
pub const SOCK_PROTO_PROTO_126: SockProto = SockProto(126);
pub const SOCK_PROTO_PROTO_127: SockProto = SockProto(127);
pub const SOCK_PROTO_PROTO_128: SockProto = SockProto(128);
pub const SOCK_PROTO_PROTO_129: SockProto = SockProto(129);
pub const SOCK_PROTO_PROTO_130: SockProto = SockProto(130);
pub const SOCK_PROTO_PROTO_131: SockProto = SockProto(131);
pub const SOCK_PROTO_SCTP: SockProto = SockProto(132);
pub const SOCK_PROTO_PROTO_133: SockProto = SockProto(133);
pub const SOCK_PROTO_PROTO_134: SockProto = SockProto(134);
pub const SOCK_PROTO_MH: SockProto = SockProto(135);
pub const SOCK_PROTO_UDPLITE: SockProto = SockProto(136);
pub const SOCK_PROTO_MPLS: SockProto = SockProto(137);
pub const SOCK_PROTO_PROTO_138: SockProto = SockProto(138);
pub const SOCK_PROTO_PROTO_139: SockProto = SockProto(139);
pub const SOCK_PROTO_PROTO_140: SockProto = SockProto(140);
pub const SOCK_PROTO_PROTO_141: SockProto = SockProto(141);
pub const SOCK_PROTO_PROTO_142: SockProto = SockProto(142);
pub const SOCK_PROTO_ETHERNET: SockProto = SockProto(143);
pub const SOCK_PROTO_PROTO_144: SockProto = SockProto(144);
pub const SOCK_PROTO_PROTO_145: SockProto = SockProto(145);
pub const SOCK_PROTO_PROTO_146: SockProto = SockProto(146);
pub const SOCK_PROTO_PROTO_147: SockProto = SockProto(147);
pub const SOCK_PROTO_PROTO_148: SockProto = SockProto(148);
pub const SOCK_PROTO_PROTO_149: SockProto = SockProto(149);
pub const SOCK_PROTO_PROTO_150: SockProto = SockProto(150);
pub const SOCK_PROTO_PROTO_151: SockProto = SockProto(151);
pub const SOCK_PROTO_PROTO_152: SockProto = SockProto(152);
pub const SOCK_PROTO_PROTO_153: SockProto = SockProto(153);
pub const SOCK_PROTO_PROTO_154: SockProto = SockProto(154);
pub const SOCK_PROTO_PROTO_155: SockProto = SockProto(155);
pub const SOCK_PROTO_PROTO_156: SockProto = SockProto(156);
pub const SOCK_PROTO_PROTO_157: SockProto = SockProto(157);
pub const SOCK_PROTO_PROTO_158: SockProto = SockProto(158);
pub const SOCK_PROTO_PROTO_159: SockProto = SockProto(159);
pub const SOCK_PROTO_PROTO_160: SockProto = SockProto(160);
pub const SOCK_PROTO_PROTO_161: SockProto = SockProto(161);
pub const SOCK_PROTO_PROTO_162: SockProto = SockProto(162);
pub const SOCK_PROTO_PROTO_163: SockProto = SockProto(163);
pub const SOCK_PROTO_PROTO_164: SockProto = SockProto(164);
pub const SOCK_PROTO_PROTO_165: SockProto = SockProto(165);
pub const SOCK_PROTO_PROTO_166: SockProto = SockProto(166);
pub const SOCK_PROTO_PROTO_167: SockProto = SockProto(167);
pub const SOCK_PROTO_PROTO_168: SockProto = SockProto(168);
pub const SOCK_PROTO_PROTO_169: SockProto = SockProto(169);
pub const SOCK_PROTO_PROTO_170: SockProto = SockProto(170);
pub const SOCK_PROTO_PROTO_171: SockProto = SockProto(171);
pub const SOCK_PROTO_PROTO_172: SockProto = SockProto(172);
pub const SOCK_PROTO_PROTO_173: SockProto = SockProto(173);
pub const SOCK_PROTO_PROTO_174: SockProto = SockProto(174);
pub const SOCK_PROTO_PROTO_175: SockProto = SockProto(175);
pub const SOCK_PROTO_PROTO_176: SockProto = SockProto(176);
pub const SOCK_PROTO_PROTO_177: SockProto = SockProto(177);
pub const SOCK_PROTO_PROTO_178: SockProto = SockProto(178);
pub const SOCK_PROTO_PROTO_179: SockProto = SockProto(179);
pub const SOCK_PROTO_PROTO_180: SockProto = SockProto(180);
pub const SOCK_PROTO_PROTO_181: SockProto = SockProto(181);
pub const SOCK_PROTO_PROTO_182: SockProto = SockProto(182);
pub const SOCK_PROTO_PROTO_183: SockProto = SockProto(183);
pub const SOCK_PROTO_PROTO_184: SockProto = SockProto(184);
pub const SOCK_PROTO_PROTO_185: SockProto = SockProto(185);
pub const SOCK_PROTO_PROTO_186: SockProto = SockProto(186);
pub const SOCK_PROTO_PROTO_187: SockProto = SockProto(187);
pub const SOCK_PROTO_PROTO_188: SockProto = SockProto(188);
pub const SOCK_PROTO_PROTO_189: SockProto = SockProto(189);
pub const SOCK_PROTO_PROTO_190: SockProto = SockProto(190);
pub const SOCK_PROTO_PROTO_191: SockProto = SockProto(191);
pub const SOCK_PROTO_PROTO_192: SockProto = SockProto(192);
pub const SOCK_PROTO_PROTO_193: SockProto = SockProto(193);
pub const SOCK_PROTO_PROTO_194: SockProto = SockProto(194);
pub const SOCK_PROTO_PROTO_195: SockProto = SockProto(195);
pub const SOCK_PROTO_PROTO_196: SockProto = SockProto(196);
pub const SOCK_PROTO_PROTO_197: SockProto = SockProto(197);
pub const SOCK_PROTO_PROTO_198: SockProto = SockProto(198);
pub const SOCK_PROTO_PROTO_199: SockProto = SockProto(199);
pub const SOCK_PROTO_PROTO_200: SockProto = SockProto(200);
pub const SOCK_PROTO_PROTO_201: SockProto = SockProto(201);
pub const SOCK_PROTO_PROTO_202: SockProto = SockProto(202);
pub const SOCK_PROTO_PROTO_203: SockProto = SockProto(203);
pub const SOCK_PROTO_PROTO_204: SockProto = SockProto(204);
pub const SOCK_PROTO_PROTO_205: SockProto = SockProto(205);
pub const SOCK_PROTO_PROTO_206: SockProto = SockProto(206);
pub const SOCK_PROTO_PROTO_207: SockProto = SockProto(207);
pub const SOCK_PROTO_PROTO_208: SockProto = SockProto(208);
pub const SOCK_PROTO_PROTO_209: SockProto = SockProto(209);
pub const SOCK_PROTO_PROTO_210: SockProto = SockProto(210);
pub const SOCK_PROTO_PROTO_211: SockProto = SockProto(211);
pub const SOCK_PROTO_PROTO_212: SockProto = SockProto(212);
pub const SOCK_PROTO_PROTO_213: SockProto = SockProto(213);
pub const SOCK_PROTO_PROTO_214: SockProto = SockProto(214);
pub const SOCK_PROTO_PROTO_215: SockProto = SockProto(215);
pub const SOCK_PROTO_PROTO_216: SockProto = SockProto(216);
pub const SOCK_PROTO_PROTO_217: SockProto = SockProto(217);
pub const SOCK_PROTO_PROTO_218: SockProto = SockProto(218);
pub const SOCK_PROTO_PROTO_219: SockProto = SockProto(219);
pub const SOCK_PROTO_PROTO_220: SockProto = SockProto(220);
pub const SOCK_PROTO_PROTO_221: SockProto = SockProto(221);
pub const SOCK_PROTO_PROTO_222: SockProto = SockProto(222);
pub const SOCK_PROTO_PROTO_223: SockProto = SockProto(223);
pub const SOCK_PROTO_PROTO_224: SockProto = SockProto(224);
pub const SOCK_PROTO_PROTO_225: SockProto = SockProto(225);
pub const SOCK_PROTO_PROTO_226: SockProto = SockProto(226);
pub const SOCK_PROTO_PROTO_227: SockProto = SockProto(227);
pub const SOCK_PROTO_PROTO_228: SockProto = SockProto(228);
pub const SOCK_PROTO_PROTO_229: SockProto = SockProto(229);
pub const SOCK_PROTO_PROTO_230: SockProto = SockProto(230);
pub const SOCK_PROTO_PROTO_231: SockProto = SockProto(231);
pub const SOCK_PROTO_PROTO_232: SockProto = SockProto(232);
pub const SOCK_PROTO_PROTO_233: SockProto = SockProto(233);
pub const SOCK_PROTO_PROTO_234: SockProto = SockProto(234);
pub const SOCK_PROTO_PROTO_235: SockProto = SockProto(235);
pub const SOCK_PROTO_PROTO_236: SockProto = SockProto(236);
pub const SOCK_PROTO_PROTO_237: SockProto = SockProto(237);
pub const SOCK_PROTO_PROTO_238: SockProto = SockProto(238);
pub const SOCK_PROTO_PROTO_239: SockProto = SockProto(239);
pub const SOCK_PROTO_PROTO_240: SockProto = SockProto(240);
pub const SOCK_PROTO_PROTO_241: SockProto = SockProto(241);
pub const SOCK_PROTO_PROTO_242: SockProto = SockProto(242);
pub const SOCK_PROTO_PROTO_243: SockProto = SockProto(243);
pub const SOCK_PROTO_PROTO_244: SockProto = SockProto(244);
pub const SOCK_PROTO_PROTO_245: SockProto = SockProto(245);
pub const SOCK_PROTO_PROTO_246: SockProto = SockProto(246);
pub const SOCK_PROTO_PROTO_247: SockProto = SockProto(247);
pub const SOCK_PROTO_PROTO_248: SockProto = SockProto(248);
pub const SOCK_PROTO_PROTO_249: SockProto = SockProto(249);
pub const SOCK_PROTO_PROTO_250: SockProto = SockProto(250);
pub const SOCK_PROTO_PROTO_251: SockProto = SockProto(251);
pub const SOCK_PROTO_PROTO_252: SockProto = SockProto(252);
pub const SOCK_PROTO_PROTO_253: SockProto = SockProto(253);
pub const SOCK_PROTO_PROTO_254: SockProto = SockProto(254);
pub const SOCK_PROTO_PROTO_RAW: SockProto = SockProto(255);
pub const SOCK_PROTO_PROTO_256: SockProto = SockProto(256);
pub const SOCK_PROTO_PROTO_257: SockProto = SockProto(257);
pub const SOCK_PROTO_PROTO_258: SockProto = SockProto(258);
pub const SOCK_PROTO_PROTO_259: SockProto = SockProto(259);
pub const SOCK_PROTO_PROTO_260: SockProto = SockProto(260);
pub const SOCK_PROTO_PROTO_261: SockProto = SockProto(261);
pub const SOCK_PROTO_MPTCP: SockProto = SockProto(262);
pub const SOCK_PROTO_MAX: SockProto = SockProto(263);
impl SockProto {
    pub const fn raw(&self) -> u16 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "IP",
            1 => "ICMP",
            2 => "IGMP",
            3 => "PROTO_3",
            4 => "IPIP",
            5 => "PROTO_5",
            6 => "TCP",
            7 => "PROTO_7",
            8 => "EGP",
            9 => "PROTO_9",
            10 => "PROTO_10",
            11 => "PROTO_11",
            12 => "PUP",
            13 => "PROTO_13",
            14 => "PROTO_14",
            15 => "PROTO_15",
            16 => "PROTO_16",
            17 => "UDP",
            18 => "PROTO_18",
            19 => "PROTO_19",
            20 => "PROTO_20",
            21 => "PROTO_21",
            22 => "IDP",
            23 => "PROTO_23",
            24 => "PROTO_24",
            25 => "PROTO_25",
            26 => "PROTO_26",
            27 => "PROTO_27",
            28 => "PROTO_28",
            29 => "PROTO_TP",
            30 => "PROTO_30",
            31 => "PROTO_31",
            32 => "PROTO_32",
            33 => "DCCP",
            34 => "PROTO_34",
            35 => "PROTO_35",
            36 => "PROTO_36",
            37 => "PROTO_37",
            38 => "PROTO_38",
            39 => "PROTO_39",
            40 => "PROTO_40",
            41 => "IPV6",
            42 => "PROTO_42",
            43 => "ROUTING",
            44 => "FRAGMENT",
            45 => "PROTO_45",
            46 => "RSVP",
            47 => "GRE",
            48 => "PROTO_48",
            49 => "PROTO_49",
            50 => "ESP",
            51 => "AH",
            52 => "PROTO_52",
            53 => "PROTO_53",
            54 => "PROTO_54",
            55 => "PROTO_55",
            56 => "PROTO_56",
            57 => "PROTO_57",
            58 => "ICMPV6",
            59 => "NONE",
            60 => "DSTOPTS",
            61 => "PROTO_61",
            62 => "PROTO_62",
            63 => "PROTO_63",
            64 => "PROTO_64",
            65 => "PROTO_65",
            66 => "PROTO_66",
            67 => "PROTO_67",
            68 => "PROTO_68",
            69 => "PROTO_69",
            70 => "PROTO_70",
            71 => "PROTO_71",
            72 => "PROTO_72",
            73 => "PROTO_73",
            74 => "PROTO_74",
            75 => "PROTO_75",
            76 => "PROTO_76",
            77 => "PROTO_77",
            78 => "PROTO_78",
            79 => "PROTO_79",
            80 => "PROTO_80",
            81 => "PROTO_81",
            82 => "PROTO_82",
            83 => "PROTO_83",
            84 => "PROTO_84",
            85 => "PROTO_85",
            86 => "PROTO_86",
            87 => "PROTO_87",
            88 => "PROTO_88",
            89 => "PROTO_89",
            90 => "PROTO_90",
            91 => "PROTO_91",
            92 => "MTP",
            93 => "PROTO_93",
            94 => "BEETPH",
            95 => "PROTO_95",
            96 => "PROTO_96",
            97 => "PROTO_97",
            98 => "ENCAP",
            99 => "PROTO_99",
            100 => "PROTO_100",
            101 => "PROTO_101",
            102 => "PROTO_102",
            103 => "PIM",
            104 => "PROTO_104",
            105 => "PROTO_105",
            106 => "PROTO_106",
            107 => "PROTO_107",
            108 => "COMP",
            109 => "PROTO_109",
            110 => "PROTO_110",
            111 => "PROTO_111",
            112 => "PROTO_112",
            113 => "PROTO_113",
            114 => "PROTO_114",
            115 => "PROTO_115",
            116 => "PROTO_116",
            117 => "PROTO_117",
            118 => "PROTO_118",
            119 => "PROTO_119",
            120 => "PROTO_120",
            121 => "PROTO_121",
            122 => "PROTO_122",
            123 => "PROTO_123",
            124 => "PROTO_124",
            125 => "PROTO_125",
            126 => "PROTO_126",
            127 => "PROTO_127",
            128 => "PROTO_128",
            129 => "PROTO_129",
            130 => "PROTO_130",
            131 => "PROTO_131",
            132 => "SCTP",
            133 => "PROTO_133",
            134 => "PROTO_134",
            135 => "MH",
            136 => "UDPLITE",
            137 => "MPLS",
            138 => "PROTO_138",
            139 => "PROTO_139",
            140 => "PROTO_140",
            141 => "PROTO_141",
            142 => "PROTO_142",
            143 => "ETHERNET",
            144 => "PROTO_144",
            145 => "PROTO_145",
            146 => "PROTO_146",
            147 => "PROTO_147",
            148 => "PROTO_148",
            149 => "PROTO_149",
            150 => "PROTO_150",
            151 => "PROTO_151",
            152 => "PROTO_152",
            153 => "PROTO_153",
            154 => "PROTO_154",
            155 => "PROTO_155",
            156 => "PROTO_156",
            157 => "PROTO_157",
            158 => "PROTO_158",
            159 => "PROTO_159",
            160 => "PROTO_160",
            161 => "PROTO_161",
            162 => "PROTO_162",
            163 => "PROTO_163",
            164 => "PROTO_164",
            165 => "PROTO_165",
            166 => "PROTO_166",
            167 => "PROTO_167",
            168 => "PROTO_168",
            169 => "PROTO_169",
            170 => "PROTO_170",
            171 => "PROTO_171",
            172 => "PROTO_172",
            173 => "PROTO_173",
            174 => "PROTO_174",
            175 => "PROTO_175",
            176 => "PROTO_176",
            177 => "PROTO_177",
            178 => "PROTO_178",
            179 => "PROTO_179",
            180 => "PROTO_180",
            181 => "PROTO_181",
            182 => "PROTO_182",
            183 => "PROTO_183",
            184 => "PROTO_184",
            185 => "PROTO_185",
            186 => "PROTO_186",
            187 => "PROTO_187",
            188 => "PROTO_188",
            189 => "PROTO_189",
            190 => "PROTO_190",
            191 => "PROTO_191",
            192 => "PROTO_192",
            193 => "PROTO_193",
            194 => "PROTO_194",
            195 => "PROTO_195",
            196 => "PROTO_196",
            197 => "PROTO_197",
            198 => "PROTO_198",
            199 => "PROTO_199",
            200 => "PROTO_200",
            201 => "PROTO_201",
            202 => "PROTO_202",
            203 => "PROTO_203",
            204 => "PROTO_204",
            205 => "PROTO_205",
            206 => "PROTO_206",
            207 => "PROTO_207",
            208 => "PROTO_208",
            209 => "PROTO_209",
            210 => "PROTO_210",
            211 => "PROTO_211",
            212 => "PROTO_212",
            213 => "PROTO_213",
            214 => "PROTO_214",
            215 => "PROTO_215",
            216 => "PROTO_216",
            217 => "PROTO_217",
            218 => "PROTO_218",
            219 => "PROTO_219",
            220 => "PROTO_220",
            221 => "PROTO_221",
            222 => "PROTO_222",
            223 => "PROTO_223",
            224 => "PROTO_224",
            225 => "PROTO_225",
            226 => "PROTO_226",
            227 => "PROTO_227",
            228 => "PROTO_228",
            229 => "PROTO_229",
            230 => "PROTO_230",
            231 => "PROTO_231",
            232 => "PROTO_232",
            233 => "PROTO_233",
            234 => "PROTO_234",
            235 => "PROTO_235",
            236 => "PROTO_236",
            237 => "PROTO_237",
            238 => "PROTO_238",
            239 => "PROTO_239",
            240 => "PROTO_240",
            241 => "PROTO_241",
            242 => "PROTO_242",
            243 => "PROTO_243",
            244 => "PROTO_244",
            245 => "PROTO_245",
            246 => "PROTO_246",
            247 => "PROTO_247",
            248 => "PROTO_248",
            249 => "PROTO_249",
            250 => "PROTO_250",
            251 => "PROTO_251",
            252 => "PROTO_252",
            253 => "PROTO_253",
            254 => "PROTO_254",
            255 => "PROTO_RAW",
            256 => "PROTO_256",
            257 => "PROTO_257",
            258 => "PROTO_258",
            259 => "PROTO_259",
            260 => "PROTO_260",
            261 => "PROTO_261",
            262 => "MPTCP",
            263 => "MAX",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "",
            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 => "",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for SockProto {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("SockProto")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u16> for SockProto {
    fn from(a: u16) -> Self {
        Self(a)
    }
}

#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct SockStatus(u8);
/// The socket is still opening
pub const SOCK_STATUS_OPENING: SockStatus = SockStatus(0);
/// The socket has fully opened
pub const SOCK_STATUS_OPENED: SockStatus = SockStatus(1);
/// The socket has closed
pub const SOCK_STATUS_CLOSED: SockStatus = SockStatus(2);
/// The socket has failed
pub const SOCK_STATUS_FAILED: SockStatus = SockStatus(3);
impl SockStatus {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "OPENING",
            1 => "OPENED",
            2 => "CLOSED",
            3 => "FAILED",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "The socket is still opening",
            1 => "The socket has fully opened",
            2 => "The socket has closed",
            3 => "The socket has failed",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for SockStatus {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("SockStatus")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for SockStatus {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct SockOption(u8);
/// Socket option that does nothing
pub const SOCK_OPTION_NOOP: SockOption = SockOption(0);
/// Reuse Port
pub const SOCK_OPTION_REUSE_PORT: SockOption = SockOption(1);
/// Reuse Address
pub const SOCK_OPTION_REUSE_ADDR: SockOption = SockOption(2);
/// No delay
pub const SOCK_OPTION_NO_DELAY: SockOption = SockOption(3);
/// Dont route
pub const SOCK_OPTION_DONT_ROUTE: SockOption = SockOption(4);
/// Only accept IPv6
pub const SOCK_OPTION_ONLY_V6: SockOption = SockOption(5);
/// Broadcast
pub const SOCK_OPTION_BROADCAST: SockOption = SockOption(6);
/// Multicast Loop IPv4
pub const SOCK_OPTION_MULTICAST_LOOP_V4: SockOption = SockOption(7);
/// Multicast Loop IPv6
pub const SOCK_OPTION_MULTICAST_LOOP_V6: SockOption = SockOption(8);
/// Promiscuous
pub const SOCK_OPTION_PROMISCUOUS: SockOption = SockOption(9);
/// Socket is listening
pub const SOCK_OPTION_LISTENING: SockOption = SockOption(10);
/// Last error
pub const SOCK_OPTION_LAST_ERROR: SockOption = SockOption(11);
/// Keep alive
pub const SOCK_OPTION_KEEP_ALIVE: SockOption = SockOption(12);
/// Linger time
pub const SOCK_OPTION_LINGER: SockOption = SockOption(13);
/// Out-of-band inline
pub const SOCK_OPTION_OOB_INLINE: SockOption = SockOption(14);
/// Receive buffer size
pub const SOCK_OPTION_RECV_BUF_SIZE: SockOption = SockOption(15);
/// Send buffer size
pub const SOCK_OPTION_SEND_BUF_SIZE: SockOption = SockOption(16);
/// Receive lowat
pub const SOCK_OPTION_RECV_LOWAT: SockOption = SockOption(17);
/// Send lowat
pub const SOCK_OPTION_SEND_LOWAT: SockOption = SockOption(18);
/// Receive timeout
pub const SOCK_OPTION_RECV_TIMEOUT: SockOption = SockOption(19);
/// Send timeout
pub const SOCK_OPTION_SEND_TIMEOUT: SockOption = SockOption(20);
/// Connect timeout
pub const SOCK_OPTION_CONNECT_TIMEOUT: SockOption = SockOption(21);
/// Accept timeout
pub const SOCK_OPTION_ACCEPT_TIMEOUT: SockOption = SockOption(22);
/// TTL of packets
pub const SOCK_OPTION_TTL: SockOption = SockOption(23);
/// Multicast TTL for IPv4
pub const SOCK_OPTION_MULTICAST_TTL_V4: SockOption = SockOption(24);
/// Type of socket
pub const SOCK_OPTION_TYPE: SockOption = SockOption(25);
/// Protocol of the socket
pub const SOCK_OPTION_PROTO: SockOption = SockOption(26);
impl SockOption {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "NOOP",
            1 => "REUSE_PORT",
            2 => "REUSE_ADDR",
            3 => "NO_DELAY",
            4 => "DONT_ROUTE",
            5 => "ONLY_V6",
            6 => "BROADCAST",
            7 => "MULTICAST_LOOP_V4",
            8 => "MULTICAST_LOOP_V6",
            9 => "PROMISCUOUS",
            10 => "LISTENING",
            11 => "LAST_ERROR",
            12 => "KEEP_ALIVE",
            13 => "LINGER",
            14 => "OOB_INLINE",
            15 => "RECV_BUF_SIZE",
            16 => "SEND_BUF_SIZE",
            17 => "RECV_LOWAT",
            18 => "SEND_LOWAT",
            19 => "RECV_TIMEOUT",
            20 => "SEND_TIMEOUT",
            21 => "CONNECT_TIMEOUT",
            22 => "ACCEPT_TIMEOUT",
            23 => "TTL",
            24 => "MULTICAST_TTL_V4",
            25 => "TYPE",
            26 => "PROTO",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "Socket option that does nothing",
            1 => "Reuse Port",
            2 => "Reuse Address",
            3 => "No delay",
            4 => "Dont route",
            5 => "Only accept IPv6",
            6 => "Broadcast",
            7 => "Multicast Loop IPv4",
            8 => "Multicast Loop IPv6",
            9 => "Promiscuous",
            10 => "Socket is listening",
            11 => "Last error",
            12 => "Keep alive",
            13 => "Linger time",
            14 => "Out-of-band inline",
            15 => "Receive buffer size",
            16 => "Send buffer size",
            17 => "Receive lowat",
            18 => "Send lowat",
            19 => "Receive timeout",
            20 => "Send timeout",
            21 => "Connect timeout",
            22 => "Accept timeout",
            23 => "TTL of packets",
            24 => "Multicast TTL for IPv4",
            25 => "Type of socket",
            26 => "Protocol of the socket",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for SockOption {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("SockOption")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for SockOption {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

pub type StreamSecurity = u8;
/// Unencrypted
pub const STREAM_SECURITY_UNENCRYPTED: StreamSecurity = 1 << 0;
/// Any encryption
pub const STREAM_SECURITY_ANY_ENCRYPTION: StreamSecurity = 1 << 1;
/// Classic encryption
pub const STREAM_SECURITY_CLASSIC_ENCRYPTION: StreamSecurity = 1 << 2;
/// Double encryption
pub const STREAM_SECURITY_DOUBLE_ENCRYPTION: StreamSecurity = 1 << 3;

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct HardwareAddress {
    pub n0: u8,
    pub n1: u8,
    pub n2: u8,
    pub h0: u8,
    pub h1: u8,
    pub h2: u8,
}
pub type IpPort = u16;
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct AddressFamily(u8);
/// Unspecified
pub const ADDRESS_FAMILY_UNSPEC: AddressFamily = AddressFamily(0);
/// IP v4
pub const ADDRESS_FAMILY_INET4: AddressFamily = AddressFamily(1);
/// IP v6
pub const ADDRESS_FAMILY_INET6: AddressFamily = AddressFamily(2);
/// Unix
pub const ADDRESS_FAMILY_UNIX: AddressFamily = AddressFamily(3);
impl AddressFamily {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "UNSPEC",
            1 => "INET4",
            2 => "INET6",
            3 => "UNIX",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "Unspecified",
            1 => "IP v4",
            2 => "IP v6",
            3 => "Unix",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for AddressFamily {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("AddressFamily")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for AddressFamily {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct AddressFamilyIp(u8);
/// Unspecified - this is unused, but this enum must be
/// backwards-compatible with $address_family
pub const ADDRESS_FAMILY_IP_UNSPEC: AddressFamilyIp = AddressFamilyIp(0);
/// IP v4
pub const ADDRESS_FAMILY_IP_INET4: AddressFamilyIp = AddressFamilyIp(1);
/// IP v6
pub const ADDRESS_FAMILY_IP_INET6: AddressFamilyIp = AddressFamilyIp(2);
impl AddressFamilyIp {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "UNSPEC",
            1 => "INET4",
            2 => "INET6",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => {
                "Unspecified - this is unused, but this enum must be
backwards-compatible with $address_family"
            }
            1 => "IP v4",
            2 => "IP v6",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for AddressFamilyIp {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("AddressFamilyIp")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for AddressFamilyIp {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AddrUnspec {
    pub n0: u8,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AddrUnspecPort {
    pub port: IpPort,
    pub addr: AddrUnspec,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AddrUnspecCidr {
    pub addr: AddrUnspec,
    pub prefix: u8,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AddrIp4 {
    pub n0: u8,
    pub n1: u8,
    pub h0: u8,
    pub h1: u8,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AddrIp4Port {
    pub port: IpPort,
    pub addr: AddrIp4,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AddrIp4Cidr {
    pub addr: AddrIp4,
    pub prefix: u8,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AddrIp6 {
    pub n0: u16,
    pub n1: u16,
    pub n2: u16,
    pub n3: u16,
    pub h0: u16,
    pub h1: u16,
    pub h2: u16,
    pub h3: u16,
    /// flow_info1 contains the most significant two bytes, and comes first in keeping with all wasix syscalls being little endian
    pub flow_info1: u16,
    /// flow_info0 contains the least significant two bytes
    pub flow_info0: u16,
    /// Same as flow_info1 and flow_info0
    pub scope_id1: u16,
    pub scope_id0: u16,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AddrIp6Bare {
    pub n0: u16,
    pub n1: u16,
    pub n2: u16,
    pub n3: u16,
    pub h0: u16,
    pub h1: u16,
    pub h2: u16,
    pub h3: u16,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AddrUnix {
    pub b0: u8,
    pub b1: u8,
    pub b2: u8,
    pub b3: u8,
    pub b4: u8,
    pub b5: u8,
    pub b6: u8,
    pub b7: u8,
    pub b8: u8,
    pub b9: u8,
    pub b10: u8,
    pub b11: u8,
    pub b12: u8,
    pub b13: u8,
    pub b14: u8,
    pub b15: u8,
    pub b16: u8,
    pub b17: u8,
    pub b18: u8,
    pub b19: u8,
    pub b20: u8,
    pub b21: u8,
    pub b22: u8,
    pub b23: u8,
    pub b24: u8,
    pub b25: u8,
    pub b26: u8,
    pub b27: u8,
    pub b28: u8,
    pub b29: u8,
    pub b30: u8,
    pub b31: u8,
    pub b32: u8,
    pub b33: u8,
    pub b34: u8,
    pub b35: u8,
    pub b36: u8,
    pub b37: u8,
    pub b38: u8,
    pub b39: u8,
    pub b40: u8,
    pub b41: u8,
    pub b42: u8,
    pub b43: u8,
    pub b44: u8,
    pub b45: u8,
    pub b46: u8,
    pub b47: u8,
    pub b48: u8,
    pub b49: u8,
    pub b50: u8,
    pub b51: u8,
    pub b52: u8,
    pub b53: u8,
    pub b54: u8,
    pub b55: u8,
    pub b56: u8,
    pub b57: u8,
    pub b58: u8,
    pub b59: u8,
    pub b60: u8,
    pub b61: u8,
    pub b62: u8,
    pub b63: u8,
    pub b64: u8,
    pub b65: u8,
    pub b66: u8,
    pub b67: u8,
    pub b68: u8,
    pub b69: u8,
    pub b70: u8,
    pub b71: u8,
    pub b72: u8,
    pub b73: u8,
    pub b74: u8,
    pub b75: u8,
    pub b76: u8,
    pub b77: u8,
    pub b78: u8,
    pub b79: u8,
    pub b80: u8,
    pub b81: u8,
    pub b82: u8,
    pub b83: u8,
    pub b84: u8,
    pub b85: u8,
    pub b86: u8,
    pub b87: u8,
    pub b88: u8,
    pub b89: u8,
    pub b90: u8,
    pub b91: u8,
    pub b92: u8,
    pub b93: u8,
    pub b94: u8,
    pub b95: u8,
    pub b96: u8,
    pub b97: u8,
    pub b98: u8,
    pub b99: u8,
    pub b100: u8,
    pub b101: u8,
    pub b102: u8,
    pub b103: u8,
    pub b104: u8,
    pub b105: u8,
    pub b106: u8,
    pub b107: u8,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AddrUnixCidr {
    pub unused: u8,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AddrIp6Port {
    pub port: IpPort,
    pub addr: AddrIp6,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AddrIp6Cidr {
    pub addr: AddrIp6,
    pub prefix: u8,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union AddrU {
    pub unspec: AddrUnspec,
    pub inet4: AddrIp4,
    pub inet6: AddrIp6,
    pub unix: AddrUnix,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct Addr {
    pub tag: u8,
    pub u: AddrU,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub union AddrIpU {
    pub unspec: AddrUnspec,
    pub inet4: AddrIp4,
    pub inet6: AddrIp6Bare,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct AddrIp {
    pub tag: u8,
    pub u: AddrIpU,
}

pub type AddrArray<'a> = &'a [Addr];
#[repr(C)]
#[derive(Copy, Clone)]
pub union AddrPortU {
    pub unspec: AddrUnspecPort,
    pub inet4: AddrIp4Port,
    pub inet6: AddrIp6Port,
    pub unix: AddrUnix,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct AddrPort {
    pub tag: u8,
    pub u: AddrPortU,
}

pub type AddrPortArray<'a> = &'a [AddrPort];
#[repr(C)]
#[derive(Copy, Clone)]
pub union AddrCidrU {
    pub unspec: AddrUnspecCidr,
    pub inet4: AddrIp4Cidr,
    pub inet6: AddrIp6Cidr,
    pub unix: AddrUnixCidr,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct AddrCidr {
    pub tag: u8,
    pub u: AddrCidrU,
}

pub type AddrCidrArray<'a> = &'a [AddrCidr];
#[repr(C)]
#[derive(Copy, Clone)]
pub struct Route {
    pub cidr: AddrCidr,
    pub via_router: Addr,
    pub preferred_until: OptionTimestamp,
    pub expires_at: OptionTimestamp,
}
pub type JoinFlags = u32;
/// Non-blocking join on the process
pub const JOIN_FLAGS_NON_BLOCKING: JoinFlags = 1 << 0;
/// Return if a process is stopped
pub const JOIN_FLAGS_WAKE_STOPPED: JoinFlags = 1 << 1;

#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct JoinStatusType(u8);
/// Nothing has happened
pub const JOIN_STATUS_TYPE_NOTHING: JoinStatusType = JoinStatusType(0);
/// The process has exited by a normal exit code
pub const JOIN_STATUS_TYPE_EXIT_NORMAL: JoinStatusType = JoinStatusType(1);
/// The process was terminated by a signal
pub const JOIN_STATUS_TYPE_EXIT_SIGNAL: JoinStatusType = JoinStatusType(2);
/// The process was stopped by a signal and can be resumed with SIGCONT
pub const JOIN_STATUS_TYPE_STOPPED: JoinStatusType = JoinStatusType(3);
impl JoinStatusType {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "NOTHING",
            1 => "EXIT_NORMAL",
            2 => "EXIT_SIGNAL",
            3 => "STOPPED",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "Nothing has happened",
            1 => "The process has exited by a normal exit code",
            2 => "The process was terminated by a signal",
            3 => "The process was stopped by a signal and can be resumed with SIGCONT",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for JoinStatusType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("JoinStatusType")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for JoinStatusType {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct ErrnoSignal {
    /// The exit code that was returned
    pub exit_code: Errno,
    /// The signal that was returned
    pub signal: Signal,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union JoinStatusU {
    pub nothing: u8,
    pub exit_normal: Errno,
    pub exit_signal: ErrnoSignal,
    pub stopped: Signal,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct JoinStatus {
    pub tag: u8,
    pub u: JoinStatusU,
}

pub type ThreadFlags = u16;
/// tsd_used
pub const THREAD_FLAGS_TSD_USED: ThreadFlags = 1 << 0;
/// dlerror_flag
pub const THREAD_FLAGS_DLERROR_FLAG: ThreadFlags = 1 << 1;

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct ThreadState {
    pub thread_self: Pointersize,
    pub dtv: Pointersize,
    pub thread_prev: Pointersize,
    pub thread_next: Pointersize,
    pub sysinfo: Pointersize,
    pub canary: Pointersize,
    pub tid: i32,
    pub errno_val: i32,
    pub detach_state: i32,
    pub cancel: i32,
    pub canceldisable: u8,
    pub cancelasync: u8,
    pub flags: ThreadFlags,
    pub map_base: Pointersize,
    pub map_size: Pointersize,
    pub stack: Pointersize,
    pub stack_size: Pointersize,
    pub guard_size: Pointersize,
    pub result: Pointersize,
    pub cancelbuf: Pointersize,
    pub tsd: Pointersize,
    pub robust_list_head: Pointersize,
    pub robust_list_off: Pointersize,
    pub robust_list_pending: Pointersize,
    pub h_errno_val: i32,
    pub timer_id: i32,
    pub locale: Pointersize,
    pub killlock: i32,
    pub dlerror_buf: Pointersize,
    pub stdio_locks: Pointersize,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct ThreadStart {
    /// Address where the stack starts
    pub stack: Pointersize,
    /// Address where the TLS starts
    pub tls_base: Pointersize,
    /// Function that will be invoked when the thread starts
    pub start_funct: Pointersize,
    /// Arguments to pass the callback function
    pub start_args: Pointersize,
    /// Reserved for future WASI usage
    pub reserved0: Pointersize,
    pub reserved1: Pointersize,
    pub reserved2: Pointersize,
    pub reserved3: Pointersize,
    pub reserved4: Pointersize,
    pub reserved5: Pointersize,
    pub reserved6: Pointersize,
    pub reserved7: Pointersize,
    pub reserved8: Pointersize,
    pub reserved9: Pointersize,
    /// The size of the stack
    pub stack_size: Pointersize,
    /// The size of the guards at the end of the stack
    pub guard_size: Pointersize,
}
pub type EpollType = u32;
pub const EPOLL_TYPE_EPOLLIN: EpollType = 1 << 0;
pub const EPOLL_TYPE_EPOLLOUT: EpollType = 1 << 1;
pub const EPOLL_TYPE_EPOLLRDHUP: EpollType = 1 << 2;
pub const EPOLL_TYPE_EPOLLPRI: EpollType = 1 << 3;
pub const EPOLL_TYPE_EPOLLERR: EpollType = 1 << 4;
pub const EPOLL_TYPE_EPOLLHUP: EpollType = 1 << 5;
pub const EPOLL_TYPE_EPOLLET: EpollType = 1 << 6;
pub const EPOLL_TYPE_EPOLLONESHOT: EpollType = 1 << 7;

#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct EpollCtl(u32);
/// Add an entry to the interest list of the epoll file descriptor, epfd.
pub const EPOLL_CTL_ADD: EpollCtl = EpollCtl(0);
/// Change the settings associated with fd in the interest list to the new settings specified in event.
pub const EPOLL_CTL_MOD: EpollCtl = EpollCtl(1);
/// Remove (deregister) the target file descriptor fd from the interest list.
pub const EPOLL_CTL_DEL: EpollCtl = EpollCtl(2);
impl EpollCtl {
    pub const fn raw(&self) -> u32 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "ADD",
            1 => "MOD",
            2 => "DEL",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {0 => "Add an entry to the interest list of the epoll file descriptor, epfd.",1 => "Change the settings associated with fd in the interest list to the new settings specified in event.",2 => "Remove (deregister) the target file descriptor fd from the interest list.",_ => unsafe { core::hint::unreachable_unchecked() },}
    }
}
impl fmt::Debug for EpollCtl {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("EpollCtl")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u32> for EpollCtl {
    fn from(a: u32) -> Self {
        Self(a)
    }
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct EpollData {
    /// Pointer to some user defined data
    pub ptr: Pointersize,
    /// The file descriptor of the event
    pub fd: Fd,
    /// User data for the event
    pub data1: u32,
    /// User data for the event
    pub data2: u64,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct EpollEvent {
    /// The events that are triggered for this
    pub events: EpollType,
    /// The data of the event
    pub data: EpollData,
}
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct ProcSpawnFdOpName(u8);
/// Close an FD.
pub const PROC_SPAWN_FD_OP_NAME_CLOSE: ProcSpawnFdOpName = ProcSpawnFdOpName(0);
/// Duplicate (i.e. renumber) an FD.
pub const PROC_SPAWN_FD_OP_NAME_DUP2: ProcSpawnFdOpName = ProcSpawnFdOpName(1);
/// Open a file.
pub const PROC_SPAWN_FD_OP_NAME_OPEN: ProcSpawnFdOpName = ProcSpawnFdOpName(2);
/// Change directory to a path.
pub const PROC_SPAWN_FD_OP_NAME_CHDIR: ProcSpawnFdOpName = ProcSpawnFdOpName(3);
/// Change directory to an FD.
pub const PROC_SPAWN_FD_OP_NAME_FCHDIR: ProcSpawnFdOpName = ProcSpawnFdOpName(4);
impl ProcSpawnFdOpName {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "CLOSE",
            1 => "DUP2",
            2 => "OPEN",
            3 => "CHDIR",
            4 => "FCHDIR",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "Close an FD.",
            1 => "Duplicate (i.e. renumber) an FD.",
            2 => "Open a file.",
            3 => "Change directory to a path.",
            4 => "Change directory to an FD.",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for ProcSpawnFdOpName {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("ProcSpawnFdOpName")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for ProcSpawnFdOpName {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct ProcSpawnFdOp {
    pub cmd: ProcSpawnFdOpName,
    pub fd: Fd,
    pub src_fd: Fd,
    pub path: *mut u8,
    pub path_len: Pointersize,
    pub dirflags: Lookupflags,
    pub oflags: Oflags,
    pub fs_rights_base: Rights,
    pub fs_rights_inheriting: Rights,
    pub fdflags: Fdflags,
    pub fdflagsext: Fdflagsext,
}
pub type ProcSpawnFdOpArray<'a> = &'a [ProcSpawnFdOp];
pub type DlHandle = u32;
pub type DlFlags = u32;
pub const DL_FLAGS_LAZY: DlFlags = 1 << 0;
pub const DL_FLAGS_NOW: DlFlags = 1 << 1;
pub const DL_FLAGS_GLOBAL: DlFlags = 1 << 2;
pub const DL_FLAGS_NOLOAD: DlFlags = 1 << 3;
pub const DL_FLAGS_NODELETE: DlFlags = 1 << 4;
pub const DL_FLAGS_DEEPBIND: DlFlags = 1 << 5;

pub type FunctionPointer = usize;
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct WasmValueType(u8);
/// A i32 value.
pub const WASM_VALUE_TYPE_I32: WasmValueType = WasmValueType(0);
/// A i64 value.
pub const WASM_VALUE_TYPE_I64: WasmValueType = WasmValueType(1);
/// A f32 value.
pub const WASM_VALUE_TYPE_F32: WasmValueType = WasmValueType(2);
/// A f64 value.
pub const WASM_VALUE_TYPE_F64: WasmValueType = WasmValueType(3);
/// A v128 value.
pub const WASM_VALUE_TYPE_V128: WasmValueType = WasmValueType(4);
impl WasmValueType {
    pub const fn raw(&self) -> u8 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "I32",
            1 => "I64",
            2 => "F32",
            3 => "F64",
            4 => "V128",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "A i32 value.",
            1 => "A i64 value.",
            2 => "A f32 value.",
            3 => "A f64 value.",
            4 => "A v128 value.",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for WasmValueType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("WasmValueType")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl From<u8> for WasmValueType {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

pub type WasmValueTypeArray<'a> = &'a [WasmValueType];
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct ReflectionResult {
    /// Cacheable is set if the signature of the function will not change in the future
    pub cacheable: Bool,
    /// Number of arguments of the function.
    /// 0 if the function does not exist
    pub arguments: u16,
    /// Number of results of the function.
    /// 0 if the function does not exist
    pub results: u16,
}
/// Sets the time value of a clock.
/// Note: This is similar to `clock_settime` in POSIX.
///
/// ## Parameters
///
/// * `id` - The clock for which to set the time.
/// * `timestamp` - The value of the time to be set.
///
/// ## Return
///
/// The time value of the clock.
pub unsafe fn clock_time_set(id: Clockid, timestamp: Timestamp) -> Result<(), Errno> {
    let ret = wasix_32v1::clock_time_set(id.raw() as i32, timestamp as i64);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Atomically duplicate a file handle.
pub unsafe fn fd_dup(fd: Fd) -> Result<Fd, Errno> {
    let mut rp0 = MaybeUninit::<Fd>::uninit();
    let ret = wasix_32v1::fd_dup(fd as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fd)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Atomically duplicate a file handle.
pub unsafe fn fd_dup2(fd: Fd, min_result_fd: Fd, cloexec: Bool) -> Result<Fd, Errno> {
    let mut rp0 = MaybeUninit::<Fd>::uninit();
    let ret = wasix_32v1::fd_dup2(
        fd as i32,
        min_result_fd as i32,
        cloexec.0 as i32,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fd)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Creates a file handle for event notifications
///
pub unsafe fn fd_event(initial_val: u64, flags: Eventfdflags) -> Result<Fd, Errno> {
    let mut rp0 = MaybeUninit::<Fd>::uninit();
    let ret = wasix_32v1::fd_event(initial_val as i64, flags as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fd)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Opens a pipe with two file handles
///
/// Pipes are bidirectional
pub unsafe fn fd_pipe() -> Result<(Fd, Fd), Errno> {
    let mut rp0 = MaybeUninit::<Fd>::uninit();
    let mut rp1 = MaybeUninit::<Fd>::uninit();
    let ret = wasix_32v1::fd_pipe(rp0.as_mut_ptr() as i32, rp1.as_mut_ptr() as i32);
    match ret {
        0 => Ok((
            core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fd),
            core::ptr::read(rp1.as_mut_ptr() as i32 as *const Fd),
        )),
        _ => Err(Errno(ret as u16)),
    }
}

/// Retrieves the current state of the TTY
pub unsafe fn tty_get(state: *mut Tty) -> Result<(), Errno> {
    let ret = wasix_32v1::tty_get(state as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Updates the properties of the the TTY
pub unsafe fn tty_set(state: *mut Tty) -> Result<(), Errno> {
    let ret = wasix_32v1::tty_set(state as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Returns the current working directory
///
/// If the path exceeds the size of the buffer then this function
/// will fill the path_len with the needed size and return EOVERFLOW
///
/// ## Parameters
///
/// * `path` - The buffer where current directory is stored
pub unsafe fn getcwd(path: *mut u8, path_len: *mut Pointersize) -> Result<(), Errno> {
    let ret = wasix_32v1::getcwd(path as i32, path_len as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Sets the current working directory
///
/// ## Parameters
///
/// * `path` - Path to change the current working directory to
pub unsafe fn chdir(path: &str) -> Result<(), Errno> {
    let ret = wasix_32v1::chdir(path.as_ptr() as i32, path.len() as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Registers a callback function for signals
///
/// ## Parameters
///
/// * `callback` - Exported function that will be called back when the signal triggers
///   (must match the callback signature that takes the signal value)
///   (if this is not specified the default will be "_signal")
pub unsafe fn callback_signal(callback: &str) {
    wasix_32v1::callback_signal(callback.as_ptr() as i32, callback.len() as i32);
}

/// Creates a new thread by spawning that shares the same
/// memory address space, file handles and main event loops.
/// The web assembly process must export function named 'wasi_thread_start'
///
/// ## Parameters
///
/// * `args` - Pointer to the structure the describes the thread
///   that is being spawened
///
/// ## Return
///
/// Returns the thread index of the newly created thread
/// (indices always start from zero)
pub unsafe fn thread_spawn_v2(args: *mut ThreadStart) -> Result<Tid, Errno> {
    let mut rp0 = MaybeUninit::<Tid>::uninit();
    let ret = wasix_32v1::thread_spawn_v2(args as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Tid)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Sends the current thread to sleep for a period of time
///
/// ## Parameters
///
/// * `duration` - Amount of time that the thread should sleep
pub unsafe fn thread_sleep(duration: Timestamp) -> Result<(), Errno> {
    let ret = wasix_32v1::thread_sleep(duration as i64);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Returns the index of the current thread
/// (threads indices are sequential from zero while the
///  main thread ID equals the process ID)
pub unsafe fn thread_id() -> Result<Tid, Errno> {
    let mut rp0 = MaybeUninit::<Tid>::uninit();
    let ret = wasix_32v1::thread_id(rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Tid)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Joins this thread with another thread, blocking this
/// one until the other finishes
///
/// ## Parameters
///
/// * `tid` - Handle of the thread to wait on
pub unsafe fn thread_join(tid: Tid) -> Result<(), Errno> {
    let ret = wasix_32v1::thread_join(tid as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Returns the available parallelism which is normally the
/// number of available cores that can run concurrently
pub unsafe fn thread_parallelism() -> Result<Size, Errno> {
    let mut rp0 = MaybeUninit::<Size>::uninit();
    let ret = wasix_32v1::thread_parallelism(rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Sends a signal to a specific thread
///
/// ## Parameters
///
/// * `tid` - Handle of the thread to send a signal
/// * `signal` - Signal to send to the thread
pub unsafe fn thread_signal(tid: Tid, signal: Signal) -> Result<(), Errno> {
    let ret = wasix_32v1::thread_signal(tid as i32, signal.0 as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Wait for a futex_wake operation to wake us.
///
/// Returns with EINVAL if the futex doesn't hold the expected value.
/// Returns false on timeout, and true in all other cases.
///
/// ## Parameters
///
/// * `futex` - Memory location that holds the value that will be checked
/// * `expected` - Expected value that should be currently held at the memory location
/// * `timeout` - Timeout should the futex not be triggered in the allocated time
pub unsafe fn futex_wait(
    futex: *mut u32,
    expected: u32,
    timeout: *const OptionTimestamp,
) -> Result<Bool, Errno> {
    let mut rp0 = MaybeUninit::<Bool>::uninit();
    let ret = wasix_32v1::futex_wait(
        futex as i32,
        expected as i32,
        timeout as i32,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Bool)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Wake up one thread that's blocked on futex_wait on this futex.
///
/// Returns true if this actually woke up such a thread,
/// or false if no thread was waiting on this futex.
///
/// ## Parameters
///
/// * `futex` - Memory location that holds a futex that others may be waiting on
pub unsafe fn futex_wake(futex: *mut u32) -> Result<Bool, Errno> {
    let mut rp0 = MaybeUninit::<Bool>::uninit();
    let ret = wasix_32v1::futex_wake(futex as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Bool)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Wake up all threads that are waiting on futex_wait on this futex.
///
/// ## Parameters
///
/// * `futex` - Memory location that holds a futex that others may be waiting on
pub unsafe fn futex_wake_all(futex: *mut u32) -> Result<Bool, Errno> {
    let mut rp0 = MaybeUninit::<Bool>::uninit();
    let ret = wasix_32v1::futex_wake_all(futex as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Bool)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Terminates the current running thread, if this is the last thread then
/// the process will also exit with the specified exit code. An exit code
/// of 0 indicates successful termination of the thread. The meanings of
/// other values is dependent on the environment.
///
/// ## Parameters
///
/// * `rval` - The exit code returned by the process.
pub unsafe fn thread_exit(rval: Exitcode) {
    wasix_32v1::thread_exit(rval as i32);
}

/// Creates a checkpoint of the current stack which allows it to be restored
/// later using its stack hash. The value supplied will be returned upon
/// restoration (and hence must be none zero) - zero will be returned when
/// the stack is first recorded.
///
/// This is used by `longjmp` and `setjmp`
///
/// This function will read the __stack_pointer global
///
/// ## Parameters
///
/// * `snapshot` - Reference to the stack snapshot that will be filled
///
/// ## Return
///
/// Returns zero upon registration and the value when restored
pub unsafe fn stack_checkpoint(snapshot: *mut StackSnapshot) -> Result<Longsize, Errno> {
    let mut rp0 = MaybeUninit::<Longsize>::uninit();
    let ret = wasix_32v1::stack_checkpoint(snapshot as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Longsize)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Restores the current stack to a previous stack described by supplying
/// stack snapshot.
///
/// This function will manipulate the __stack_pointer global
///
/// ## Parameters
///
/// * `snapshot` - Reference to the stack snapshot that will be restored
/// * `val` - Value to be returned when the stack is restored
///   (if zero this will change to one)
pub unsafe fn stack_restore(snapshot: *const StackSnapshot, val: Longsize) {
    wasix_32v1::stack_restore(snapshot as i32, val as i64);
}

/// Open a file or directory.
/// The returned file descriptor is not guaranteed to be the lowest-numbered
/// file descriptor not currently open; it is randomized to prevent
/// applications from depending on making assumptions about indexes, since this
/// is error-prone in multi-threaded contexts. The returned file descriptor is
/// guaranteed to be less than 2**31.
/// Note: This is similar to `openat` in POSIX.
/// Recreated in WASIX from the original WASI function to add support for
/// fdflagsext.
///
/// ## Parameters
///
/// * `dirflags` - Flags determining the method of how the path is resolved.
/// * `path` - The relative path of the file or directory to open, relative to the
///   `path_open::fd` directory.
/// * `oflags` - The method by which to open the file.
/// * `fs_rights_base` - The initial rights of the newly created file descriptor. The
///   implementation is allowed to return a file descriptor with fewer rights
///   than specified, if and only if those rights do not apply to the type of
///   file being opened.
///   The *base* rights are rights that will apply to operations using the file
///   descriptor itself, while the *inheriting* rights are rights that apply to
///   file descriptors derived from it.
///
/// ## Return
///
/// The file descriptor of the file that has been opened.
pub unsafe fn path_open2(
    fd: Fd,
    dirflags: Lookupflags,
    path: &str,
    oflags: Oflags,
    fs_rights_base: Rights,
    fs_rights_inheriting: Rights,
    fdflags: Fdflags,
    fdflagsext: Fdflagsext,
) -> Result<Fd, Errno> {
    let mut rp0 = MaybeUninit::<Fd>::uninit();
    let ret = wasix_32v1::path_open2(
        fd as i32,
        dirflags as i32,
        path.as_ptr() as i32,
        path.len() as i32,
        oflags as i32,
        fs_rights_base as i64,
        fs_rights_inheriting as i64,
        fdflags as i32,
        fdflagsext as i32,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fd)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Get the FD flags of a file descriptor (fdflagsext).
/// Note: This returns similar flags to `fsync(fd, F_GETFD)` in POSIX.
///
/// ## Return
///
/// The buffer where the file descriptor's attributes are stored.
pub unsafe fn fd_fdflags_get(fd: Fd) -> Result<Fdflagsext, Errno> {
    let mut rp0 = MaybeUninit::<Fdflagsext>::uninit();
    let ret = wasix_32v1::fd_fdflags_get(fd as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fdflagsext)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Adjust the FD flags associated with a file descriptor.
/// Note: This is similar to `fcntl(fd, F_SETFD, flags)` in POSIX.
///
/// ## Parameters
///
/// * `flags` - The desired values of the file descriptor flags.
pub unsafe fn fd_fdflags_set(fd: Fd, flags: Fdflagsext) -> Result<(), Errno> {
    let ret = wasix_32v1::fd_fdflags_set(fd as i32, flags as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Send a signal to the process of the calling thread on a regular basis
/// Note: This is similar to `setitimer` in POSIX.
///
/// ## Parameters
///
/// * `sig` - The signal condition to trigger.
/// * `interval` - Time to wait before raising the signal
///   (zero here indicates the signal interval is cancelled)
/// * `repeat` - Flag that indicates if the signal will trigger indefinately
pub unsafe fn proc_raise_interval(
    sig: Signal,
    interval: Timestamp,
    repeat: Bool,
) -> Result<(), Errno> {
    let ret = wasix_32v1::proc_raise_interval(sig.0 as i32, interval as i64, repeat.0 as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Forks the current process into a new subprocess. If the function
/// returns a zero then its the new subprocess. If it returns a positive
/// number then its the current process and the $pid represents the child.
///
/// ## Parameters
///
/// * `copy_memory` - Indicates if the memory will be copied into the new process
///   (if it is not copied this then becomes similar to `vfork` in
///    that the current process pauses until `proc_exec` is called)
pub unsafe fn proc_fork(copy_memory: Bool) -> Result<Pid, Errno> {
    let mut rp0 = MaybeUninit::<Pid>::uninit();
    let ret = wasix_32v1::proc_fork(copy_memory.0 as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Pid)),
        _ => Err(Errno(ret as u16)),
    }
}

/// execv()  executes  the  program  referred to by pathname.  This causes the
/// program that is currently being run by the calling process to  be  replaced
/// with  a  new  program, with newly initialized stack, heap, and (initialized
/// and uninitialized) data segments
///
/// If the named process does not exist then the process will fail and terminate
///
/// ## Parameters
///
/// * `name` - Name of the process to be spawned
/// * `args` - List of the arguments to pass the process
///   (entries are separated by line feeds)
pub unsafe fn proc_exec(name: &str, args: &str) {
    wasix_32v1::proc_exec(
        name.as_ptr() as i32,
        name.len() as i32,
        args.as_ptr() as i32,
        args.len() as i32,
    );
}

/// execve()  executes  the  program  referred to by pathname.  This causes the
/// program that is currently being run by the calling process to  be  replaced
/// with  a  new  program, with newly initialized stack, heap, and (initialized
/// and uninitialized) data segments
///
/// If the named process does not exist then the process will fail and terminate
///
/// ## Parameters
///
/// * `name` - Name of the process to be spawned
/// * `args` - List of the arguments to pass the process
///   (entries are separated by line feeds)
/// * `envs` - List of the env vars to pass the process
///   (entries are separated by line feeds)
pub unsafe fn proc_exec2(name: &str, args: &str, envs: &str) {
    wasix_32v1::proc_exec2(
        name.as_ptr() as i32,
        name.len() as i32,
        args.as_ptr() as i32,
        args.len() as i32,
        envs.as_ptr() as i32,
        envs.len() as i32,
    );
}

/// execve()  executes  the  program  referred to by pathname.  This causes the
/// program that is currently being run by the calling process to  be  replaced
/// with  a  new  program, with newly initialized stack, heap, and (initialized
/// and uninitialized) data segments.
///
/// If the named process does not exist an error will be returned.
///
/// ## Parameters
///
/// * `name` - Name of the process to be spawned
/// * `args` - List of the arguments to pass the process
///   (entries are separated by line feeds)
/// * `envs` - List of the env vars to pass the process
///   (entries are separated by line feeds)
/// * `search_path` - Whether to search for the file in PATH.
/// * `path` - The current value of the PATH env var.
///
/// ## Return
///
/// If the named process does not exist an error will be returned.
pub unsafe fn proc_exec3(
    name: &str,
    args: &str,
    envs: &str,
    search_path: Bool,
    path: &str,
) -> Result<(), Errno> {
    let ret = wasix_32v1::proc_exec3(
        name.as_ptr() as i32,
        name.len() as i32,
        args.as_ptr() as i32,
        args.len() as i32,
        envs.as_ptr() as i32,
        envs.len() as i32,
        search_path.0 as i32,
        path.as_ptr() as i32,
        path.len() as i32,
    );
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Spawns a new process within the context of the parent process
/// (i.e. this process). It inherits the filesystem and sandbox
/// permissions but runs standalone.
///
/// ## Parameters
///
/// * `name` - Name of the process to be spawned
/// * `chroot` - Indicates if the process will chroot or not
/// * `args` - List of the arguments to pass the process
///   (entries are separated by line feeds)
/// * `preopen` - List of the preopens for this process
///   (entries are separated by line feeds)
/// * `stdin` - How will stdin be handled
/// * `stdout` - How will stdout be handled
/// * `stderr` - How will stderr be handled
/// * `working_dir` - Working directory where this process should run
///   (passing '.' will use the current directory)
///
/// ## Return
///
/// Returns a bus process id that can be used to invoke calls
pub unsafe fn proc_spawn(
    name: &str,
    chroot: Bool,
    args: &str,
    preopen: &str,
    stdin: StdioMode,
    stdout: StdioMode,
    stderr: StdioMode,
    working_dir: &str,
) -> Result<ProcessHandles, Errno> {
    let mut rp0 = MaybeUninit::<ProcessHandles>::uninit();
    let ret = wasix_32v1::proc_spawn(
        name.as_ptr() as i32,
        name.len() as i32,
        chroot.0 as i32,
        args.as_ptr() as i32,
        args.len() as i32,
        preopen.as_ptr() as i32,
        preopen.len() as i32,
        stdin.0 as i32,
        stdout.0 as i32,
        stderr.0 as i32,
        working_dir.as_ptr() as i32,
        working_dir.len() as i32,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(
            rp0.as_mut_ptr() as i32 as *const ProcessHandles
        )),
        _ => Err(Errno(ret as u16)),
    }
}

/// Spawns a new process within the context of the parent process
/// (i.e. this process). It inherits the filesystem and sandbox
/// permissions but runs standalone.
///
/// ## Parameters
///
/// * `name` - Name of the process to be spawned
/// * `args` - List of the arguments to pass the process
///   (entries are separated by line feeds)
/// * `envs` - List of the env vars to pass the process
///   (entries are separated by line feeds)
/// * `fd_ops` - List of FD operations to perform before
///   spawning the new process.
/// * `signal_dispositions` - List of signal dispositions to override
///   for the new process.
/// * `search_path` - Whether to search for the file in PATH.
/// * `path` - The current value of the PATH env var.
///
/// ## Return
///
/// If the named process does not exist an error will be returned.
pub unsafe fn proc_spawn2(
    name: &str,
    args: &str,
    envs: &str,
    fd_ops: ProcSpawnFdOpArray<'_>,
    signal_dispositions: SignalDispositionArray<'_>,
    search_path: Bool,
    path: &str,
) -> Result<Pid, Errno> {
    let mut rp0 = MaybeUninit::<Pid>::uninit();
    let ret = wasix_32v1::proc_spawn2(
        name.as_ptr() as i32,
        name.len() as i32,
        args.as_ptr() as i32,
        args.len() as i32,
        envs.as_ptr() as i32,
        envs.len() as i32,
        fd_ops.as_ptr() as i32,
        fd_ops.len() as i32,
        signal_dispositions.as_ptr() as i32,
        signal_dispositions.len() as i32,
        search_path.0 as i32,
        path.as_ptr() as i32,
        path.len() as i32,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Pid)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Returns the handle of the current process
pub unsafe fn proc_id() -> Result<Pid, Errno> {
    let mut rp0 = MaybeUninit::<Pid>::uninit();
    let ret = wasix_32v1::proc_id(rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Pid)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Returns the parent handle of a particular process
///
/// ## Parameters
///
/// * `pid` - Handle of the process to get the parent handle for
pub unsafe fn proc_parent(pid: Pid) -> Result<Pid, Errno> {
    let mut rp0 = MaybeUninit::<Pid>::uninit();
    let ret = wasix_32v1::proc_parent(pid as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Pid)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Wait for process to exit
///
/// Passing none to PID will mean that the call will wait
/// for any subprocess to exit. PID will be populated with
/// the process that exited.
///
/// ## Parameters
///
/// * `pid` - ID of the process to wait on
/// * `flags` - Flags that determine how the join behaves
///
/// ## Return
///
/// Returns the status of the process
pub unsafe fn proc_join(pid: *mut OptionPid, flags: JoinFlags) -> Result<JoinStatus, Errno> {
    let mut rp0 = MaybeUninit::<JoinStatus>::uninit();
    let ret = wasix_32v1::proc_join(pid as i32, flags as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const JoinStatus)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Sends a signal to another process
///
/// ## Parameters
///
/// * `pid` - ID of the process to send a singal
/// * `signal` - Signal to send to the thread
pub unsafe fn proc_signal(pid: Pid, signal: Signal) -> Result<(), Errno> {
    let ret = wasix_32v1::proc_signal(pid as i32, signal.0 as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Read host-provided signal dispositions.
/// The size of the array should match that returned by `proc_signals_sizes_get`.
pub unsafe fn proc_signals_get(buf: *mut u8) -> Result<(), Errno> {
    let ret = wasix_32v1::proc_signals_get(buf as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Return host-provided signal count.
///
/// ## Return
///
/// Returns the number of signal dispositions, or an error.
pub unsafe fn proc_signals_sizes_get() -> Result<Size, Errno> {
    let mut rp0 = MaybeUninit::<Size>::uninit();
    let ret = wasix_32v1::proc_signals_sizes_get(rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Explicitly requests for the runtime to create a
/// snapshot of the guest module's state.
pub unsafe fn proc_snapshot() -> Result<(), Errno> {
    let ret = wasix_32v1::proc_snapshot();
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Securely connects to a particular remote network
///
/// ## Parameters
///
/// * `network` - Fully qualified identifier for the network
/// * `token` - Access token used to authenticate with the network
/// * `security` - Level of encryption to encapsulate the network connection with
pub unsafe fn port_bridge(
    network: &str,
    token: &str,
    security: StreamSecurity,
) -> Result<(), Errno> {
    let ret = wasix_32v1::port_bridge(
        network.as_ptr() as i32,
        network.len() as i32,
        token.as_ptr() as i32,
        token.len() as i32,
        security as i32,
    );
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Disconnects from a remote network
pub unsafe fn port_unbridge() -> Result<(), Errno> {
    let ret = wasix_32v1::port_unbridge();
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Acquires a set of addresses using DHCP
pub unsafe fn port_dhcp_acquire() -> Result<(), Errno> {
    let ret = wasix_32v1::port_dhcp_acquire();
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Adds another static address to the local port
///
/// ## Parameters
///
/// * `addr` - Address to be added
pub unsafe fn port_addr_add(addr: *const AddrCidr) -> Result<(), Errno> {
    let ret = wasix_32v1::port_addr_add(addr as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Removes an address from the local port
///
/// ## Parameters
///
/// * `addr` - Address to be removed
pub unsafe fn port_addr_remove(addr: *const Addr) -> Result<(), Errno> {
    let ret = wasix_32v1::port_addr_remove(addr as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Clears all the addresses on the local port
pub unsafe fn port_addr_clear() -> Result<(), Errno> {
    let ret = wasix_32v1::port_addr_clear();
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Returns the MAC address of the local port
pub unsafe fn port_mac() -> Result<HardwareAddress, Errno> {
    let mut rp0 = MaybeUninit::<HardwareAddress>::uninit();
    let ret = wasix_32v1::port_mac(rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(
            rp0.as_mut_ptr() as i32 as *const HardwareAddress
        )),
        _ => Err(Errno(ret as u16)),
    }
}

/// Returns a list of all the addresses owned by the local port
///
/// This function fills the output buffer as much as possible.
/// If the buffer is not big enough then the naddrs address will be
/// filled with the buffer size needed and the EOVERFLOW will be returned
///
/// ## Parameters
///
/// * `addrs` - The buffer where addresses will be stored
///
/// ## Return
///
/// The number of addresses returned.
pub unsafe fn port_addr_list(addrs: *mut AddrCidr, naddrs: *mut Size) -> Result<(), Errno> {
    let ret = wasix_32v1::port_addr_list(addrs as i32, naddrs as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Adds a default gateway to the local port
///
/// ## Parameters
///
/// * `addr` - Address of the default gateway
pub unsafe fn port_gateway_set(addr: *const Addr) -> Result<(), Errno> {
    let ret = wasix_32v1::port_gateway_set(addr as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Adds a new route to the local port
pub unsafe fn port_route_add(
    cidr: *const AddrCidr,
    via_router: *const Addr,
    preferred_until: *const OptionTimestamp,
    expires_at: *const OptionTimestamp,
) -> Result<(), Errno> {
    let ret = wasix_32v1::port_route_add(
        cidr as i32,
        via_router as i32,
        preferred_until as i32,
        expires_at as i32,
    );
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Removes an existing route from the local port
pub unsafe fn port_route_remove(cidr: *const Addr) -> Result<(), Errno> {
    let ret = wasix_32v1::port_route_remove(cidr as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Clears all the routes in the local port
pub unsafe fn port_route_clear() -> Result<(), Errno> {
    let ret = wasix_32v1::port_route_clear();
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Returns a list of all the routes owned by the local port
/// This function fills the output buffer as much as possible.
/// If the buffer is too small this will return EOVERFLOW and
/// fill nroutes with the size of the buffer needed.
///
/// ## Parameters
///
/// * `routes` - The buffer where routes will be stored
pub unsafe fn port_route_list(routes: *mut Route, nroutes: *mut Size) -> Result<(), Errno> {
    let ret = wasix_32v1::port_route_list(routes as i32, nroutes as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Returns the current status of a socket
pub unsafe fn sock_status(fd: Fd) -> Result<SockStatus, Errno> {
    let mut rp0 = MaybeUninit::<SockStatus>::uninit();
    let ret = wasix_32v1::sock_status(fd as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const SockStatus)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Returns the local address to which the socket is bound.
///
/// Note: This is similar to `getsockname` in POSIX
///
/// When successful, the contents of the output buffer consist of an IP address,
/// either IP4 or IP6.
///
/// ## Parameters
///
/// * `fd` - Socket that the address is bound to
pub unsafe fn sock_addr_local(fd: Fd) -> Result<AddrPort, Errno> {
    let mut rp0 = MaybeUninit::<AddrPort>::uninit();
    let ret = wasix_32v1::sock_addr_local(fd as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const AddrPort)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Returns the remote address to which the socket is connected to.
///
/// Note: This is similar to `getpeername` in POSIX
///
/// When successful, the contents of the output buffer consist of an IP address,
/// either IP4 or IP6.
///
/// ## Parameters
///
/// * `fd` - Socket that the address is bound to
pub unsafe fn sock_addr_peer(fd: Fd) -> Result<AddrPort, Errno> {
    let mut rp0 = MaybeUninit::<AddrPort>::uninit();
    let ret = wasix_32v1::sock_addr_peer(fd as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const AddrPort)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Create an endpoint for communication.
///
/// creates an endpoint for communication and returns a file descriptor
/// tor that refers to that endpoint. The file descriptor returned by a successful
/// call will be the lowest-numbered file descriptor not currently open
/// for the process.
///
/// Note: This is similar to `socket` in POSIX using PF_INET
///
/// ## Parameters
///
/// * `af` - Address family
/// * `socktype` - Socket type, either datagram or stream
/// * `sock_proto` - Socket protocol
///
/// ## Return
///
/// The file descriptor of the socket that has been opened.
pub unsafe fn sock_open(
    af: AddressFamily,
    socktype: SockType,
    sock_proto: SockProto,
) -> Result<Fd, Errno> {
    let mut rp0 = MaybeUninit::<Fd>::uninit();
    let ret = wasix_32v1::sock_open(
        af.0 as i32,
        socktype.0 as i32,
        sock_proto.0 as i32,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fd)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Create a pair of interconnected sockets.
///
/// creates a pair of interconnected sockets and returns both file
/// descriptors. The file descriptors returned by a successful
/// call will be the lowest-numbered file descriptors not currently open
/// for the process.
///
/// Note: This is similar to `socketpair` in POSIX using PF_INET
///
/// ## Parameters
///
/// * `af` - Address family
/// * `socktype` - Socket type, either datagram or stream
/// * `sock_proto` - Socket protocol
///
/// ## Return
///
/// The file descriptors of the sockets that have been opened.
pub unsafe fn sock_pair(
    af: AddressFamily,
    socktype: SockType,
    sock_proto: SockProto,
) -> Result<(Fd, Fd), Errno> {
    let mut rp0 = MaybeUninit::<Fd>::uninit();
    let mut rp1 = MaybeUninit::<Fd>::uninit();
    let ret = wasix_32v1::sock_pair(
        af.0 as i32,
        socktype.0 as i32,
        sock_proto.0 as i32,
        rp0.as_mut_ptr() as i32,
        rp1.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok((
            core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fd),
            core::ptr::read(rp1.as_mut_ptr() as i32 as *const Fd),
        )),
        _ => Err(Errno(ret as u16)),
    }
}

/// Sets a particular socket setting
/// Note: This is similar to `setsockopt` in POSIX for SO_REUSEADDR
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `sockopt` - Socket option to be set
/// * `flag` - Value to set the option to
pub unsafe fn sock_set_opt_flag(fd: Fd, sockopt: SockOption, flag: Bool) -> Result<(), Errno> {
    let ret = wasix_32v1::sock_set_opt_flag(fd as i32, sockopt.0 as i32, flag.0 as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Retrieve status of particular socket seting
/// Note: This is similar to `getsockopt` in POSIX for SO_REUSEADDR
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `sockopt` - Socket option to be retrieved
pub unsafe fn sock_get_opt_flag(fd: Fd, sockopt: SockOption) -> Result<Bool, Errno> {
    let mut rp0 = MaybeUninit::<Bool>::uninit();
    let ret = wasix_32v1::sock_get_opt_flag(fd as i32, sockopt.0 as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Bool)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Sets one of the times the socket
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `sockopt` - Socket option to be set
/// * `timeout` - Value to set the time to
pub unsafe fn sock_set_opt_time(
    fd: Fd,
    sockopt: SockOption,
    timeout: *const OptionTimestamp,
) -> Result<(), Errno> {
    let ret = wasix_32v1::sock_set_opt_time(fd as i32, sockopt.0 as i32, timeout as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Retrieve one of the times on the socket
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `sockopt` - Socket option to be retrieved
pub unsafe fn sock_get_opt_time(fd: Fd, sockopt: SockOption) -> Result<OptionTimestamp, Errno> {
    let mut rp0 = MaybeUninit::<OptionTimestamp>::uninit();
    let ret = wasix_32v1::sock_get_opt_time(fd as i32, sockopt.0 as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(
            rp0.as_mut_ptr() as i32 as *const OptionTimestamp
        )),
        _ => Err(Errno(ret as u16)),
    }
}

/// Set size of particular option for this socket
/// Note: This is similar to `setsockopt` in POSIX for SO_RCVBUF
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `sockopt` - Socket option to be set
/// * `size` - Buffer size
pub unsafe fn sock_set_opt_size(fd: Fd, sockopt: SockOption, size: Filesize) -> Result<(), Errno> {
    let ret = wasix_32v1::sock_set_opt_size(fd as i32, sockopt.0 as i32, size as i64);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Retrieve the size of particular option for this socket
/// Note: This is similar to `getsockopt` in POSIX for SO_RCVBUF
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `sockopt` - Socket option to be retrieved
pub unsafe fn sock_get_opt_size(fd: Fd, sockopt: SockOption) -> Result<Filesize, Errno> {
    let mut rp0 = MaybeUninit::<Filesize>::uninit();
    let ret = wasix_32v1::sock_get_opt_size(fd as i32, sockopt.0 as i32, rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Filesize)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Joins a particular multicast IPv4 group
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `multiaddr` - Multicast group to joined
/// * `interface` - Interface that will join
pub unsafe fn sock_join_multicast_v4(
    fd: Fd,
    multiaddr: *const AddrIp4,
    interface: *const AddrIp4,
) -> Result<(), Errno> {
    let ret = wasix_32v1::sock_join_multicast_v4(fd as i32, multiaddr as i32, interface as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Leaves a particular multicast IPv4 group
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `multiaddr` - Multicast group to leave
/// * `interface` - Interface that will left
pub unsafe fn sock_leave_multicast_v4(
    fd: Fd,
    multiaddr: *const AddrIp4,
    interface: *const AddrIp4,
) -> Result<(), Errno> {
    let ret = wasix_32v1::sock_leave_multicast_v4(fd as i32, multiaddr as i32, interface as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Joins a particular multicast IPv6 group
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `multiaddr` - Multicast group to joined
/// * `interface` - Interface that will join
pub unsafe fn sock_join_multicast_v6(
    fd: Fd,
    multiaddr: *const AddrIp6,
    interface: u32,
) -> Result<(), Errno> {
    let ret = wasix_32v1::sock_join_multicast_v6(fd as i32, multiaddr as i32, interface as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Leaves a particular multicast IPv6 group
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `multiaddr` - Multicast group to leave
/// * `interface` - Interface that will left
pub unsafe fn sock_leave_multicast_v6(
    fd: Fd,
    multiaddr: *const AddrIp6,
    interface: u32,
) -> Result<(), Errno> {
    let ret = wasix_32v1::sock_leave_multicast_v6(fd as i32, multiaddr as i32, interface as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Bind a socket
/// Note: This is similar to `bind` in POSIX using PF_INET
///
/// ## Parameters
///
/// * `fd` - File descriptor of the socket to be bind
/// * `addr` - Address to bind the socket to
pub unsafe fn sock_bind(fd: Fd, addr: *const AddrPort) -> Result<(), Errno> {
    let ret = wasix_32v1::sock_bind(fd as i32, addr as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Listen for connections on a socket
///
/// Polling the socket handle will wait until a connection
/// attempt is made
///
/// Note: This is similar to `listen`
///
/// ## Parameters
///
/// * `fd` - File descriptor of the socket to be bind
/// * `backlog` - Maximum size of the queue for pending connections
pub unsafe fn sock_listen(fd: Fd, backlog: Size) -> Result<(), Errno> {
    let ret = wasix_32v1::sock_listen(fd as i32, backlog as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Accept a new incoming connection.
/// Note: This is similar to `accept` in POSIX.
///
/// ## Parameters
///
/// * `fd` - The listening socket.
/// * `flags` - The desired values of the file descriptor flags.
///
/// ## Return
///
/// New socket connection
pub unsafe fn sock_accept_v2(fd: Fd, flags: Fdflags) -> Result<(Fd, AddrPort), Errno> {
    let mut rp0 = MaybeUninit::<Fd>::uninit();
    let mut rp1 = MaybeUninit::<AddrPort>::uninit();
    let ret = wasix_32v1::sock_accept_v2(
        fd as i32,
        flags as i32,
        rp0.as_mut_ptr() as i32,
        rp1.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok((
            core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fd),
            core::ptr::read(rp1.as_mut_ptr() as i32 as *const AddrPort),
        )),
        _ => Err(Errno(ret as u16)),
    }
}

/// Initiate a connection on a socket to the specified address
///
/// Polling the socket handle will wait for data to arrive or for
/// the socket status to change which can be queried via 'sock_status'
///
/// Note: This is similar to `connect` in POSIX
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `addr` - Address of the socket to connect to
pub unsafe fn sock_connect(fd: Fd, addr: *const AddrPort) -> Result<(), Errno> {
    let ret = wasix_32v1::sock_connect(fd as i32, addr as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Receive a message and its peer address from a socket.
/// Note: This is similar to `recvfrom` in POSIX, though it also supports reading
/// the data into multiple buffers in the manner of `readv`.
///
/// ## Parameters
///
/// * `ri_data` - List of scatter/gather vectors to which to store data.
/// * `ri_flags` - Message flags.
///
/// ## Return
///
/// Number of bytes stored in ri_data and message flags.
pub unsafe fn sock_recv_from(
    fd: Fd,
    ri_data: IovecArray<'_>,
    ri_flags: Riflags,
) -> Result<(Size, Roflags, AddrPort), Errno> {
    let mut rp0 = MaybeUninit::<Size>::uninit();
    let mut rp1 = MaybeUninit::<Roflags>::uninit();
    let mut rp2 = MaybeUninit::<AddrPort>::uninit();
    let ret = wasix_32v1::sock_recv_from(
        fd as i32,
        ri_data.as_ptr() as i32,
        ri_data.len() as i32,
        ri_flags as i32,
        rp0.as_mut_ptr() as i32,
        rp1.as_mut_ptr() as i32,
        rp2.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok((
            core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size),
            core::ptr::read(rp1.as_mut_ptr() as i32 as *const Roflags),
            core::ptr::read(rp2.as_mut_ptr() as i32 as *const AddrPort),
        )),
        _ => Err(Errno(ret as u16)),
    }
}

/// Send a message on a socket to a specific address.
/// Note: This is similar to `sendto` in POSIX, though it also supports writing
/// the data from multiple buffers in the manner of `writev`.
///
/// ## Parameters
///
/// * `si_data` - List of scatter/gather vectors to which to retrieve data
/// * `si_flags` - Message flags.
/// * `addr` - Address of the socket to send message to
///
/// ## Return
///
/// Number of bytes transmitted.
pub unsafe fn sock_send_to(
    fd: Fd,
    si_data: CiovecArray<'_>,
    si_flags: Siflags,
    addr: *const AddrPort,
) -> Result<Size, Errno> {
    let mut rp0 = MaybeUninit::<Size>::uninit();
    let ret = wasix_32v1::sock_send_to(
        fd as i32,
        si_data.as_ptr() as i32,
        si_data.len() as i32,
        si_flags as i32,
        addr as i32,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Sends the entire contents of a file down a socket
///
/// ## Parameters
///
/// * `in_fd` - Open file that has the data to be transmitted
/// * `offset` - Offset into the file to start reading at
/// * `count` - Number of bytes to be sent
///
/// ## Return
///
/// Number of bytes transmitted.
pub unsafe fn sock_send_file(
    out_fd: Fd,
    in_fd: Fd,
    offset: Filesize,
    count: Filesize,
) -> Result<Filesize, Errno> {
    let mut rp0 = MaybeUninit::<Filesize>::uninit();
    let ret = wasix_32v1::sock_send_file(
        out_fd as i32,
        in_fd as i32,
        offset as i64,
        count as i64,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Filesize)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Resolves a hostname and a port to one or more IP addresses.
///
/// Note: This is similar to `getaddrinfo` in POSIX
///
/// When successful, the contents of the output buffer consist of a sequence of
/// IPv4 and/or IPv6 addresses. Each address entry consists of a addr_t object.
/// This function fills the output buffer as much as possible.
///
/// ## Parameters
///
/// * `host` - Host to resolve
/// * `port` - Port hint (zero if no hint is supplied)
/// * `addrs` - The buffer where addresses will be stored
///
/// ## Return
///
/// The number of IP addresses returned during the DNS resolution.
pub unsafe fn resolve(
    host: &str,
    port: u16,
    addrs: *mut AddrIp,
    naddrs: Size,
) -> Result<Size, Errno> {
    let mut rp0 = MaybeUninit::<Size>::uninit();
    let ret = wasix_32v1::resolve(
        host.as_ptr() as i32,
        host.len() as i32,
        port as i32,
        addrs as i32,
        naddrs as i32,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Create an epoll interest list
///
///
/// ## Return
///
/// The file descriptor for this epoll interest list
pub unsafe fn epoll_create() -> Result<Fd, Errno> {
    let mut rp0 = MaybeUninit::<Fd>::uninit();
    let ret = wasix_32v1::epoll_create(rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fd)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Modifies an epoll interest list
///
///
/// ## Parameters
///
/// * `epfd` - File descriptor of the epoll interest list
/// * `op` - Operation to be made on the list
/// * `fd` - File descriptor to be added, deleted or modified
/// * `event` - Reference to the event to be added, deleted or modified
///
/// ## Return
///
/// The number of bytes written.
pub unsafe fn epoll_ctl(
    epfd: Fd,
    op: EpollCtl,
    fd: Fd,
    event: *const EpollEvent,
) -> Result<(), Errno> {
    let ret = wasix_32v1::epoll_ctl(epfd as i32, op.0 as i32, fd as i32, event as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// wait for an I/O event on an epoll file descriptor
///
///
/// ## Parameters
///
/// * `epfd` - File descriptor of the epoll interest list
/// * `event` - Reference to the array of events
/// * `maxevents` - Maximum number of events that will be returned in the array
/// * `timeout` - Timeout for the wait event
///
/// ## Return
///
/// The number of events returned.
pub unsafe fn epoll_wait(
    epfd: Fd,
    event: *mut EpollEvent,
    maxevents: Size,
    timeout: Timestamp,
) -> Result<Size, Errno> {
    let mut rp0 = MaybeUninit::<Size>::uninit();
    let ret = wasix_32v1::epoll_wait(
        epfd as i32,
        event as i32,
        maxevents as i32,
        timeout as i64,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Close a dynamically-linked module.
///
pub unsafe fn dl_invalid_handle(handle: DlHandle) -> Result<(), Errno> {
    let ret = wasix_32v1::dl_invalid_handle(handle as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Open a dynamically-linked module.
///
pub unsafe fn dlopen(
    path: &str,
    flags: DlFlags,
    err_buf: *mut u8,
    err_buf_len: Size,
    ld_library_path: &str,
) -> Result<DlHandle, Errno> {
    let mut rp0 = MaybeUninit::<DlHandle>::uninit();
    let ret = wasix_32v1::dlopen(
        path.as_ptr() as i32,
        path.len() as i32,
        flags as i32,
        err_buf as i32,
        err_buf_len as i32,
        ld_library_path.as_ptr() as i32,
        ld_library_path.len() as i32,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const DlHandle)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Load a symbol from a dynamically-linked module.
///
pub unsafe fn dlsym(
    handle: DlHandle,
    symbol: &str,
    err_buf: *mut u8,
    err_buf_len: Size,
) -> Result<Size, Errno> {
    let mut rp0 = MaybeUninit::<Size>::uninit();
    let ret = wasix_32v1::dlsym(
        handle as i32,
        symbol.as_ptr() as i32,
        symbol.len() as i32,
        err_buf as i32,
        err_buf_len as i32,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
        _ => Err(Errno(ret as u16)),
    }
}

/// Call a function pointer with dynamic parameters.
///
/// ## Parameters
///
/// * `function_id` - An index into the __indirect_function_table
///   
///   Your module needs to either import or export the table to be able
///   to call this function.
/// * `values` - A buffer with the parameters to pass to the function.
///   This buffer is expected to contain all parameters sequentially
///   
///   For example if the function takes an i32 and an i64, the
///   buffer will be 12 bytes long, with the first 4 bytes
///   being the i32 and the next 8 bytes being the i64.
/// * `results` - A pointer to a buffer for the results of the function call.
///   
///   In most cases this will be a single value, but it could also
///   contain multiple values. The same rules apply as for the
///   parameters, i.e. the buffer needs to be large enough
///   to hold all the results sequentially.
/// * `strict` -
///   If this is set to true, the function will return an error if the
///   length and types of the parameters and results do not match the
///   function signature.
///   
///   If this is set to false, the function will not perform any checks.
///   Any missing bytes will be assumed to be zero and any extra bytes
///   will be ignored.
pub unsafe fn call_dynamic(
    function_id: FunctionPointer,
    values: &[u8],
    results: *mut u8,
    results_len: Pointersize,
    strict: Bool,
) -> Result<(), Errno> {
    let ret = wasix_32v1::call_dynamic(
        function_id as i32,
        values.as_ptr() as i32,
        values.len() as i32,
        results as i32,
        results_len as i32,
        strict.0 as i32,
    );
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Prepare a closure for execution.
///
/// ## Parameters
///
/// * `backing_function_id` - A index into the indirect function table that points to the function that will be called when the closure is executed.
///   
///   That function needs to conform to the following signature:
///     uint8_t* values - a pointer to a buffer containing the arguments. See call_dynamic for more details.
///     uint8_t* results - a pointer to a buffer where the results will be written. See call_dynamic for more details.
///     void* user_data_ptr - the user_data_ptr that was passed to closure_prepare
/// * `closure_id` - An index into the indirect function table that was previously allocated with closure_alloc
///   
///   After closure_prepare the slot in the indirect function table will contain a funcref to a closure with the requested signature.
///   Every call to the closure will be translated to a call to the backing function.
/// * `argument_types` - A list of types of the arguments that the closure will take.
/// * `result_types` - A list of types that the closure will return.
/// * `user_data_ptr` - A pointer to a buffer that will be passed to the closure when it is executed.
pub unsafe fn closure_prepare(
    backing_function_id: FunctionPointer,
    closure_id: FunctionPointer,
    argument_types: WasmValueTypeArray<'_>,
    result_types: WasmValueTypeArray<'_>,
    user_data_ptr: *mut u8,
) -> Result<(), Errno> {
    let ret = wasix_32v1::closure_prepare(
        backing_function_id as i32,
        closure_id as i32,
        argument_types.as_ptr() as i32,
        argument_types.len() as i32,
        result_types.as_ptr() as i32,
        result_types.len() as i32,
        user_data_ptr as i32,
    );
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Allocate a closure for use with the closure_prepare function.
pub unsafe fn closure_allocate() -> Result<FunctionPointer, Errno> {
    let mut rp0 = MaybeUninit::<FunctionPointer>::uninit();
    let ret = wasix_32v1::closure_allocate(rp0.as_mut_ptr() as i32);
    match ret {
        0 => Ok(core::ptr::read(
            rp0.as_mut_ptr() as i32 as *const FunctionPointer
        )),
        _ => Err(Errno(ret as u16)),
    }
}

/// Free a closure that was previously allocated with closure_allocate.
///
/// After this call it is undefined what happens when you call the funcref at the index specified by closure_id.
///
/// ## Parameters
///
/// * `closure_id` - An index into the indirect function table that was previously allocated with closure_allocate
pub unsafe fn closure_free(closure_id: FunctionPointer) -> Result<(), Errno> {
    let ret = wasix_32v1::closure_free(closure_id as i32);
    match ret {
        0 => Ok(()),
        _ => Err(Errno(ret as u16)),
    }
}

/// Provides information about the signature of a function in the indirect
/// function table at runtime.
///
/// ### Errors
///
/// Besides the standard error codes, `reflect_signature` may set `errno` to the
/// following errors:
///
/// - EINVAL: The function pointer is not valid, i.e. it does not point to a
/// function in the indirect function table or the function has a unsupported
/// signature. The sizes in the result are undefined in this case.
///
/// - EOVERFLOW: The argument_types and result_types buffers were not big enough
/// to hold the signature. They will be left unchanged. The reflection result
/// will be valid.
///
/// ## Parameters
///
/// * `function_id` - An index into the indirect function table.
///   
///   If there is no function at the requested slot, `EINVAL` will be returned.
/// * `argument_types` - A buffer for a list of types that the function takes as arguments.
///   
///   - If the buffer is too small to hold all argument types, it and
///   `result_types` remain untouched, and `EOVERFLOW` is returned.
///   - If the buffer is big enough, the types will be written to the buffer.
///   - If the buffer is too big, all remaining bytes will be unchanged.
///   
///   If the `argument_types_len` is 0 this buffer is never accessed and can be
///   null.
/// * `argument_types_len` - Size of the buffer for argument types.
/// * `result_types` - A buffer for a list of types that the function returns as results.
///   
///   - If the buffer is too small to hold all argument types, it and
///   `argument_types` remain untouched, and `EOVERFLOW` is returned.
///   - If  the buffer is big enough, the types will be written to the buffer.
///   - If the buffer is too big, all remaining bytes will be unchanged.
///   
///   If the `result_types_len` is 0 this buffer is never accessed and can be
///   null.
/// * `result_types_len` - Size of the buffer for result types.
///
/// ## Return
///
/// The number of arguments and results and whether this result is cacheable.
pub unsafe fn reflect_signature(
    function_id: FunctionPointer,
    argument_types: *mut WasmValueType,
    argument_types_len: u16,
    result_types: *mut WasmValueType,
    result_types_len: u16,
) -> Result<ReflectionResult, Errno> {
    let mut rp0 = MaybeUninit::<ReflectionResult>::uninit();
    let ret = wasix_32v1::reflect_signature(
        function_id as i32,
        argument_types as i32,
        argument_types_len as i32,
        result_types as i32,
        result_types_len as i32,
        rp0.as_mut_ptr() as i32,
    );
    match ret {
        0 => Ok(core::ptr::read(
            rp0.as_mut_ptr() as i32 as *const ReflectionResult
        )),
        _ => Err(Errno(ret as u16)),
    }
}

pub mod wasix_32v1 {
    #[link(wasm_import_module = "wasix_32v1")]
    extern "C" {
        /// Sets the time value of a clock.
        /// Note: This is similar to `clock_settime` in POSIX.
        pub fn clock_time_set(arg0: i32, arg1: i64) -> i32;
        /// Atomically duplicate a file handle.
        pub fn fd_dup(arg0: i32, arg1: i32) -> i32;
        /// Atomically duplicate a file handle.
        pub fn fd_dup2(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
        /// Creates a file handle for event notifications
        ///
        pub fn fd_event(arg0: i64, arg1: i32, arg2: i32) -> i32;
        /// Opens a pipe with two file handles
        ///
        /// Pipes are bidirectional
        pub fn fd_pipe(arg0: i32, arg1: i32) -> i32;
        /// Retrieves the current state of the TTY
        pub fn tty_get(arg0: i32) -> i32;
        /// Updates the properties of the the TTY
        pub fn tty_set(arg0: i32) -> i32;
        /// Returns the current working directory
        ///
        /// If the path exceeds the size of the buffer then this function
        /// will fill the path_len with the needed size and return EOVERFLOW
        pub fn getcwd(arg0: i32, arg1: i32) -> i32;
        /// Sets the current working directory
        pub fn chdir(arg0: i32, arg1: i32) -> i32;
        /// Registers a callback function for signals
        pub fn callback_signal(arg0: i32, arg1: i32);
        /// Creates a new thread by spawning that shares the same
        /// memory address space, file handles and main event loops.
        /// The web assembly process must export function named 'wasi_thread_start'
        pub fn thread_spawn_v2(arg0: i32, arg1: i32) -> i32;
        /// Sends the current thread to sleep for a period of time
        pub fn thread_sleep(arg0: i64) -> i32;
        /// Returns the index of the current thread
        /// (threads indices are sequential from zero while the
        ///  main thread ID equals the process ID)
        pub fn thread_id(arg0: i32) -> i32;
        /// Joins this thread with another thread, blocking this
        /// one until the other finishes
        pub fn thread_join(arg0: i32) -> i32;
        /// Returns the available parallelism which is normally the
        /// number of available cores that can run concurrently
        pub fn thread_parallelism(arg0: i32) -> i32;
        /// Sends a signal to a specific thread
        pub fn thread_signal(arg0: i32, arg1: i32) -> i32;
        /// Wait for a futex_wake operation to wake us.
        ///
        /// Returns with EINVAL if the futex doesn't hold the expected value.
        /// Returns false on timeout, and true in all other cases.
        pub fn futex_wait(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
        /// Wake up one thread that's blocked on futex_wait on this futex.
        ///
        /// Returns true if this actually woke up such a thread,
        /// or false if no thread was waiting on this futex.
        pub fn futex_wake(arg0: i32, arg1: i32) -> i32;
        /// Wake up all threads that are waiting on futex_wait on this futex.
        pub fn futex_wake_all(arg0: i32, arg1: i32) -> i32;
        /// Terminates the current running thread, if this is the last thread then
        /// the process will also exit with the specified exit code. An exit code
        /// of 0 indicates successful termination of the thread. The meanings of
        /// other values is dependent on the environment.
        pub fn thread_exit(arg0: i32) -> !;
        /// Creates a checkpoint of the current stack which allows it to be restored
        /// later using its stack hash. The value supplied will be returned upon
        /// restoration (and hence must be none zero) - zero will be returned when
        /// the stack is first recorded.
        ///
        /// This is used by `longjmp` and `setjmp`
        ///
        /// This function will read the __stack_pointer global
        pub fn stack_checkpoint(arg0: i32, arg1: i32) -> i32;
        /// Restores the current stack to a previous stack described by supplying
        /// stack snapshot.
        ///
        /// This function will manipulate the __stack_pointer global
        pub fn stack_restore(arg0: i32, arg1: i64) -> !;
        /// Open a file or directory.
        /// The returned file descriptor is not guaranteed to be the lowest-numbered
        /// file descriptor not currently open; it is randomized to prevent
        /// applications from depending on making assumptions about indexes, since this
        /// is error-prone in multi-threaded contexts. The returned file descriptor is
        /// guaranteed to be less than 2**31.
        /// Note: This is similar to `openat` in POSIX.
        /// Recreated in WASIX from the original WASI function to add support for
        /// fdflagsext.
        pub fn path_open2(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i64,
            arg6: i64,
            arg7: i32,
            arg8: i32,
            arg9: i32,
        ) -> i32;
        /// Get the FD flags of a file descriptor (fdflagsext).
        /// Note: This returns similar flags to `fsync(fd, F_GETFD)` in POSIX.
        pub fn fd_fdflags_get(arg0: i32, arg1: i32) -> i32;
        /// Adjust the FD flags associated with a file descriptor.
        /// Note: This is similar to `fcntl(fd, F_SETFD, flags)` in POSIX.
        pub fn fd_fdflags_set(arg0: i32, arg1: i32) -> i32;
        /// Send a signal to the process of the calling thread on a regular basis
        /// Note: This is similar to `setitimer` in POSIX.
        pub fn proc_raise_interval(arg0: i32, arg1: i64, arg2: i32) -> i32;
        /// Forks the current process into a new subprocess. If the function
        /// returns a zero then its the new subprocess. If it returns a positive
        /// number then its the current process and the $pid represents the child.
        pub fn proc_fork(arg0: i32, arg1: i32) -> i32;
        /// execv()  executes  the  program  referred to by pathname.  This causes the
        /// program that is currently being run by the calling process to  be  replaced
        /// with  a  new  program, with newly initialized stack, heap, and (initialized
        /// and uninitialized) data segments
        ///
        /// If the named process does not exist then the process will fail and terminate
        pub fn proc_exec(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> !;
        /// execve()  executes  the  program  referred to by pathname.  This causes the
        /// program that is currently being run by the calling process to  be  replaced
        /// with  a  new  program, with newly initialized stack, heap, and (initialized
        /// and uninitialized) data segments
        ///
        /// If the named process does not exist then the process will fail and terminate
        pub fn proc_exec2(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32, arg5: i32) -> !;
        /// execve()  executes  the  program  referred to by pathname.  This causes the
        /// program that is currently being run by the calling process to  be  replaced
        /// with  a  new  program, with newly initialized stack, heap, and (initialized
        /// and uninitialized) data segments.
        ///
        /// If the named process does not exist an error will be returned.
        pub fn proc_exec3(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
            arg6: i32,
            arg7: i32,
            arg8: i32,
        ) -> i32;
        /// Spawns a new process within the context of the parent process
        /// (i.e. this process). It inherits the filesystem and sandbox
        /// permissions but runs standalone.
        pub fn proc_spawn(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
            arg6: i32,
            arg7: i32,
            arg8: i32,
            arg9: i32,
            arg10: i32,
            arg11: i32,
            arg12: i32,
        ) -> i32;
        /// Spawns a new process within the context of the parent process
        /// (i.e. this process). It inherits the filesystem and sandbox
        /// permissions but runs standalone.
        pub fn proc_spawn2(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
            arg6: i32,
            arg7: i32,
            arg8: i32,
            arg9: i32,
            arg10: i32,
            arg11: i32,
            arg12: i32,
            arg13: i32,
        ) -> i32;
        /// Returns the handle of the current process
        pub fn proc_id(arg0: i32) -> i32;
        /// Returns the parent handle of a particular process
        pub fn proc_parent(arg0: i32, arg1: i32) -> i32;
        /// Wait for process to exit
        ///
        /// Passing none to PID will mean that the call will wait
        /// for any subprocess to exit. PID will be populated with
        /// the process that exited.
        pub fn proc_join(arg0: i32, arg1: i32, arg2: i32) -> i32;
        /// Sends a signal to another process
        pub fn proc_signal(arg0: i32, arg1: i32) -> i32;
        /// Read host-provided signal dispositions.
        /// The size of the array should match that returned by `proc_signals_sizes_get`.
        pub fn proc_signals_get(arg0: i32) -> i32;
        /// Return host-provided signal count.
        pub fn proc_signals_sizes_get(arg0: i32) -> i32;
        /// Explicitly requests for the runtime to create a
        /// snapshot of the guest module's state.
        pub fn proc_snapshot() -> i32;
        /// Securely connects to a particular remote network
        pub fn port_bridge(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32) -> i32;
        /// Disconnects from a remote network
        pub fn port_unbridge() -> i32;
        /// Acquires a set of addresses using DHCP
        pub fn port_dhcp_acquire() -> i32;
        /// Adds another static address to the local port
        pub fn port_addr_add(arg0: i32) -> i32;
        /// Removes an address from the local port
        pub fn port_addr_remove(arg0: i32) -> i32;
        /// Clears all the addresses on the local port
        pub fn port_addr_clear() -> i32;
        /// Returns the MAC address of the local port
        pub fn port_mac(arg0: i32) -> i32;
        /// Returns a list of all the addresses owned by the local port
        ///
        /// This function fills the output buffer as much as possible.
        /// If the buffer is not big enough then the naddrs address will be
        /// filled with the buffer size needed and the EOVERFLOW will be returned
        pub fn port_addr_list(arg0: i32, arg1: i32) -> i32;
        /// Adds a default gateway to the local port
        pub fn port_gateway_set(arg0: i32) -> i32;
        /// Adds a new route to the local port
        pub fn port_route_add(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
        /// Removes an existing route from the local port
        pub fn port_route_remove(arg0: i32) -> i32;
        /// Clears all the routes in the local port
        pub fn port_route_clear() -> i32;
        /// Returns a list of all the routes owned by the local port
        /// This function fills the output buffer as much as possible.
        /// If the buffer is too small this will return EOVERFLOW and
        /// fill nroutes with the size of the buffer needed.
        pub fn port_route_list(arg0: i32, arg1: i32) -> i32;
        /// Returns the current status of a socket
        pub fn sock_status(arg0: i32, arg1: i32) -> i32;
        /// Returns the local address to which the socket is bound.
        ///
        /// Note: This is similar to `getsockname` in POSIX
        ///
        /// When successful, the contents of the output buffer consist of an IP address,
        /// either IP4 or IP6.
        pub fn sock_addr_local(arg0: i32, arg1: i32) -> i32;
        /// Returns the remote address to which the socket is connected to.
        ///
        /// Note: This is similar to `getpeername` in POSIX
        ///
        /// When successful, the contents of the output buffer consist of an IP address,
        /// either IP4 or IP6.
        pub fn sock_addr_peer(arg0: i32, arg1: i32) -> i32;
        /// Create an endpoint for communication.
        ///
        /// creates an endpoint for communication and returns a file descriptor
        /// tor that refers to that endpoint. The file descriptor returned by a successful
        /// call will be the lowest-numbered file descriptor not currently open
        /// for the process.
        ///
        /// Note: This is similar to `socket` in POSIX using PF_INET
        pub fn sock_open(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
        /// Create a pair of interconnected sockets.
        ///
        /// creates a pair of interconnected sockets and returns both file
        /// descriptors. The file descriptors returned by a successful
        /// call will be the lowest-numbered file descriptors not currently open
        /// for the process.
        ///
        /// Note: This is similar to `socketpair` in POSIX using PF_INET
        pub fn sock_pair(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32) -> i32;
        /// Sets a particular socket setting
        /// Note: This is similar to `setsockopt` in POSIX for SO_REUSEADDR
        pub fn sock_set_opt_flag(arg0: i32, arg1: i32, arg2: i32) -> i32;
        /// Retrieve status of particular socket seting
        /// Note: This is similar to `getsockopt` in POSIX for SO_REUSEADDR
        pub fn sock_get_opt_flag(arg0: i32, arg1: i32, arg2: i32) -> i32;
        /// Sets one of the times the socket
        pub fn sock_set_opt_time(arg0: i32, arg1: i32, arg2: i32) -> i32;
        /// Retrieve one of the times on the socket
        pub fn sock_get_opt_time(arg0: i32, arg1: i32, arg2: i32) -> i32;
        /// Set size of particular option for this socket
        /// Note: This is similar to `setsockopt` in POSIX for SO_RCVBUF
        pub fn sock_set_opt_size(arg0: i32, arg1: i32, arg2: i64) -> i32;
        /// Retrieve the size of particular option for this socket
        /// Note: This is similar to `getsockopt` in POSIX for SO_RCVBUF
        pub fn sock_get_opt_size(arg0: i32, arg1: i32, arg2: i32) -> i32;
        /// Joins a particular multicast IPv4 group
        pub fn sock_join_multicast_v4(arg0: i32, arg1: i32, arg2: i32) -> i32;
        /// Leaves a particular multicast IPv4 group
        pub fn sock_leave_multicast_v4(arg0: i32, arg1: i32, arg2: i32) -> i32;
        /// Joins a particular multicast IPv6 group
        pub fn sock_join_multicast_v6(arg0: i32, arg1: i32, arg2: i32) -> i32;
        /// Leaves a particular multicast IPv6 group
        pub fn sock_leave_multicast_v6(arg0: i32, arg1: i32, arg2: i32) -> i32;
        /// Bind a socket
        /// Note: This is similar to `bind` in POSIX using PF_INET
        pub fn sock_bind(arg0: i32, arg1: i32) -> i32;
        /// Listen for connections on a socket
        ///
        /// Polling the socket handle will wait until a connection
        /// attempt is made
        ///
        /// Note: This is similar to `listen`
        pub fn sock_listen(arg0: i32, arg1: i32) -> i32;
        /// Accept a new incoming connection.
        /// Note: This is similar to `accept` in POSIX.
        pub fn sock_accept_v2(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
        /// Initiate a connection on a socket to the specified address
        ///
        /// Polling the socket handle will wait for data to arrive or for
        /// the socket status to change which can be queried via 'sock_status'
        ///
        /// Note: This is similar to `connect` in POSIX
        pub fn sock_connect(arg0: i32, arg1: i32) -> i32;
        /// Receive a message and its peer address from a socket.
        /// Note: This is similar to `recvfrom` in POSIX, though it also supports reading
        /// the data into multiple buffers in the manner of `readv`.
        pub fn sock_recv_from(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
            arg6: i32,
        ) -> i32;
        /// Send a message on a socket to a specific address.
        /// Note: This is similar to `sendto` in POSIX, though it also supports writing
        /// the data from multiple buffers in the manner of `writev`.
        pub fn sock_send_to(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
        ) -> i32;
        /// Sends the entire contents of a file down a socket
        pub fn sock_send_file(arg0: i32, arg1: i32, arg2: i64, arg3: i64, arg4: i32) -> i32;
        /// Resolves a hostname and a port to one or more IP addresses.
        ///
        /// Note: This is similar to `getaddrinfo` in POSIX
        ///
        /// When successful, the contents of the output buffer consist of a sequence of
        /// IPv4 and/or IPv6 addresses. Each address entry consists of a addr_t object.
        /// This function fills the output buffer as much as possible.
        pub fn resolve(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32, arg5: i32) -> i32;
        /// Create an epoll interest list
        ///
        pub fn epoll_create(arg0: i32) -> i32;
        /// Modifies an epoll interest list
        ///
        pub fn epoll_ctl(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
        /// wait for an I/O event on an epoll file descriptor
        ///
        pub fn epoll_wait(arg0: i32, arg1: i32, arg2: i32, arg3: i64, arg4: i32) -> i32;
        /// Close a dynamically-linked module.
        ///
        pub fn dl_invalid_handle(arg0: i32) -> i32;
        /// Open a dynamically-linked module.
        ///
        pub fn dlopen(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
            arg6: i32,
            arg7: i32,
        ) -> i32;
        /// Load a symbol from a dynamically-linked module.
        ///
        pub fn dlsym(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32, arg5: i32) -> i32;
        /// Call a function pointer with dynamic parameters.
        pub fn call_dynamic(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
        ) -> i32;
        /// Prepare a closure for execution.
        pub fn closure_prepare(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
            arg6: i32,
        ) -> i32;
        /// Allocate a closure for use with the closure_prepare function.
        pub fn closure_allocate(arg0: i32) -> i32;
        /// Free a closure that was previously allocated with closure_allocate.
        ///
        /// After this call it is undefined what happens when you call the funcref at the index specified by closure_id.
        pub fn closure_free(arg0: i32) -> i32;
        /// Provides information about the signature of a function in the indirect
        /// function table at runtime.
        ///
        /// ### Errors
        ///
        /// Besides the standard error codes, `reflect_signature` may set `errno` to the
        /// following errors:
        ///
        /// - EINVAL: The function pointer is not valid, i.e. it does not point to a
        /// function in the indirect function table or the function has a unsupported
        /// signature. The sizes in the result are undefined in this case.
        ///
        /// - EOVERFLOW: The argument_types and result_types buffers were not big enough
        /// to hold the signature. They will be left unchanged. The reflection result
        /// will be valid.
        pub fn reflect_signature(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
        ) -> i32;
    }
}