fdtrack: add wrapper for socketpair.

Bug: https://issuetracker.google.com/154450436
Test: bionic-unit-tests
Change-Id: I8b25accf00dc01f6fab351f3ba612f6b0ff9d094
diff --git a/libc/Android.bp b/libc/Android.bp
index ac961d4..d5d0afb 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1113,6 +1113,7 @@
         "bionic/signal.cpp",
         "bionic/sigprocmask.cpp",
         "bionic/sleep.cpp",
+        "bionic/socketpair.cpp",
         "bionic/spawn.cpp",
         "bionic/stat.cpp",
         "bionic/stdlib_l.cpp",
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index f235bc8..6142baf 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -243,7 +243,7 @@
 
 # sockets
 int           __socket:socket(int, int, int)              arm,lp64
-int           socketpair(int, int, int, int*)    arm,lp64
+int           __socketpair:socketpair(int, int, int, int*)    arm,lp64
 int           bind(int, struct sockaddr*, socklen_t)  arm,lp64
 int           __connect:connect(int, struct sockaddr*, socklen_t)   arm,lp64
 int           listen(int, int)                   arm,lp64
@@ -267,7 +267,7 @@
 int           listen:socketcall:4(int, int)                   x86
 int           getsockname:socketcall:6(int, struct sockaddr*, socklen_t*)  x86
 int           getpeername:socketcall:7(int, struct sockaddr*, socklen_t*)  x86
-int           socketpair:socketcall:8(int, int, int, int*)    x86
+int           __socketpair:socketcall:8(int, int, int, int*)    x86
 ssize_t       __sendto:socketcall:11(int, const void*, size_t, int, const struct sockaddr*, socklen_t)  x86
 ssize_t       recvfrom:socketcall:12(int, void*, size_t, unsigned int, struct sockaddr*, socklen_t*)  x86
 int           shutdown:socketcall:13(int, int)  x86
diff --git a/libc/bionic/socketpair.cpp b/libc/bionic/socketpair.cpp
new file mode 100644
index 0000000..d2b4c19
--- /dev/null
+++ b/libc/bionic/socketpair.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include "private/bionic_fdtrack.h"
+
+extern "C" int __socketpair(int domain, int type, int protocol, int sv[2]);
+
+int socketpair(int domain, int type, int protocol, int sv[2]) {
+  int rc = __socketpair(domain, type, protocol, sv);
+  if (rc == 0) {
+    FDTRACK_CREATE(sv[0]);
+    FDTRACK_CREATE(sv[1]);
+  }
+  return rc;
+}