-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
solaris.zig
1928 lines (1757 loc) · 48 KB
/
solaris.zig
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
const std = @import("../std.zig");
const builtin = @import("builtin");
const maxInt = std.math.maxInt;
const iovec = std.os.iovec;
const iovec_const = std.os.iovec_const;
const timezone = std.c.timezone;
extern "c" fn ___errno() *c_int;
pub const _errno = ___errno;
pub const dl_iterate_phdr_callback = switch (builtin.zig_backend) {
.stage1 => fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int,
else => *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int,
};
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
pub extern "c" fn sysconf(sc: c_int) i64;
pub extern "c" fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) c_int;
pub extern "c" fn madvise(address: [*]u8, len: usize, advise: u32) c_int;
pub const pthread_mutex_t = extern struct {
flag1: u16 = 0,
flag2: u8 = 0,
ceiling: u8 = 0,
@"type": u16 = 0,
magic: u16 = 0x4d58,
lock: u64 = 0,
data: u64 = 0,
};
pub const pthread_cond_t = extern struct {
flag: [4]u8 = [_]u8{0} ** 4,
@"type": u16 = 0,
magic: u16 = 0x4356,
data: u64 = 0,
};
pub const pthread_rwlock_t = extern struct {
readers: i32 = 0,
@"type": u16 = 0,
magic: u16 = 0x5257,
mutex: pthread_mutex_t = .{},
readercv: pthread_cond_t = .{},
writercv: pthread_cond_t = .{},
};
pub const pthread_attr_t = extern struct {
mutexattr: ?*anyopaque = null,
};
pub const pthread_key_t = c_int;
pub const sem_t = extern struct {
count: u32 = 0,
@"type": u16 = 0,
magic: u16 = 0x534d,
__pad1: [3]u64 = [_]u64{0} ** 3,
__pad2: [2]u64 = [_]u64{0} ** 2,
};
pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) E;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
pub const blkcnt_t = i64;
pub const blksize_t = i32;
pub const clock_t = i64;
pub const dev_t = i32;
pub const fd_t = c_int;
pub const gid_t = u32;
pub const ino_t = u64;
pub const mode_t = u32;
pub const nlink_t = u32;
pub const off_t = i64;
pub const pid_t = i32;
pub const socklen_t = u32;
pub const time_t = i64;
pub const suseconds_t = i64;
pub const uid_t = u32;
pub const major_t = u32;
pub const minor_t = u32;
pub const port_t = c_int;
pub const nfds_t = usize;
pub const id_t = i32;
pub const taskid_t = id_t;
pub const projid_t = id_t;
pub const poolid_t = id_t;
pub const zoneid_t = id_t;
pub const ctid_t = id_t;
pub const dl_phdr_info = extern struct {
dlpi_addr: std.elf.Addr,
dlpi_name: ?[*:0]const u8,
dlpi_phdr: [*]std.elf.Phdr,
dlpi_phnum: std.elf.Half,
/// Incremented when a new object is mapped into the process.
dlpi_adds: u64,
/// Incremented when an object is unmapped from the process.
dlpi_subs: u64,
};
pub const RTLD = struct {
pub const LAZY = 0x00001;
pub const NOW = 0x00002;
pub const NOLOAD = 0x00004;
pub const GLOBAL = 0x00100;
pub const LOCAL = 0x00000;
pub const PARENT = 0x00200;
pub const GROUP = 0x00400;
pub const WORLD = 0x00800;
pub const NODELETE = 0x01000;
pub const FIRST = 0x02000;
pub const CONFGEN = 0x10000;
pub const NEXT = @intToPtr(*anyopaque, @bitCast(usize, @as(isize, -1)));
pub const DEFAULT = @intToPtr(*anyopaque, @bitCast(usize, @as(isize, -2)));
pub const SELF = @intToPtr(*anyopaque, @bitCast(usize, @as(isize, -3)));
pub const PROBE = @intToPtr(*anyopaque, @bitCast(usize, @as(isize, -4)));
};
pub const Flock = extern struct {
type: c_short,
whence: c_short,
start: off_t,
// len == 0 means until end of file.
len: off_t,
sysid: c_int,
pid: pid_t,
__pad: [4]c_long,
};
pub const utsname = extern struct {
sysname: [256:0]u8,
nodename: [256:0]u8,
release: [256:0]u8,
version: [256:0]u8,
machine: [256:0]u8,
domainname: [256:0]u8,
};
pub const addrinfo = extern struct {
flags: i32,
family: i32,
socktype: i32,
protocol: i32,
addrlen: socklen_t,
canonname: ?[*:0]u8,
addr: ?*sockaddr,
next: ?*addrinfo,
};
pub const EAI = enum(c_int) {
/// address family for hostname not supported
ADDRFAMILY = 1,
/// name could not be resolved at this time
AGAIN = 2,
/// flags parameter had an invalid value
BADFLAGS = 3,
/// non-recoverable failure in name resolution
FAIL = 4,
/// address family not recognized
FAMILY = 5,
/// memory allocation failure
MEMORY = 6,
/// no address associated with hostname
NODATA = 7,
/// name does not resolve
NONAME = 8,
/// service not recognized for socket type
SERVICE = 9,
/// intended socket type was not recognized
SOCKTYPE = 10,
/// system error returned in errno
SYSTEM = 11,
/// argument buffer overflow
OVERFLOW = 12,
/// resolved protocol is unknown
PROTOCOL = 13,
_,
};
pub const EAI_MAX = 14;
pub const msghdr = extern struct {
/// optional address
msg_name: ?*sockaddr,
/// size of address
msg_namelen: socklen_t,
/// scatter/gather array
msg_iov: [*]iovec,
/// # elements in msg_iov
msg_iovlen: i32,
/// ancillary data
msg_control: ?*anyopaque,
/// ancillary data buffer len
msg_controllen: socklen_t,
/// flags on received message
msg_flags: i32,
};
pub const msghdr_const = extern struct {
/// optional address
msg_name: ?*const sockaddr,
/// size of address
msg_namelen: socklen_t,
/// scatter/gather array
msg_iov: [*]const iovec_const,
/// # elements in msg_iov
msg_iovlen: i32,
/// ancillary data
msg_control: ?*const anyopaque,
/// ancillary data buffer len
msg_controllen: socklen_t,
/// flags on received message
msg_flags: i32,
};
pub const cmsghdr = extern struct {
cmsg_len: socklen_t,
cmsg_level: i32,
cmsg_type: i32,
};
/// The stat structure used by libc.
pub const Stat = extern struct {
dev: dev_t,
ino: ino_t,
mode: mode_t,
nlink: nlink_t,
uid: uid_t,
gid: gid_t,
rdev: dev_t,
size: off_t,
atim: timespec,
mtim: timespec,
ctim: timespec,
blksize: blksize_t,
blocks: blkcnt_t,
fstype: [16]u8,
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};
pub const timespec = extern struct {
tv_sec: i64,
tv_nsec: isize,
};
pub const timeval = extern struct {
/// seconds
tv_sec: time_t,
/// microseconds
tv_usec: suseconds_t,
};
pub const MAXNAMLEN = 511;
pub const dirent = extern struct {
/// Inode number of entry.
d_ino: ino_t,
/// Offset of this entry on disk.
d_off: off_t,
/// Length of this record.
d_reclen: u16,
/// File name.
d_name: [MAXNAMLEN:0]u8,
pub fn reclen(self: dirent) u16 {
return self.d_reclen;
}
};
pub const SOCK = struct {
/// Datagram.
pub const DGRAM = 1;
/// STREAM.
pub const STREAM = 2;
/// Raw-protocol interface.
pub const RAW = 4;
/// Reliably-delivered message.
pub const RDM = 5;
/// Sequenced packed stream.
pub const SEQPACKET = 6;
pub const NONBLOCK = 0x100000;
pub const NDELAY = 0x200000;
pub const CLOEXEC = 0x080000;
};
pub const SO = struct {
pub const DEBUG = 0x0001;
pub const ACCEPTCONN = 0x0002;
pub const REUSEADDR = 0x0004;
pub const KEEPALIVE = 0x0008;
pub const DONTROUTE = 0x0010;
pub const BROADCAST = 0x0020;
pub const USELOOPBACK = 0x0040;
pub const LINGER = 0x0080;
pub const OOBINLINE = 0x0100;
pub const DGRAM_ERRIND = 0x0200;
pub const RECVUCRED = 0x0400;
pub const SNDBUF = 0x1001;
pub const RCVBUF = 0x1002;
pub const SNDLOWAT = 0x1003;
pub const RCVLOWAT = 0x1004;
pub const SNDTIMEO = 0x1005;
pub const RCVTIMEO = 0x1006;
pub const ERROR = 0x1007;
pub const TYPE = 0x1008;
pub const PROTOTYPE = 0x1009;
pub const ANON_MLP = 0x100a;
pub const MAC_EXEMPT = 0x100b;
pub const DOMAIN = 0x100c;
pub const RCVPSH = 0x100d;
pub const SECATTR = 0x1011;
pub const TIMESTAMP = 0x1013;
pub const ALLZONES = 0x1014;
pub const EXCLBIND = 0x1015;
pub const MAC_IMPLICIT = 0x1016;
pub const VRRP = 0x1017;
};
pub const SOMAXCONN = 128;
pub const SCM = struct {
pub const UCRED = 0x1012;
pub const RIGHTS = 0x1010;
pub const TIMESTAMP = SO.TIMESTAMP;
};
pub const AF = struct {
pub const UNSPEC = 0;
pub const UNIX = 1;
pub const LOCAL = UNIX;
pub const FILE = UNIX;
pub const INET = 2;
pub const IMPLINK = 3;
pub const PUP = 4;
pub const CHAOS = 5;
pub const NS = 6;
pub const NBS = 7;
pub const ECMA = 8;
pub const DATAKIT = 9;
pub const CCITT = 10;
pub const SNA = 11;
pub const DECnet = 12;
pub const DLI = 13;
pub const LAT = 14;
pub const HYLINK = 15;
pub const APPLETALK = 16;
pub const NIT = 17;
pub const @"802" = 18;
pub const OSI = 19;
pub const X25 = 20;
pub const OSINET = 21;
pub const GOSIP = 22;
pub const IPX = 23;
pub const ROUTE = 24;
pub const LINK = 25;
pub const INET6 = 26;
pub const KEY = 27;
pub const NCA = 28;
pub const POLICY = 29;
pub const INET_OFFLOAD = 30;
pub const TRILL = 31;
pub const PACKET = 32;
pub const LX_NETLINK = 33;
pub const MAX = 33;
};
pub const SOL = struct {
pub const SOCKET = 0xffff;
pub const ROUTE = 0xfffe;
pub const PACKET = 0xfffd;
pub const FILTER = 0xfffc;
};
pub const PF = struct {
pub const UNSPEC = AF.UNSPEC;
pub const UNIX = AF.UNIX;
pub const LOCAL = UNIX;
pub const FILE = UNIX;
pub const INET = AF.INET;
pub const IMPLINK = AF.IMPLINK;
pub const PUP = AF.PUP;
pub const CHAOS = AF.CHAOS;
pub const NS = AF.NS;
pub const NBS = AF.NBS;
pub const ECMA = AF.ECMA;
pub const DATAKIT = AF.DATAKIT;
pub const CCITT = AF.CCITT;
pub const SNA = AF.SNA;
pub const DECnet = AF.DECnet;
pub const DLI = AF.DLI;
pub const LAT = AF.LAT;
pub const HYLINK = AF.HYLINK;
pub const APPLETALK = AF.APPLETALK;
pub const NIT = AF.NIT;
pub const @"802" = AF.@"802";
pub const OSI = AF.OSI;
pub const X25 = AF.X25;
pub const OSINET = AF.OSINET;
pub const GOSIP = AF.GOSIP;
pub const IPX = AF.IPX;
pub const ROUTE = AF.ROUTE;
pub const LINK = AF.LINK;
pub const INET6 = AF.INET6;
pub const KEY = AF.KEY;
pub const NCA = AF.NCA;
pub const POLICY = AF.POLICY;
pub const TRILL = AF.TRILL;
pub const PACKET = AF.PACKET;
pub const LX_NETLINK = AF.LX_NETLINK;
pub const MAX = AF.MAX;
};
pub const in_port_t = u16;
pub const sa_family_t = u16;
pub const sockaddr = extern struct {
/// address family
family: sa_family_t,
/// actually longer; address value
data: [14]u8,
pub const SS_MAXSIZE = 256;
pub const storage = std.x.os.Socket.Address.Native.Storage;
pub const in = extern struct {
family: sa_family_t = AF.INET,
port: in_port_t,
addr: u32,
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
};
pub const in6 = extern struct {
family: sa_family_t = AF.INET6,
port: in_port_t,
flowinfo: u32,
addr: [16]u8,
scope_id: u32,
__src_id: u32 = 0,
};
/// Definitions for UNIX IPC domain.
pub const un = extern struct {
family: sa_family_t = AF.UNIX,
path: [108]u8,
};
};
pub const AI = struct {
/// IPv4-mapped IPv6 address
pub const V4MAPPED = 0x0001;
pub const ALL = 0x0002;
/// only if any address is assigned
pub const ADDRCONFIG = 0x0004;
/// get address to use bind()
pub const PASSIVE = 0x0008;
/// fill ai_canonname
pub const CANONNAME = 0x0010;
/// prevent host name resolution
pub const NUMERICHOST = 0x0020;
/// prevent service name resolution
pub const NUMERICSERV = 0x0040;
};
pub const NI = struct {
pub const NOFQDN = 0x0001;
pub const NUMERICHOST = 0x0002;
pub const NAMEREQD = 0x0004;
pub const NUMERICSERV = 0x0008;
pub const DGRAM = 0x0010;
pub const WITHSCOPEID = 0x0020;
pub const NUMERICSCOPE = 0x0040;
pub const MAXHOST = 1025;
pub const MAXSERV = 32;
};
pub const PATH_MAX = 1024;
pub const IOV_MAX = 1024;
pub const STDIN_FILENO = 0;
pub const STDOUT_FILENO = 1;
pub const STDERR_FILENO = 2;
pub const PROT = struct {
pub const NONE = 0;
pub const READ = 1;
pub const WRITE = 2;
pub const EXEC = 4;
};
pub const CLOCK = struct {
pub const VIRTUAL = 1;
pub const THREAD_CPUTIME_ID = 2;
pub const REALTIME = 3;
pub const MONOTONIC = 4;
pub const PROCESS_CPUTIME_ID = 5;
pub const HIGHRES = MONOTONIC;
pub const PROF = THREAD_CPUTIME_ID;
};
pub const MAP = struct {
pub const FAILED = @intToPtr(*anyopaque, maxInt(usize));
pub const SHARED = 0x0001;
pub const PRIVATE = 0x0002;
pub const TYPE = 0x000f;
pub const FILE = 0x0000;
pub const FIXED = 0x0010;
// Unimplemented
pub const RENAME = 0x0020;
pub const NORESERVE = 0x0040;
/// Force mapping in lower 4G address space
pub const @"32BIT" = 0x0080;
pub const ANON = 0x0100;
pub const ANONYMOUS = ANON;
pub const ALIGN = 0x0200;
pub const TEXT = 0x0400;
pub const INITDATA = 0x0800;
};
pub const MSF = struct {
pub const ASYNC = 1;
pub const INVALIDATE = 2;
pub const SYNC = 4;
};
pub const MADV = struct {
/// no further special treatment
pub const NORMAL = 0;
/// expect random page references
pub const RANDOM = 1;
/// expect sequential page references
pub const SEQUENTIAL = 2;
/// will need these pages
pub const WILLNEED = 3;
/// don't need these pages
pub const DONTNEED = 4;
/// contents can be freed
pub const FREE = 5;
/// default access
pub const ACCESS_DEFAULT = 6;
/// next LWP to access heavily
pub const ACCESS_LWP = 7;
/// many processes to access heavily
pub const ACCESS_MANY = 8;
/// contents will be purged
pub const PURGE = 9;
};
pub const W = struct {
pub const EXITED = 0o001;
pub const TRAPPED = 0o002;
pub const UNTRACED = 0o004;
pub const STOPPED = UNTRACED;
pub const CONTINUED = 0o010;
pub const NOHANG = 0o100;
pub const NOWAIT = 0o200;
pub fn EXITSTATUS(s: u32) u8 {
return @intCast(u8, (s >> 8) & 0xff);
}
pub fn TERMSIG(s: u32) u32 {
return s & 0x7f;
}
pub fn STOPSIG(s: u32) u32 {
return EXITSTATUS(s);
}
pub fn IFEXITED(s: u32) bool {
return TERMSIG(s) == 0;
}
pub fn IFCONTINUED(s: u32) bool {
return ((s & 0o177777) == 0o177777);
}
pub fn IFSTOPPED(s: u32) bool {
return (s & 0x00ff != 0o177) and !(s & 0xff00 != 0);
}
pub fn IFSIGNALED(s: u32) bool {
return s & 0x00ff > 0 and s & 0xff00 == 0;
}
};
pub const SA = struct {
pub const ONSTACK = 0x00000001;
pub const RESETHAND = 0x00000002;
pub const RESTART = 0x00000004;
pub const SIGINFO = 0x00000008;
pub const NODEFER = 0x00000010;
pub const NOCLDWAIT = 0x00010000;
};
// access function
pub const F_OK = 0; // test for existence of file
pub const X_OK = 1; // test for execute or search permission
pub const W_OK = 2; // test for write permission
pub const R_OK = 4; // test for read permission
pub const F = struct {
/// Unlock a previously locked region
pub const ULOCK = 0;
/// Lock a region for exclusive use
pub const LOCK = 1;
/// Test and lock a region for exclusive use
pub const TLOCK = 2;
/// Test a region for other processes locks
pub const TEST = 3;
/// Duplicate fildes
pub const DUPFD = 0;
/// Get fildes flags
pub const GETFD = 1;
/// Set fildes flags
pub const SETFD = 2;
/// Get file flags
pub const GETFL = 3;
/// Get file flags including open-only flags
pub const GETXFL = 45;
/// Set file flags
pub const SETFL = 4;
/// Unused
pub const CHKFL = 8;
/// Duplicate fildes at third arg
pub const DUP2FD = 9;
/// Like DUP2FD with O_CLOEXEC set EINVAL is fildes matches arg1
pub const DUP2FD_CLOEXEC = 36;
/// Like DUPFD with O_CLOEXEC set
pub const DUPFD_CLOEXEC = 37;
/// Is the file desc. a stream ?
pub const ISSTREAM = 13;
/// Turn on private access to file
pub const PRIV = 15;
/// Turn off private access to file
pub const NPRIV = 16;
/// UFS quota call
pub const QUOTACTL = 17;
/// Get number of BLKSIZE blocks allocated
pub const BLOCKS = 18;
/// Get optimal I/O block size
pub const BLKSIZE = 19;
/// Get owner (socket emulation)
pub const GETOWN = 23;
/// Set owner (socket emulation)
pub const SETOWN = 24;
/// Object reuse revoke access to file desc.
pub const REVOKE = 25;
/// Does vp have NFS locks private to lock manager
pub const HASREMOTELOCKS = 26;
/// Set file lock
pub const SETLK = 6;
/// Set file lock and wait
pub const SETLKW = 7;
/// Allocate file space
pub const ALLOCSP = 10;
/// Free file space
pub const FREESP = 11;
/// Get file lock
pub const GETLK = 14;
/// Get file lock owned by file
pub const OFD_GETLK = 47;
/// Set file lock owned by file
pub const OFD_SETLK = 48;
/// Set file lock owned by file and wait
pub const OFD_SETLKW = 49;
/// Set a file share reservation
pub const SHARE = 40;
/// Remove a file share reservation
pub const UNSHARE = 41;
/// Create Poison FD
pub const BADFD = 46;
/// Read lock
pub const RDLCK = 1;
/// Write lock
pub const WRLCK = 2;
/// Remove lock(s)
pub const UNLCK = 3;
/// remove remote locks for a given system
pub const UNLKSYS = 4;
// f_access values
/// Read-only share access
pub const RDACC = 0x1;
/// Write-only share access
pub const WRACC = 0x2;
/// Read-Write share access
pub const RWACC = 0x3;
// f_deny values
/// Don't deny others access
pub const NODNY = 0x0;
/// Deny others read share access
pub const RDDNY = 0x1;
/// Deny others write share access
pub const WRDNY = 0x2;
/// Deny others read or write share access
pub const RWDNY = 0x3;
/// private flag: Deny delete share access
pub const RMDNY = 0x4;
};
pub const O = struct {
pub const RDONLY = 0;
pub const WRONLY = 1;
pub const RDWR = 2;
pub const SEARCH = 0x200000;
pub const EXEC = 0x400000;
pub const NDELAY = 0x04;
pub const APPEND = 0x08;
pub const SYNC = 0x10;
pub const DSYNC = 0x40;
pub const RSYNC = 0x8000;
pub const NONBLOCK = 0x80;
pub const LARGEFILE = 0x2000;
pub const CREAT = 0x100;
pub const TRUNC = 0x200;
pub const EXCL = 0x400;
pub const NOCTTY = 0x800;
pub const XATTR = 0x4000;
pub const NOFOLLOW = 0x20000;
pub const NOLINKS = 0x40000;
pub const CLOEXEC = 0x800000;
pub const DIRECTORY = 0x1000000;
pub const DIRECT = 0x2000000;
};
pub const LOCK = struct {
pub const SH = 1;
pub const EX = 2;
pub const NB = 4;
pub const UN = 8;
};
pub const FD_CLOEXEC = 1;
pub const SEEK = struct {
pub const SET = 0;
pub const CUR = 1;
pub const END = 2;
pub const DATA = 3;
pub const HOLE = 4;
};
pub const tcflag_t = c_uint;
pub const cc_t = u8;
pub const speed_t = c_uint;
pub const NCCS = 19;
pub const termios = extern struct {
c_iflag: tcflag_t,
c_oflag: tcflag_t,
c_cflag: tcflag_t,
c_lflag: tcflag_t,
c_cc: [NCCS]cc_t,
};
fn tioc(t: u16, num: u8) u16 {
return (t << 8) | num;
}
pub const T = struct {
pub const CGETA = tioc('T', 1);
pub const CSETA = tioc('T', 2);
pub const CSETAW = tioc('T', 3);
pub const CSETAF = tioc('T', 4);
pub const CSBRK = tioc('T', 5);
pub const CXONC = tioc('T', 6);
pub const CFLSH = tioc('T', 7);
pub const IOCGWINSZ = tioc('T', 104);
pub const IOCSWINSZ = tioc('T', 103);
// Softcarrier ioctls
pub const IOCGSOFTCAR = tioc('T', 105);
pub const IOCSSOFTCAR = tioc('T', 106);
// termios ioctls
pub const CGETS = tioc('T', 13);
pub const CSETS = tioc('T', 14);
pub const CSANOW = tioc('T', 14);
pub const CSETSW = tioc('T', 15);
pub const CSADRAIN = tioc('T', 15);
pub const CSETSF = tioc('T', 16);
pub const IOCSETLD = tioc('T', 123);
pub const IOCGETLD = tioc('T', 124);
// NTP PPS ioctls
pub const IOCGPPS = tioc('T', 125);
pub const IOCSPPS = tioc('T', 126);
pub const IOCGPPSEV = tioc('T', 127);
pub const IOCGETD = tioc('t', 0);
pub const IOCSETD = tioc('t', 1);
pub const IOCHPCL = tioc('t', 2);
pub const IOCGETP = tioc('t', 8);
pub const IOCSETP = tioc('t', 9);
pub const IOCSETN = tioc('t', 10);
pub const IOCEXCL = tioc('t', 13);
pub const IOCNXCL = tioc('t', 14);
pub const IOCFLUSH = tioc('t', 16);
pub const IOCSETC = tioc('t', 17);
pub const IOCGETC = tioc('t', 18);
/// bis local mode bits
pub const IOCLBIS = tioc('t', 127);
/// bic local mode bits
pub const IOCLBIC = tioc('t', 126);
/// set entire local mode word
pub const IOCLSET = tioc('t', 125);
/// get local modes
pub const IOCLGET = tioc('t', 124);
/// set break bit
pub const IOCSBRK = tioc('t', 123);
/// clear break bit
pub const IOCCBRK = tioc('t', 122);
/// set data terminal ready
pub const IOCSDTR = tioc('t', 121);
/// clear data terminal ready
pub const IOCCDTR = tioc('t', 120);
/// set local special chars
pub const IOCSLTC = tioc('t', 117);
/// get local special chars
pub const IOCGLTC = tioc('t', 116);
/// driver output queue size
pub const IOCOUTQ = tioc('t', 115);
/// void tty association
pub const IOCNOTTY = tioc('t', 113);
/// get a ctty
pub const IOCSCTTY = tioc('t', 132);
/// stop output, like ^S
pub const IOCSTOP = tioc('t', 111);
/// start output, like ^Q
pub const IOCSTART = tioc('t', 110);
/// get pgrp of tty
pub const IOCGPGRP = tioc('t', 20);
/// set pgrp of tty
pub const IOCSPGRP = tioc('t', 21);
/// get session id on ctty
pub const IOCGSID = tioc('t', 22);
/// simulate terminal input
pub const IOCSTI = tioc('t', 23);
/// set all modem bits
pub const IOCMSET = tioc('t', 26);
/// bis modem bits
pub const IOCMBIS = tioc('t', 27);
/// bic modem bits
pub const IOCMBIC = tioc('t', 28);
/// get all modem bits
pub const IOCMGET = tioc('t', 29);
};
pub const winsize = extern struct {
ws_row: u16,
ws_col: u16,
ws_xpixel: u16,
ws_ypixel: u16,
};
const NSIG = 75;
pub const SIG = struct {
pub const DFL = @intToPtr(?Sigaction.handler_fn, 0);
pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize));
pub const IGN = @intToPtr(?Sigaction.handler_fn, 1);
pub const HOLD = @intToPtr(?Sigaction.handler_fn, 2);
pub const WORDS = 4;
pub const MAXSIG = 75;
pub const SIG_BLOCK = 1;
pub const SIG_UNBLOCK = 2;
pub const SIG_SETMASK = 3;
pub const HUP = 1;
pub const INT = 2;
pub const QUIT = 3;
pub const ILL = 4;
pub const TRAP = 5;
pub const IOT = 6;
pub const ABRT = 6;
pub const EMT = 7;
pub const FPE = 8;
pub const KILL = 9;
pub const BUS = 10;
pub const SEGV = 11;
pub const SYS = 12;
pub const PIPE = 13;
pub const ALRM = 14;
pub const TERM = 15;
pub const USR1 = 16;
pub const USR2 = 17;
pub const CLD = 18;
pub const CHLD = 18;
pub const PWR = 19;
pub const WINCH = 20;
pub const URG = 21;
pub const POLL = 22;
pub const IO = .POLL;
pub const STOP = 23;
pub const TSTP = 24;
pub const CONT = 25;
pub const TTIN = 26;
pub const TTOU = 27;
pub const VTALRM = 28;
pub const PROF = 29;
pub const XCPU = 30;
pub const XFSZ = 31;
pub const WAITING = 32;
pub const LWP = 33;
pub const FREEZE = 34;
pub const THAW = 35;
pub const CANCEL = 36;
pub const LOST = 37;
pub const XRES = 38;
pub const JVM1 = 39;
pub const JVM2 = 40;
pub const INFO = 41;
pub const RTMIN = 42;
pub const RTMAX = 74;
pub inline fn IDX(sig: usize) usize {
return sig - 1;
}
pub inline fn WORD(sig: usize) usize {
return IDX(sig) >> 5;
}
pub inline fn BIT(sig: usize) usize {
return 1 << (IDX(sig) & 31);
}
pub inline fn VALID(sig: usize) usize {
return sig <= MAXSIG and sig > 0;
}
};
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
pub const handler_fn = switch (builtin.zig_backend) {
.stage1 => fn (c_int) callconv(.C) void,
else => *const fn (c_int) callconv(.C) void,
};
pub const sigaction_fn = switch (builtin.zig_backend) {
.stage1 => fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void,
else => *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void,
};
/// signal options
flags: c_uint,
/// signal handler
handler: extern union {
handler: ?handler_fn,
sigaction: ?sigaction_fn,
},
/// signal mask to apply
mask: sigset_t,
};
pub const sigval_t = extern union {
int: c_int,
ptr: ?*anyopaque,
};
pub const siginfo_t = extern struct {
signo: c_int,
code: c_int,
errno: c_int,
// 64bit architectures insert 4bytes of padding here, this is done by
// correctly aligning the reason field
reason: extern union {
proc: extern struct {
pid: pid_t,
pdata: extern union {
kill: extern struct {
uid: uid_t,
value: sigval_t,
},
cld: extern struct {
utime: clock_t,
status: c_int,
stime: clock_t,