Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: util/mach/mach_message_server.cc

Issue 755313004: Pass Mach message trailers to server handler functions (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « util/mach/exception_ports_test.cc ('k') | util/mach/mach_message_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 104 }
105 105
106 if (receive_large == kReceiveLargeResize) { 106 if (receive_large == kReceiveLargeResize) {
107 options |= MACH_RCV_LARGE; 107 options |= MACH_RCV_LARGE;
108 } else { 108 } else {
109 options &= ~MACH_RCV_LARGE; 109 options &= ~MACH_RCV_LARGE;
110 } 110 }
111 111
112 mach_msg_size_t trailer_alloc = REQUESTED_TRAILER_SIZE(options); 112 mach_msg_size_t trailer_alloc = REQUESTED_TRAILER_SIZE(options);
113 mach_msg_size_t max_request_size = interface->MachMessageServerRequestSize(); 113 mach_msg_size_t max_request_size = interface->MachMessageServerRequestSize();
114 mach_msg_size_t request_alloc = round_page(max_request_size + trailer_alloc); 114 mach_msg_size_t request_alloc =
115 round_page(round_msg(max_request_size) + trailer_alloc);
115 116
116 // mach_msg_server() and mach_msg_server_once() invert this condition, but 117 // mach_msg_server() and mach_msg_server_once() invert this condition, but
117 // their interpretation is incorrect. When it is desirable to retry a receive 118 // their interpretation is incorrect. When it is desirable to retry a receive
118 // attempt that returns MACH_RCV_TOO_LARGE with a larger receive buffer, it is 119 // attempt that returns MACH_RCV_TOO_LARGE with a larger receive buffer, it is
119 // also desirable to use the full receive buffer rounded up to a page size for 120 // also desirable to use the full receive buffer rounded up to a page size for
120 // the initial receive attempt. On the other hand, when this behavior is not 121 // the initial receive attempt. On the other hand, when this behavior is not
121 // requested, there is no reason to attempt receiving messages any larger than 122 // requested, there is no reason to attempt receiving messages any larger than
122 // expected. 123 // expected.
123 mach_msg_size_t request_size = (receive_large == kReceiveLargeResize) 124 mach_msg_size_t request_size =
124 ? max_request_size + trailer_alloc 125 (receive_large == kReceiveLargeResize)
125 : request_alloc; 126 ? round_msg(max_request_size) + trailer_alloc
127 : request_alloc;
126 128
127 mach_msg_size_t max_reply_size = interface->MachMessageServerReplySize(); 129 mach_msg_size_t max_reply_size = interface->MachMessageServerReplySize();
128 130
129 // mach_msg_server() and mach_msg_server_once() would consider whether 131 // mach_msg_server() and mach_msg_server_once() would consider whether
130 // |options| contains MACH_SEND_TRAILER and include MAX_TRAILER_SIZE in this 132 // |options| contains MACH_SEND_TRAILER and include MAX_TRAILER_SIZE in this
131 // computation if it does, but that option is ineffective on OS X. 133 // computation if it does, but that option is ineffective on OS X.
132 mach_msg_size_t reply_alloc = round_page(max_reply_size); 134 mach_msg_size_t reply_alloc = round_page(max_reply_size);
133 135
134 kern_return_t kr; 136 kern_return_t kr;
135 137
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } else if (kr == MACH_RCV_INTERRUPTED) { 181 } else if (kr == MACH_RCV_INTERRUPTED) {
180 run_mach_msg_receive = true; 182 run_mach_msg_receive = true;
181 } 183 }
182 } while (run_mach_msg_receive); 184 } while (run_mach_msg_receive);
183 185
184 if (kr == MACH_MSG_SUCCESS) { 186 if (kr == MACH_MSG_SUCCESS) {
185 request_scoper.swap(trial_request_scoper); 187 request_scoper.swap(trial_request_scoper);
186 } else if (kr == MACH_RCV_TOO_LARGE && 188 } else if (kr == MACH_RCV_TOO_LARGE &&
187 receive_large == kReceiveLargeResize) { 189 receive_large == kReceiveLargeResize) {
188 this_request_size = 190 this_request_size =
189 round_page(request_header->msgh_size + trailer_alloc); 191 round_page(round_msg(request_header->msgh_size) + trailer_alloc);
190 this_request_alloc = this_request_size; 192 this_request_alloc = this_request_size;
191 } else { 193 } else {
192 return kr; 194 return kr;
193 } 195 }
194 } 196 }
195 197
196 vm_address_t reply_addr; 198 vm_address_t reply_addr;
197 kr = vm_allocate(mach_task_self(), 199 kr = vm_allocate(mach_task_self(),
198 &reply_addr, 200 &reply_addr,
199 reply_alloc, 201 reply_alloc,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 // persistent mode, and just return success when not in persistent mode. 286 // persistent mode, and just return success when not in persistent mode.
285 return (persistent == kPersistent) ? MACH_RCV_TIMED_OUT : kr; 287 return (persistent == kPersistent) ? MACH_RCV_TIMED_OUT : kr;
286 } 288 }
287 } 289 }
288 } while (persistent == kPersistent); 290 } while (persistent == kPersistent);
289 291
290 return kr; 292 return kr;
291 } 293 }
292 294
293 } // namespace crashpad 295 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/mach/exception_ports_test.cc ('k') | util/mach/mach_message_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698