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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 EXPECT_EQ(&test.receive.trailer, MachMessageTrailerFromHeader(&test.receive)); | 108 EXPECT_EQ(&test.receive.trailer, MachMessageTrailerFromHeader(&test.receive)); |
109 } | 109 } |
110 | 110 |
111 TEST(MachMessage, AuditPIDFromMachMessageTrailer) { | 111 TEST(MachMessage, AuditPIDFromMachMessageTrailer) { |
112 base::mac::ScopedMachReceiveRight port(NewMachPort(MACH_PORT_RIGHT_RECEIVE)); | 112 base::mac::ScopedMachReceiveRight port(NewMachPort(MACH_PORT_RIGHT_RECEIVE)); |
113 ASSERT_NE(kMachPortNull, port); | 113 ASSERT_NE(kMachPortNull, port); |
114 | 114 |
115 mach_msg_empty_send_t send = {}; | 115 mach_msg_empty_send_t send = {}; |
116 send.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MAKE_SEND_ONCE, 0); | 116 send.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MAKE_SEND_ONCE, 0); |
117 send.header.msgh_size = sizeof(send); | 117 send.header.msgh_size = sizeof(send); |
118 send.header.msgh_remote_port = port; | 118 send.header.msgh_remote_port = port.get(); |
119 mach_msg_return_t mr = | 119 mach_msg_return_t mr = |
120 MachMessageWithDeadline(&send.header, | 120 MachMessageWithDeadline(&send.header, |
121 MACH_SEND_MSG, | 121 MACH_SEND_MSG, |
122 0, | 122 0, |
123 MACH_PORT_NULL, | 123 MACH_PORT_NULL, |
124 kMachMessageDeadlineNonblocking, | 124 kMachMessageDeadlineNonblocking, |
125 MACH_PORT_NULL, | 125 MACH_PORT_NULL, |
126 false); | 126 false); |
127 ASSERT_EQ(MACH_MSG_SUCCESS, mr) | 127 ASSERT_EQ(MACH_MSG_SUCCESS, mr) |
128 << MachErrorMessage(mr, "MachMessageWithDeadline send"); | 128 << MachErrorMessage(mr, "MachMessageWithDeadline send"); |
129 | 129 |
130 struct EmptyReceiveMessageWithAuditTrailer : public mach_msg_empty_send_t { | 130 struct EmptyReceiveMessageWithAuditTrailer : public mach_msg_empty_send_t { |
131 union { | 131 union { |
132 mach_msg_trailer_t trailer; | 132 mach_msg_trailer_t trailer; |
133 mach_msg_audit_trailer_t audit_trailer; | 133 mach_msg_audit_trailer_t audit_trailer; |
134 }; | 134 }; |
135 }; | 135 }; |
136 | 136 |
137 EmptyReceiveMessageWithAuditTrailer receive; | 137 EmptyReceiveMessageWithAuditTrailer receive; |
138 mr = MachMessageWithDeadline(&receive.header, | 138 mr = MachMessageWithDeadline(&receive.header, |
139 MACH_RCV_MSG | kMachMessageReceiveAuditTrailer, | 139 MACH_RCV_MSG | kMachMessageReceiveAuditTrailer, |
140 sizeof(receive), | 140 sizeof(receive), |
141 port, | 141 port.get(), |
142 kMachMessageDeadlineNonblocking, | 142 kMachMessageDeadlineNonblocking, |
143 MACH_PORT_NULL, | 143 MACH_PORT_NULL, |
144 false); | 144 false); |
145 ASSERT_EQ(MACH_MSG_SUCCESS, mr) | 145 ASSERT_EQ(MACH_MSG_SUCCESS, mr) |
146 << MachErrorMessage(mr, "MachMessageWithDeadline receive"); | 146 << MachErrorMessage(mr, "MachMessageWithDeadline receive"); |
147 | 147 |
148 EXPECT_EQ(getpid(), AuditPIDFromMachMessageTrailer(&receive.trailer)); | 148 EXPECT_EQ(getpid(), AuditPIDFromMachMessageTrailer(&receive.trailer)); |
149 } | 149 } |
150 | 150 |
151 } // namespace | 151 } // namespace |
152 } // namespace test | 152 } // namespace test |
153 } // namespace crashpad | 153 } // namespace crashpad |
OLD | NEW |