Tell people when they've messed up with fcntl(FD_SETFD).

This is a subtle bug that even experts struggle with.

Test: treehugger
Change-Id: If9cf16a1c32c836f5688bb3374cfd21d55125b17
diff --git a/libc/bionic/fcntl.cpp b/libc/bionic/fcntl.cpp
index c508131..35af78b 100644
--- a/libc/bionic/fcntl.cpp
+++ b/libc/bionic/fcntl.cpp
@@ -30,6 +30,7 @@
 #include <fcntl.h>
 
 #include "private/bionic_fdtrack.h"
+#include "private/bionic_fortify.h"
 
 #if defined(__LP64__)
 
@@ -44,6 +45,10 @@
   void* arg = va_arg(args, void*);
   va_end(args);
 
+  if (cmd == F_SETFD && (reinterpret_cast<uintptr_t>(arg) & ~FD_CLOEXEC) != 0) {
+    __fortify_fatal("fcntl(F_SETFD) passed non-FD_CLOEXEC flag: %p", arg);
+  }
+
   int rc = __fcntl(fd, cmd, arg);
   if (cmd == F_DUPFD) {
     return FDTRACK_CREATE_NAME("F_DUPFD", rc);