2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-08-20 13:58:42 -04:00
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
test: Move util/test to its own top-level directory, test.
After 9e79ea1da719, it no longer makes sense for crashpad_util_test_lib
to “hide” in util/util_test.gyp. All of util/test is moved to its own
top-level directory, test, which all other test code is allowed to
depend on. test, too, is allowed to depend on all other non-test code.
In a future change, when crashpad_util_test_lib gains a dependency on
crashpad_client, it won’t look so weird for something in util (even
though it’s in util/test) to depend on something in client, because the
thing that needs to depend on client will live in test, not util.
BUG=crashpad:33
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/1051533002
2015-03-31 17:44:14 -04:00
|
|
|
|
#include "test/mac/mach_multiprocess.h"
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
mac: Switch from <AvailabilityMacros.h> to <Availability.h>
The macOS 11.0 SDK, as of Xcode 12b6 12A8189n, has not updated
<AvailabilityMacros.h> with a MAC_OS_X_VERSION_11_0 or
MAC_OS_X_VERSION_10_16 constant. However, the <Availability.h> interface
has been updated to provide both __MAC_11_0 and __MAC_10_16.
<AvailabilityMacros.h>’s MAC_OS_X_VERSION_MAX_ALLOWED, which is supposed
to identify the SDK version, is broken in the 11.0 SDK in that whenever
the deployment target is set to 10.15 or earlier, the SDK will be
mis-identified through this interface as 10.15. When using the
<Availability.h> equivalent, __MAC_OS_X_VERSION_MAX_ALLOWED, the 11.0
SDK is identified as 10.16 (arguably it should be internally versioned
as 11.0, but at least this interface allows it to be detected
unambiguously.) It’s clear that the <AvailabilityMacros.h> interface
provides no meaningful support for the macOS 11.0 SDK at all, but
<Availability.h> does.
<Availability.h> was introduced in the Mac OS X 10.5 SDK, so there is no
relevant SDK version compatibility problem with this interface.
Key differences between these interfaces for the purposes used by
Crashpad:
- <AvailabilityMacros.h> → <Availability.h>
- MAC_OS_X_VERSION_MIN_REQUIRED (DT) → __MAC_OS_X_VERSION_MIN_REQUIRED
- MAC_OS_X_VERSION_MAX_ALLOWED (SDK) → __MAC_OS_X_VERSION_MAX_ALLOWED
- MAC_OS_X_VERSION_x_y → __MAC_x_y
- <Availability.h> __MAC_OS_X_VERSION_* SDK/DT macros are only
available when targeting macOS, while <AvailabilityMacros.h>
MAC_OS_X_VERSION_* SDK/DT macros are available on all Apple platforms,
which may be a source of confusion. (<Availability.h> __MAC_* macros
do remain available on all Apple platforms.)
This change was made mostly mechanically by:
sed -i '' -Ee 's/<AvailabilityMacros.h>/<Availability.h>/g' \
$(git grep -E -l '<AvailabilityMacros.h>' |
grep -v AvailabilityMacros.h)
sed -i '' -Ee 's/(MAC_OS_X_VERSION_(MIN_REQUIRED|MAX_ALLOWED))/__\1/g' \
$(git grep -E -l 'MAC_OS_X_VERSION_(MIN_REQUIRED|MAX_ALLOWED)' |
grep -v AvailabilityMacros.h)
sed -i '' -Ee 's/(MAC_OS_X_VERSION_(10_[0-9]+))/__MAC_\2/g' \
$(git grep -E -l 'MAC_OS_X_VERSION_(10_[0-9]+)' |
grep -v AvailabilityMacros.h)
Bug: crashpad:347
Change-Id: Ibdcd7a6215a82f7060b7b67d98691f88454085fc
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2382421
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2020-08-28 20:00:15 -04:00
|
|
|
|
#include <Availability.h>
|
2014-08-20 13:58:42 -04:00
|
|
|
|
#include <bsm/libbsm.h>
|
|
|
|
|
|
2016-04-25 12:13:07 -07:00
|
|
|
|
#include <memory>
|
2014-08-20 13:58:42 -04:00
|
|
|
|
#include <string>
|
2022-01-07 17:19:37 -05:00
|
|
|
|
#include <tuple>
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
2023-08-16 16:30:40 -04:00
|
|
|
|
#include "base/apple/scoped_mach_port.h"
|
2014-08-20 13:58:42 -04:00
|
|
|
|
#include "base/auto_reset.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
test: Move util/test to its own top-level directory, test.
After 9e79ea1da719, it no longer makes sense for crashpad_util_test_lib
to “hide” in util/util_test.gyp. All of util/test is moved to its own
top-level directory, test, which all other test code is allowed to
depend on. test, too, is allowed to depend on all other non-test code.
In a future change, when crashpad_util_test_lib gains a dependency on
crashpad_client, it won’t look so weird for something in util (even
though it’s in util/test) to depend on something in client, because the
thing that needs to depend on client will live in test, not util.
BUG=crashpad:33
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/1051533002
2015-03-31 17:44:14 -04:00
|
|
|
|
#include "test/errors.h"
|
|
|
|
|
#include "test/mac/mach_errors.h"
|
2014-12-17 14:35:18 -08:00
|
|
|
|
#include "util/file/file_io.h"
|
2020-04-17 11:29:09 -04:00
|
|
|
|
#include "util/mach/bootstrap.h"
|
2014-09-10 17:29:07 -04:00
|
|
|
|
#include "util/mach/mach_extensions.h"
|
2015-03-12 14:00:38 -04:00
|
|
|
|
#include "util/mach/mach_message.h"
|
2015-09-14 14:51:05 -07:00
|
|
|
|
#include "util/misc/implicit_cast.h"
|
2015-11-16 13:39:01 -05:00
|
|
|
|
#include "util/misc/random_string.h"
|
2014-08-26 17:10:19 -04:00
|
|
|
|
#include "util/misc/scoped_forbid_return.h"
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
// The “hello” message contains a send right to the child process’ task port.
|
|
|
|
|
struct SendHelloMessage : public mach_msg_base_t {
|
|
|
|
|
mach_msg_port_descriptor_t port_descriptor;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ReceiveHelloMessage : public SendHelloMessage {
|
2015-03-12 14:00:38 -04:00
|
|
|
|
union {
|
|
|
|
|
mach_msg_trailer_t trailer;
|
|
|
|
|
mach_msg_audit_trailer_t audit_trailer;
|
|
|
|
|
};
|
2014-08-20 13:58:42 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
struct MachMultiprocessInfo {
|
|
|
|
|
MachMultiprocessInfo()
|
|
|
|
|
: service_name(),
|
|
|
|
|
local_port(MACH_PORT_NULL),
|
|
|
|
|
remote_port(MACH_PORT_NULL),
|
2014-10-13 12:59:21 -04:00
|
|
|
|
child_task(TASK_NULL) {
|
|
|
|
|
}
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
|
|
|
|
std::string service_name;
|
2023-08-16 16:30:40 -04:00
|
|
|
|
base::apple::ScopedMachReceiveRight local_port;
|
|
|
|
|
base::apple::ScopedMachSendRight remote_port;
|
|
|
|
|
base::apple::ScopedMachSendRight child_task; // valid only in parent
|
2014-08-20 13:58:42 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
2014-10-14 11:10:45 -04:00
|
|
|
|
MachMultiprocess::MachMultiprocess() : Multiprocess(), info_(nullptr) {
|
2014-08-20 13:58:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MachMultiprocess::Run() {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(info_, nullptr);
|
2016-04-25 12:13:07 -07:00
|
|
|
|
std::unique_ptr<internal::MachMultiprocessInfo> info(
|
2014-08-20 13:58:42 -04:00
|
|
|
|
new internal::MachMultiprocessInfo);
|
|
|
|
|
base::AutoReset<internal::MachMultiprocessInfo*> reset_info(&info_,
|
|
|
|
|
info.get());
|
|
|
|
|
|
2014-08-26 17:10:19 -04:00
|
|
|
|
return Multiprocess::Run();
|
|
|
|
|
}
|
2014-08-22 14:00:10 -04:00
|
|
|
|
|
2014-08-26 17:10:19 -04:00
|
|
|
|
MachMultiprocess::~MachMultiprocess() {
|
|
|
|
|
}
|
2014-08-22 14:00:10 -04:00
|
|
|
|
|
2014-08-26 17:10:19 -04:00
|
|
|
|
void MachMultiprocess::PreFork() {
|
2014-10-09 15:08:54 -04:00
|
|
|
|
ASSERT_NO_FATAL_FAILURE(Multiprocess::PreFork());
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
|
|
|
|
// Set up the parent port and register it with the bootstrap server before
|
|
|
|
|
// forking, so that it’s guaranteed to be there when the child attempts to
|
|
|
|
|
// look it up.
|
2015-10-29 18:31:20 -04:00
|
|
|
|
info_->service_name = "org.chromium.crashpad.test.mach_multiprocess.";
|
2015-11-16 13:39:01 -05:00
|
|
|
|
info_->service_name.append(RandomString());
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
2015-10-05 17:07:15 -04:00
|
|
|
|
info_->local_port = BootstrapCheckIn(info_->service_name);
|
2015-10-20 11:03:25 -04:00
|
|
|
|
ASSERT_TRUE(info_->local_port.is_valid());
|
2014-08-20 13:58:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mach_port_t MachMultiprocess::LocalPort() const {
|
2015-10-20 11:03:25 -04:00
|
|
|
|
EXPECT_TRUE(info_->local_port.is_valid());
|
|
|
|
|
return info_->local_port.get();
|
2014-08-20 13:58:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mach_port_t MachMultiprocess::RemotePort() const {
|
2015-10-20 11:03:25 -04:00
|
|
|
|
EXPECT_TRUE(info_->remote_port.is_valid());
|
|
|
|
|
return info_->remote_port.get();
|
2014-08-20 13:58:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 13:53:43 -04:00
|
|
|
|
task_t MachMultiprocess::ChildTask() const {
|
2015-10-20 11:03:25 -04:00
|
|
|
|
EXPECT_TRUE(info_->child_task.is_valid());
|
|
|
|
|
return info_->child_task.get();
|
2014-08-20 13:58:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 17:10:19 -04:00
|
|
|
|
void MachMultiprocess::MultiprocessParent() {
|
2014-08-20 13:58:42 -04:00
|
|
|
|
ReceiveHelloMessage message = {};
|
|
|
|
|
|
2015-03-12 14:00:38 -04:00
|
|
|
|
kern_return_t kr = mach_msg(&message.header,
|
|
|
|
|
MACH_RCV_MSG | kMachMessageReceiveAuditTrailer,
|
|
|
|
|
0,
|
|
|
|
|
sizeof(message),
|
2015-10-20 11:03:25 -04:00
|
|
|
|
info_->local_port.get(),
|
2015-03-12 14:00:38 -04:00
|
|
|
|
MACH_MSG_TIMEOUT_NONE,
|
|
|
|
|
MACH_PORT_NULL);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(kr, MACH_MSG_SUCCESS) << MachErrorMessage(kr, "mach_msg");
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
|
|
|
|
// Comb through the entire message, checking every field against its expected
|
|
|
|
|
// value.
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(message.header.msgh_bits,
|
|
|
|
|
MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND, MACH_MSG_TYPE_MOVE_SEND) |
|
|
|
|
|
MACH_MSGH_BITS_COMPLEX);
|
|
|
|
|
ASSERT_EQ(message.header.msgh_size, sizeof(SendHelloMessage));
|
|
|
|
|
EXPECT_EQ(message.header.msgh_local_port, info_->local_port);
|
|
|
|
|
ASSERT_EQ(message.body.msgh_descriptor_count, 1u);
|
|
|
|
|
EXPECT_EQ(message.port_descriptor.disposition,
|
|
|
|
|
implicit_cast<mach_msg_type_name_t>(MACH_MSG_TYPE_MOVE_SEND));
|
|
|
|
|
ASSERT_EQ(
|
|
|
|
|
message.port_descriptor.type,
|
|
|
|
|
implicit_cast<mach_msg_descriptor_type_t>(MACH_MSG_PORT_DESCRIPTOR));
|
|
|
|
|
ASSERT_EQ(message.audit_trailer.msgh_trailer_type,
|
|
|
|
|
implicit_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0));
|
|
|
|
|
ASSERT_EQ(message.audit_trailer.msgh_trailer_size,
|
|
|
|
|
sizeof(message.audit_trailer));
|
|
|
|
|
EXPECT_EQ(message.audit_trailer.msgh_seqno, 0u);
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
|
|
|
|
// Check the audit trailer’s values for sanity. This is a little bit of
|
|
|
|
|
// overkill, but because the service was registered with the bootstrap server
|
|
|
|
|
// and other processes will be able to look it up and send messages to it,
|
|
|
|
|
// these checks disambiguate genuine failures later on in the test from those
|
|
|
|
|
// that would occur if an errant process sends a message to this service.
|
mac: Switch from <AvailabilityMacros.h> to <Availability.h>
The macOS 11.0 SDK, as of Xcode 12b6 12A8189n, has not updated
<AvailabilityMacros.h> with a MAC_OS_X_VERSION_11_0 or
MAC_OS_X_VERSION_10_16 constant. However, the <Availability.h> interface
has been updated to provide both __MAC_11_0 and __MAC_10_16.
<AvailabilityMacros.h>’s MAC_OS_X_VERSION_MAX_ALLOWED, which is supposed
to identify the SDK version, is broken in the 11.0 SDK in that whenever
the deployment target is set to 10.15 or earlier, the SDK will be
mis-identified through this interface as 10.15. When using the
<Availability.h> equivalent, __MAC_OS_X_VERSION_MAX_ALLOWED, the 11.0
SDK is identified as 10.16 (arguably it should be internally versioned
as 11.0, but at least this interface allows it to be detected
unambiguously.) It’s clear that the <AvailabilityMacros.h> interface
provides no meaningful support for the macOS 11.0 SDK at all, but
<Availability.h> does.
<Availability.h> was introduced in the Mac OS X 10.5 SDK, so there is no
relevant SDK version compatibility problem with this interface.
Key differences between these interfaces for the purposes used by
Crashpad:
- <AvailabilityMacros.h> → <Availability.h>
- MAC_OS_X_VERSION_MIN_REQUIRED (DT) → __MAC_OS_X_VERSION_MIN_REQUIRED
- MAC_OS_X_VERSION_MAX_ALLOWED (SDK) → __MAC_OS_X_VERSION_MAX_ALLOWED
- MAC_OS_X_VERSION_x_y → __MAC_x_y
- <Availability.h> __MAC_OS_X_VERSION_* SDK/DT macros are only
available when targeting macOS, while <AvailabilityMacros.h>
MAC_OS_X_VERSION_* SDK/DT macros are available on all Apple platforms,
which may be a source of confusion. (<Availability.h> __MAC_* macros
do remain available on all Apple platforms.)
This change was made mostly mechanically by:
sed -i '' -Ee 's/<AvailabilityMacros.h>/<Availability.h>/g' \
$(git grep -E -l '<AvailabilityMacros.h>' |
grep -v AvailabilityMacros.h)
sed -i '' -Ee 's/(MAC_OS_X_VERSION_(MIN_REQUIRED|MAX_ALLOWED))/__\1/g' \
$(git grep -E -l 'MAC_OS_X_VERSION_(MIN_REQUIRED|MAX_ALLOWED)' |
grep -v AvailabilityMacros.h)
sed -i '' -Ee 's/(MAC_OS_X_VERSION_(10_[0-9]+))/__MAC_\2/g' \
$(git grep -E -l 'MAC_OS_X_VERSION_(10_[0-9]+)' |
grep -v AvailabilityMacros.h)
Bug: crashpad:347
Change-Id: Ibdcd7a6215a82f7060b7b67d98691f88454085fc
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2382421
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2020-08-28 20:00:15 -04:00
|
|
|
|
#if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_8
|
2014-08-20 13:58:42 -04:00
|
|
|
|
uid_t audit_auid;
|
|
|
|
|
uid_t audit_euid;
|
|
|
|
|
gid_t audit_egid;
|
|
|
|
|
uid_t audit_ruid;
|
|
|
|
|
gid_t audit_rgid;
|
|
|
|
|
pid_t audit_pid;
|
|
|
|
|
au_asid_t audit_asid;
|
|
|
|
|
audit_token_to_au32(message.audit_trailer.msgh_audit,
|
|
|
|
|
&audit_auid,
|
|
|
|
|
&audit_euid,
|
|
|
|
|
&audit_egid,
|
|
|
|
|
&audit_ruid,
|
|
|
|
|
&audit_rgid,
|
|
|
|
|
&audit_pid,
|
|
|
|
|
&audit_asid,
|
2014-10-14 11:10:45 -04:00
|
|
|
|
nullptr);
|
2014-08-20 13:58:42 -04:00
|
|
|
|
#else
|
|
|
|
|
uid_t audit_auid = audit_token_to_auid(message.audit_trailer.msgh_audit);
|
|
|
|
|
uid_t audit_euid = audit_token_to_euid(message.audit_trailer.msgh_audit);
|
|
|
|
|
gid_t audit_egid = audit_token_to_egid(message.audit_trailer.msgh_audit);
|
|
|
|
|
uid_t audit_ruid = audit_token_to_ruid(message.audit_trailer.msgh_audit);
|
|
|
|
|
gid_t audit_rgid = audit_token_to_rgid(message.audit_trailer.msgh_audit);
|
|
|
|
|
pid_t audit_pid = audit_token_to_pid(message.audit_trailer.msgh_audit);
|
|
|
|
|
au_asid_t audit_asid = audit_token_to_asid(message.audit_trailer.msgh_audit);
|
|
|
|
|
#endif
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(audit_euid, geteuid());
|
|
|
|
|
EXPECT_EQ(audit_egid, getegid());
|
|
|
|
|
EXPECT_EQ(audit_ruid, getuid());
|
|
|
|
|
EXPECT_EQ(audit_rgid, getgid());
|
|
|
|
|
ASSERT_EQ(audit_pid, ChildPID());
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(AuditPIDFromMachMessageTrailer(&message.trailer), ChildPID());
|
2015-03-12 14:00:38 -04:00
|
|
|
|
|
2014-08-20 13:58:42 -04:00
|
|
|
|
auditinfo_addr_t audit_info;
|
|
|
|
|
int rv = getaudit_addr(&audit_info, sizeof(audit_info));
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(rv, 0) << ErrnoMessage("getaudit_addr");
|
|
|
|
|
EXPECT_EQ(audit_auid, audit_info.ai_auid);
|
|
|
|
|
EXPECT_EQ(audit_asid, audit_info.ai_asid);
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
|
|
|
|
// Retrieve the remote port from the message header, and the child’s task port
|
|
|
|
|
// from the message body.
|
|
|
|
|
info_->remote_port.reset(message.header.msgh_remote_port);
|
|
|
|
|
info_->child_task.reset(message.port_descriptor.name);
|
|
|
|
|
|
|
|
|
|
// Verify that the child’s task port is what it purports to be.
|
|
|
|
|
int mach_pid;
|
2015-10-20 11:03:25 -04:00
|
|
|
|
kr = pid_for_task(info_->child_task.get(), &mach_pid);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "pid_for_task");
|
|
|
|
|
ASSERT_EQ(mach_pid, ChildPID());
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
2014-08-26 17:10:19 -04:00
|
|
|
|
MachMultiprocessParent();
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
|
|
|
|
info_->remote_port.reset();
|
|
|
|
|
info_->local_port.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 17:10:19 -04:00
|
|
|
|
void MachMultiprocess::MultiprocessChild() {
|
2015-12-01 12:56:03 -05:00
|
|
|
|
ScopedForbidReturn forbid_return;
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
|
|
|
|
// local_port is not valid in the forked child process.
|
2022-01-07 17:19:37 -05:00
|
|
|
|
std::ignore = info_->local_port.release();
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
2014-12-17 15:10:38 -05:00
|
|
|
|
info_->local_port.reset(NewMachPort(MACH_PORT_RIGHT_RECEIVE));
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_NE(info_->local_port, kMachPortNull);
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
|
|
|
|
// The remote port can be obtained from the bootstrap server.
|
2015-10-05 17:07:15 -04:00
|
|
|
|
info_->remote_port = BootstrapLookUp(info_->service_name);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_NE(info_->remote_port, kMachPortNull);
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
|
|
|
|
// The “hello” message will provide the parent with its remote port, a send
|
|
|
|
|
// right to the child task’s local port receive right. It will also carry a
|
|
|
|
|
// send right to the child task’s task port.
|
|
|
|
|
SendHelloMessage message = {};
|
|
|
|
|
message.header.msgh_bits =
|
|
|
|
|
MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND) |
|
|
|
|
|
MACH_MSGH_BITS_COMPLEX;
|
|
|
|
|
message.header.msgh_size = sizeof(message);
|
2015-10-20 11:03:25 -04:00
|
|
|
|
message.header.msgh_remote_port = info_->remote_port.get();
|
|
|
|
|
message.header.msgh_local_port = info_->local_port.get();
|
2014-08-20 13:58:42 -04:00
|
|
|
|
message.body.msgh_descriptor_count = 1;
|
|
|
|
|
message.port_descriptor.name = mach_task_self();
|
|
|
|
|
message.port_descriptor.disposition = MACH_MSG_TYPE_COPY_SEND;
|
|
|
|
|
message.port_descriptor.type = MACH_MSG_PORT_DESCRIPTOR;
|
|
|
|
|
|
2015-10-05 17:07:15 -04:00
|
|
|
|
kern_return_t kr = mach_msg(&message.header,
|
|
|
|
|
MACH_SEND_MSG,
|
|
|
|
|
message.header.msgh_size,
|
|
|
|
|
0,
|
|
|
|
|
MACH_PORT_NULL,
|
|
|
|
|
MACH_MSG_TIMEOUT_NONE,
|
|
|
|
|
MACH_PORT_NULL);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(kr, MACH_MSG_SUCCESS) << MachErrorMessage(kr, "mach_msg");
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
2014-08-26 17:10:19 -04:00
|
|
|
|
MachMultiprocessChild();
|
2014-08-20 13:58:42 -04:00
|
|
|
|
|
|
|
|
|
info_->remote_port.reset();
|
|
|
|
|
info_->local_port.reset();
|
|
|
|
|
|
2014-09-22 13:06:12 -04:00
|
|
|
|
// Close the write pipe now, for cases where the parent is waiting on it to
|
|
|
|
|
// be closed as an indication that the child has finished.
|
|
|
|
|
CloseWritePipe();
|
|
|
|
|
|
|
|
|
|
// Wait for the parent process to close its end of the pipe. The child process
|
|
|
|
|
// needs to remain alive until then because the parent process will attempt to
|
|
|
|
|
// verify it using the task port it has access to via ChildTask().
|
2015-01-28 14:49:42 -08:00
|
|
|
|
CheckedReadFileAtEOF(ReadPipeHandle());
|
2014-09-22 13:06:12 -04:00
|
|
|
|
|
2014-10-07 17:28:50 -04:00
|
|
|
|
if (testing::Test::HasFailure()) {
|
2014-08-26 17:10:19 -04:00
|
|
|
|
// Trigger the ScopedForbidReturn destructor.
|
2014-08-20 13:58:42 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 17:10:19 -04:00
|
|
|
|
forbid_return.Disarm();
|
2014-08-20 13:58:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace crashpad
|