| author | |
| committer | |
| log | 2d33cc2e42d40ce0ee798d4d56c2d7da93ead44a |
| tree | bad7965f8787aaf5a84b63996cb384d0866f0743 |
| parent | d8153fa74ab01f8cdc117e0049e0a2d2e4187892 |
| parent | bcb4ba9afd610a0f3ab66ad828c90fd57dc95a6f |
| signature |
13 files changed, 324 insertions(+), 51 deletions(-)
lib/std/c.zig-4| ... | @@ -1601,10 +1601,6 @@ pub const MSF = switch (native_os) { | ... | @@ -1601,10 +1601,6 @@ pub const MSF = switch (native_os) { |
| 1601 | }, | 1601 | }, |
| 1602 | else => void, | 1602 | else => void, |
| 1603 | }; | 1603 | }; |
| 1604 | pub const MMAP2_UNIT = switch (native_os) { | ||
| 1605 | .linux => linux.MMAP2_UNIT, | ||
| 1606 | else => void, | ||
| 1607 | }; | ||
| 1608 | pub const NAME_MAX = switch (native_os) { | 1604 | pub const NAME_MAX = switch (native_os) { |
| 1609 | .linux => linux.NAME_MAX, | 1605 | .linux => linux.NAME_MAX, |
| 1610 | .emscripten => emscripten.NAME_MAX, | 1606 | .emscripten => emscripten.NAME_MAX, |
lib/std/os/linux.zig+32-11| ... | @@ -39,6 +39,7 @@ const arch_bits = switch (native_arch) { | ... | @@ -39,6 +39,7 @@ const arch_bits = switch (native_arch) { |
| 39 | .riscv64 => @import("linux/riscv64.zig"), | 39 | .riscv64 => @import("linux/riscv64.zig"), |
| 40 | .sparc64 => @import("linux/sparc64.zig"), | 40 | .sparc64 => @import("linux/sparc64.zig"), |
| 41 | .loongarch64 => @import("linux/loongarch64.zig"), | 41 | .loongarch64 => @import("linux/loongarch64.zig"), |
| 42 | .m68k => @import("linux/m68k.zig"), | ||
| 42 | .mips, .mipsel => @import("linux/mips.zig"), | 43 | .mips, .mipsel => @import("linux/mips.zig"), |
| 43 | .mips64, .mips64el => @import("linux/mips64.zig"), | 44 | .mips64, .mips64el => @import("linux/mips64.zig"), |
| 44 | .powerpc, .powerpcle => @import("linux/powerpc.zig"), | 45 | .powerpc, .powerpcle => @import("linux/powerpc.zig"), |
| ... | @@ -92,7 +93,6 @@ pub const Elf_Symndx = arch_bits.Elf_Symndx; | ... | @@ -92,7 +93,6 @@ pub const Elf_Symndx = arch_bits.Elf_Symndx; |
| 92 | pub const F = arch_bits.F; | 93 | pub const F = arch_bits.F; |
| 93 | pub const Flock = arch_bits.Flock; | 94 | pub const Flock = arch_bits.Flock; |
| 94 | pub const HWCAP = arch_bits.HWCAP; | 95 | pub const HWCAP = arch_bits.HWCAP; |
| 95 | pub const MMAP2_UNIT = arch_bits.MMAP2_UNIT; | ||
| 96 | pub const REG = arch_bits.REG; | 96 | pub const REG = arch_bits.REG; |
| 97 | pub const SC = arch_bits.SC; | 97 | pub const SC = arch_bits.SC; |
| 98 | pub const Stat = arch_bits.Stat; | 98 | pub const Stat = arch_bits.Stat; |
| ... | @@ -279,7 +279,7 @@ pub const MAP = switch (native_arch) { | ... | @@ -279,7 +279,7 @@ pub const MAP = switch (native_arch) { |
| 279 | UNINITIALIZED: bool = false, | 279 | UNINITIALIZED: bool = false, |
| 280 | _: u5 = 0, | 280 | _: u5 = 0, |
| 281 | }, | 281 | }, |
| 282 | .hexagon, .s390x => packed struct(u32) { | 282 | .hexagon, .m68k, .s390x => packed struct(u32) { |
| 283 | TYPE: MAP_TYPE, | 283 | TYPE: MAP_TYPE, |
| 284 | FIXED: bool = false, | 284 | FIXED: bool = false, |
| 285 | ANONYMOUS: bool = false, | 285 | ANONYMOUS: bool = false, |
| ... | @@ -333,7 +333,7 @@ pub const O = switch (native_arch) { | ... | @@ -333,7 +333,7 @@ pub const O = switch (native_arch) { |
| 333 | SYNC: bool = false, | 333 | SYNC: bool = false, |
| 334 | PATH: bool = false, | 334 | PATH: bool = false, |
| 335 | TMPFILE: bool = false, | 335 | TMPFILE: bool = false, |
| 336 | _: u9 = 0, | 336 | _23: u9 = 0, |
| 337 | }, | 337 | }, |
| 338 | .x86, .riscv32, .riscv64, .loongarch64 => packed struct(u32) { | 338 | .x86, .riscv32, .riscv64, .loongarch64 => packed struct(u32) { |
| 339 | ACCMODE: ACCMODE = .RDONLY, | 339 | ACCMODE: ACCMODE = .RDONLY, |
| ... | @@ -355,7 +355,7 @@ pub const O = switch (native_arch) { | ... | @@ -355,7 +355,7 @@ pub const O = switch (native_arch) { |
| 355 | SYNC: bool = false, | 355 | SYNC: bool = false, |
| 356 | PATH: bool = false, | 356 | PATH: bool = false, |
| 357 | TMPFILE: bool = false, | 357 | TMPFILE: bool = false, |
| 358 | _: u9 = 0, | 358 | _23: u9 = 0, |
| 359 | }, | 359 | }, |
| 360 | .aarch64, .aarch64_be, .arm, .armeb, .thumb, .thumbeb => packed struct(u32) { | 360 | .aarch64, .aarch64_be, .arm, .armeb, .thumb, .thumbeb => packed struct(u32) { |
| 361 | ACCMODE: ACCMODE = .RDONLY, | 361 | ACCMODE: ACCMODE = .RDONLY, |
| ... | @@ -377,7 +377,7 @@ pub const O = switch (native_arch) { | ... | @@ -377,7 +377,7 @@ pub const O = switch (native_arch) { |
| 377 | SYNC: bool = false, | 377 | SYNC: bool = false, |
| 378 | PATH: bool = false, | 378 | PATH: bool = false, |
| 379 | TMPFILE: bool = false, | 379 | TMPFILE: bool = false, |
| 380 | _: u9 = 0, | 380 | _23: u9 = 0, |
| 381 | }, | 381 | }, |
| 382 | .sparc64 => packed struct(u32) { | 382 | .sparc64 => packed struct(u32) { |
| 383 | ACCMODE: ACCMODE = .RDONLY, | 383 | ACCMODE: ACCMODE = .RDONLY, |
| ... | @@ -402,7 +402,7 @@ pub const O = switch (native_arch) { | ... | @@ -402,7 +402,7 @@ pub const O = switch (native_arch) { |
| 402 | SYNC: bool = false, | 402 | SYNC: bool = false, |
| 403 | PATH: bool = false, | 403 | PATH: bool = false, |
| 404 | TMPFILE: bool = false, | 404 | TMPFILE: bool = false, |
| 405 | _: u6 = 0, | 405 | _27: u6 = 0, |
| 406 | }, | 406 | }, |
| 407 | .mips, .mipsel, .mips64, .mips64el => packed struct(u32) { | 407 | .mips, .mipsel, .mips64, .mips64el => packed struct(u32) { |
| 408 | ACCMODE: ACCMODE = .RDONLY, | 408 | ACCMODE: ACCMODE = .RDONLY, |
| ... | @@ -426,7 +426,7 @@ pub const O = switch (native_arch) { | ... | @@ -426,7 +426,7 @@ pub const O = switch (native_arch) { |
| 426 | _20: u1 = 0, | 426 | _20: u1 = 0, |
| 427 | PATH: bool = false, | 427 | PATH: bool = false, |
| 428 | TMPFILE: bool = false, | 428 | TMPFILE: bool = false, |
| 429 | _: u9 = 0, | 429 | _23: u9 = 0, |
| 430 | }, | 430 | }, |
| 431 | .powerpc, .powerpcle, .powerpc64, .powerpc64le => packed struct(u32) { | 431 | .powerpc, .powerpcle, .powerpc64, .powerpc64le => packed struct(u32) { |
| 432 | ACCMODE: ACCMODE = .RDONLY, | 432 | ACCMODE: ACCMODE = .RDONLY, |
| ... | @@ -448,7 +448,7 @@ pub const O = switch (native_arch) { | ... | @@ -448,7 +448,7 @@ pub const O = switch (native_arch) { |
| 448 | SYNC: bool = false, | 448 | SYNC: bool = false, |
| 449 | PATH: bool = false, | 449 | PATH: bool = false, |
| 450 | TMPFILE: bool = false, | 450 | TMPFILE: bool = false, |
| 451 | _: u9 = 0, | 451 | _23: u9 = 0, |
| 452 | }, | 452 | }, |
| 453 | .hexagon, .s390x => packed struct(u32) { | 453 | .hexagon, .s390x => packed struct(u32) { |
| 454 | ACCMODE: ACCMODE = .RDONLY, | 454 | ACCMODE: ACCMODE = .RDONLY, |
| ... | @@ -467,15 +467,36 @@ pub const O = switch (native_arch) { | ... | @@ -467,15 +467,36 @@ pub const O = switch (native_arch) { |
| 467 | NOFOLLOW: bool = false, | 467 | NOFOLLOW: bool = false, |
| 468 | NOATIME: bool = false, | 468 | NOATIME: bool = false, |
| 469 | CLOEXEC: bool = false, | 469 | CLOEXEC: bool = false, |
| 470 | _17: u1 = 0, | 470 | _20: u1 = 0, |
| 471 | PATH: bool = false, | 471 | PATH: bool = false, |
| 472 | _: u10 = 0, | 472 | _22: u10 = 0, |
| 473 | 473 | ||
| 474 | // #define O_RSYNC 04010000 | 474 | // #define O_RSYNC 04010000 |
| 475 | // #define O_SYNC 04010000 | 475 | // #define O_SYNC 04010000 |
| 476 | // #define O_TMPFILE 020200000 | 476 | // #define O_TMPFILE 020200000 |
| 477 | // #define O_NDELAY O_NONBLOCK | 477 | // #define O_NDELAY O_NONBLOCK |
| 478 | }, | 478 | }, |
| 479 | .m68k => packed struct(u32) { | ||
| 480 | ACCMODE: ACCMODE = .RDONLY, | ||
| 481 | _2: u4 = 0, | ||
| 482 | CREAT: bool = false, | ||
| 483 | EXCL: bool = false, | ||
| 484 | NOCTTY: bool = false, | ||
| 485 | TRUNC: bool = false, | ||
| 486 | APPEND: bool = false, | ||
| 487 | NONBLOCK: bool = false, | ||
| 488 | DSYNC: bool = false, | ||
| 489 | ASYNC: bool = false, | ||
| 490 | DIRECTORY: bool = false, | ||
| 491 | NOFOLLOW: bool = false, | ||
| 492 | DIRECT: bool = false, | ||
| 493 | LARGEFILE: bool = false, | ||
| 494 | NOATIME: bool = false, | ||
| 495 | CLOEXEC: bool = false, | ||
| 496 | _20: u1 = 0, | ||
| 497 | PATH: bool = false, | ||
| 498 | _22: u10 = 0, | ||
| 499 | }, | ||
| 479 | else => @compileError("missing std.os.linux.O constants for this architecture"), | 500 | else => @compileError("missing std.os.linux.O constants for this architecture"), |
| 480 | }; | 501 | }; |
| 481 | 502 | ||
| ... | @@ -906,7 +927,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: MAP, fd: i32, of | ... | @@ -906,7 +927,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: MAP, fd: i32, of |
| 906 | prot, | 927 | prot, |
| 907 | @as(u32, @bitCast(flags)), | 928 | @as(u32, @bitCast(flags)), |
| 908 | @bitCast(@as(isize, fd)), | 929 | @bitCast(@as(isize, fd)), |
| 909 | @truncate(@as(u64, @bitCast(offset)) / MMAP2_UNIT), | 930 | @truncate(@as(u64, @bitCast(offset)) / std.heap.pageSize()), |
| 910 | ); | 931 | ); |
| 911 | } else { | 932 | } else { |
| 912 | // The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so | 933 | // The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so |
lib/std/os/linux/arm.zig-2| ... | @@ -170,8 +170,6 @@ pub fn restore_rt() callconv(.naked) noreturn { | ... | @@ -170,8 +170,6 @@ pub fn restore_rt() callconv(.naked) noreturn { |
| 170 | } | 170 | } |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | pub const MMAP2_UNIT = 4096; | ||
| 174 | |||
| 175 | pub const F = struct { | 173 | pub const F = struct { |
| 176 | pub const DUPFD = 0; | 174 | pub const DUPFD = 0; |
| 177 | pub const GETFD = 1; | 175 | pub const GETFD = 1; |
lib/std/os/linux/hexagon.zig-2| ... | @@ -251,8 +251,6 @@ pub const Stat = extern struct { | ... | @@ -251,8 +251,6 @@ pub const Stat = extern struct { |
| 251 | 251 | ||
| 252 | pub const Elf_Symndx = u32; | 252 | pub const Elf_Symndx = u32; |
| 253 | 253 | ||
| 254 | pub const MMAP2_UNIT = 4096; | ||
| 255 | |||
| 256 | pub const VDSO = void; | 254 | pub const VDSO = void; |
| 257 | 255 | ||
| 258 | /// TODO | 256 | /// TODO |
lib/std/os/linux/m68k.zig created+271| ... | @@ -0,0 +1,271 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("../../std.zig"); | ||
| 3 | const iovec = std.posix.iovec; | ||
| 4 | const iovec_const = std.posix.iovec_const; | ||
| 5 | const linux = std.os.linux; | ||
| 6 | const SYS = linux.SYS; | ||
| 7 | const uid_t = std.os.linux.uid_t; | ||
| 8 | const gid_t = std.os.linux.uid_t; | ||
| 9 | const pid_t = std.os.linux.pid_t; | ||
| 10 | const sockaddr = linux.sockaddr; | ||
| 11 | const socklen_t = linux.socklen_t; | ||
| 12 | const timespec = std.os.linux.timespec; | ||
| 13 | |||
| 14 | pub fn syscall0(number: SYS) usize { | ||
| 15 | return asm volatile ("trap #0" | ||
| 16 | : [ret] "={d0}" (-> usize), | ||
| 17 | : [number] "{d0}" (@intFromEnum(number)), | ||
| 18 | : "memory" | ||
| 19 | ); | ||
| 20 | } | ||
| 21 | |||
| 22 | pub fn syscall1(number: SYS, arg1: usize) usize { | ||
| 23 | return asm volatile ("trap #0" | ||
| 24 | : [ret] "={d0}" (-> usize), | ||
| 25 | : [number] "{d0}" (@intFromEnum(number)), | ||
| 26 | [arg1] "{d1}" (arg1), | ||
| 27 | : "memory" | ||
| 28 | ); | ||
| 29 | } | ||
| 30 | |||
| 31 | pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize { | ||
| 32 | return asm volatile ("trap #0" | ||
| 33 | : [ret] "={d0}" (-> usize), | ||
| 34 | : [number] "{d0}" (@intFromEnum(number)), | ||
| 35 | [arg1] "{d1}" (arg1), | ||
| 36 | [arg2] "{d2}" (arg2), | ||
| 37 | : "memory" | ||
| 38 | ); | ||
| 39 | } | ||
| 40 | |||
| 41 | pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize { | ||
| 42 | return asm volatile ("trap #0" | ||
| 43 | : [ret] "={d0}" (-> usize), | ||
| 44 | : [number] "{d0}" (@intFromEnum(number)), | ||
| 45 | [arg1] "{d1}" (arg1), | ||
| 46 | [arg2] "{d2}" (arg2), | ||
| 47 | [arg3] "{d3}" (arg3), | ||
| 48 | : "memory" | ||
| 49 | ); | ||
| 50 | } | ||
| 51 | |||
| 52 | pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | ||
| 53 | return asm volatile ("trap #0" | ||
| 54 | : [ret] "={d0}" (-> usize), | ||
| 55 | : [number] "{d0}" (@intFromEnum(number)), | ||
| 56 | [arg1] "{d1}" (arg1), | ||
| 57 | [arg2] "{d2}" (arg2), | ||
| 58 | [arg3] "{d3}" (arg3), | ||
| 59 | [arg4] "{d4}" (arg4), | ||
| 60 | : "memory" | ||
| 61 | ); | ||
| 62 | } | ||
| 63 | |||
| 64 | pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | ||
| 65 | return asm volatile ("trap #0" | ||
| 66 | : [ret] "={d0}" (-> usize), | ||
| 67 | : [number] "{d0}" (@intFromEnum(number)), | ||
| 68 | [arg1] "{d1}" (arg1), | ||
| 69 | [arg2] "{d2}" (arg2), | ||
| 70 | [arg3] "{d3}" (arg3), | ||
| 71 | [arg4] "{d4}" (arg4), | ||
| 72 | [arg5] "{d5}" (arg5), | ||
| 73 | : "memory" | ||
| 74 | ); | ||
| 75 | } | ||
| 76 | |||
| 77 | pub fn syscall6( | ||
| 78 | number: SYS, | ||
| 79 | arg1: usize, | ||
| 80 | arg2: usize, | ||
| 81 | arg3: usize, | ||
| 82 | arg4: usize, | ||
| 83 | arg5: usize, | ||
| 84 | arg6: usize, | ||
| 85 | ) usize { | ||
| 86 | return asm volatile ("trap #0" | ||
| 87 | : [ret] "={d0}" (-> usize), | ||
| 88 | : [number] "{d0}" (@intFromEnum(number)), | ||
| 89 | [arg1] "{d1}" (arg1), | ||
| 90 | [arg2] "{d2}" (arg2), | ||
| 91 | [arg3] "{d3}" (arg3), | ||
| 92 | [arg4] "{d4}" (arg4), | ||
| 93 | [arg5] "{d5}" (arg5), | ||
| 94 | [arg6] "{a0}" (arg6), | ||
| 95 | : "memory" | ||
| 96 | ); | ||
| 97 | } | ||
| 98 | |||
| 99 | pub fn clone() callconv(.naked) usize { | ||
| 100 | // __clone(func, stack, flags, arg, ptid, tls, ctid) | ||
| 101 | // +4, +8, +12, +16, +20, +24, +28 | ||
| 102 | // | ||
| 103 | // syscall(SYS_clone, flags, stack, ptid, ctid, tls) | ||
| 104 | // d0, d1, d2, d3, d4, d5 | ||
| 105 | asm volatile ( | ||
| 106 | \\ // Save callee-saved registers. | ||
| 107 | \\ movem.l %%d2-%%d5, -(%%sp) // sp -= 16 | ||
| 108 | \\ | ||
| 109 | \\ // Save func and arg. | ||
| 110 | \\ move.l 16+4(%%sp), %%a0 | ||
| 111 | \\ move.l 16+16(%%sp), %%a1 | ||
| 112 | \\ | ||
| 113 | \\ // d0 = syscall(d0, d1, d2, d3, d4, d5) | ||
| 114 | \\ move.l #120, %%d0 // SYS_clone | ||
| 115 | \\ move.l 16+12(%%sp), %%d1 | ||
| 116 | \\ move.l 16+8(%%sp), %%d2 | ||
| 117 | \\ move.l 16+20(%%sp), %%d3 | ||
| 118 | \\ move.l 16+28(%%sp), %%d4 | ||
| 119 | \\ move.l 16+24(%%sp), %%d5 | ||
| 120 | \\ and.l #-4, %%d2 // Align the child stack pointer. | ||
| 121 | \\ trap #0 | ||
| 122 | \\ | ||
| 123 | \\ // Are we in the parent or child? | ||
| 124 | \\ tst.l %%d0 | ||
| 125 | \\ beq 1f | ||
| 126 | \\ // Parent: | ||
| 127 | \\ | ||
| 128 | \\ // Restore callee-saved registers and return. | ||
| 129 | \\ movem.l (%%sp)+, %%d2-%%d5 // sp += 16 | ||
| 130 | \\ rts | ||
| 131 | \\ | ||
| 132 | \\ // Child: | ||
| 133 | \\1: | ||
| 134 | ); | ||
| 135 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( | ||
| 136 | \\ .cfi_undefined %%pc | ||
| 137 | ); | ||
| 138 | asm volatile ( | ||
| 139 | \\ suba.l %%fp, %%fp | ||
| 140 | \\ | ||
| 141 | \\ // d0 = func(a1) | ||
| 142 | \\ move.l %%a1, -(%%sp) | ||
| 143 | \\ jsr (%%a0) | ||
| 144 | \\ | ||
| 145 | \\ // syscall(d0, d1) | ||
| 146 | \\ move.l %%d0, %%d1 | ||
| 147 | \\ move.l #1, %%d0 // SYS_exit | ||
| 148 | \\ trap #0 | ||
| 149 | ); | ||
| 150 | } | ||
| 151 | |||
| 152 | pub const restore = restore_rt; | ||
| 153 | |||
| 154 | pub fn restore_rt() callconv(.naked) noreturn { | ||
| 155 | asm volatile ("trap #0" | ||
| 156 | : | ||
| 157 | : [number] "{d0}" (@intFromEnum(SYS.rt_sigreturn)), | ||
| 158 | : "memory" | ||
| 159 | ); | ||
| 160 | } | ||
| 161 | |||
| 162 | pub const F = struct { | ||
| 163 | pub const DUPFD = 0; | ||
| 164 | pub const GETFD = 1; | ||
| 165 | pub const SETFD = 2; | ||
| 166 | pub const GETFL = 3; | ||
| 167 | pub const SETFL = 4; | ||
| 168 | |||
| 169 | pub const SETOWN = 8; | ||
| 170 | pub const GETOWN = 9; | ||
| 171 | pub const SETSIG = 10; | ||
| 172 | pub const GETSIG = 11; | ||
| 173 | |||
| 174 | pub const GETLK = 12; | ||
| 175 | pub const SETLK = 13; | ||
| 176 | pub const SETLKW = 14; | ||
| 177 | |||
| 178 | pub const SETOWN_EX = 15; | ||
| 179 | pub const GETOWN_EX = 16; | ||
| 180 | |||
| 181 | pub const GETOWNER_UIDS = 17; | ||
| 182 | |||
| 183 | pub const RDLCK = 0; | ||
| 184 | pub const WRLCK = 1; | ||
| 185 | pub const UNLCK = 2; | ||
| 186 | }; | ||
| 187 | |||
| 188 | pub const blksize_t = i32; | ||
| 189 | pub const nlink_t = u32; | ||
| 190 | pub const time_t = i32; | ||
| 191 | pub const mode_t = u32; | ||
| 192 | pub const off_t = i64; | ||
| 193 | pub const ino_t = u64; | ||
| 194 | pub const dev_t = u64; | ||
| 195 | pub const blkcnt_t = i64; | ||
| 196 | |||
| 197 | pub const timeval = extern struct { | ||
| 198 | sec: time_t, | ||
| 199 | usec: i32, | ||
| 200 | }; | ||
| 201 | |||
| 202 | pub const Flock = extern struct { | ||
| 203 | type: i16, | ||
| 204 | whence: i16, | ||
| 205 | start: off_t, | ||
| 206 | len: off_t, | ||
| 207 | pid: pid_t, | ||
| 208 | }; | ||
| 209 | |||
| 210 | // TODO: not 100% sure of padding for msghdr | ||
| 211 | pub const msghdr = extern struct { | ||
| 212 | name: ?*sockaddr, | ||
| 213 | namelen: socklen_t, | ||
| 214 | iov: [*]iovec, | ||
| 215 | iovlen: i32, | ||
| 216 | control: ?*anyopaque, | ||
| 217 | controllen: socklen_t, | ||
| 218 | flags: i32, | ||
| 219 | }; | ||
| 220 | |||
| 221 | pub const msghdr_const = extern struct { | ||
| 222 | name: ?*const sockaddr, | ||
| 223 | namelen: socklen_t, | ||
| 224 | iov: [*]const iovec_const, | ||
| 225 | iovlen: i32, | ||
| 226 | control: ?*const anyopaque, | ||
| 227 | controllen: socklen_t, | ||
| 228 | flags: i32, | ||
| 229 | }; | ||
| 230 | |||
| 231 | pub const Stat = extern struct { | ||
| 232 | dev: dev_t, | ||
| 233 | __pad: i16, | ||
| 234 | __ino_truncated: i32, | ||
| 235 | mode: mode_t, | ||
| 236 | nlink: nlink_t, | ||
| 237 | uid: uid_t, | ||
| 238 | gid: gid_t, | ||
| 239 | rdev: dev_t, | ||
| 240 | __pad2: i16, | ||
| 241 | size: off_t, | ||
| 242 | blksize: blksize_t, | ||
| 243 | blocks: blkcnt_t, | ||
| 244 | atim: timespec, | ||
| 245 | mtim: timespec, | ||
| 246 | ctim: timespec, | ||
| 247 | ino: ino_t, | ||
| 248 | |||
| 249 | pub fn atime(self: @This()) timespec { | ||
| 250 | return self.atim; | ||
| 251 | } | ||
| 252 | |||
| 253 | pub fn mtime(self: @This()) timespec { | ||
| 254 | return self.mtim; | ||
| 255 | } | ||
| 256 | |||
| 257 | pub fn ctime(self: @This()) timespec { | ||
| 258 | return self.ctim; | ||
| 259 | } | ||
| 260 | }; | ||
| 261 | |||
| 262 | pub const Elf_Symndx = u32; | ||
| 263 | |||
| 264 | // No VDSO used as of glibc 112a0ae18b831bf31f44d81b82666980312511d6. | ||
| 265 | pub const VDSO = void; | ||
| 266 | |||
| 267 | /// TODO | ||
| 268 | pub const ucontext_t = void; | ||
| 269 | |||
| 270 | /// TODO | ||
| 271 | pub const getcontext = {}; | ||
lib/std/os/linux/mips.zig-2| ... | @@ -294,8 +294,6 @@ pub const F = struct { | ... | @@ -294,8 +294,6 @@ pub const F = struct { |
| 294 | pub const GETOWNER_UIDS = 17; | 294 | pub const GETOWNER_UIDS = 17; |
| 295 | }; | 295 | }; |
| 296 | 296 | ||
| 297 | pub const MMAP2_UNIT = 4096; | ||
| 298 | |||
| 299 | pub const VDSO = struct { | 297 | pub const VDSO = struct { |
| 300 | pub const CGT_SYM = "__vdso_clock_gettime"; | 298 | pub const CGT_SYM = "__vdso_clock_gettime"; |
| 301 | pub const CGT_VER = "LINUX_2.6"; | 299 | pub const CGT_VER = "LINUX_2.6"; |
lib/std/os/linux/mips64.zig-2| ... | @@ -273,8 +273,6 @@ pub const F = struct { | ... | @@ -273,8 +273,6 @@ pub const F = struct { |
| 273 | pub const GETOWNER_UIDS = 17; | 273 | pub const GETOWNER_UIDS = 17; |
| 274 | }; | 274 | }; |
| 275 | 275 | ||
| 276 | pub const MMAP2_UNIT = 4096; | ||
| 277 | |||
| 278 | pub const VDSO = struct { | 276 | pub const VDSO = struct { |
| 279 | pub const CGT_SYM = "__vdso_clock_gettime"; | 277 | pub const CGT_SYM = "__vdso_clock_gettime"; |
| 280 | pub const CGT_VER = "LINUX_2.6"; | 278 | pub const CGT_VER = "LINUX_2.6"; |
lib/std/os/linux/powerpc.zig-2| ... | @@ -348,7 +348,5 @@ pub const ucontext_t = extern struct { | ... | @@ -348,7 +348,5 @@ pub const ucontext_t = extern struct { |
| 348 | 348 | ||
| 349 | pub const Elf_Symndx = u32; | 349 | pub const Elf_Symndx = u32; |
| 350 | 350 | ||
| 351 | pub const MMAP2_UNIT = 4096; | ||
| 352 | |||
| 353 | /// TODO | 351 | /// TODO |
| 354 | pub const getcontext = {}; | 352 | pub const getcontext = {}; |
lib/std/os/linux/riscv32.zig-2| ... | @@ -256,8 +256,6 @@ pub const Stat = extern struct { | ... | @@ -256,8 +256,6 @@ pub const Stat = extern struct { |
| 256 | 256 | ||
| 257 | pub const Elf_Symndx = u32; | 257 | pub const Elf_Symndx = u32; |
| 258 | 258 | ||
| 259 | pub const MMAP2_UNIT = 4096; | ||
| 260 | |||
| 261 | pub const VDSO = struct { | 259 | pub const VDSO = struct { |
| 262 | pub const CGT_SYM = "__vdso_clock_gettime"; | 260 | pub const CGT_SYM = "__vdso_clock_gettime"; |
| 263 | pub const CGT_VER = "LINUX_4.15"; | 261 | pub const CGT_VER = "LINUX_4.15"; |
lib/std/os/linux/tls.zig+14-18| ... | @@ -508,14 +508,7 @@ pub fn initStatic(phdrs: []elf.Phdr) void { | ... | @@ -508,14 +508,7 @@ pub fn initStatic(phdrs: []elf.Phdr) void { |
| 508 | break :blk main_thread_area_buffer[0..area_desc.size]; | 508 | break :blk main_thread_area_buffer[0..area_desc.size]; |
| 509 | } | 509 | } |
| 510 | 510 | ||
| 511 | const begin_addr = mmap( | 511 | const begin_addr = mmap_tls(area_desc.size + area_desc.alignment - 1); |
| 512 | null, | ||
| 513 | area_desc.size + area_desc.alignment - 1, | ||
| 514 | posix.PROT.READ | posix.PROT.WRITE, | ||
| 515 | .{ .TYPE = .PRIVATE, .ANONYMOUS = true }, | ||
| 516 | -1, | ||
| 517 | 0, | ||
| 518 | ); | ||
| 519 | if (@call(.always_inline, linux.E.init, .{begin_addr}) != .SUCCESS) @trap(); | 512 | if (@call(.always_inline, linux.E.init, .{begin_addr}) != .SUCCESS) @trap(); |
| 520 | 513 | ||
| 521 | const area_ptr: [*]align(page_size_min) u8 = @ptrFromInt(begin_addr); | 514 | const area_ptr: [*]align(page_size_min) u8 = @ptrFromInt(begin_addr); |
| ... | @@ -530,16 +523,19 @@ pub fn initStatic(phdrs: []elf.Phdr) void { | ... | @@ -530,16 +523,19 @@ pub fn initStatic(phdrs: []elf.Phdr) void { |
| 530 | setThreadPointer(tp_value); | 523 | setThreadPointer(tp_value); |
| 531 | } | 524 | } |
| 532 | 525 | ||
| 533 | inline fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: linux.MAP, fd: i32, offset: i64) usize { | 526 | inline fn mmap_tls(length: usize) usize { |
| 527 | const prot = posix.PROT.READ | posix.PROT.WRITE; | ||
| 528 | const flags: linux.MAP = .{ .TYPE = .PRIVATE, .ANONYMOUS = true }; | ||
| 529 | |||
| 534 | if (@hasField(linux.SYS, "mmap2")) { | 530 | if (@hasField(linux.SYS, "mmap2")) { |
| 535 | return @call(.always_inline, linux.syscall6, .{ | 531 | return @call(.always_inline, linux.syscall6, .{ |
| 536 | .mmap2, | 532 | .mmap2, |
| 537 | @intFromPtr(address), | 533 | 0, |
| 538 | length, | 534 | length, |
| 539 | prot, | 535 | prot, |
| 540 | @as(u32, @bitCast(flags)), | 536 | @as(u32, @bitCast(flags)), |
| 541 | @as(usize, @bitCast(@as(isize, fd))), | 537 | @as(usize, @bitCast(@as(isize, -1))), |
| 542 | @as(usize, @truncate(@as(u64, @bitCast(offset)) / linux.MMAP2_UNIT)), | 538 | 0, |
| 543 | }); | 539 | }); |
| 544 | } else { | 540 | } else { |
| 545 | // The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so | 541 | // The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so |
| ... | @@ -547,21 +543,21 @@ inline fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: linux.MAP, fd | ... | @@ -547,21 +543,21 @@ inline fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: linux.MAP, fd |
| 547 | return if (native_arch == .s390x) @call(.always_inline, linux.syscall1, .{ | 543 | return if (native_arch == .s390x) @call(.always_inline, linux.syscall1, .{ |
| 548 | .mmap, | 544 | .mmap, |
| 549 | @intFromPtr(&[_]usize{ | 545 | @intFromPtr(&[_]usize{ |
| 550 | @intFromPtr(address), | 546 | 0, |
| 551 | length, | 547 | length, |
| 552 | prot, | 548 | prot, |
| 553 | @as(u32, @bitCast(flags)), | 549 | @as(u32, @bitCast(flags)), |
| 554 | @as(usize, @bitCast(@as(isize, fd))), | 550 | @as(usize, @bitCast(@as(isize, -1))), |
| 555 | @as(u64, @bitCast(offset)), | 551 | 0, |
| 556 | }), | 552 | }), |
| 557 | }) else @call(.always_inline, linux.syscall6, .{ | 553 | }) else @call(.always_inline, linux.syscall6, .{ |
| 558 | .mmap, | 554 | .mmap, |
| 559 | @intFromPtr(address), | 555 | 0, |
| 560 | length, | 556 | length, |
| 561 | prot, | 557 | prot, |
| 562 | @as(u32, @bitCast(flags)), | 558 | @as(u32, @bitCast(flags)), |
| 563 | @as(usize, @bitCast(@as(isize, fd))), | 559 | @as(usize, @bitCast(@as(isize, -1))), |
| 564 | @as(u64, @bitCast(offset)), | 560 | 0, |
| 565 | }); | 561 | }); |
| 566 | } | 562 | } |
| 567 | } | 563 | } |
lib/std/os/linux/x86.zig-2| ... | @@ -230,8 +230,6 @@ pub const F = struct { | ... | @@ -230,8 +230,6 @@ pub const F = struct { |
| 230 | pub const UNLCK = 2; | 230 | pub const UNLCK = 2; |
| 231 | }; | 231 | }; |
| 232 | 232 | ||
| 233 | pub const MMAP2_UNIT = 4096; | ||
| 234 | |||
| 235 | pub const VDSO = struct { | 233 | pub const VDSO = struct { |
| 236 | pub const CGT_SYM = "__vdso_clock_gettime"; | 234 | pub const CGT_SYM = "__vdso_clock_gettime"; |
| 237 | pub const CGT_VER = "LINUX_2.6"; | 235 | pub const CGT_VER = "LINUX_2.6"; |
lib/std/posix.zig-1| ... | @@ -82,7 +82,6 @@ pub const MADV = system.MADV; | ... | @@ -82,7 +82,6 @@ pub const MADV = system.MADV; |
| 82 | pub const MAP = system.MAP; | 82 | pub const MAP = system.MAP; |
| 83 | pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN; | 83 | pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN; |
| 84 | pub const MFD = system.MFD; | 84 | pub const MFD = system.MFD; |
| 85 | pub const MMAP2_UNIT = system.MMAP2_UNIT; | ||
| 86 | pub const MREMAP = system.MREMAP; | 85 | pub const MREMAP = system.MREMAP; |
| 87 | pub const MSF = system.MSF; | 86 | pub const MSF = system.MSF; |
| 88 | pub const MSG = system.MSG; | 87 | pub const MSG = system.MSG; |
lib/std/start.zig+7-3| ... | @@ -250,7 +250,7 @@ fn _start() callconv(.naked) noreturn { | ... | @@ -250,7 +250,7 @@ fn _start() callconv(.naked) noreturn { |
| 250 | .csky => ".cfi_undefined lr", | 250 | .csky => ".cfi_undefined lr", |
| 251 | .hexagon => ".cfi_undefined r31", | 251 | .hexagon => ".cfi_undefined r31", |
| 252 | .loongarch32, .loongarch64 => ".cfi_undefined 1", | 252 | .loongarch32, .loongarch64 => ".cfi_undefined 1", |
| 253 | .m68k => ".cfi_undefined pc", | 253 | .m68k => ".cfi_undefined %%pc", |
| 254 | .mips, .mipsel, .mips64, .mips64el => ".cfi_undefined $ra", | 254 | .mips, .mipsel, .mips64, .mips64el => ".cfi_undefined $ra", |
| 255 | .powerpc, .powerpcle, .powerpc64, .powerpc64le => ".cfi_undefined lr", | 255 | .powerpc, .powerpcle, .powerpc64, .powerpc64le => ".cfi_undefined lr", |
| 256 | .riscv32, .riscv64 => if (builtin.zig_backend == .stage2_riscv64) | 256 | .riscv32, .riscv64 => if (builtin.zig_backend == .stage2_riscv64) |
| ... | @@ -343,7 +343,7 @@ fn _start() callconv(.naked) noreturn { | ... | @@ -343,7 +343,7 @@ fn _start() callconv(.naked) noreturn { |
| 343 | \\ r30 = #0 | 343 | \\ r30 = #0 |
| 344 | \\ r31 = #0 | 344 | \\ r31 = #0 |
| 345 | \\ r0 = r29 | 345 | \\ r0 = r29 |
| 346 | \\ r29 = and(r29, #-16) | 346 | \\ r29 = and(r29, #-8) |
| 347 | \\ memw(r29 + #-8) = r29 | 347 | \\ memw(r29 + #-8) = r29 |
| 348 | \\ r29 = add(r29, #-8) | 348 | \\ r29 = add(r29, #-8) |
| 349 | \\ call %[posixCallMainAndExit] | 349 | \\ call %[posixCallMainAndExit] |
| ... | @@ -366,7 +366,11 @@ fn _start() callconv(.naked) noreturn { | ... | @@ -366,7 +366,11 @@ fn _start() callconv(.naked) noreturn { |
| 366 | // Note that the - 8 is needed because pc in the jsr instruction points into the middle | 366 | // Note that the - 8 is needed because pc in the jsr instruction points into the middle |
| 367 | // of the jsr instruction. (The lea is 6 bytes, the jsr is 4 bytes.) | 367 | // of the jsr instruction. (The lea is 6 bytes, the jsr is 4 bytes.) |
| 368 | \\ suba.l %%fp, %%fp | 368 | \\ suba.l %%fp, %%fp |
| 369 | \\ move.l %%sp, -(%%sp) | 369 | \\ move.l %%sp, %%a0 |
| 370 | \\ move.l %%a0, %%d0 | ||
| 371 | \\ and.l #-4, %%d0 | ||
| 372 | \\ move.l %%d0, %%sp | ||
| 373 | \\ move.l %%a0, -(%%sp) | ||
| 370 | \\ lea %[posixCallMainAndExit] - . - 8, %%a0 | 374 | \\ lea %[posixCallMainAndExit] - . - 8, %%a0 |
| 371 | \\ jsr (%%pc, %%a0) | 375 | \\ jsr (%%pc, %%a0) |
| 372 | , | 376 | , |