OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/edk/system/channel.h" | 5 #include "mojo/edk/system/channel.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 Channel::Message::Message(size_t payload_size, size_t num_handles) { | 30 Channel::Message::Message(size_t payload_size, size_t num_handles) { |
31 size_ = payload_size + sizeof(Header); | 31 size_ = payload_size + sizeof(Header); |
32 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
33 // On Windows we serialize platform handles directly into the message buffer. | 33 // On Windows we serialize platform handles directly into the message buffer. |
34 size_ += num_handles * sizeof(PlatformHandle); | 34 size_ += num_handles * sizeof(PlatformHandle); |
35 #endif | 35 #endif |
36 | 36 |
37 data_ = static_cast<char*>(base::AlignedAlloc(size_, | 37 data_ = static_cast<char*>(base::AlignedAlloc(size_, |
38 kChannelMessageAlignment)); | 38 kChannelMessageAlignment)); |
| 39 memset(data_, 0, size_); |
39 header_ = reinterpret_cast<Header*>(data_); | 40 header_ = reinterpret_cast<Header*>(data_); |
40 | 41 |
41 DCHECK_LE(size_, std::numeric_limits<uint32_t>::max()); | 42 DCHECK_LE(size_, std::numeric_limits<uint32_t>::max()); |
42 header_->num_bytes = static_cast<uint32_t>(size_); | 43 header_->num_bytes = static_cast<uint32_t>(size_); |
43 | 44 |
44 DCHECK_LE(num_handles, std::numeric_limits<uint16_t>::max()); | 45 DCHECK_LE(num_handles, std::numeric_limits<uint16_t>::max()); |
45 header_->num_handles = static_cast<uint16_t>(num_handles); | 46 header_->num_handles = static_cast<uint16_t>(num_handles); |
46 | 47 |
47 header_->padding = 0; | 48 header_->padding = 0; |
48 | 49 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 return true; | 331 return true; |
331 } | 332 } |
332 | 333 |
333 void Channel::OnError() { | 334 void Channel::OnError() { |
334 if (delegate_) | 335 if (delegate_) |
335 delegate_->OnChannelError(); | 336 delegate_->OnChannelError(); |
336 } | 337 } |
337 | 338 |
338 } // namespace edk | 339 } // namespace edk |
339 } // namespace mojo | 340 } // namespace mojo |
OLD | NEW |