2016-05-28 00:54:31 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2011-06-03 22:33:56 +04:00
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2015-12-04 02:23:00 +03:00
|
|
|
#include "base/eintr_wrapper.h"
|
|
|
|
|
2011-06-03 22:33:56 +04:00
|
|
|
#include "mozilla/ipc/Transport.h"
|
2013-06-03 14:14:37 +04:00
|
|
|
#include "mozilla/ipc/FileDescriptor.h"
|
2016-04-01 09:33:52 +03:00
|
|
|
#include "ProtocolUtils.h"
|
2011-06-03 22:33:56 +04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2015-02-11 23:01:26 +03:00
|
|
|
using base::ProcessHandle;
|
|
|
|
|
2011-06-03 22:33:56 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
2015-07-10 03:07:49 +03:00
|
|
|
nsresult CreateTransport(base::ProcessId aProcIdOne, TransportDescriptor* aOne,
|
|
|
|
TransportDescriptor* aTwo) {
|
2015-04-23 13:09:04 +03:00
|
|
|
wstring id = IPC::Channel::GenerateVerifiedChannelID(std::wstring());
|
2011-06-03 22:33:56 +04:00
|
|
|
// Use MODE_SERVER to force creation of the socketpair
|
2012-07-30 18:20:58 +04:00
|
|
|
Transport t(id, Transport::MODE_SERVER, nullptr);
|
2013-05-31 17:16:54 +04:00
|
|
|
int fd1 = t.GetFileDescriptor();
|
2011-06-03 22:33:56 +04:00
|
|
|
int fd2, dontcare;
|
|
|
|
t.GetClientFileDescriptorMapping(&fd2, &dontcare);
|
|
|
|
if (fd1 < 0 || fd2 < 0) {
|
2015-07-10 03:07:49 +03:00
|
|
|
return NS_ERROR_TRANSPORT_INIT;
|
2011-06-03 22:33:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The Transport closes these fds when it goes out of scope, so we
|
|
|
|
// dup them here
|
|
|
|
fd1 = dup(fd1);
|
2016-08-23 08:52:04 +03:00
|
|
|
if (fd1 < 0) {
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
AnnotateCrashReportWithErrno(
|
|
|
|
CrashReporter::Annotation::IpcCreateTransportDupErrno, errno);
|
2016-08-23 08:52:04 +03:00
|
|
|
}
|
2011-06-03 22:33:56 +04:00
|
|
|
fd2 = dup(fd2);
|
2016-08-23 08:52:04 +03:00
|
|
|
if (fd2 < 0) {
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
AnnotateCrashReportWithErrno(
|
|
|
|
CrashReporter::Annotation::IpcCreateTransportDupErrno, errno);
|
2016-08-23 08:52:04 +03:00
|
|
|
}
|
|
|
|
|
2011-06-03 22:33:56 +04:00
|
|
|
if (fd1 < 0 || fd2 < 0) {
|
2018-04-10 23:36:00 +03:00
|
|
|
IGNORE_EINTR(close(fd1));
|
|
|
|
IGNORE_EINTR(close(fd2));
|
2015-07-10 03:07:49 +03:00
|
|
|
return NS_ERROR_DUPLICATE_HANDLE;
|
2011-06-03 22:33:56 +04:00
|
|
|
}
|
|
|
|
|
2013-06-03 14:14:37 +04:00
|
|
|
aOne->mFd = base::FileDescriptor(fd1, true /*close after sending*/);
|
|
|
|
aTwo->mFd = base::FileDescriptor(fd2, true /*close after sending*/);
|
2015-07-10 03:07:49 +03:00
|
|
|
return NS_OK;
|
2011-06-03 22:33:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
UniquePtr<Transport> OpenDescriptor(const TransportDescriptor& aTd,
|
|
|
|
Transport::Mode aMode) {
|
2016-07-07 04:51:20 +03:00
|
|
|
return MakeUnique<Transport>(aTd.mFd.fd, aMode, nullptr);
|
2011-06-03 22:33:56 +04:00
|
|
|
}
|
|
|
|
|
2013-06-03 14:14:37 +04:00
|
|
|
UniquePtr<Transport> OpenDescriptor(const FileDescriptor& aFd,
|
|
|
|
Transport::Mode aMode) {
|
2016-05-27 11:12:51 +03:00
|
|
|
auto rawFD = aFd.ClonePlatformHandle();
|
|
|
|
return MakeUnique<Transport>(rawFD.release(), aMode, nullptr);
|
2013-06-03 14:14:37 +04:00
|
|
|
}
|
|
|
|
|
2015-11-01 06:02:08 +03:00
|
|
|
TransportDescriptor DuplicateDescriptor(const TransportDescriptor& aTd) {
|
|
|
|
TransportDescriptor result = aTd;
|
|
|
|
result.mFd.fd = dup(aTd.mFd.fd);
|
2016-04-01 09:33:52 +03:00
|
|
|
if (result.mFd.fd == -1) {
|
|
|
|
AnnotateSystemError();
|
|
|
|
}
|
2015-11-01 06:02:08 +03:00
|
|
|
MOZ_RELEASE_ASSERT(result.mFd.fd != -1, "DuplicateDescriptor failed");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-06-03 22:33:56 +04:00
|
|
|
void CloseDescriptor(const TransportDescriptor& aTd) { close(aTd.mFd.fd); }
|
|
|
|
|
2011-06-03 22:33:56 +04:00
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|