authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-05-23 06:18:59+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-05-23 06:18:59+02:00
log6e30fc78328173215b27017d46fb6cc6add1222c
tree8e69187375214bae9960f48a018e2020b9b774f6
parent6e6df110279701807fcf8c7fe8a9be71a66ae070
parented4303fe59a1fd166ce88d1ad3253d4f8f919d0d
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Merge branch 'add-alpha-arch-linux'


10 files changed, 1631 insertions(+), 33 deletions(-)

lib/std/Thread.zig+2-2
......@@ -1217,8 +1217,8 @@ const LinuxThreadImpl = struct {
12171217 \\ ldi $16, 0
12181218 \\ callsys
12191219 :
1220 : [ptr] "{r16}" (@intFromPtr(self.mapped.ptr)),
1221 [len] "{r17}" (self.mapped.len),
1220 : [ptr] "{$16}" (@intFromPtr(self.mapped.ptr)),
1221 [len] "{$17}" (self.mapped.len),
12221222 ),
12231223 .hexagon => asm volatile (
12241224 \\ r6 = #215 // SYS_munmap
lib/std/debug/Dwarf.zig+3
......@@ -1436,6 +1436,7 @@ pub fn compactUnwindToDwarfRegNumber(unwind_reg_number: u3) !u16 {
14361436pub fn ipRegNum(arch: std.Target.Cpu.Arch) ?u16 {
14371437 return switch (arch) {
14381438 .aarch64, .aarch64_be => 32,
1439 .alpha => 64,
14391440 .arc, .arceb => 160,
14401441 .arm, .armeb, .thumb, .thumbeb => 15,
14411442 .csky => 64,
......@@ -1460,6 +1461,7 @@ pub fn ipRegNum(arch: std.Target.Cpu.Arch) ?u16 {
14601461pub fn fpRegNum(arch: std.Target.Cpu.Arch) u16 {
14611462 return switch (arch) {
14621463 .aarch64, .aarch64_be => 29,
1464 .alpha => 15,
14631465 .arc, .arceb => 27,
14641466 .arm, .armeb, .thumb, .thumbeb => 11,
14651467 .csky => 14,
......@@ -1484,6 +1486,7 @@ pub fn fpRegNum(arch: std.Target.Cpu.Arch) u16 {
14841486pub fn spRegNum(arch: std.Target.Cpu.Arch) u16 {
14851487 return switch (arch) {
14861488 .aarch64, .aarch64_be => 31,
1489 .alpha => 30,
14871490 .arc, .arceb => 28,
14881491 .arm, .armeb, .thumb, .thumbeb => 13,
14891492 .csky => 14,
lib/std/debug/cpu_context.zig+74
......@@ -5,6 +5,7 @@ pub const Native = if (@hasDecl(root, "debug") and @hasDecl(root.debug, "CpuCont
55 root.debug.CpuContext
66else switch (native_arch) {
77 .aarch64, .aarch64_be => Aarch64,
8 .alpha => Alpha,
89 .arc, .arceb => Arc,
910 .arm, .armeb, .thumb, .thumbeb => Arm,
1011 .csky => Csky,
......@@ -103,6 +104,10 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
103104 .sp = uc.mcontext.sp,
104105 .pc = uc.mcontext.pc,
105106 },
107 .alpha => .{
108 .r = uc.mcontext.r,
109 .pc = uc.mcontext.pc,
110 },
106111 .csky => .{
107112 .r = uc.mcontext.r0_13 ++
108113 [_]u32{ uc.mcontext.r14, uc.mcontext.r15 } ++
......@@ -293,6 +298,75 @@ const Aarch64 = extern struct {
293298 }
294299};
295300
301const Alpha = extern struct {
302 /// The numbered general-purpose registers R0 - R31.
303 r: [32]u64,
304 pc: u64,
305
306 pub inline fn current() Alpha {
307 var ctx: Alpha = undefined;
308 asm volatile (
309 \\ stq $0 , 0x000($0)
310 \\ stq $1 , 0x008($0)
311 \\ stq $2 , 0x010($0)
312 \\ stq $3 , 0x018($0)
313 \\ stq $4 , 0x020($0)
314 \\ stq $5 , 0x028($0)
315 \\ stq $6 , 0x030($0)
316 \\ stq $7 , 0x038($0)
317 \\ stq $8 , 0x040($0)
318 \\ stq $9 , 0x048($0)
319 \\ stq $10, 0x050($0)
320 \\ stq $11, 0x058($0)
321 \\ stq $12, 0x060($0)
322 \\ stq $13, 0x068($0)
323 \\ stq $14, 0x070($0)
324 \\ stq $15, 0x078($0)
325 \\ stq $16, 0x080($0)
326 \\ stq $17, 0x088($0)
327 \\ stq $18, 0x090($0)
328 \\ stq $19, 0x098($0)
329 \\ stq $20, 0x0a0($0)
330 \\ stq $21, 0x0a8($0)
331 \\ stq $22, 0x0b0($0)
332 \\ stq $23, 0x0b8($0)
333 \\ stq $24, 0x0c0($0)
334 \\ stq $25, 0x0c8($0)
335 \\ stq $26, 0x0d0($0)
336 \\ stq $27, 0x0d8($0)
337 \\ stq $28, 0x0e0($0)
338 \\ stq $29, 0x0e8($0)
339 \\ stq $30, 0x0f0($0)
340 \\
341 \\ br $1, 1f
342 \\1:
343 \\ stq $1, 0x100($0)
344 :
345 : [ctx] "{r0}" (&ctx),
346 : .{ .r1 = true, .memory = true });
347 return ctx;
348 }
349
350 pub fn getFp(ctx: *const Alpha) u64 {
351 return ctx.r[15];
352 }
353 pub fn getPc(ctx: *const Alpha) u64 {
354 return ctx.pc;
355 }
356
357 pub fn dwarfRegisterBytes(ctx: *Aarch64, register_num: u16) DwarfRegisterError![]u8 {
358 switch (register_num) {
359 0...31 => return @ptrCast(&ctx.r[register_num]),
360 64 => return @ptrCast(&ctx.pc),
361
362 32...63 => return error.UnsupportedRegister, // f0 - f31
363 66 => return error.UnsupportedRegister, // uniq
364
365 else => return error.InvalidRegister,
366 }
367 }
368};
369
296370/// This is an `extern struct` so that inline assembly in `current` can use field offsets.
297371const Arc = extern struct {
298372 /// The numbered general-purpose registers r0 - r31.
lib/std/os/linux.zig+682-30
......@@ -18,6 +18,7 @@ const is_mips = native_arch.isMIPS();
1818const is_ppc = native_arch.isPowerPC();
1919const is_riscv = native_arch.isRISCV();
2020const is_sparc = native_arch.isSPARC();
21const is_hppa = native_arch.isHppa();
2122const iovec = std.posix.iovec;
2223const iovec_const = std.posix.iovec_const;
2324const winsize = std.posix.winsize;
......@@ -31,6 +32,7 @@ test {
3132
3233const arch_bits = switch (native_arch) {
3334 .aarch64, .aarch64_be => @import("linux/aarch64.zig"),
35 .alpha => @import("linux/alpha.zig"),
3436 .arc, .arceb => @import("linux/arc.zig"),
3537 .arm, .armeb, .thumb, .thumbeb => @import("linux/arm.zig"),
3638 .hexagon => @import("linux/hexagon.zig"),
......@@ -124,6 +126,7 @@ pub const syscalls = @import("linux/syscalls.zig");
124126pub const SYS = switch (native_arch) {
125127 .arc, .arceb => syscalls.Arc,
126128 .aarch64, .aarch64_be => syscalls.Arm64,
129 .alpha => syscalls.Alpha,
127130 .arm, .armeb, .thumb, .thumbeb => syscalls.Arm,
128131 .csky => syscalls.CSky,
129132 .hexagon => syscalls.Hexagon,
......@@ -311,6 +314,30 @@ pub const MAP = switch (native_arch) {
311314 UNINITIALIZED: bool = false,
312315 _: u5 = 0,
313316 },
317 .alpha => packed struct(u32) {
318 TYPE: MAP_TYPE,
319 ANONYMOUS: bool = false,
320 _3: u1 = 0,
321 _4: u1 = 0,
322 _5: u1 = 0,
323 FIXED: bool = false,
324 _7: u1 = 0,
325 _8: u1 = 0,
326 _9: u1 = 0,
327 GROWSDOWN: bool = false,
328 DENYWRITE: bool = false,
329 EXECUTABLE: bool = false,
330 LOCKED: bool = false,
331 NORESERVE: bool = false,
332 POPULATE: bool = false,
333 NONBLOCK: bool = false,
334 STACK: bool = false,
335 HUGHETLB: bool = false,
336 FIXED_NOREPLACE: bool = false,
337 _19: u4 = 0,
338 _20: u1 = 0,
339 _: u5 = 0,
340 },
314341 else => @compileError("missing std.os.linux.MAP constants for this architecture"),
315342};
316343
......@@ -520,6 +547,29 @@ pub const O = switch (native_arch) {
520547 PATH: bool = false,
521548 _22: u10 = 0,
522549 },
550 .alpha => packed struct(u32) {
551 ACCMODE: ACCMODE = .RDONLY,
552 NONBLOCK: bool = false,
553 APPEND: bool = false,
554 _4: u5 = 0,
555 CREAT: bool = false,
556 TRUNC: bool = false,
557 EXCL: bool = false,
558 NOCTTY: bool = false,
559 _9: u1 = 0,
560 DSYNC: bool = false,
561 DIRECTORY: bool = false,
562 NOFOLLOW: bool = false,
563 LARGEFILE: bool = false,
564 _14: u1 = 0,
565 DIRECT: bool = false,
566 NOATIME: bool = false,
567 CLOEXEC: bool = false,
568 SYNC: bool = false,
569 PATH: bool = false,
570 TMPFILE: bool = false,
571 _: u7 = 0,
572 },
523573 else => @compileError("missing std.os.linux.O constants for this architecture"),
524574};
525575
......@@ -1894,23 +1944,68 @@ pub const F = struct {
18941944 pub const SETLK = GET_SET_LK.SETLK;
18951945 pub const SETLKW = GET_SET_LK.SETLKW;
18961946
1897 const GET_SET_LK = if (@sizeOf(usize) == 64) extern struct {
1898 pub const GETLK = if (is_mips) 14 else if (is_sparc) 7 else 5;
1899 pub const SETLK = if (is_mips) 6 else if (is_sparc) 8 else 6;
1900 pub const SETLKW = if (is_mips) 7 else if (is_sparc) 9 else 7;
1901 } else extern struct {
1902 // Ensure that 32-bit code uses the large-file variants (GETLK64, etc).
1947 pub const SETOWN = GET_SET_OWN.SETOWN;
1948 pub const GETOWN = GET_SET_OWN.GETOWN;
19031949
1904 pub const GETLK = if (is_mips) 33 else 12;
1905 pub const SETLK = if (is_mips) 34 else 13;
1906 pub const SETLKW = if (is_mips) 35 else 14;
1950 const GET_SET_LK = switch (native_arch) {
1951 .mips, .mipsel => struct {
1952 const GETLK = 33;
1953 const SETLK = 34;
1954 const SETLKW = 35;
1955 },
1956 .mips64, .mips64el => switch (native_abi) {
1957 .gnuabin32, .muslabin32 => struct {
1958 const GETLK = 33;
1959 const SETLK = 34;
1960 const SETLKW = 35;
1961 },
1962 else => struct {
1963 const GETLK = 14;
1964 const SETLK = 6;
1965 const SETLKW = 7;
1966 },
1967 },
1968 .alpha, .sparc64 => struct {
1969 const GETLK = 7;
1970 const SETLK = 8;
1971 const SETLKW = 9;
1972 },
1973 .hppa, .hppa64 => struct {
1974 const GETLK = 8;
1975 const SETLK = 9;
1976 const SETLKW = 10;
1977 },
1978 else => if (@sizeOf(usize) == 8) struct {
1979 const GETLK = 5;
1980 const SETLK = 6;
1981 const SETLKW = 7;
1982 } else struct {
1983 const GETLK = 12;
1984 const SETLK = 13;
1985 const SETLKW = 14;
1986 },
1987 };
1988 const GET_SET_OWN = switch (native_arch) {
1989 .mips, .mipsel, .mips64, .mips64el => struct {
1990 const GETOWN = 23;
1991 const SETOWN = 24;
1992 },
1993 .alpha, .sparc, .sparc64 => struct {
1994 const GETOWN = 5;
1995 const SETOWN = 6;
1996 },
1997 .hppa, .hppa64 => struct {
1998 const GETOWN = 11;
1999 const SETOWN = 12;
2000 },
2001 else => struct {
2002 const GETOWN = 8;
2003 const SETOWN = 9;
2004 },
19072005 };
19082006
1909 pub const SETOWN = if (is_mips) 24 else if (is_sparc) 6 else 8;
1910 pub const GETOWN = if (is_mips) 23 else if (is_sparc) 5 else 9;
1911
1912 pub const SETSIG = 10;
1913 pub const GETSIG = 11;
2007 pub const SETSIG = if (is_hppa or native_arch == .alpha) 13 else 11;
2008 pub const GETSIG = if (is_hppa or native_arch == .alpha) 14 else 12;
19142009
19152010 pub const SETOWN_EX = 15;
19162011 pub const GETOWN_EX = 16;
......@@ -1923,7 +2018,7 @@ pub const F = struct {
19232018
19242019 pub const RDLCK = if (is_sparc) 1 else 0;
19252020 pub const WRLCK = if (is_sparc) 2 else 1;
1926 pub const UNLCK = if (is_sparc) 3 else 2;
2021 pub const UNLCK = if (is_sparc) 3 else if (native_arch == .alpha) 8 else 2;
19272022
19282023 pub const LINUX_SPECIFIC_BASE = 1024;
19292024
......@@ -3388,6 +3483,294 @@ pub const E = switch (native_arch) {
33883483 HWPOISON = 135,
33893484 _,
33903485 },
3486 .alpha => enum(u16) {
3487 /// No error occurred.
3488 SUCCESS = 0,
3489
3490 /// Operation not permitted
3491 PERM = 1,
3492 /// No such file or directory
3493 NOENT = 2,
3494 /// No such process
3495 SRCH = 3,
3496 /// Interrupted system call
3497 INTR = 4,
3498 /// I/O error
3499 IO = 5,
3500 /// No such device or address
3501 NXIO = 6,
3502 /// Argument list too long
3503 @"2BIG" = 7,
3504 /// Exec format error
3505 NOEXEC = 8,
3506 /// Bad file number
3507 BADF = 9,
3508 /// No child processes
3509 CHILD = 10,
3510 /// Out of memory
3511 NOMEM = 12,
3512 /// Permission denied
3513 ACCES = 13,
3514 /// Bad address
3515 FAULT = 14,
3516 /// Block device required
3517 NOTBLK = 15,
3518 /// Device or resource busy
3519 BUSY = 16,
3520 /// File exists
3521 EXIST = 17,
3522 /// Cross-device link
3523 XDEV = 18,
3524 /// No such device
3525 NODEV = 19,
3526 /// Not a directory
3527 NOTDIR = 20,
3528 /// Is a directory
3529 ISDIR = 21,
3530 /// Invalid argument
3531 INVAL = 22,
3532 /// File table overflow
3533 NFILE = 23,
3534 /// Too many open files
3535 MFILE = 24,
3536 /// Not a typewriter
3537 NOTTY = 25,
3538 /// Text file busy
3539 TXTBSY = 26,
3540 /// File too large
3541 FBIG = 27,
3542 /// No space left on device
3543 NOSPC = 28,
3544 /// Illegal seek
3545 SPIPE = 29,
3546 /// Read-only file system
3547 ROFS = 30,
3548 /// Too many links
3549 MLINK = 31,
3550 /// Broken pipe
3551 PIPE = 32,
3552 /// Math argument out of domain of func
3553 DOM = 33,
3554 /// Math result not representable
3555 RANGE = 34,
3556
3557 /// Resource deadlock would occur
3558 DEADLK = 11,
3559
3560 /// Try again.
3561 /// Also used for WOULDBLOCK.
3562 AGAIN = 35,
3563 /// Operation now in progress
3564 INPROGRESS = 36,
3565 /// Operation already in progress
3566 ALREADY = 37,
3567 /// Socket operation on non-socket
3568 NOTSOCK = 38,
3569 /// Destination address required
3570 DESTADDRREQ = 39,
3571 /// Message too long
3572 MSGSIZE = 40,
3573 /// Protocol wrong type for socket
3574 PROTOTYPE = 41,
3575 /// Protocol not available
3576 NOPROTOOPT = 42,
3577 /// Protocol not supported
3578 PROTONOSUPPORT = 43,
3579 /// Socket type not supported
3580 SOCKTNOSUPPORT = 44,
3581 /// Operation not supported on transport endpoint
3582 OPNOTSUPP = 45,
3583 /// Protocol family not supported
3584 PFNOSUPPORT = 46,
3585 /// Address family not supported by protocol
3586 AFNOSUPPORT = 47,
3587 /// Address already in use
3588 ADDRINUSE = 48,
3589 /// Cannot assign requested address
3590 ADDRNOTAVAIL = 49,
3591 /// Network is down
3592 NETDOWN = 50,
3593 /// Network is unreachable
3594 NETUNREACH = 51,
3595 /// Network dropped connection because of reset
3596 NETRESET = 52,
3597 /// Software caused connection abort
3598 CONNABORTED = 53,
3599 /// Connection reset by peer
3600 CONNRESET = 54,
3601 /// No buffer space available
3602 NOBUFS = 55,
3603 /// Transport endpoint is already connected
3604 ISCONN = 56,
3605 /// Transport endpoint is not connected
3606 NOTCONN = 57,
3607 /// Cannot send after transport endpoint shutdown
3608 SHUTDOWN = 58,
3609 /// Too many references: cannot splice
3610 TOOMANYREFS = 59,
3611 /// Connection timed out
3612 TIMEDOUT = 60,
3613 /// Connection refused
3614 CONNREFUSED = 61,
3615 /// Too many symbolic links encountered
3616 LOOP = 62,
3617 /// File name too long
3618 NAMETOOLONG = 63,
3619 /// Host is down
3620 HOSTDOWN = 64,
3621 /// No route to host
3622 HOSTUNREACH = 65,
3623 /// Directory not empty
3624 NOTEMPTY = 66,
3625
3626 /// Too many users
3627 USERS = 68,
3628 /// Quota exceeded
3629 DQUOT = 69,
3630 /// Stale file handle
3631 STALE = 70,
3632 /// Object is remote
3633 REMOTE = 71,
3634
3635 /// No record locks available
3636 NOLCK = 77,
3637 /// Function not implemented
3638 NOSYS = 78,
3639
3640 /// No message of desired type
3641 NOMSG = 80,
3642 /// Identifier removed
3643 IDRM = 81,
3644 /// Out of streams resources
3645 NOSR = 82,
3646 /// Timer expired
3647 TIME = 83,
3648 /// Not a data message
3649 /// Also used for FSBADCRC.
3650 BADMSG = 84,
3651 /// Protocol error
3652 PROTO = 85,
3653 /// No data available
3654 NODATA = 86,
3655 /// Device not a stream
3656 NOSTR = 87,
3657
3658 /// Package not installed
3659 NOPKG = 92,
3660
3661 /// Illegal byte sequence
3662 ILSEQ = 116,
3663
3664 // The following are designated "random noise" by the kernel sources.
3665 /// Channel number out of range
3666 CHRNG = 88,
3667 /// Level 2 not synchronized
3668 L2NSYNC = 89,
3669 /// Level 3 halted
3670 L3HLT = 90,
3671 /// Level 3 reset
3672 L3RST = 91,
3673
3674 /// Link number out of range
3675 LNRNG = 93,
3676 /// Protocol driver not attached
3677 UNATCH = 94,
3678 /// No CSI structure available
3679 NOCSI = 95,
3680 /// Level 2 halted
3681 L2HLT = 96,
3682 /// Invalid exchange
3683 BADE = 97,
3684 /// Invalid request descriptor
3685 BADR = 98,
3686 /// Exchange full
3687 XFULL = 99,
3688 /// No anode
3689 NOANO = 100,
3690 /// Invalid request code
3691 BADRQC = 101,
3692 /// Invalid slot
3693 BADSLT = 102,
3694
3695 /// Bad font file format
3696 BFONT = 104,
3697 /// Machine is not on the network
3698 NONET = 105,
3699 /// Link has been severed
3700 NOLINK = 106,
3701 /// Advertise error
3702 ADV = 107,
3703 /// Srmount error
3704 SRMNT = 108,
3705 /// Communication error on send
3706 COMM = 109,
3707 /// Multihop attempted
3708 MULTIHOP = 110,
3709 /// RFS specific error
3710 DOTDOT = 111,
3711 /// Value too large for defined data type
3712 OVERFLOW = 112,
3713 /// Name not unique on network
3714 NOTUNIQ = 113,
3715 /// File descriptor in bad state
3716 BADFD = 114,
3717 /// Remote address changed
3718 REMCHG = 115,
3719
3720 /// Structure needs cleaning
3721 /// Also used for FSCORRUPTED.
3722 UCLEAN = 117,
3723 /// Not a XENIX named type file
3724 NOTNAM = 118,
3725 /// No XENIX semaphores available
3726 NAVAIL = 119,
3727 /// Is a named type file
3728 ISNAM = 120,
3729 /// Remote I/O error
3730 REMOTEIO = 121,
3731
3732 /// Can not access a needed shared library
3733 LIBACC = 122,
3734 /// Accessing a corrupted shared library
3735 LIBBAD = 123,
3736 /// .lib section in a.out corrupted
3737 LIBSCN = 124,
3738 /// Attempting to link in too many shared libraries
3739 LIBMAX = 125,
3740 /// Cannot exec a shared library directly
3741 LIBEXEC = 126,
3742 /// Interrupted system call should be restarted
3743 RESTART = 127,
3744 /// Streams pipe error
3745 STRPIPE = 128,
3746
3747 /// No medium found
3748 NOMEDIUM = 129,
3749 /// Wrong medium type
3750 MEDIUMTYPE = 130,
3751 /// Operation Cancelled
3752 CANCELED = 131,
3753 /// Required key not available
3754 NOKEY = 132,
3755 /// Key has expired
3756 KEYEXPIRED = 133,
3757 /// Key has been revoked
3758 KEYREVOKED = 134,
3759 /// Key was rejected by service
3760 KEYREJECTED = 135,
3761
3762 // For robust mutexes
3763 /// Owner died
3764 OWNERDEAD = 136,
3765 /// State not recoverable
3766 NOTRECOVERABLE = 137,
3767
3768 /// Operation not possible due to RF-kill
3769 RFKILL = 138,
3770 /// Memory page has hardware error
3771 HWPOISON = 139,
3772 _,
3773 },
33913774 else => enum(u16) {
33923775 /// No error occurred.
33933776 /// Same code used for `NSROK`.
......@@ -3959,6 +4342,14 @@ pub const SA = if (is_mips) struct {
39594342 pub const RESETHAND = 0x80000000;
39604343 pub const ONSTACK = 0x08000000;
39614344 pub const NODEFER = 0x40000000;
4345} else if (native_arch == .alpha) struct {
4346 pub const ONSTACK = 0x00000001;
4347 pub const RESTART = 0x00000002;
4348 pub const NOCLDSTOP = 0x00000004;
4349 pub const NODEFER = 0x00000008;
4350 pub const RESETHAND = 0x00000010;
4351 pub const NOCLDWAIT = 0x00000020;
4352 pub const SIGINFO = 0x00000040;
39624353} else struct {
39634354 pub const NOCLDSTOP = 1;
39644355 pub const NOCLDWAIT = 2;
......@@ -4061,6 +4452,95 @@ pub const SIG = if (is_mips) enum(u32) {
40614452 USR1 = 30,
40624453 USR2 = 31,
40634454 _,
4455} else if (native_arch == .alpha) enum(u32) {
4456 pub const BLOCK = 1;
4457 pub const UNBLOCK = 2;
4458 pub const SETMASK = 3;
4459
4460 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
4461 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
4462 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
4463
4464 pub const POLL: SIG = .IO;
4465 pub const PWR: SIG = .INFO;
4466 pub const IOT: SIG = .ABRT;
4467
4468 HUP = 1,
4469 INT = 2,
4470 QUIT = 3,
4471 ILL = 4,
4472 TRAP = 5,
4473 ABRT = 6,
4474 EMT = 7,
4475 FPE = 8,
4476 KILL = 9,
4477 BUS = 10,
4478 SEGV = 11,
4479 SYS = 12,
4480 PIPE = 13,
4481 ALRM = 14,
4482 TERM = 15,
4483 URG = 16,
4484 STOP = 17,
4485 TSTP = 18,
4486 CONT = 19,
4487 CHLD = 20,
4488 TTIN = 21,
4489 TTOU = 22,
4490 IO = 23,
4491 XCPU = 24,
4492 XFSZ = 25,
4493 VTALRM = 26,
4494 PROF = 27,
4495 WINCH = 28,
4496 INFO = 29,
4497 USR1 = 30,
4498 USR2 = 31,
4499 _,
4500} else if (is_hppa) enum(u32) {
4501 pub const BLOCK = 0;
4502 pub const UNBLOCK = 1;
4503 pub const SETMASK = 2;
4504
4505 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
4506 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
4507 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
4508
4509 pub const POLL: SIG = .IO;
4510 pub const IOT: SIG = .ABRT;
4511
4512 HUP = 1,
4513 INT = 2,
4514 QUIT = 3,
4515 ILL = 4,
4516 TRAP = 5,
4517 ABRT = 6,
4518 STKFLT = 7,
4519 FPE = 8,
4520 KILL = 9,
4521 BUS = 10,
4522 SEGV = 11,
4523 XCPU = 12,
4524 PIPE = 13,
4525 ALRM = 14,
4526 TERM = 15,
4527 USR1 = 16,
4528 USR2 = 17,
4529 CHLD = 18,
4530 PWR = 19,
4531 VTALRM = 20,
4532 PROF = 21,
4533 IO = 22,
4534 WINCH = 23,
4535 STOP = 24,
4536 TSTP = 25,
4537 CONT = 26,
4538 TTIN = 27,
4539 TTOU = 28,
4540 URG = 29,
4541 XFSZ = 30,
4542 SYS = 31,
4543 _,
40644544} else enum(u32) {
40654545 pub const BLOCK = 0;
40664546 pub const UNBLOCK = 1;
......@@ -4137,8 +4617,20 @@ pub const SOCK = struct {
41374617 pub const SEQPACKET = 5;
41384618 pub const DCCP = 6;
41394619 pub const PACKET = 10;
4140 pub const CLOEXEC = if (is_sparc) 0o20000000 else 0o2000000;
4141 pub const NONBLOCK = if (is_mips) 0o200 else if (is_sparc) 0o40000 else 0o4000;
4620 pub const CLOEXEC = if (is_sparc)
4621 0o20000000
4622 else if (native_arch == .alpha)
4623 0o10000000
4624 else
4625 0o2000000;
4626 pub const NONBLOCK = if (is_mips)
4627 0o200
4628 else if (is_sparc)
4629 0o40000
4630 else if (is_hppa or native_arch == .alpha)
4631 0x40000000
4632 else
4633 0o4000;
41424634};
41434635
41444636pub const TCP = struct {
......@@ -4552,6 +5044,77 @@ pub const SO = if (is_mips) struct {
45525044 pub const RCVTIMEO_NEW = 68;
45535045 pub const SNDTIMEO_NEW = 69;
45545046 pub const DETACH_REUSEPORT_BPF = 71;
5047} else if (native_arch == .alpha) struct {
5048 pub const DEBUG = 1;
5049 pub const REUSEADDR = 0x0004;
5050 pub const KEEPALIVE = 0x0008;
5051 pub const DONTROUTE = 0x0010;
5052 pub const BROADCAST = 0x0020;
5053 pub const LINGER = 0x0080;
5054 pub const OOBINLINE = 0x0100;
5055 pub const REUSEPORT = 0x0200;
5056
5057 pub const SNDBUF = 0x1001;
5058 pub const RCVBUF = 0x1002;
5059 pub const SNDLOWAT = 0x1011;
5060 pub const RCVLOWAT = 0x1010;
5061 pub const RCVTIMEO = 0x1012;
5062 pub const SNDTIMEO = 0x1013;
5063 pub const ERROR = 0x1007;
5064 pub const TYPE = 0x1008;
5065 pub const ACCEPTCONN = 0x1014;
5066 pub const PROTOCOL = 0x1028;
5067 pub const DOMAIN = 0x1029;
5068
5069 pub const NO_CHECK = 11;
5070 pub const PRIORITY = 12;
5071 pub const BSDCOMPAT = 14;
5072 pub const PASSCRED = 17;
5073 pub const PEERCRED = 18;
5074 pub const PEERSEC = 30;
5075 pub const SNDBUFFORCE = 0x100a;
5076 pub const RCVBUFFORCE = 0x100b;
5077 pub const SECURITY_AUTHENTICATION = 19;
5078 pub const SECURITY_ENCRYPTION_TRANSPORT = 20;
5079 pub const SECURITY_ENCRYPTION_NETWORK = 21;
5080 pub const BINDTODEVICE = 25;
5081 pub const ATTACH_FILTER = 26;
5082 pub const DETACH_FILTER = 27;
5083 pub const GET_FILTER = ATTACH_FILTER;
5084 pub const PEERNAME = 28;
5085 pub const TIMESTAMP_OLD = 29;
5086 pub const PASSSEC = 34;
5087 pub const TIMESTAMPNS_OLD = 35;
5088 pub const MARK = 36;
5089 pub const TIMESTAMPING_OLD = 37;
5090 pub const RXQ_OVFL = 40;
5091 pub const WIFI_STATUS = 41;
5092 pub const PEEK_OFF = 42;
5093 pub const NOFCS = 43;
5094 pub const LOCK_FILTER = 44;
5095 pub const SELECT_ERR_QUEUE = 45;
5096 pub const BUSY_POLL = 46;
5097 pub const MAX_PACING_RATE = 47;
5098 pub const BPF_EXTENSIONS = 48;
5099 pub const INCOMING_CPU = 49;
5100 pub const ATTACH_BPF = 50;
5101 pub const DETACH_BPF = DETACH_FILTER;
5102 pub const ATTACH_REUSEPORT_CBPF = 51;
5103 pub const ATTACH_REUSEPORT_EBPF = 52;
5104 pub const CNX_ADVICE = 53;
5105 pub const MEMINFO = 55;
5106 pub const INCOMING_NAPI_ID = 56;
5107 pub const COOKIE = 57;
5108 pub const PEERGROUPS = 59;
5109 pub const ZEROCOPY = 60;
5110 pub const TXTIME = 61;
5111 pub const BINDTOIFINDEX = 62;
5112 pub const TIMESTAMP_NEW = 63;
5113 pub const TIMESTAMPNS_NEW = 64;
5114 pub const TIMESTAMPING_NEW = 65;
5115 pub const RCVTIMEO_NEW = 66;
5116 pub const SNDTIMEO_NEW = 67;
5117 pub const DETACH_REUSEPORT_BPF = 68;
45555118} else struct {
45565119 pub const DEBUG = 1;
45575120 pub const REUSEADDR = 2;
......@@ -4637,7 +5200,10 @@ pub const SCM = struct {
46375200};
46385201
46395202pub const SOL = struct {
4640 pub const SOCKET = if (is_mips or is_sparc) 65535 else 1;
5203 pub const SOCKET = if (is_mips or is_sparc or native_arch == .alpha)
5204 0xffff
5205 else
5206 1;
46415207
46425208 pub const IP = 0;
46435209 pub const IPV6 = 41;
......@@ -5224,7 +5790,7 @@ pub const T = if (is_mips) struct {
52245790 pub const IOCSERSETMULTI = 0x5490;
52255791 pub const IOCMIWAIT = 0x5491;
52265792 pub const IOCGICOUNT = 0x5492;
5227} else if (is_ppc) struct {
5793} else if (is_ppc or native_arch == .alpha) struct {
52285794 pub const FIOCLEX = IOCTL.IO('f', 1);
52295795 pub const FIONCLEX = IOCTL.IO('f', 2);
52305796 pub const FIOASYNC = IOCTL.IOW('f', 125, c_int);
......@@ -6008,6 +6574,15 @@ pub const TFD = switch (native_arch) {
60086574
60096575 pub const TIMER = TFD_TIMER;
60106576 },
6577 .alpha => packed struct(u32) {
6578 _0: u2 = 0,
6579 NONBLOCK: bool = false,
6580 _3: u18 = 0,
6581 CLOEXEC: bool = false,
6582 _: u10 = 0,
6583
6584 pub const TIMER = TFD_TIMER;
6585 },
60116586 else => packed struct(u32) {
60126587 _0: u11 = 0,
60136588 NONBLOCK: bool = false,
......@@ -6037,6 +6612,11 @@ pub const k_sigaction = switch (native_arch) {
60376612 flags: c_ulong,
60386613 mask: sigset_t,
60396614 },
6615 .alpha => extern struct {
6616 handler: k_sigaction_funcs.handler,
6617 mask: sigset_t,
6618 flags: c_int,
6619 },
60406620 else => extern struct {
60416621 handler: k_sigaction_funcs.handler,
60426622 flags: c_ulong,
......@@ -6061,6 +6641,7 @@ pub const Sigaction = struct {
60616641 mask: sigset_t,
60626642 flags: switch (native_arch) {
60636643 .mips, .mipsel, .mips64, .mips64el => c_uint,
6644 .alpha => c_int,
60646645 else => c_ulong,
60656646 },
60666647};
......@@ -7531,7 +8112,14 @@ pub const rusage = extern struct {
75318112};
75328113
75338114pub const NCC = if (is_ppc) 10 else 8;
7534pub const NCCS = if (is_mips) 32 else if (is_ppc) 19 else if (is_sparc) 17 else 32;
8115pub const NCCS = if (is_mips)
8116 32
8117else if (is_ppc or native_arch == .alpha)
8118 19
8119else if (is_sparc)
8120 17
8121else
8122 32;
75358123
75368124pub const speed_t = if (is_ppc) enum(c_uint) {
75378125 B0 = 0x0000000,
......@@ -7645,7 +8233,7 @@ pub const speed_t = if (is_ppc) enum(c_uint) {
76458233
76468234pub const tcflag_t = if (native_arch == .sparc) c_ulong else c_uint;
76478235
7648pub const tc_iflag_t = if (is_ppc) packed struct(tcflag_t) {
8236pub const tc_iflag_t = if (is_ppc or native_arch == .alpha) packed struct(tcflag_t) {
76498237 IGNBRK: bool = false,
76508238 BRKINT: bool = false,
76518239 IGNPAR: bool = false,
......@@ -7681,7 +8269,7 @@ pub const tc_iflag_t = if (is_ppc) packed struct(tcflag_t) {
76818269 _15: u17 = 0,
76828270};
76838271
7684pub const NLDLY = if (is_ppc) enum(u2) {
8272pub const NLDLY = if (is_ppc or native_arch == .alpha) enum(u2) {
76858273 NL0 = 0,
76868274 NL1 = 1,
76878275 NL2 = 2,
......@@ -7722,7 +8310,7 @@ pub const FFDLY = enum(u1) {
77228310 FF1 = 1,
77238311};
77248312
7725pub const tc_oflag_t = if (is_ppc) packed struct(tcflag_t) {
8313pub const tc_oflag_t = if (is_ppc or native_arch == .alpha) packed struct(tcflag_t) {
77268314 OPOST: bool = false,
77278315 ONLCR: bool = false,
77288316 OLCUC: bool = false,
......@@ -7781,7 +8369,7 @@ pub const CSIZE = enum(u2) {
77818369 CS8 = 3,
77828370};
77838371
7784pub const tc_cflag_t = if (is_ppc) packed struct(tcflag_t) {
8372pub const tc_cflag_t = if (is_ppc or native_arch == .alpha) packed struct(tcflag_t) {
77858373 _0: u8 = 0,
77868374 CSIZE: CSIZE = .CS5,
77878375 CSTOPB: bool = false,
......@@ -7828,7 +8416,7 @@ pub const tc_lflag_t = if (is_mips) packed struct(tcflag_t) {
78288416 TOSTOP: bool = false,
78298417 EXTPROC: bool = false,
78308418 _17: u15 = 0,
7831} else if (is_ppc) packed struct(tcflag_t) {
8419} else if (is_ppc or native_arch == .alpha) packed struct(tcflag_t) {
78328420 ECHOKE: bool = false,
78338421 ECHOE: bool = false,
78348422 ECHOK: bool = false,
......@@ -7929,6 +8517,24 @@ pub const V = if (is_mips) enum(u32) {
79298517 STOP = 14,
79308518 LNEXT = 15,
79318519 DISCARD = 16,
8520} else if (arch_bits == .alpha) enum(u32) {
8521 EOF = 0,
8522 EOL = 1,
8523 EOL2 = 2,
8524 ERASE = 3,
8525 WERASE = 4,
8526 KILL = 5,
8527 REPRINT = 6,
8528 SWTC = 7,
8529 INTR = 8,
8530 QUIT = 9,
8531 SUSP = 10,
8532 START = 12,
8533 STOP = 13,
8534 LNEXT = 14,
8535 DISCARD = 15,
8536 MIN = 16,
8537 TIME = 17,
79328538} else enum(u32) {
79338539 INTR = 0,
79348540 QUIT = 1,
......@@ -7959,7 +8565,7 @@ pub const sgttyb = if (is_mips or is_ppc or is_sparc) extern struct {
79598565 flags: if (is_mips) c_int else c_short,
79608566} else void;
79618567
7962pub const tchars = if (is_mips or is_ppc or is_sparc) extern struct {
8568pub const tchars = if (is_mips or is_ppc or is_sparc or native_arch == .alpha) extern struct {
79638569 intrc: c_char,
79648570 quitc: c_char,
79658571 startc: c_char,
......@@ -7968,7 +8574,7 @@ pub const tchars = if (is_mips or is_ppc or is_sparc) extern struct {
79688574 brkc: c_char,
79698575} else void;
79708576
7971pub const ltchars = if (is_mips or is_ppc or is_sparc) extern struct {
8577pub const ltchars = if (is_mips or is_ppc or is_sparc or native_arch == .alpha) extern struct {
79728578 suspc: c_char,
79738579 dsuspc: c_char,
79748580 rprntc: c_char,
......@@ -7993,7 +8599,7 @@ pub const termios = if (is_mips or is_sparc) extern struct {
79938599 lflag: tc_lflag_t,
79948600 line: cc_t,
79958601 cc: [NCCS]cc_t,
7996} else if (is_ppc) extern struct {
8602} else if (is_ppc or native_arch == .alpha) extern struct {
79978603 iflag: tc_iflag_t,
79988604 oflag: tc_oflag_t,
79998605 cflag: tc_cflag_t,
......@@ -8013,7 +8619,7 @@ pub const termios = if (is_mips or is_sparc) extern struct {
80138619 ospeed: speed_t,
80148620};
80158621
8016pub const termios2 = if (is_mips) extern struct {
8622pub const termios2 = if (is_mips or native_arch == .alpha) extern struct {
80178623 iflag: tc_iflag_t,
80188624 oflag: tc_oflag_t,
80198625 cflag: tc_cflag_t,
......@@ -8592,6 +9198,49 @@ pub const rlimit_resource = if (native_arch.isMIPS()) enum(c_int) {
85929198 /// call before being forcibly descheduled.
85939199 RTTIME = 15,
85949200
9201 _,
9202} else if (native_arch == .alpha) enum(c_int) {
9203 /// Per-process CPU limit, in seconds.
9204 CPU = 0,
9205 /// Largest file that can be created, in bytes.
9206 FSIZE = 1,
9207 /// Maximum size of data segment, in bytes.
9208 DATA = 2,
9209 /// Maximum size of stack segment, in bytes.
9210 STACK = 3,
9211 /// Largest core file that can be created, in bytes.
9212 CORE = 4,
9213 /// Largest resident set size, in bytes.
9214 /// This affects swapping; processes that are exceeding their
9215 /// resident set size will be more likely to have physical memory
9216 /// taken from them.
9217 RSS = 5,
9218 /// Number of open files.
9219 NOFILE = 6,
9220 /// Address space limit.
9221 AS = 7,
9222 /// Number of processes.
9223 NPROC = 8,
9224 /// Locked-in-memory address space.
9225 MEMLOCK = 9,
9226 /// Maximum number of file locks.
9227 LOCKS = 10,
9228 /// Maximum number of pending signals.
9229 SIGPENDING = 11,
9230 /// Maximum bytes in POSIX message queues.
9231 MSGQUEUE = 12,
9232 /// Maximum nice priority allowed to raise to.
9233 /// Nice levels 19 .. -20 correspond to 0 .. 39
9234 /// values of this resource limit.
9235 NICE = 13,
9236 /// Maximum realtime priority allowed for non-privileged
9237 /// processes.
9238 RTPRIO = 14,
9239 /// Maximum CPU time in µs that a process scheduled under a real-time
9240 /// scheduling policy may consume without making a blocking system
9241 /// call before being forcibly descheduled.
9242 RTTIME = 15,
9243
85959244 _,
85969245} else enum(c_int) {
85979246 /// Per-process CPU limit, in seconds.
......@@ -8642,7 +9291,10 @@ pub const rlim_t = u64;
86429291
86439292pub const RLIM = struct {
86449293 /// No limit
8645 pub const INFINITY = ~@as(rlim_t, 0);
9294 pub const INFINITY: rlim_t = if (native_arch == .alpha)
9295 ~@as(u63, 0)
9296 else
9297 ~@as(rlim_t, 0);
86469298
86479299 pub const SAVED_MAX = INFINITY;
86489300 pub const SAVED_CUR = INFINITY;
lib/std/os/linux/IoUring/test.zig+2
......@@ -1273,6 +1273,8 @@ test "symlinkat" {
12731273 .SUCCESS => {},
12741274 // This kernel's io_uring does not yet implement symlinkat (kernel version < 5.15)
12751275 .BADF, .INVAL => return error.SkipZigTest,
1276 // Can occur on certain filesystems (seen on CIFS)
1277 .OPNOTSUPP => return error.SkipZigTest,
12761278 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
12771279 }
12781280 try testing.expectEqual(linux.io_uring_cqe{
lib/std/os/linux/alpha.zig created+358
......@@ -0,0 +1,358 @@
1const builtin = @import("builtin");
2const std = @import("../../std.zig");
3const SYS = std.os.linux.SYS;
4
5pub fn syscall0(number: SYS) u64 {
6 return asm volatile (
7 \\ callsys
8 \\ beq $19, 1f
9 \\ negq $0, $0
10 \\1:
11 : [ret] "={$0}" (-> u64),
12 : [number] "{$0}" (number),
13 : .{
14 .r1 = true,
15 .r2 = true,
16 .r3 = true,
17 .r4 = true,
18 .r5 = true,
19 .r6 = true,
20 .r7 = true,
21 .r8 = true,
22 .r22 = true,
23 .r23 = true,
24 .r24 = true,
25 .r25 = true,
26 .r27 = true,
27 .r28 = true,
28 .memory = true,
29 .r16 = true,
30 .r17 = true,
31 .r18 = true,
32 .r20 = true,
33 .r21 = true,
34 });
35}
36
37pub fn syscall1(number: SYS, arg1: u64) u64 {
38 // These registers are both inputs and clobbers.
39 var r16_out: u64 = undefined;
40 return asm volatile (
41 \\ callsys
42 \\ beq $19, 1f
43 \\ negq $0, $0
44 \\1:
45 : [ret] "={$0}" (-> u64),
46 [r16_out] "={$16}" (r16_out),
47 : [number] "{$0}" (number),
48 [arg1] "{$16}" (arg1),
49 : .{
50 .r1 = true,
51 .r2 = true,
52 .r3 = true,
53 .r4 = true,
54 .r5 = true,
55 .r6 = true,
56 .r7 = true,
57 .r8 = true,
58 .r22 = true,
59 .r23 = true,
60 .r24 = true,
61 .r25 = true,
62 .r27 = true,
63 .r28 = true,
64 .memory = true,
65 .r17 = true,
66 .r18 = true,
67 .r20 = true,
68 .r21 = true,
69 });
70}
71
72pub fn syscall2(number: SYS, arg1: u64, arg2: u64) u64 {
73 // These registers are both inputs and clobbers.
74 var r16_out: u64 = undefined;
75 var r17_out: u64 = undefined;
76 return asm volatile (
77 \\ callsys
78 \\ beq $19, 1f
79 \\ negq $0, $0
80 \\1:
81 : [ret] "={$0}" (-> u64),
82 [r16_out] "={$16}" (r16_out),
83 [r17_out] "={$17}" (r17_out),
84 : [number] "{$0}" (number),
85 [arg1] "{$16}" (arg1),
86 [arg2] "{$17}" (arg2),
87 : .{
88 .r1 = true,
89 .r2 = true,
90 .r3 = true,
91 .r4 = true,
92 .r5 = true,
93 .r6 = true,
94 .r7 = true,
95 .r8 = true,
96 .r22 = true,
97 .r23 = true,
98 .r24 = true,
99 .r25 = true,
100 .r27 = true,
101 .r28 = true,
102 .memory = true,
103 .r18 = true,
104 .r20 = true,
105 .r21 = true,
106 });
107}
108
109pub fn syscall3(number: SYS, arg1: u64, arg2: u64, arg3: u64) u64 {
110 // These registers are both inputs and clobbers.
111 var r16_out: u64 = undefined;
112 var r17_out: u64 = undefined;
113 var r18_out: u64 = undefined;
114 return asm volatile (
115 \\ callsys
116 \\ beq $19, 1f
117 \\ negq $0, $0
118 \\1:
119 : [ret] "={$0}" (-> u64),
120 [r16_out] "={$16}" (r16_out),
121 [r17_out] "={$17}" (r17_out),
122 [r18_out] "={$18}" (r18_out),
123 : [number] "{$0}" (number),
124 [arg1] "{$16}" (arg1),
125 [arg2] "{$17}" (arg2),
126 [arg3] "{$18}" (arg3),
127 : .{
128 .r1 = true,
129 .r2 = true,
130 .r3 = true,
131 .r4 = true,
132 .r5 = true,
133 .r6 = true,
134 .r7 = true,
135 .r8 = true,
136 .r22 = true,
137 .r23 = true,
138 .r24 = true,
139 .r25 = true,
140 .r27 = true,
141 .r28 = true,
142 .memory = true,
143 .r20 = true,
144 .r21 = true,
145 });
146}
147
148pub fn syscall4(number: SYS, arg1: u64, arg2: u64, arg3: u64, arg4: u64) u64 {
149 // These registers are both inputs and clobbers.
150 var r16_out: u64 = undefined;
151 var r17_out: u64 = undefined;
152 var r18_out: u64 = undefined;
153 var r19_out: u64 = undefined;
154 return asm volatile (
155 \\ callsys
156 \\ beq $19, 1f
157 \\ negq $0, $0
158 \\1:
159 : [ret] "={$0}" (-> u64),
160 [r16_out] "={$16}" (r16_out),
161 [r17_out] "={$17}" (r17_out),
162 [r18_out] "={$18}" (r18_out),
163 [r19_out] "={$19}" (r19_out),
164 : [number] "{$0}" (number),
165 [arg1] "{$16}" (arg1),
166 [arg2] "{$17}" (arg2),
167 [arg3] "{$18}" (arg3),
168 [arg4] "{$19}" (arg4),
169 : .{
170 .r1 = true,
171 .r2 = true,
172 .r3 = true,
173 .r4 = true,
174 .r5 = true,
175 .r6 = true,
176 .r7 = true,
177 .r8 = true,
178 .r22 = true,
179 .r23 = true,
180 .r24 = true,
181 .r25 = true,
182 .r27 = true,
183 .r28 = true,
184 .memory = true,
185 .r20 = true,
186 .r21 = true,
187 });
188}
189
190pub fn syscall5(number: SYS, arg1: u64, arg2: u64, arg3: u64, arg4: u64, arg5: u64) u64 {
191 // These registers are both inputs and clobbers.
192 var r16_out: u64 = undefined;
193 var r17_out: u64 = undefined;
194 var r18_out: u64 = undefined;
195 var r19_out: u64 = undefined;
196 var r20_out: u64 = undefined;
197 return asm volatile (
198 \\ callsys
199 \\ beq $19, 1f
200 \\ negq $0, $0
201 \\1:
202 : [ret] "={$0}" (-> u64),
203 [r16_out] "={$16}" (r16_out),
204 [r17_out] "={$17}" (r17_out),
205 [r18_out] "={$18}" (r18_out),
206 [r19_out] "={$19}" (r19_out),
207 [r20_out] "={$20}" (r20_out),
208 : [number] "{$0}" (number),
209 [arg1] "{$16}" (arg1),
210 [arg2] "{$17}" (arg2),
211 [arg3] "{$18}" (arg3),
212 [arg4] "{$19}" (arg4),
213 [arg5] "{$20}" (arg5),
214 : .{
215 .r1 = true,
216 .r2 = true,
217 .r3 = true,
218 .r4 = true,
219 .r5 = true,
220 .r6 = true,
221 .r7 = true,
222 .r8 = true,
223 .r22 = true,
224 .r23 = true,
225 .r24 = true,
226 .r25 = true,
227 .r27 = true,
228 .r28 = true,
229 .memory = true,
230 .r21 = true,
231 });
232}
233
234pub fn syscall6(
235 number: SYS,
236 arg1: u64,
237 arg2: u64,
238 arg3: u64,
239 arg4: u64,
240 arg5: u64,
241 arg6: u64,
242) u64 {
243 // These registers are both inputs and clobbers.
244 var r16_out: u64 = undefined;
245 var r17_out: u64 = undefined;
246 var r18_out: u64 = undefined;
247 var r19_out: u64 = undefined;
248 var r20_out: u64 = undefined;
249 var r21_out: u64 = undefined;
250 return asm volatile (
251 \\ callsys
252 \\ beq $19, 1f
253 \\ negq $0, $0
254 \\1:
255 : [ret] "={$0}" (-> u64),
256 [r16_out] "={$16}" (r16_out),
257 [r17_out] "={$17}" (r17_out),
258 [r18_out] "={$18}" (r18_out),
259 [r19_out] "={$19}" (r19_out),
260 [r20_out] "={$20}" (r20_out),
261 [r21_out] "={$21}" (r21_out),
262 : [number] "{$0}" (number),
263 [arg1] "{$16}" (arg1),
264 [arg2] "{$17}" (arg2),
265 [arg3] "{$18}" (arg3),
266 [arg4] "{$19}" (arg4),
267 [arg5] "{$20}" (arg5),
268 [arg6] "{$21}" (arg6),
269 : .{
270 .r1 = true,
271 .r2 = true,
272 .r3 = true,
273 .r4 = true,
274 .r5 = true,
275 .r6 = true,
276 .r7 = true,
277 .r8 = true,
278 .r22 = true,
279 .r23 = true,
280 .r24 = true,
281 .r25 = true,
282 .r27 = true,
283 .r28 = true,
284 .memory = true,
285 });
286}
287
288pub fn clone() callconv(.naked) u64 {
289 // __clone(func, stack, flags, arg, ptid, tls, ctid)
290 // a0, a1, a2, a3, a4, a5, +0
291 //
292 // syscall(SYS_clone, flags, stack, ptid, ctid, tls)
293 // v0 a0, a1, a2, a3, a4
294 asm volatile (
295 // a0 = $16, a1 = $17, a2 = $18, a3 = $19,
296 // a4 = $20, a5 = $21, sp = $30, v0 = $0
297 \\ # Save function pointer and argument pointer on new thread stack
298 \\ ldi $1, -8
299 \\ and $17, $17, $1
300 \\ lda $17, -16($17)
301 \\ stq $16, 0($17)
302 \\ stq $19, 8($17)
303 \\
304 \\ # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,ctid,tls)
305 \\ mov $18, $16
306 \\ mov $20, $18
307 \\ ldq $19, 0($30)
308 \\ mov $21, $20
309 \\
310 \\ # Actual syscall
311 \\ ldi $0, 312 # SYS_clone
312 \\ callsys
313 \\ beq $19, 1f
314 \\ negq $0, $0
315 \\ ret
316 \\1:
317 \\ beq $0, 2f
318 \\ ret
319 \\2:
320 );
321 if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
322 // ra = $26
323 \\ .cfi_undefined $26
324 );
325 asm volatile (
326 // v0 = $0, t9 = $23, a0 = $16, ra = $26, sp = $30, fp = $15
327 \\ mov 0, $15
328 \\
329 \\ ldq $23, 0($30)
330 \\ ldq $16, 8($30)
331 \\ lda $30, 16($30)
332 \\ jsr $26, ($23)
333 \\
334 \\ mov $0, $16
335 \\ ldi $0, 1 # SYS_EXIT
336 \\ callsys
337 );
338}
339
340pub fn restore() noreturn {
341 asm volatile (
342 // v0 = $0, a0 = $16, sp = $30
343 \\ mov $30, $16
344 \\ ldi $0, 103 # SIGRETURN
345 \\ callsys
346 );
347}
348
349pub fn restore_rt() noreturn {
350 asm volatile (
351 // v0 = $0, a0 = $16, sp = $30
352 \\ mov $30, $16
353 \\ ldi $0, 351 # RT_SIGRETURN
354 \\ callsys
355 );
356}
357
358pub const VDSO = void;
lib/std/os/linux/ioctl.zig+1
......@@ -11,6 +11,7 @@ const bits = switch (@import("builtin").cpu.arch) {
1111 .powerpc64le,
1212 .sparc,
1313 .sparc64,
14 .alpha,
1415 => .{ .size = 13, .dir = 3, .none = 1, .read = 2, .write = 4 },
1516 else => .{ .size = 14, .dir = 2, .none = 0, .read = 2, .write = 1 },
1617};
lib/std/os/linux/syscalls.zig+502
......@@ -5851,6 +5851,508 @@ pub const Xtensa = enum(usize) {
58515851 rseq_slice_yield = 471,
58525852};
58535853
5854pub const Alpha = enum(usize) {
5855 osf_syscall = 0,
5856 exit = 1,
5857 fork = 2,
5858 read = 3,
5859 write = 4,
5860 osf_old_open = 5,
5861 close = 6,
5862 osf_wait4 = 7,
5863 osf_old_creat = 8,
5864 link = 9,
5865 unlink = 10,
5866 osf_execve = 11,
5867 chdir = 12,
5868 fchdir = 13,
5869 mknod = 14,
5870 chmod = 15,
5871 chown = 16,
5872 brk = 17,
5873 osf_getfsstat = 18,
5874 lseek = 19,
5875 getpid = 20,
5876 osf_mount = 21,
5877 umount2 = 22,
5878 setuid = 23,
5879 getuid = 24,
5880 exec_with_loader = 25,
5881 ptrace = 26,
5882 osf_nrecvmsg = 27,
5883 osf_nsendmsg = 28,
5884 osf_nrecvfrom = 29,
5885 osf_naccept = 30,
5886 osf_ngetpeername = 31,
5887 osf_ngetsockname = 32,
5888 access = 33,
5889 osf_chflags = 34,
5890 osf_fchflags = 35,
5891 sync = 36,
5892 kill = 37,
5893 osf_old_stat = 38,
5894 setpgid = 39,
5895 osf_old_lstat = 40,
5896 dup = 41,
5897 pipe = 42,
5898 osf_set_program_attributes = 43,
5899 osf_profil = 44,
5900 open = 45,
5901 osf_old_sigaction = 46,
5902 getgid = 47,
5903 osf_sigprocmask = 48,
5904 osf_getlogin = 49,
5905 osf_setlogin = 50,
5906 acct = 51,
5907 sigpending = 52,
5908 ioctl = 54,
5909 osf_reboot = 55,
5910 osf_revoke = 56,
5911 symlink = 57,
5912 readlink = 58,
5913 execve = 59,
5914 umask = 60,
5915 chroot = 61,
5916 osf_old_fstat = 62,
5917 getpgrp = 63,
5918 getpagesize = 64,
5919 osf_mremap = 65,
5920 vfork = 66,
5921 stat = 67,
5922 lstat = 68,
5923 osf_sbrk = 69,
5924 osf_sstk = 70,
5925 mmap = 71,
5926 osf_old_vadvise = 72,
5927 munmap = 73,
5928 mprotect = 74,
5929 madvise = 75,
5930 vhangup = 76,
5931 osf_kmodcall = 77,
5932 osf_mincore = 78,
5933 getgroups = 79,
5934 setgroups = 80,
5935 osf_old_getpgrp = 81,
5936 setpgrp = 82,
5937 osf_setitimer = 83,
5938 osf_old_wait = 84,
5939 osf_table = 85,
5940 osf_getitimer = 86,
5941 gethostname = 87,
5942 sethostname = 88,
5943 getdtablesize = 89,
5944 dup2 = 90,
5945 fstat = 91,
5946 fcntl = 92,
5947 osf_select = 93,
5948 poll = 94,
5949 fsync = 95,
5950 setpriority = 96,
5951 socket = 97,
5952 connect = 98,
5953 accept = 99,
5954 getpriority = 100,
5955 send = 101,
5956 recv = 102,
5957 sigreturn = 103,
5958 bind = 104,
5959 setsockopt = 105,
5960 listen = 106,
5961 osf_plock = 107,
5962 osf_old_sigvec = 108,
5963 osf_old_sigblock = 109,
5964 osf_old_sigsetmask = 110,
5965 sigsuspend = 111,
5966 osf_sigstack = 112,
5967 recvmsg = 113,
5968 sendmsg = 114,
5969 osf_old_vtrace = 115,
5970 osf_gettimeofday = 116,
5971 osf_getrusage = 117,
5972 getsockopt = 118,
5973 readv = 120,
5974 writev = 121,
5975 osf_settimeofday = 122,
5976 fchown = 123,
5977 fchmod = 124,
5978 recvfrom = 125,
5979 setreuid = 126,
5980 setregid = 127,
5981 rename = 128,
5982 truncate = 129,
5983 ftruncate = 130,
5984 flock = 131,
5985 setgid = 132,
5986 sendto = 133,
5987 shutdown = 134,
5988 socketpair = 135,
5989 mkdir = 136,
5990 rmdir = 137,
5991 osf_utimes = 138,
5992 osf_old_sigreturn = 139,
5993 osf_adjtime = 140,
5994 getpeername = 141,
5995 osf_gethostid = 142,
5996 osf_sethostid = 143,
5997 getrlimit = 144,
5998 setrlimit = 145,
5999 osf_old_killpg = 146,
6000 setsid = 147,
6001 quotactl = 148,
6002 osf_oldquota = 149,
6003 getsockname = 150,
6004 osf_pid_block = 153,
6005 osf_pid_unblock = 154,
6006 sigaction = 156,
6007 osf_sigwaitprim = 157,
6008 osf_nfssvc = 158,
6009 osf_getdirentries = 159,
6010 osf_statfs = 160,
6011 osf_fstatfs = 161,
6012 osf_asynch_daemon = 163,
6013 osf_getfh = 164,
6014 osf_getdomainname = 165,
6015 setdomainname = 166,
6016 osf_exportfs = 169,
6017 osf_alt_plock = 181,
6018 osf_getmnt = 184,
6019 osf_alt_sigpending = 187,
6020 osf_alt_setsid = 188,
6021 osf_swapon = 199,
6022 msgctl = 200,
6023 msgget = 201,
6024 msgrcv = 202,
6025 msgsnd = 203,
6026 semctl = 204,
6027 semget = 205,
6028 semop = 206,
6029 osf_utsname = 207,
6030 lchown = 208,
6031 shmat = 209,
6032 shmctl = 210,
6033 shmdt = 211,
6034 shmget = 212,
6035 osf_mvalid = 213,
6036 osf_getaddressconf = 214,
6037 osf_msleep = 215,
6038 osf_mwakeup = 216,
6039 msync = 217,
6040 osf_signal = 218,
6041 osf_utc_gettime = 219,
6042 osf_utc_adjtime = 220,
6043 osf_security = 222,
6044 osf_kloadcall = 223,
6045 osf_stat = 224,
6046 osf_lstat = 225,
6047 osf_fstat = 226,
6048 osf_statfs64 = 227,
6049 osf_fstatfs64 = 228,
6050 getpgid = 233,
6051 getsid = 234,
6052 sigaltstack = 235,
6053 osf_waitid = 236,
6054 osf_priocntlset = 237,
6055 osf_sigsendset = 238,
6056 osf_set_speculative = 239,
6057 osf_msfs_syscall = 240,
6058 osf_sysinfo = 241,
6059 osf_uadmin = 242,
6060 osf_fuser = 243,
6061 osf_proplist_syscall = 244,
6062 osf_ntp_adjtime = 245,
6063 osf_ntp_gettime = 246,
6064 osf_pathconf = 247,
6065 osf_fpathconf = 248,
6066 osf_uswitch = 250,
6067 osf_usleep_thread = 251,
6068 osf_audcntl = 252,
6069 osf_audgen = 253,
6070 sysfs = 254,
6071 osf_subsys_info = 255,
6072 osf_getsysinfo = 256,
6073 osf_setsysinfo = 257,
6074 osf_afs_syscall = 258,
6075 osf_swapctl = 259,
6076 osf_memcntl = 260,
6077 osf_fdatasync = 261,
6078 bdflush = 300,
6079 sethae = 301,
6080 mount = 302,
6081 old_adjtimex = 303,
6082 swapoff = 304,
6083 getdents = 305,
6084 create_module = 306,
6085 init_module = 307,
6086 delete_module = 308,
6087 get_kernel_syms = 309,
6088 syslog = 310,
6089 reboot = 311,
6090 clone = 312,
6091 uselib = 313,
6092 mlock = 314,
6093 munlock = 315,
6094 mlockall = 316,
6095 munlockall = 317,
6096 sysinfo = 318,
6097 sysctl = 319,
6098 oldumount = 321,
6099 swapon = 322,
6100 times = 323,
6101 personality = 324,
6102 setfsuid = 325,
6103 setfsgid = 326,
6104 ustat = 327,
6105 statfs = 328,
6106 fstatfs = 329,
6107 sched_setparam = 330,
6108 sched_getparam = 331,
6109 sched_setscheduler = 332,
6110 sched_getscheduler = 333,
6111 sched_yield = 334,
6112 sched_get_priority_max = 335,
6113 sched_get_priority_min = 336,
6114 sched_rr_get_interval = 337,
6115 afs_syscall = 338,
6116 uname = 339,
6117 nanosleep = 340,
6118 mremap = 341,
6119 nfsservctl = 342,
6120 setresuid = 343,
6121 getresuid = 344,
6122 pciconfig_read = 345,
6123 pciconfig_write = 346,
6124 query_module = 347,
6125 prctl = 348,
6126 pread64 = 349,
6127 pwrite64 = 350,
6128 rt_sigreturn = 351,
6129 rt_sigaction = 352,
6130 rt_sigprocmask = 353,
6131 rt_sigpending = 354,
6132 rt_sigtimedwait = 355,
6133 rt_sigqueueinfo = 356,
6134 rt_sigsuspend = 357,
6135 select = 358,
6136 gettimeofday = 359,
6137 settimeofday = 360,
6138 getitimer = 361,
6139 setitimer = 362,
6140 utimes = 363,
6141 getrusage = 364,
6142 wait4 = 365,
6143 adjtimex = 366,
6144 getcwd = 367,
6145 capget = 368,
6146 capset = 369,
6147 sendfile = 370,
6148 setresgid = 371,
6149 getresgid = 372,
6150 dipc = 373,
6151 pivot_root = 374,
6152 mincore = 375,
6153 pciconfig_iobase = 376,
6154 getdents64 = 377,
6155 gettid = 378,
6156 readahead = 379,
6157 tkill = 381,
6158 setxattr = 382,
6159 lsetxattr = 383,
6160 fsetxattr = 384,
6161 getxattr = 385,
6162 lgetxattr = 386,
6163 fgetxattr = 387,
6164 listxattr = 388,
6165 llistxattr = 389,
6166 flistxattr = 390,
6167 removexattr = 391,
6168 lremovexattr = 392,
6169 fremovexattr = 393,
6170 futex = 394,
6171 sched_setaffinity = 395,
6172 sched_getaffinity = 396,
6173 tuxcall = 397,
6174 io_setup = 398,
6175 io_destroy = 399,
6176 io_getevents = 400,
6177 io_submit = 401,
6178 io_cancel = 402,
6179 exit_group = 405,
6180 lookup_dcookie = 406,
6181 epoll_create = 407,
6182 epoll_ctl = 408,
6183 epoll_wait = 409,
6184 remap_file_pages = 410,
6185 set_tid_address = 411,
6186 restart_syscall = 412,
6187 fadvise64 = 413,
6188 timer_create = 414,
6189 timer_settime = 415,
6190 timer_gettime = 416,
6191 timer_getoverrun = 417,
6192 timer_delete = 418,
6193 clock_settime = 419,
6194 clock_gettime = 420,
6195 clock_getres = 421,
6196 clock_nanosleep = 422,
6197 semtimedop = 423,
6198 tgkill = 424,
6199 stat64 = 425,
6200 lstat64 = 426,
6201 fstat64 = 427,
6202 vserver = 428,
6203 mbind = 429,
6204 get_mempolicy = 430,
6205 set_mempolicy = 431,
6206 mq_open = 432,
6207 mq_unlink = 433,
6208 mq_timedsend = 434,
6209 mq_timedreceive = 435,
6210 mq_notify = 436,
6211 mq_getsetattr = 437,
6212 waitid = 438,
6213 add_key = 439,
6214 request_key = 440,
6215 keyctl = 441,
6216 ioprio_set = 442,
6217 ioprio_get = 443,
6218 inotify_init = 444,
6219 inotify_add_watch = 445,
6220 inotify_rm_watch = 446,
6221 fdatasync = 447,
6222 kexec_load = 448,
6223 migrate_pages = 449,
6224 openat = 450,
6225 mkdirat = 451,
6226 mknodat = 452,
6227 fchownat = 453,
6228 futimesat = 454,
6229 fstatat64 = 455,
6230 unlinkat = 456,
6231 renameat = 457,
6232 linkat = 458,
6233 symlinkat = 459,
6234 readlinkat = 460,
6235 fchmodat = 461,
6236 faccessat = 462,
6237 pselect6 = 463,
6238 ppoll = 464,
6239 unshare = 465,
6240 set_robust_list = 466,
6241 get_robust_list = 467,
6242 splice = 468,
6243 sync_file_range = 469,
6244 tee = 470,
6245 vmsplice = 471,
6246 move_pages = 472,
6247 getcpu = 473,
6248 epoll_pwait = 474,
6249 utimensat = 475,
6250 signalfd = 476,
6251 timerfd = 477,
6252 eventfd = 478,
6253 recvmmsg = 479,
6254 fallocate = 480,
6255 timerfd_create = 481,
6256 timerfd_settime = 482,
6257 timerfd_gettime = 483,
6258 signalfd4 = 484,
6259 eventfd2 = 485,
6260 epoll_create1 = 486,
6261 dup3 = 487,
6262 pipe2 = 488,
6263 inotify_init1 = 489,
6264 preadv = 490,
6265 pwritev = 491,
6266 rt_tgsigqueueinfo = 492,
6267 perf_event_open = 493,
6268 fanotify_init = 494,
6269 fanotify_mark = 495,
6270 prlimit64 = 496,
6271 name_to_handle_at = 497,
6272 open_by_handle_at = 498,
6273 clock_adjtime = 499,
6274 syncfs = 500,
6275 setns = 501,
6276 accept4 = 502,
6277 sendmmsg = 503,
6278 process_vm_readv = 504,
6279 process_vm_writev = 505,
6280 kcmp = 506,
6281 finit_module = 507,
6282 sched_setattr = 508,
6283 sched_getattr = 509,
6284 renameat2 = 510,
6285 getrandom = 511,
6286 memfd_create = 512,
6287 execveat = 513,
6288 seccomp = 514,
6289 bpf = 515,
6290 userfaultfd = 516,
6291 membarrier = 517,
6292 mlock2 = 518,
6293 copy_file_range = 519,
6294 preadv2 = 520,
6295 pwritev2 = 521,
6296 statx = 522,
6297 io_pgetevents = 523,
6298 pkey_mprotect = 524,
6299 pkey_alloc = 525,
6300 pkey_free = 526,
6301 rseq = 527,
6302 statfs64 = 528,
6303 fstatfs64 = 529,
6304 getegid = 530,
6305 geteuid = 531,
6306 getppid = 532,
6307 pidfd_send_signal = 534,
6308 io_uring_setup = 535,
6309 io_uring_enter = 536,
6310 io_uring_register = 537,
6311 open_tree = 538,
6312 move_mount = 539,
6313 fsopen = 540,
6314 fsconfig = 541,
6315 fsmount = 542,
6316 fspick = 543,
6317 pidfd_open = 544,
6318 clone3 = 545,
6319 close_range = 546,
6320 openat2 = 547,
6321 pidfd_getfd = 548,
6322 faccessat2 = 549,
6323 process_madvise = 550,
6324 epoll_pwait2 = 551,
6325 mount_setattr = 552,
6326 quotactl_fd = 553,
6327 landlock_create_ruleset = 554,
6328 landlock_add_rule = 555,
6329 landlock_restrict_self = 556,
6330 process_mrelease = 558,
6331 futex_waitv = 559,
6332 set_mempolicy_home_node = 560,
6333 cachestat = 561,
6334 fchmodat2 = 562,
6335 map_shadow_stack = 563,
6336 futex_wake = 564,
6337 futex_wait = 565,
6338 futex_requeue = 566,
6339 statmount = 567,
6340 listmount = 568,
6341 lsm_get_self_attr = 569,
6342 lsm_set_self_attr = 570,
6343 lsm_list_modules = 571,
6344 mseal = 572,
6345 setxattrat = 573,
6346 getxattrat = 574,
6347 listxattrat = 575,
6348 removexattrat = 576,
6349 open_tree_attr = 577,
6350 file_getattr = 578,
6351 file_setattr = 579,
6352 listns = 580,
6353 rseq_slice_yield = 581,
6354};
6355
58546356pub const Arm64 = enum(usize) {
58556357 io_setup = 0,
58566358 io_destroy = 1,
lib/std/os/linux/tls.zig+1-1
......@@ -256,7 +256,7 @@ pub fn setThreadPointer(addr: usize) void {
256256 },
257257 .alpha => {
258258 asm volatile (
259 \\ lda a0, %[addr]
259 \\ lda $16, 0(%[addr])
260260 \\ wruniq
261261 :
262262 : [addr] "r" (addr),
tools/generate_linux_syscalls.zig+6
......@@ -28,6 +28,11 @@ const stdlib_renames = std.StaticStringMap([]const u8).initComptime(.{
2828 // ARM EABI/Thumb.
2929 .{ "arm_sync_file_range", "sync_file_range" },
3030 .{ "arm_fadvise64_64", "fadvise64_64" },
31 // Alpha
32 // See https://github.com/torvalds/linux/blob/8bf22c33e7a172fbc72464f4cc484d23a6b412ba/arch/alpha/include/uapi/asm/unistd.h#L10
33 .{ "getxpid", "getpid" },
34 .{ "getxuid", "getuid" },
35 .{ "getxgid", "getgid" },
3136});
3237
3338/// Filter syscalls that aren't actually syscalls.
......@@ -156,6 +161,7 @@ const architectures: []const Arch = &.{
156161 .{ .@"var" = "PowerPC64", .table = .{ .specific = "arch/powerpc/kernel/syscalls/syscall.tbl" }, .abi = &.{ .common, .@"64", .nospu } },
157162 .{ .@"var" = "S390x", .table = .{ .specific = "arch/s390/kernel/syscalls/syscall.tbl" }, .abi = &.{ .common, .@"64" } },
158163 .{ .@"var" = "Xtensa", .table = .{ .specific = "arch/xtensa/kernel/syscalls/syscall.tbl" } },
164 .{ .@"var" = "Alpha", .table = .{ .specific = "arch/alpha/kernel/syscalls/syscall.tbl" } },
159165 .{ .@"var" = "Arm64", .table = .generic, .abi = &.{ .common, .@"64", .renameat, .rlimit, .memfd_secret } },
160166 .{ .@"var" = "RiscV32", .table = .generic, .abi = &.{ .common, .@"32", .riscv, .memfd_secret } },
161167 .{ .@"var" = "RiscV64", .table = .generic, .abi = &.{ .common, .@"64", .riscv, .rlimit, .memfd_secret } },