libc: Add missing pipe2() declaration and implementation.

Change-Id: Iacb914bd6ac5adc60c5671e6fef680ede21f9b0c
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index f66ff40..4bcccb5 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -112,6 +112,7 @@
 int         fchmod(int, mode_t)  94
 int         dup(int)  41
 int         pipe(int *)  42,42,-1
+int         pipe2(int *, int) 359,331
 int         dup2(int, int)   63
 int         select:_newselect(int, struct fd_set *, struct fd_set *, struct fd_set *, struct timeval *)  142
 int         ftruncate(int, off_t)  93
@@ -229,8 +230,8 @@
 int sched_rr_get_interval(pid_t pid, struct timespec *interval)  161
 
 # io priorities
-int ioprio_set(int which, int who, int ioprio) 314,289
-int ioprio_get(int which, int who) 315,290
+int ioprio_set(int which, int who, int ioprio) 314,289,288
+int ioprio_get(int which, int who) 315,290,289
 
 # other
 int     uname(struct utsname *)  122
diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk
index c466166..2d944ca 100644
--- a/libc/arch-arm/syscalls.mk
+++ b/libc/arch-arm/syscalls.mk
@@ -66,6 +66,7 @@
 syscall_src += arch-arm/syscalls/fchmod.S
 syscall_src += arch-arm/syscalls/dup.S
 syscall_src += arch-arm/syscalls/pipe.S
+syscall_src += arch-arm/syscalls/pipe2.S
 syscall_src += arch-arm/syscalls/dup2.S
 syscall_src += arch-arm/syscalls/select.S
 syscall_src += arch-arm/syscalls/ftruncate.S
diff --git a/libc/arch-arm/syscalls/pipe2.S b/libc/arch-arm/syscalls/pipe2.S
new file mode 100644
index 0000000..df77094
--- /dev/null
+++ b/libc/arch-arm/syscalls/pipe2.S
@@ -0,0 +1,19 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type pipe2, #function
+    .globl pipe2
+    .align 4
+    .fnstart
+
+pipe2:
+    .save   {r4, r7}
+    stmfd   sp!, {r4, r7}
+    ldr     r7, =__NR_pipe2
+    swi     #0
+    ldmfd   sp!, {r4, r7}
+    movs    r0, r0
+    bxpl    lr
+    b       __set_syscall_errno
+    .fnend
diff --git a/libc/arch-sh/syscalls.mk b/libc/arch-sh/syscalls.mk
index ddae8d3..b690bbf 100644
--- a/libc/arch-sh/syscalls.mk
+++ b/libc/arch-sh/syscalls.mk
@@ -69,6 +69,7 @@
 syscall_src += arch-sh/syscalls/flock.S
 syscall_src += arch-sh/syscalls/fchmod.S
 syscall_src += arch-sh/syscalls/dup.S
+syscall_src += arch-sh/syscalls/pipe2.S
 syscall_src += arch-sh/syscalls/dup2.S
 syscall_src += arch-sh/syscalls/select.S
 syscall_src += arch-sh/syscalls/ftruncate.S
diff --git a/libc/arch-sh/syscalls/pipe2.S b/libc/arch-sh/syscalls/pipe2.S
new file mode 100644
index 0000000..f6d9964
--- /dev/null
+++ b/libc/arch-sh/syscalls/pipe2.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type pipe2, @function
+    .globl pipe2
+    .align 4
+
+pipe2:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_pipe2_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_pipe2_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_pipe2
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-x86/syscalls.mk b/libc/arch-x86/syscalls.mk
index 6ac3716..27153f9 100644
--- a/libc/arch-x86/syscalls.mk
+++ b/libc/arch-x86/syscalls.mk
@@ -69,6 +69,7 @@
 syscall_src += arch-x86/syscalls/fchmod.S
 syscall_src += arch-x86/syscalls/dup.S
 syscall_src += arch-x86/syscalls/pipe.S
+syscall_src += arch-x86/syscalls/pipe2.S
 syscall_src += arch-x86/syscalls/dup2.S
 syscall_src += arch-x86/syscalls/select.S
 syscall_src += arch-x86/syscalls/ftruncate.S
