mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-10 06:36:02 +00:00
MachMessageServer: add some DCHECKs.
These DCHECKs make sure that buffer sizes and message sizes are as expected. TEST=util_test MachMessageServer.* R=rsesek@chromium.org Review URL: https://codereview.chromium.org/781593003
This commit is contained in:
parent
ef0b7cf6d5
commit
9f520e3fbf
@ -43,7 +43,7 @@ class MachMessageBuffer {
|
|||||||
//! If the existing buffer is a different size, it will be reallocated without
|
//! If the existing buffer is a different size, it will be reallocated without
|
||||||
//! copying any of the old buffer’s contents to the new buffer. The contents
|
//! copying any of the old buffer’s contents to the new buffer. The contents
|
||||||
//! of the buffer are unspecified after this call, even if no reallocation is
|
//! of the buffer are unspecified after this call, even if no reallocation is
|
||||||
//! made.
|
//! performed.
|
||||||
kern_return_t Reallocate(vm_size_t size) {
|
kern_return_t Reallocate(vm_size_t size) {
|
||||||
// This test uses == instead of > so that a large reallocation to receive a
|
// This test uses == instead of > so that a large reallocation to receive a
|
||||||
// large message doesn’t cause permanent memory bloat for the duration of
|
// large message doesn’t cause permanent memory bloat for the duration of
|
||||||
@ -55,6 +55,7 @@ class MachMessageBuffer {
|
|||||||
// reset() first, so that two allocations don’t exist simultaneously.
|
// reset() first, so that two allocations don’t exist simultaneously.
|
||||||
vm_.reset();
|
vm_.reset();
|
||||||
|
|
||||||
|
if (size) {
|
||||||
vm_address_t address;
|
vm_address_t address;
|
||||||
kern_return_t kr =
|
kern_return_t kr =
|
||||||
vm_allocate(mach_task_self(),
|
vm_allocate(mach_task_self(),
|
||||||
@ -66,6 +67,8 @@ class MachMessageBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vm_.reset(address, size);
|
vm_.reset(address, size);
|
||||||
|
}
|
||||||
|
|
||||||
return KERN_SUCCESS;
|
return KERN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,12 +144,14 @@ mach_msg_return_t MachMessageServer::Run(Interface* interface,
|
|||||||
const mach_msg_size_t request_size = (receive_large == kReceiveLargeResize)
|
const mach_msg_size_t request_size = (receive_large == kReceiveLargeResize)
|
||||||
? round_page(expected_receive_size)
|
? round_page(expected_receive_size)
|
||||||
: expected_receive_size;
|
: expected_receive_size;
|
||||||
|
DCHECK_GE(request_size, sizeof(mach_msg_empty_rcv_t));
|
||||||
|
|
||||||
// mach_msg_server() and mach_msg_server_once() would consider whether
|
// mach_msg_server() and mach_msg_server_once() would consider whether
|
||||||
// |options| contains MACH_SEND_TRAILER and include MAX_TRAILER_SIZE in this
|
// |options| contains MACH_SEND_TRAILER and include MAX_TRAILER_SIZE in this
|
||||||
// computation if it does, but that option is ineffective on OS X.
|
// computation if it does, but that option is ineffective on OS X.
|
||||||
const mach_msg_size_t reply_alloc =
|
const mach_msg_size_t reply_size = interface->MachMessageServerReplySize();
|
||||||
round_page(interface->MachMessageServerReplySize());
|
DCHECK_GE(reply_size, sizeof(mach_msg_empty_send_t));
|
||||||
|
const mach_msg_size_t reply_alloc = round_page(reply_size);
|
||||||
|
|
||||||
MachMessageBuffer request;
|
MachMessageBuffer request;
|
||||||
MachMessageBuffer reply;
|
MachMessageBuffer reply;
|
||||||
@ -184,6 +189,7 @@ mach_msg_return_t MachMessageServer::Run(Interface* interface,
|
|||||||
case kReceiveLargeResize: {
|
case kReceiveLargeResize: {
|
||||||
mach_msg_size_t this_request_size = round_page(
|
mach_msg_size_t this_request_size = round_page(
|
||||||
round_msg(request.Header()->msgh_size) + trailer_alloc);
|
round_msg(request.Header()->msgh_size) + trailer_alloc);
|
||||||
|
DCHECK_GT(this_request_size, request_size);
|
||||||
|
|
||||||
kr = MachMessageAllocateReceive(&request,
|
kr = MachMessageAllocateReceive(&request,
|
||||||
options & ~MACH_RCV_LARGE,
|
options & ~MACH_RCV_LARGE,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user