| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/system/message_in_transit.h" | 5 #include "mojo/system/message_in_transit.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 STATIC_CONST_MEMBER_DEFINITION const MessageInTransit::Subtype | 31 STATIC_CONST_MEMBER_DEFINITION const MessageInTransit::Subtype |
| 32 MessageInTransit::kSubtypeChannelRemoveMessagePipeEndpointAck; | 32 MessageInTransit::kSubtypeChannelRemoveMessagePipeEndpointAck; |
| 33 STATIC_CONST_MEMBER_DEFINITION const MessageInTransit::Subtype | 33 STATIC_CONST_MEMBER_DEFINITION const MessageInTransit::Subtype |
| 34 MessageInTransit::kSubtypeRawChannelPosixExtraPlatformHandles; | 34 MessageInTransit::kSubtypeRawChannelPosixExtraPlatformHandles; |
| 35 STATIC_CONST_MEMBER_DEFINITION const MessageInTransit::EndpointId | 35 STATIC_CONST_MEMBER_DEFINITION const MessageInTransit::EndpointId |
| 36 MessageInTransit::kInvalidEndpointId; | 36 MessageInTransit::kInvalidEndpointId; |
| 37 STATIC_CONST_MEMBER_DEFINITION const size_t MessageInTransit::kMessageAlignment; | 37 STATIC_CONST_MEMBER_DEFINITION const size_t MessageInTransit::kMessageAlignment; |
| 38 | 38 |
| 39 struct MessageInTransit::PrivateStructForCompileAsserts { | 39 struct MessageInTransit::PrivateStructForCompileAsserts { |
| 40 // The size of |Header| must be a multiple of the alignment. | 40 // The size of |Header| must be a multiple of the alignment. |
| 41 COMPILE_ASSERT(sizeof(Header) % kMessageAlignment == 0, | 41 static_assert(sizeof(Header) % kMessageAlignment == 0, |
| 42 sizeof_MessageInTransit_Header_invalid); | 42 "sizeof(MessageInTransit::Header) invalid"); |
| 43 // Avoid dangerous situations, but making sure that the size of the "header" + | 43 // Avoid dangerous situations, but making sure that the size of the "header" + |
| 44 // the size of the data fits into a 31-bit number. | 44 // the size of the data fits into a 31-bit number. |
| 45 COMPILE_ASSERT(static_cast<uint64_t>(sizeof(Header)) + kMaxMessageNumBytes <= | 45 static_assert(static_cast<uint64_t>(sizeof(Header)) + kMaxMessageNumBytes <= |
| 46 0x7fffffffULL, | 46 0x7fffffffULL, |
| 47 kMaxMessageNumBytes_too_big); | 47 "kMaxMessageNumBytes too big"); |
| 48 | 48 |
| 49 // We assume (to avoid extra rounding code) that the maximum message (data) | 49 // We assume (to avoid extra rounding code) that the maximum message (data) |
| 50 // size is a multiple of the alignment. | 50 // size is a multiple of the alignment. |
| 51 COMPILE_ASSERT(kMaxMessageNumBytes % kMessageAlignment == 0, | 51 static_assert(kMaxMessageNumBytes % kMessageAlignment == 0, |
| 52 kMessageAlignment_not_a_multiple_of_alignment); | 52 "kMessageAlignment not a multiple of alignment"); |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 MessageInTransit::View::View(size_t message_size, const void* buffer) | 55 MessageInTransit::View::View(size_t message_size, const void* buffer) |
| 56 : buffer_(buffer) { | 56 : buffer_(buffer) { |
| 57 size_t next_message_size = 0; | 57 size_t next_message_size = 0; |
| 58 DCHECK(MessageInTransit::GetNextMessageSize( | 58 DCHECK(MessageInTransit::GetNextMessageSize( |
| 59 buffer_, message_size, &next_message_size)); | 59 buffer_, message_size, &next_message_size)); |
| 60 DCHECK_EQ(message_size, next_message_size); | 60 DCHECK_EQ(message_size, next_message_size); |
| 61 // This should be equivalent. | 61 // This should be equivalent. |
| 62 DCHECK_EQ(message_size, total_size()); | 62 DCHECK_EQ(message_size, total_size()); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 DCHECK_EQ(main_buffer_size_ % kMessageAlignment, 0u); | 215 DCHECK_EQ(main_buffer_size_ % kMessageAlignment, 0u); |
| 216 header()->total_size = static_cast<uint32_t>(main_buffer_size_); | 216 header()->total_size = static_cast<uint32_t>(main_buffer_size_); |
| 217 if (transport_data_) { | 217 if (transport_data_) { |
| 218 header()->total_size += | 218 header()->total_size += |
| 219 static_cast<uint32_t>(transport_data_->buffer_size()); | 219 static_cast<uint32_t>(transport_data_->buffer_size()); |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 | 222 |
| 223 } // namespace system | 223 } // namespace system |
| 224 } // namespace mojo | 224 } // namespace mojo |
| OLD | NEW |