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 <new> | 9 #include <new> |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 kMessageAlignment)); | 70 kMessageAlignment)); |
71 memcpy(buffer, main_buffer(), buffer_size); | 71 memcpy(buffer, main_buffer(), buffer_size); |
72 return reinterpret_cast<MessageInTransit*>(buffer); | 72 return reinterpret_cast<MessageInTransit*>(buffer); |
73 } | 73 } |
74 | 74 |
75 void MessageInTransit::Destroy() { | 75 void MessageInTransit::Destroy() { |
76 // No need to call the destructor, since we're POD. | 76 // No need to call the destructor, since we're POD. |
77 base::AlignedFree(this); | 77 base::AlignedFree(this); |
78 } | 78 } |
79 | 79 |
| 80 // static |
| 81 bool MessageInTransit::GetNextMessageSize(const void* buffer, |
| 82 size_t buffer_size, |
| 83 size_t* next_message_size) { |
| 84 DCHECK(buffer); |
| 85 DCHECK_EQ(reinterpret_cast<uintptr_t>(buffer) % |
| 86 MessageInTransit::kMessageAlignment, 0u); |
| 87 DCHECK(next_message_size); |
| 88 |
| 89 if (buffer_size < sizeof(Header)) |
| 90 return false; |
| 91 |
| 92 const Header* header = static_cast<const Header*>(buffer); |
| 93 *next_message_size = |
| 94 RoundUpMessageAlignment(sizeof(MessageInTransit) + header->data_size); |
| 95 return true; |
| 96 } |
| 97 |
| 98 // static |
| 99 const MessageInTransit* MessageInTransit::CreateReadOnlyFromBuffer( |
| 100 const void* buffer) { |
| 101 DCHECK(buffer); |
| 102 DCHECK_EQ(reinterpret_cast<uintptr_t>(buffer) % |
| 103 MessageInTransit::kMessageAlignment, 0u); |
| 104 return static_cast<const MessageInTransit*>(buffer); |
| 105 } |
| 106 |
80 MessageInTransit::MessageInTransit(uint32_t data_size, | 107 MessageInTransit::MessageInTransit(uint32_t data_size, |
81 Type type, | 108 Type type, |
82 Subtype subtype, | 109 Subtype subtype, |
83 uint32_t num_bytes, | 110 uint32_t num_bytes, |
84 uint32_t num_handles) | 111 uint32_t num_handles) |
85 : header_(data_size, type, subtype, kInvalidEndpointId, kInvalidEndpointId, | 112 : header_(data_size, type, subtype, kInvalidEndpointId, kInvalidEndpointId, |
86 num_bytes, num_handles) { | 113 num_bytes, num_handles) { |
87 DCHECK_GE(header()->data_size, header()->num_bytes); | 114 DCHECK_GE(header()->data_size, header()->num_bytes); |
88 } | 115 } |
89 | 116 |
90 } // namespace system | 117 } // namespace system |
91 } // namespace mojo | 118 } // namespace mojo |
OLD | NEW |