Backed out changeset 3aa492e39918 (bug 827749) for failing all tests OS X.
authorJared Wein <jwein@mozilla.com>
Thu, 10 Jan 2013 14:15:25 -0500
changeset 118453 9cb5b72a226db341ad8432354ef0e852c2c80402
parent 118452 85b09d1c1cdc0ce5346dd7803ebc7f84466bbb13
child 118454 61eddbd33e8c4c6f3ec7493465a370c4dab824bb
push id24166
push userMs2ger@gmail.com
push dateFri, 11 Jan 2013 13:57:41 +0000
treeherdermozilla-central@63c4b0f66a0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs827749
milestone21.0a1
backs out3aa492e399180896d952d960d95374c740e9b802
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 3aa492e39918 (bug 827749) for failing all tests OS X.
ipc/glue/FileDescriptor.cpp
ipc/glue/FileDescriptor.h
--- a/ipc/glue/FileDescriptor.cpp
+++ b/ipc/glue/FileDescriptor.cpp
@@ -3,116 +3,63 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "FileDescriptor.h"
 
 #include "mozilla/Assertions.h"
 #include "nsDebug.h"
 
 #ifdef XP_WIN
-
 #include <windows.h>
 #define INVALID_HANDLE INVALID_HANDLE_VALUE
-
-#else // XP_WIN
-
+#else
 #include <unistd.h>
-
-#ifndef OS_POSIX
-#define OS_POSIX
+#define INVALID_HANDLE -1
 #endif
 
-#include "base/eintr_wrapper.h"
-#define INVALID_HANDLE -1
-
-#endif // XP_WIN
-
 using mozilla::ipc::FileDescriptor;
 
 FileDescriptor::FileDescriptor()
-: mHandle(INVALID_HANDLE), mHandleCreatedByOtherProcess(false),
-  mHandleCreatedByOtherProcessWasUsed(false)
+: mHandle(INVALID_HANDLE)
 { }
 