diff --git a/libc/arch-x86/syscalls/pipe2.S b/libc/arch-x86/syscalls/pipe2.S
new file mode 100644
index 0000000..c3354a7
--- /dev/null
+++ b/libc/arch-x86/syscalls/pipe2.S
@@ -0,0 +1,26 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type pipe2, @function
+    .globl pipe2
+    .align 4
+
+pipe2:
+    pushl   %ebx
+    pushl   %ecx
+    mov     12(%esp), %ebx
+    mov     16(%esp), %ecx
+    movl    $__NR_pipe2, %eax
+    int     $0x80
+    cmpl    $-129, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno
+    addl    $4, %esp
+    orl     $-1, %eax
+1:
+    popl    %ecx
+    popl    %ebx
+    ret
diff --git a/libc/include/sys/linux-syscalls.h b/libc/include/sys/linux-syscalls.h
index 9e2aa2f..6a7fc40 100644
--- a/libc/include/sys/linux-syscalls.h
+++ b/libc/include/sys/linux-syscalls.h
@@ -138,6 +138,7 @@
 #define __NR_openat                       (__NR_SYSCALL_BASE + 322)
 #define __NR_madvise                      (__NR_SYSCALL_BASE + 220)
 #define __NR_mincore                      (__NR_SYSCALL_BASE + 219)
+#define __NR_pipe2                        (__NR_SYSCALL_BASE + 359)
 #define __NR_getdents64                   (__NR_SYSCALL_BASE + 217)
 #define __NR_fstatfs64                    (__NR_SYSCALL_BASE + 267)
 #define __NR_fstatat64                    (__NR_SYSCALL_BASE + 327)
@@ -194,6 +195,7 @@
 #define __NR_openat                       (__NR_SYSCALL_BASE + 295)
 #define __NR_madvise                      (__NR_SYSCALL_BASE + 219)
 #define __NR_mincore                      (__NR_SYSCALL_BASE + 218)
+#define __NR_pipe2                        (__NR_SYSCALL_BASE + 331)
 #define __NR_getdents64                   (__NR_SYSCALL_BASE + 220)
 #define __NR_fstatfs64                    (__NR_SYSCALL_BASE + 269)
 #define __NR_fstatat64                    (__NR_SYSCALL_BASE + 300)
@@ -235,6 +237,7 @@
 #define __NR_openat                       (__NR_SYSCALL_BASE + 295)
 #define __NR_madvise                      (__NR_SYSCALL_BASE + 219)
 #define __NR_mincore                      (__NR_SYSCALL_BASE + 218)
+#define __NR_pipe2                        (__NR_SYSCALL_BASE + 331)
 #define __NR_getdents64                   (__NR_SYSCALL_BASE + 220)
 #define __NR_fstatfs64                    (__NR_SYSCALL_BASE + 269)
 #define __NR_fstatat64                    (__NR_SYSCALL_BASE + 300)
@@ -270,8 +273,8 @@
 #define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
 #define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
 #define __NR___socketcall                 (__NR_SYSCALL_BASE + 102)
-#define __NR_ioprio_set                   (__NR_SYSCALL_BASE + 289)
-#define __NR_ioprio_get                   (__NR_SYSCALL_BASE + 290)
+#define __NR_ioprio_set                   (__NR_SYSCALL_BASE + 288)
+#define __NR_ioprio_get                   (__NR_SYSCALL_BASE + 289)
 #define __NR_epoll_create                 (__NR_SYSCALL_BASE + 254)
 #define __NR_epoll_ctl                    (__NR_SYSCALL_BASE + 255)
 #define __NR_epoll_wait                   (__NR_SYSCALL_BASE + 256)
diff --git a/libc/include/sys/linux-unistd.h b/libc/include/sys/linux-unistd.h
index 6bd9ac7..7494efe 100644
--- a/libc/include/sys/linux-unistd.h
+++ b/libc/include/sys/linux-unistd.h
@@ -79,6 +79,7 @@
 int              fchmod (int, mode_t);
 int              dup (int);
 int              pipe (int *);
+int              pipe2 (int *, int);
 int              dup2 (int, int);
 int              select (int, struct fd_set *, struct fd_set *, struct fd_set *, struct timeval *);
 int              ftruncate (int, off_t);
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 7554198..cd09e3d 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -118,6 +118,9 @@
 extern int fchdir(int);
 extern int rmdir(const char *);
 extern int pipe(int *);
+#ifdef _GNU_SOURCE  /* GLibc compatibility */
+extern int pipe2(int *, int);
+#endif
 extern int chroot(const char *);
 extern int symlink(const char *, const char *);
 extern int readlink(const char *, char *, size_t);