OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include <string> | 21 #include <string> |
22 | 22 |
23 #include "base/auto_reset.h" | 23 #include "base/auto_reset.h" |
24 #include "base/logging.h" | 24 #include "base/logging.h" |
25 #include "base/mac/scoped_mach_port.h" | 25 #include "base/mac/scoped_mach_port.h" |
26 #include "base/memory/scoped_ptr.h" | 26 #include "base/memory/scoped_ptr.h" |
27 #include "base/rand_util.h" | 27 #include "base/rand_util.h" |
28 #include "gtest/gtest.h" | 28 #include "gtest/gtest.h" |
29 #include "util/file/file_io.h" | 29 #include "util/file/file_io.h" |
30 #include "util/mach/mach_extensions.h" | 30 #include "util/mach/mach_extensions.h" |
| 31 #include "util/mach/mach_message.h" |
31 #include "util/misc/scoped_forbid_return.h" | 32 #include "util/misc/scoped_forbid_return.h" |
32 #include "util/test/errors.h" | 33 #include "util/test/errors.h" |
33 #include "util/test/mac/mach_errors.h" | 34 #include "util/test/mac/mach_errors.h" |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 // The “hello” message contains a send right to the child process’ task port. | 38 // The “hello” message contains a send right to the child process’ task port. |
38 struct SendHelloMessage : public mach_msg_base_t { | 39 struct SendHelloMessage : public mach_msg_base_t { |
39 mach_msg_port_descriptor_t port_descriptor; | 40 mach_msg_port_descriptor_t port_descriptor; |
40 }; | 41 }; |
41 | 42 |
42 struct ReceiveHelloMessage : public SendHelloMessage { | 43 struct ReceiveHelloMessage : public SendHelloMessage { |
43 mach_msg_audit_trailer_t audit_trailer; | 44 union { |
| 45 mach_msg_trailer_t trailer; |
| 46 mach_msg_audit_trailer_t audit_trailer; |
| 47 }; |
44 }; | 48 }; |
45 | 49 |
46 } // namespace | 50 } // namespace |
47 | 51 |
48 namespace crashpad { | 52 namespace crashpad { |
49 namespace test { | 53 namespace test { |
50 | 54 |
51 namespace internal { | 55 namespace internal { |
52 | 56 |
53 struct MachMultiprocessInfo { | 57 struct MachMultiprocessInfo { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 gid_t audit_rgid = audit_token_to_rgid(message.audit_trailer.msgh_audit); | 183 gid_t audit_rgid = audit_token_to_rgid(message.audit_trailer.msgh_audit); |
180 pid_t audit_pid = audit_token_to_pid(message.audit_trailer.msgh_audit); | 184 pid_t audit_pid = audit_token_to_pid(message.audit_trailer.msgh_audit); |
181 au_asid_t audit_asid = audit_token_to_asid(message.audit_trailer.msgh_audit); | 185 au_asid_t audit_asid = audit_token_to_asid(message.audit_trailer.msgh_audit); |
182 #endif | 186 #endif |
183 EXPECT_EQ(geteuid(), audit_euid); | 187 EXPECT_EQ(geteuid(), audit_euid); |
184 EXPECT_EQ(getegid(), audit_egid); | 188 EXPECT_EQ(getegid(), audit_egid); |
185 EXPECT_EQ(getuid(), audit_ruid); | 189 EXPECT_EQ(getuid(), audit_ruid); |
186 EXPECT_EQ(getgid(), audit_rgid); | 190 EXPECT_EQ(getgid(), audit_rgid); |
187 ASSERT_EQ(ChildPID(), audit_pid); | 191 ASSERT_EQ(ChildPID(), audit_pid); |
188 | 192 |
| 193 ASSERT_EQ(ChildPID(), AuditPIDFromMachMessageTrailer(&message.trailer)); |
| 194 |
189 auditinfo_addr_t audit_info; | 195 auditinfo_addr_t audit_info; |
190 int rv = getaudit_addr(&audit_info, sizeof(audit_info)); | 196 int rv = getaudit_addr(&audit_info, sizeof(audit_info)); |
191 ASSERT_EQ(0, rv) << ErrnoMessage("getaudit_addr"); | 197 ASSERT_EQ(0, rv) << ErrnoMessage("getaudit_addr"); |
192 EXPECT_EQ(audit_info.ai_auid, audit_auid); | 198 EXPECT_EQ(audit_info.ai_auid, audit_auid); |
193 EXPECT_EQ(audit_info.ai_asid, audit_asid); | 199 EXPECT_EQ(audit_info.ai_asid, audit_asid); |
194 | 200 |
195 // Retrieve the remote port from the message header, and the child’s task port | 201 // Retrieve the remote port from the message header, and the child’s task port |
196 // from the message body. | 202 // from the message body. |
197 info_->remote_port.reset(message.header.msgh_remote_port); | 203 info_->remote_port.reset(message.header.msgh_remote_port); |
198 info_->child_task.reset(message.port_descriptor.name); | 204 info_->child_task.reset(message.port_descriptor.name); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 if (testing::Test::HasFailure()) { | 273 if (testing::Test::HasFailure()) { |
268 // Trigger the ScopedForbidReturn destructor. | 274 // Trigger the ScopedForbidReturn destructor. |
269 return; | 275 return; |
270 } | 276 } |
271 | 277 |
272 forbid_return.Disarm(); | 278 forbid_return.Disarm(); |
273 } | 279 } |
274 | 280 |
275 } // namespace test | 281 } // namespace test |
276 } // namespace crashpad | 282 } // namespace crashpad |
OLD | NEW |