-FileDescriptor::FileDescriptor(PlatformHandleType aHandle)
-: mHandle(INVALID_HANDLE), mHandleCreatedByOtherProcess(false),
-  mHandleCreatedByOtherProcessWasUsed(false)
-{
-  DuplicateInCurrentProcess(aHandle);
-}
-
-void
-FileDescriptor::DuplicateInCurrentProcess(PlatformHandleType aHandle)
-{
-  MOZ_ASSERT(!mHandleCreatedByOtherProcess);
-
-  if (IsValid(aHandle)) {
-    PlatformHandleType newHandle;
-#ifdef XP_WIN
-    if (DuplicateHandle(GetCurrentProcess(), aHandle, GetCurrentProcess(),
-                        &newHandle, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
-#else // XP_WIN
-    if ((newHandle = dup(aHandle)) != INVALID_HANDLE) {
-#endif
-      mHandle = newHandle;
-      return;
-    }
-    NS_WARNING("Failed to duplicate file descriptor!");
-  }
-
-  mHandle = INVALID_HANDLE;
-}
-
-void
-FileDescriptor::CloseCurrentProcessHandle()
-{
-  MOZ_ASSERT_IF(mHandleCreatedByOtherProcess,
-                mHandleCreatedByOtherProcessWasUsed);
-
-  // Don't actually close handles created by another process.
-  if (mHandleCreatedByOtherProcess) {
-    return;
-  }
-
-  if (IsValid()) {
-#ifdef XP_WIN
-    if (!CloseHandle(mHandle)) {
-      NS_WARNING("Failed to close file handle!");
-    }
-#else // XP_WIN
-    HANDLE_EINTR(close(mHandle));
-#endif
-    mHandle = INVALID_HANDLE;
-  }
-}
-
 FileDescriptor::PickleType
 FileDescriptor::ShareTo(const FileDescriptor::IPDLPrivate&,
                         FileDescriptor::ProcessHandle aOtherProcess) const
 {
+#ifdef XP_WIN
+  if (mHandle == INVALID_HANDLE) {
+    return INVALID_HANDLE;
+  }
+
   PlatformHandleType newHandle;
-#ifdef XP_WIN
-  if (IsValid()) {
-    if (DuplicateHandle(GetCurrentProcess(), mHandle, aOtherProcess,
-                        &newHandle, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
-      return newHandle;
-    }
+  if (!DuplicateHandle(GetCurrentProcess(), mHandle, aOtherProcess, &newHandle,
+                       0, FALSE, DUPLICATE_SAME_ACCESS)) {
     NS_WARNING("Failed to duplicate file handle!");
+    return INVALID_HANDLE;
   }
-  return INVALID_HANDLE;
+
+  return newHandle;
 #else // XP_WIN
-  if (IsValid()) {
-    newHandle = dup(mHandle);
-    return base::FileDescriptor(newHandle, /* auto_close */ true);
+  if (mHandle == INVALID_HANDLE) {
+    return base::FileDescriptor();
   }
-  return base::FileDescriptor();
+
+  PlatformHandleType newHandle = dup(mHandle);
+  if (newHandle < 0) {
+    NS_WARNING("Failed to duplicate file descriptor!");
+    return base::FileDescriptor();
+  }
+
+  // This file descriptor must be closed once the caller is done using it, so
+  // pass true here for the 'auto_close' argument.
+  return base::FileDescriptor(newHandle, true);
 #endif
 
   MOZ_NOT_REACHED("Must not get here!");
   return PickleType();
 }
 
-// static
 bool
-FileDescriptor::IsValid(PlatformHandleType aHandle)
+FileDescriptor::IsValid() const
 {
-  return aHandle != INVALID_HANDLE;
+  return mHandle != INVALID_HANDLE;
 }
--- a/ipc/glue/FileDescriptor.h
+++ b/ipc/glue/FileDescriptor.h
@@ -2,17 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_ipc_FileDescriptor_h
 #define mozilla_ipc_FileDescriptor_h
 
 #include "base/basictypes.h"
 #include "base/process.h"
-#include "mozilla/DebugOnly.h"
 #include "nscore.h"
 
 #ifdef XP_WIN
 // Need the HANDLE typedef.
 #include <winnt.h>
 #else
 #include "base/file_descriptor_posix.h"
 #endif
@@ -46,105 +45,51 @@ public:
 #endif
 
   // This should only ever be created by IPDL.
   struct IPDLPrivate
   {};
 
   FileDescriptor();
 
-  FileDescriptor(const FileDescriptor& aOther)
-  {
-    *this = aOther;
-  }
-
-  FileDescriptor(PlatformHandleType aHandle);
+  FileDescriptor(PlatformHandleType aHandle)
+  : mHandle(aHandle)
+  { }
 
   FileDescriptor(const IPDLPrivate&, const PickleType& aPickle)
 #ifdef XP_WIN
   : mHandle(aPickle)
 #else
   : mHandle(aPickle.fd)
 #endif
-  , mHandleCreatedByOtherProcess(true)
-  , mHandleCreatedByOtherProcessWasUsed(false)
   { }
 
-  ~FileDescriptor()
-  {
-    CloseCurrentProcessHandle();
-  }
-
-  FileDescriptor&
-  operator=(const FileDescriptor& aOther)
-  {
-    CloseCurrentProcessHandle();
-
-    if (aOther.mHandleCreatedByOtherProcess) {
-      mHandleCreatedByOtherProcess = true;
-      mHandleCreatedByOtherProcessWasUsed =
-        aOther.mHandleCreatedByOtherProcessWasUsed;
-      mHandle = aOther.PlatformHandle();
-    } else {
-      DuplicateInCurrentProcess(aOther.PlatformHandle());
-      mHandleCreatedByOtherProcess = false;
-      mHandleCreatedByOtherProcessWasUsed = false;
-    }
-
-    return *this;
-  }
-
   // Performs platform-specific actions to duplicate mHandle in the other
   // process (e.g. dup() on POSIX, DuplicateHandle() on Windows). Returns a
   // pickled value that can be passed to the other process via IPC.
   PickleType
   ShareTo(const IPDLPrivate&, ProcessHandle aOtherProcess) const;
 
   // Tests mHandle against a well-known invalid platform-specific file handle
   // (e.g. -1 on POSIX, INVALID_HANDLE_VALUE on Windows).
   bool
-  IsValid() const
-  {
-    return IsValid(mHandle);
-  }
+  IsValid() const;
 
   PlatformHandleType
   PlatformHandle() const
   {
-    if (mHandleCreatedByOtherProcess) {
-      mHandleCreatedByOtherProcessWasUsed = true;
-    }
     return mHandle;
   }
 
   bool
   operator==(const FileDescriptor& aOther) const
   {
     return mHandle == aOther.mHandle;
   }
 
 private:
-  static bool
-  IsValid(PlatformHandleType aHandle);
-
-  void
-  DuplicateInCurrentProcess(PlatformHandleType aHandle);
-
-  void
-  CloseCurrentProcessHandle();
-
   PlatformHandleType mHandle;
-
-  // If this is true then this instance is created by IPDL to ferry a handle to
-  // its eventual consumer and we never close the handle. If this is false then
-  // we are a RAII wrapper around the handle and we close the handle on
-  // destruction.
-  bool mHandleCreatedByOtherProcess;
-
-  // This is to ensure that we don't leak the handle (which is only possible
-  // when we're in the receiving process).
-  mutable DebugOnly<bool> mHandleCreatedByOtherProcessWasUsed;
 };
 
 } // namespace ipc
 } // namespace mozilla
 
 #endif // mozilla_ipc_FileDescriptor_h