authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-10-03 15:32:47+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-03 17:07:53-04:00
log7640bec8e0e735eaba49087840b7f6e6b2dd74ab
treeb88b67a46a861962b17d32cf5570888d557b5af9
parent7481a4ad089c0195fe238ef160ec667e3f604d22

Fix pipe syscall for MIPS


3 files changed, 35 insertions(+), 1 deletions(-)

lib/std/os/linux.zig+3-1
......@@ -328,7 +328,9 @@ pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize {
328328}
329329
330330pub fn pipe(fd: *[2]i32) usize {
331 if (@hasDecl(@This(), "SYS_pipe")) {
331 if (builtin.arch == .mipsel) {
332 return syscall_pipe(fd);
333 } else if (@hasDecl(@This(), "SYS_pipe")) {
332334 return syscall1(SYS_pipe, @ptrToInt(fd));
333335 } else {
334336 return syscall2(SYS_pipe2, @ptrToInt(fd), 0);
lib/std/os/linux/mipsel.zig+19
......@@ -12,6 +12,25 @@ pub fn syscall0(number: usize) usize {
1212 );
1313}
1414
15pub fn syscall_pipe(fd: *[2]i32) usize {
16 return asm volatile (
17 \\ .set noat
18 \\ .set noreorder
19 \\ syscall
20 \\ blez $7, 1f
21 \\ nop
22 \\ b 2f
23 \\ subu $2, $0, $2
24 \\ 1:
25 \\ sw $2, 0($4)
26 \\ sw $3, 4($4)
27 \\ 2:
28 : [ret] "={$2}" (-> usize)
29 : [number] "{$2}" (usize(SYS_pipe))
30 : "memory", "cc", "$7"
31 );
32}
33
1534pub fn syscall1(number: usize, arg1: usize) usize {
1635 return asm volatile (
1736 \\ syscall
lib/std/os/test.zig+13
......@@ -219,3 +219,16 @@ test "gethostname" {
219219 const hostname = try os.gethostname(&buf);
220220 expect(hostname.len != 0);
221221}
222
223test "pipe" {
224 if (os.windows.is_the_target)
225 return error.SkipZigTest;
226
227 var fds = try os.pipe();
228 try os.write(fds[1], "hello");
229 var buf: [16]u8 = undefined;
230 expect((try os.read(fds[0], buf[0..])) == 5);
231 testing.expectEqualSlices(u8, buf[0..5], "hello");
232 os.close(fds[1]);
233 os.close(fds[0]);
234}