authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-03-19 11:44:51+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-19 13:03:55-07:00
log867ae506e3c76575043ab5189e0117823f011032
tree0a535cade335488772a9cee89523ab9717479ae9
parent652842637c31055d26f846e2249c9989104afe67

std: Add syscall7 stub for Linux/MIPS

Some syscalls such as fadvise require an extra argument to comply with the register pair alignment imposed by the ABI. Wacky, isn't it?

1 files changed, 37 insertions(+), 0 deletions(-)

lib/std/os/linux/mips.zig+37
...@@ -115,6 +115,9 @@ pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize,...@@ -115,6 +115,9 @@ pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
115 );115 );
116}116}
117117
118// NOTE: The o32 calling convention requires the callee to reserve 16 bytes for
119// the first four arguments even though they're passed in $a0-$a3.
120
118pub fn syscall6(121pub fn syscall6(
119 number: SYS,122 number: SYS,
120 arg1: usize,123 arg1: usize,
...@@ -146,6 +149,40 @@ pub fn syscall6(...@@ -146,6 +149,40 @@ pub fn syscall6(
146 );149 );
147}150}
148151
152pub fn syscall7(
153 number: SYS,
154 arg1: usize,
155 arg2: usize,
156 arg3: usize,
157 arg4: usize,
158 arg5: usize,
159 arg6: usize,
160 arg7: usize,
161) usize {
162 return asm volatile (
163 \\ .set noat
164 \\ subu $sp, $sp, 32
165 \\ sw %[arg5], 16($sp)
166 \\ sw %[arg6], 20($sp)
167 \\ sw %[arg7], 24($sp)
168 \\ syscall
169 \\ addu $sp, $sp, 32
170 \\ blez $7, 1f
171 \\ subu $2, $0, $2
172 \\ 1:
173 : [ret] "={$2}" (-> usize)
174 : [number] "{$2}" (@enumToInt(number)),
175 [arg1] "{$4}" (arg1),
176 [arg2] "{$5}" (arg2),
177 [arg3] "{$6}" (arg3),
178 [arg4] "{$7}" (arg4),
179 [arg5] "r" (arg5),
180 [arg6] "r" (arg6),
181 [arg7] "r" (arg7)
182 : "memory", "cc", "$7"
183 );
184}
185
149/// This matches the libc clone function.186/// This matches the libc clone function.
150pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;187pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
151188