authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-04-08 06:04:16+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-04-08 06:04:16+02:00
log2d33cc2e42d40ce0ee798d4d56c2d7da93ead44a
treebad7965f8787aaf5a84b63996cb384d0866f0743
parentd8153fa74ab01f8cdc117e0049e0a2d2e4187892
parentbcb4ba9afd610a0f3ab66ad828c90fd57dc95a6f
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #23376 from sweiglbosker/m68k-archbits


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};
1604pub const MMAP2_UNIT = switch (native_os) {
1605 .linux => linux.MMAP2_UNIT,
1606 else => void,
1607};
1608pub const NAME_MAX = switch (native_os) {1604pub 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;
92pub const F = arch_bits.F;93pub const F = arch_bits.F;
93pub const Flock = arch_bits.Flock;94pub const Flock = arch_bits.Flock;
94pub const HWCAP = arch_bits.HWCAP;95pub const HWCAP = arch_bits.HWCAP;
95pub const MMAP2_UNIT = arch_bits.MMAP2_UNIT;
96pub const REG = arch_bits.REG;96pub const REG = arch_bits.REG;
97pub const SC = arch_bits.SC;97pub const SC = arch_bits.SC;
98pub const Stat = arch_bits.Stat;98pub 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,
473473
474 // #define O_RSYNC 04010000474 // #define O_RSYNC 04010000
475 // #define O_SYNC 04010000475 // #define O_SYNC 04010000
476 // #define O_TMPFILE 020200000476 // #define O_TMPFILE 020200000
477 // #define O_NDELAY O_NONBLOCK477 // #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};
481502
...@@ -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, so933 // 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}
172172
173pub const MMAP2_UNIT = 4096;
174
175pub const F = struct {173pub 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 {
251251
252pub const Elf_Symndx = u32;252pub const Elf_Symndx = u32;
253253
254pub const MMAP2_UNIT = 4096;
255
256pub const VDSO = void;254pub const VDSO = void;
257255
258/// TODO256/// TODO
lib/std/os/linux/m68k.zig created+271
...@@ -0,0 +1,271 @@
1const builtin = @import("builtin");
2const std = @import("../../std.zig");
3const iovec = std.posix.iovec;
4const iovec_const = std.posix.iovec_const;
5const linux = std.os.linux;
6const SYS = linux.SYS;
7const uid_t = std.os.linux.uid_t;
8const gid_t = std.os.linux.uid_t;
9const pid_t = std.os.linux.pid_t;
10const sockaddr = linux.sockaddr;
11const socklen_t = linux.socklen_t;
12const timespec = std.os.linux.timespec;
13
14pub 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
22pub 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
31pub 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
41pub 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
52pub 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
64pub 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
77pub 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
99pub 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
152pub const restore = restore_rt;
153
154pub fn restore_rt() callconv(.naked) noreturn {
155 asm volatile ("trap #0"
156 :
157 : [number] "{d0}" (@intFromEnum(SYS.rt_sigreturn)),
158 : "memory"
159 );
160}
161
162pub 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
188pub const blksize_t = i32;
189pub const nlink_t = u32;
190pub const time_t = i32;
191pub const mode_t = u32;
192pub const off_t = i64;
193pub const ino_t = u64;
194pub const dev_t = u64;
195pub const blkcnt_t = i64;
196
197pub const timeval = extern struct {
198 sec: time_t,
199 usec: i32,
200};
201
202pub 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
211pub 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
221pub 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
231pub 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
262pub const Elf_Symndx = u32;
263
264// No VDSO used as of glibc 112a0ae18b831bf31f44d81b82666980312511d6.
265pub const VDSO = void;
266
267/// TODO
268pub const ucontext_t = void;
269
270/// TODO
271pub 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};
296296
297pub const MMAP2_UNIT = 4096;
298
299pub const VDSO = struct {297pub 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};
275275
276pub const MMAP2_UNIT = 4096;
277
278pub const VDSO = struct {276pub 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 {
348348
349pub const Elf_Symndx = u32;349pub const Elf_Symndx = u32;
350350
351pub const MMAP2_UNIT = 4096;
352
353/// TODO351/// TODO
354pub const getcontext = {};352pub 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 {
256256
257pub const Elf_Symndx = u32;257pub const Elf_Symndx = u32;
258258
259pub const MMAP2_UNIT = 4096;
260
261pub const VDSO = struct {259pub 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 }
510510
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();
520513
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}
532525
533inline fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: linux.MAP, fd: i32, offset: i64) usize {526inline 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, so541 // 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};
232232
233pub const MMAP2_UNIT = 4096;
234
235pub const VDSO = struct {233pub 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;
82pub const MAP = system.MAP;82pub const MAP = system.MAP;
83pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;83pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;
84pub const MFD = system.MFD;84pub const MFD = system.MFD;
85pub const MMAP2_UNIT = system.MMAP2_UNIT;
86pub const MREMAP = system.MREMAP;85pub const MREMAP = system.MREMAP;
87pub const MSF = system.MSF;86pub const MSF = system.MSF;
88pub const MSG = system.MSG;87pub 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 = #0343 \\ r30 = #0
344 \\ r31 = #0344 \\ r31 = #0
345 \\ r0 = r29345 \\ r0 = r29
346 \\ r29 = and(r29, #-16)346 \\ r29 = and(r29, #-8)
347 \\ memw(r29 + #-8) = r29347 \\ 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 middle366 // 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, %%fp368 \\ 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, %%a0374 \\ lea %[posixCallMainAndExit] - . - 8, %%a0
371 \\ jsr (%%pc, %%a0)375 \\ jsr (%%pc, %%a0)
372 ,376 ,