adding missed HURD adoptions
authorCarsten Schoenert <c.schoenert@t-online.de>
Sun, 24 Apr 2016 18:49:46 +0000 (20:49 +0200)
committerChristoph Goehre <chris@sigxcpu.org>
Thu, 31 Aug 2023 15:15:52 +0000 (16:15 +0100)
Based on https://lists.alioth.debian.org/pipermail/pkg-mozilla-maintainers/2016-April/027634.html

Gbp-Pq: Topic porting-kfreebsd-hurd
Gbp-Pq: Name adding-missed-HURD-adoptions.patch

ipc/chromium/src/base/platform_thread.h
ipc/chromium/src/base/platform_thread_posix.cc
ipc/chromium/src/base/port.h
ipc/chromium/src/base/process_util.h
ipc/chromium/src/base/process_util_posix.cc
security/nss/gtests/google_test/gtest/include/gtest/internal/gtest-port.h
security/sandbox/chromium/build/build_config.h
third_party/libwebrtc/build/build_config.h
third_party/sipcc/cpr_types.h

index 42f48651439f5dc71f6f4d104ff2b4439b1b52c6..41e84dca6735e0c816c9a09328b1fbfe5a603196 100644 (file)
@@ -25,7 +25,7 @@ typedef void* PlatformThreadHandle;  // HANDLE
 #  include <pthread.h>
 typedef pthread_t PlatformThreadHandle;
 #  if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_SOLARIS) || \
-      defined(__GLIBC__)
+      defined(__GLIBC__) || defined(OS_HURD)
 #    include <unistd.h>
 typedef pid_t PlatformThreadId;
 #  elif defined(OS_BSD)
