Fix pipe syscall for MIPS

This commit is contained in:
LemonBoy 2019-10-03 15:32:47 +02:00 committed by Andrew Kelley
parent 7481a4ad08
commit 7640bec8e0
3 changed files with 35 additions and 1 deletions

View File

@ -328,7 +328,9 @@ pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize {
}
pub fn pipe(fd: *[2]i32) usize {
if (@hasDecl(@This(), "SYS_pipe")) {
if (builtin.arch == .mipsel) {
return syscall_pipe(fd);
} else if (@hasDecl(@This(), "SYS_pipe")) {
return syscall1(SYS_pipe, @ptrToInt(fd));
} else {
return syscall2(SYS_pipe2, @ptrToInt(fd), 0);

View File

@ -12,6 +12,25 @@ pub fn syscall0(number: usize) usize {
);
}
pub fn syscall_pipe(fd: *[2]i32) usize {
return asm volatile (
\\ .set noat
\\ .set noreorder
\\ syscall
\\ blez $7, 1f
\\ nop
\\ b 2f
\\ subu $2, $0, $2
\\ 1:
\\ sw $2, 0($4)
\\ sw $3, 4($4)
\\ 2:
: [ret] "={$2}" (-> usize)
: [number] "{$2}" (usize(SYS_pipe))
: "memory", "cc", "$7"
);
}
pub fn syscall1(number: usize, arg1: usize) usize {
return asm volatile (
\\ syscall

View File

@ -219,3 +219,16 @@ test "gethostname" {
const hostname = try os.gethostname(&buf);
expect(hostname.len != 0);
}
test "pipe" {
if (os.windows.is_the_target)
return error.SkipZigTest;
var fds = try os.pipe();
try os.write(fds[1], "hello");
var buf: [16]u8 = undefined;
expect((try os.read(fds[0], buf[0..])) == 5);
testing.expectEqualSlices(u8, buf[0..5], "hello");
os.close(fds[1]);
os.close(fds[0]);
}