index 31b1592cd8deadfa6fcb885bdd0ccd6a1bf349a1..609260e6a18c2f1658cd47b134c9d381f6b69e5b 100644 (file)
@@ -56,7 +56,7 @@ PlatformThreadId PlatformThread::CurrentId() {
 #else
    return getpid();
 #endif
-#elif defined(OS_OPENBSD) || defined(OS_SOLARIS) || defined(__GLIBC__)
+#elif defined(OS_OPENBSD) || defined(OS_SOLARIS) || defined(__GLIBC__) || defined(OS_HURD)
   return (intptr_t)(pthread_self());
 #elif defined(OS_NETBSD)
   return _lwp_self();
index 9d78f52cb6df26f8a3ce87c197c44365d7a7993d..d6176c8cb1b646a8302532b68c0a15edd118d681 100644 (file)
@@ -58,7 +58,7 @@ namespace base {
 // Define an OS-neutral wrapper for shared library entry points
 #if defined(OS_WIN)
 #  define API_CALL __stdcall
-#elif defined(OS_LINUX) || defined(OS_MACOSX)
+#elif defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_HURD)
 #  define API_CALL
 #endif
 
index b44c3dcce19f7f54e848812cba8bb298ea058987..9ac8ec79d1c15de429b330b1dfbdec812e51305e 100644 (file)
@@ -16,7 +16,7 @@
 #  include "mozilla/ipc/EnvironmentMap.h"
 #  include <windows.h>
 #  include <tlhelp32.h>
-#elif defined(OS_LINUX) || defined(__GLIBC__)
+#elif defined(OS_LINUX) || defined(__GLIBC__) || defined(OS_HURD)
 #  include <dirent.h>
 #  include <limits.h>
 #  include <sys/types.h>
index 42052622dbb4e1b5f7fc5e1aa6c5de876d123102..ba4e5a40f10fb822377c2a102042d10828986f75 100644 (file)
@@ -125,6 +125,10 @@ void CloseSuperfluousFds(void* aCtx, bool (*aShouldPreserve)(void*, int)) {
   static const rlim_t kSystemDefaultMaxFds = 1024;
   // at least /dev/fd will exist
   static const char kFDDir[] = "/dev/fd";
+#elif defined(OS_HURD)
+  static const rlim_t kSystemDefaultMaxFds = 1024;
+  // Currently always empty, but it exists
+  static const char kFDDir[] = "/dev/fd";
 #endif
 
   // Get the maximum number of FDs possible.
@@ -187,6 +191,40 @@ void CloseSuperfluousFds(void* aCtx, bool (*aShouldPreserve)(void*, int)) {
   }
 }
 
+// Sets all file descriptors to close on exec except for stdin, stdout
+// and stderr.
+// TODO(agl): Remove this function. It's fundamentally broken for multithreaded
+// apps.
+void SetAllFDsToCloseOnExec() {
+#if defined(OS_LINUX) || defined(OS_SOLARIS)
+  const char fd_dir[] = "/proc/self/fd";
+#elif defined(OS_MACOSX) || defined(OS_BSD) || defined(OS_HURD)
+  const char fd_dir[] = "/dev/fd";
+#endif
+  ScopedDIR dir_closer(opendir(fd_dir));
+  DIR *dir = dir_closer.get();
+  if (NULL == dir) {
+    DLOG(ERROR) << "Unable to open " << fd_dir;
+    return;
+  }
+
+  struct dirent *ent;
+  while ((ent = readdir(dir))) {
+    // Skip . and .. entries.
+    if (ent->d_name[0] == '.')
+      continue;
+    int i = atoi(ent->d_name);
+    // We don't close stdin, stdout or stderr.
+    if (i <= STDERR_FILENO)
+      continue;
+
+    int flags = fcntl(i, F_GETFD);
+    if ((flags == -1) || (fcntl(i, F_SETFD, flags | FD_CLOEXEC) == -1)) {
+      DLOG(ERROR) << "fcntl failure.";
+    }
+  }
+}
+
 bool DidProcessCrash(bool* child_exited, ProcessHandle handle) {
 #ifdef MOZ_ENABLE_FORKSERVER
   if (mozilla::ipc::ForkServiceChild::Get()) {
index 0953a781c05514dea7461a49dd6b6d52587e800f..da8f9c0748844f0212b182ca2b78e2b1790eae29 100644 (file)
     (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
 #endif  // __GNUC__
 
+// Determines the platform on which Google Test is compiled.
+#ifdef __CYGWIN__
+# define GTEST_OS_CYGWIN 1
+#elif defined __SYMBIAN32__
+# define GTEST_OS_SYMBIAN 1
+#elif defined _WIN32
+# define GTEST_OS_WINDOWS 1
+# ifdef _WIN32_WCE
+#  define GTEST_OS_WINDOWS_MOBILE 1
+# elif defined(__MINGW__) || defined(__MINGW32__)
+#  define GTEST_OS_WINDOWS_MINGW 1
+# elif defined(WINAPI_FAMILY)
+#  include <winapifamily.h>
+#  if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#   define GTEST_OS_WINDOWS_DESKTOP 1
+#  elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
+#   define GTEST_OS_WINDOWS_PHONE 1
+#  elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
+#   define GTEST_OS_WINDOWS_RT 1
+#  else
+    // WINAPI_FAMILY defined but no known partition matched.
+    // Default to desktop.
+#   define GTEST_OS_WINDOWS_DESKTOP 1
+#  endif
+# else
+#  define GTEST_OS_WINDOWS_DESKTOP 1
+# endif  // _WIN32_WCE
+#elif defined __APPLE__
+# define GTEST_OS_MAC 1
+# if TARGET_OS_IPHONE
+#  define GTEST_OS_IOS 1
+#  if TARGET_IPHONE_SIMULATOR
+#   define GTEST_OS_IOS_SIMULATOR 1
+#  endif
+# endif
+#elif defined __linux__
+# define GTEST_OS_LINUX 1
+# if defined __ANDROID__
+#  define GTEST_OS_LINUX_ANDROID 1
+# endif
+#elif defined __MVS__
+# define GTEST_OS_ZOS 1
+#elif defined(__sun) && defined(__SVR4)
+# define GTEST_OS_SOLARIS 1
+#elif defined(_AIX)
+# define GTEST_OS_AIX 1
+#elif defined(__hpux)
+# define GTEST_OS_HPUX 1
+#elif defined __native_client__
+# define GTEST_OS_NACL 1
+#elif defined __OpenBSD__
+# define GTEST_OS_OPENBSD 1
+#elif defined __QNX__
+# define GTEST_OS_QNX 1
+#elif defined(__GNU__)
+# define GTEST_OS_HURD 1
+#endif  // __CYGWIN__
+
 // Macros for disabling Microsoft Visual C++ warnings.
 //
 //   GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 4385)
@@ -547,7 +605,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
   (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX || GTEST_OS_QNX ||          \
    GTEST_OS_FREEBSD || GTEST_OS_NACL || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \
    GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_OPENBSD ||          \
-   GTEST_OS_HAIKU)
+   GTEST_OS_HAIKU || GTEST_OS_HURD)
 #endif  // GTEST_HAS_PTHREAD
 
 #if GTEST_HAS_PTHREAD
index 48109c4d46af3bf6440c34ead9b58950731cf177..1bcdb30ab317260ae4a2c99012d08f382a857f3c 100644 (file)
@@ -47,6 +47,8 @@
 // we really are using glibc, not uClibc pretending to be glibc
 #define LIBC_GLIBC 1
 #endif
+#elif defined(__GNU__)
+#define OS_HURD 1
 #elif defined(_WIN32)
 #define OS_WIN 1
 #elif defined(__Fuchsia__)
@@ -82,7 +84,7 @@
 #if defined(OS_AIX) || defined(OS_ANDROID) || defined(OS_ASMJS) ||    \
     defined(OS_FREEBSD) || defined(OS_LINUX) || defined(OS_MACOSX) || \
     defined(OS_NACL) || defined(OS_NETBSD) || defined(OS_OPENBSD) ||  \
-    defined(OS_QNX) || defined(OS_SOLARIS)
+    defined(OS_QNX) || defined(OS_SOLARIS) || defined(OS_HURD)
 #define OS_POSIX 1
 #endif
 
index e312ec52a4b60842b96947c9e48d88d2e4a2b181..0ff750994f104b8b01e773ac497562171ef9b40a 100644 (file)
@@ -68,6 +68,8 @@
 // We really are using glibc, not uClibc pretending to be glibc.
 #define LIBC_GLIBC 1
 #endif
+#elif defined(__GNU__)
+#define OS_HURD 1
 #elif defined(_WIN32)
 #define OS_WIN 1
 #elif defined(__Fuchsia__)
     defined(OS_FREEBSD) || defined(OS_IOS) || defined(OS_LINUX) ||  \
     defined(OS_CHROMEOS) || defined(OS_MAC) || defined(OS_NACL) ||  \
     defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_QNX) || \
-    defined(OS_SOLARIS)
+    defined(OS_SOLARIS) || defined(OS_HURD)
 #define OS_POSIX 1
 #endif
 
index f048e72be1cffb8050a4b8302c4b7c891e1fe047..8bb0b596f53975085bd671b98ecfc2a7b88a3f10 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <inttypes.h>
 
-#if defined SIP_OS_LINUX
+#if defined SIP_OS_LINUX || defined(SIP_OS_HURD)
 #include "cpr_linux_types.h"
 #elif defined SIP_OS_WINDOWS
 #include "cpr_win_types.h"