diff options
Diffstat (limited to 'mojo/edk/system')
-rw-r--r-- | mojo/edk/system/data_pipe.cc | 17 | ||||
-rw-r--r-- | mojo/edk/system/message_pipe_dispatcher.cc | 60 | ||||
-rw-r--r-- | mojo/edk/system/platform_handle_dispatcher.cc | 9 | ||||
-rw-r--r-- | mojo/edk/system/shared_buffer_dispatcher.cc | 13 |
4 files changed, 68 insertions, 31 deletions
diff --git a/mojo/edk/system/data_pipe.cc b/mojo/edk/system/data_pipe.cc index 3f53798..54a6df4 100644 --- a/mojo/edk/system/data_pipe.cc +++ b/mojo/edk/system/data_pipe.cc @@ -8,6 +8,9 @@ #include <stdint.h> #include <string.h> +#include <algorithm> +#include <limits> + #include "mojo/edk/system/configuration.h" #include "mojo/edk/system/options_validation.h" #include "mojo/edk/system/raw_channel.h" @@ -18,17 +21,17 @@ namespace edk { namespace { -const size_t kInvalidDataPipeHandleIndex = static_cast<size_t>(-1); +const uint32_t kInvalidDataPipeHandleIndex = static_cast<uint32_t>(-1); struct MOJO_ALIGNAS(8) SerializedDataPipeHandleDispatcher { - size_t platform_handle_index; // (Or |kInvalidDataPipeHandleIndex|.) + uint32_t platform_handle_index; // (Or |kInvalidDataPipeHandleIndex|.) // These are from MojoCreateDataPipeOptions MojoCreateDataPipeOptionsFlags flags; uint32_t element_num_bytes; uint32_t capacity_num_bytes; - size_t shared_memory_handle_index; // (Or |kInvalidDataPipeHandleIndex|.) + uint32_t shared_memory_handle_index; // (Or |kInvalidDataPipeHandleIndex|.) uint32_t shared_memory_size; }; @@ -119,7 +122,9 @@ void DataPipe::EndSerialize(const MojoCreateDataPipeOptions& options, SerializedDataPipeHandleDispatcher* serialization = static_cast<SerializedDataPipeHandleDispatcher*>(destination); if (channel_handle.is_valid()) { - serialization->platform_handle_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->platform_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(channel_handle.release()); } else { serialization->platform_handle_index = kInvalidDataPipeHandleIndex; @@ -131,7 +136,9 @@ void DataPipe::EndSerialize(const MojoCreateDataPipeOptions& options, serialization->shared_memory_size = static_cast<uint32_t>(shared_memory_size); if (serialization->shared_memory_size) { - serialization->shared_memory_handle_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->shared_memory_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(shared_memory_handle.release()); } else { serialization->shared_memory_handle_index = kInvalidDataPipeHandleIndex; diff --git a/mojo/edk/system/message_pipe_dispatcher.cc b/mojo/edk/system/message_pipe_dispatcher.cc index 11dc586..b35e9cd 100644 --- a/mojo/edk/system/message_pipe_dispatcher.cc +++ b/mojo/edk/system/message_pipe_dispatcher.cc @@ -7,7 +7,9 @@ #include <stddef.h> #include <stdint.h> +#include <limits> #include <utility> +#include <vector> #include "base/bind.h" #include "base/debug/stack_trace.h" @@ -28,7 +30,7 @@ namespace edk { namespace { -const size_t kInvalidMessagePipeHandleIndex = static_cast<size_t>(-1); +const uint32_t kInvalidMessagePipeHandleIndex = static_cast<uint32_t>(-1); struct MOJO_ALIGNAS(8) SerializedMessagePipeHandleDispatcher { bool transferable; @@ -37,21 +39,22 @@ struct MOJO_ALIGNAS(8) SerializedMessagePipeHandleDispatcher { // The following members are only set if transferable is true. // Could be |kInvalidMessagePipeHandleIndex| if the other endpoint of the MP // was closed. - size_t platform_handle_index; + uint32_t platform_handle_index; - size_t shared_memory_handle_index; // (Or |kInvalidMessagePipeHandleIndex|.) + uint32_t + shared_memory_handle_index; // (Or |kInvalidMessagePipeHandleIndex|.) uint32_t shared_memory_size; - size_t serialized_read_buffer_size; - size_t serialized_write_buffer_size; - size_t serialized_message_queue_size; + uint32_t serialized_read_buffer_size; + uint32_t serialized_write_buffer_size; + uint32_t serialized_message_queue_size; // These are the FDs required as part of serializing channel_ and // message_queue_. This is only used on POSIX. - size_t serialized_fds_index; // (Or |kInvalidMessagePipeHandleIndex|.) - size_t serialized_read_fds_length; - size_t serialized_write_fds_length; - size_t serialized_message_fds_length; + uint32_t serialized_fds_index; // (Or |kInvalidMessagePipeHandleIndex|.) + uint32_t serialized_read_fds_length; + uint32_t serialized_write_fds_length; + uint32_t serialized_message_fds_length; }; char* SerializeBuffer(char* start, std::vector<char>* buffer) { @@ -805,17 +808,26 @@ bool MessagePipeDispatcher::EndSerializeAndCloseImplNoLock( serialization->transferable = transferable_; serialization->pipe_id = pipe_id_; if (serialized_platform_handle_.is_valid()) { - serialization->platform_handle_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->platform_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(serialized_platform_handle_.release()); } else { serialization->platform_handle_index = kInvalidMessagePipeHandleIndex; } serialization->write_error = write_error_; - serialization->serialized_read_buffer_size = serialized_read_buffer_.size(); - serialization->serialized_write_buffer_size = serialized_write_buffer_.size(); + DCHECK(serialized_read_buffer_.size() < std::numeric_limits<uint32_t>::max()); + serialization->serialized_read_buffer_size = + static_cast<uint32_t>(serialized_read_buffer_.size()); + DCHECK(serialized_write_buffer_.size() < + std::numeric_limits<uint32_t>::max()); + serialization->serialized_write_buffer_size = + static_cast<uint32_t>(serialized_write_buffer_.size()); + DCHECK(serialized_message_queue_.size() < + std::numeric_limits<uint32_t>::max()); serialization->serialized_message_queue_size = - serialized_message_queue_.size(); + static_cast<uint32_t>(serialized_message_queue_.size()); serialization->shared_memory_size = static_cast<uint32_t>( serialization->serialized_read_buffer_size + @@ -832,20 +844,30 @@ bool MessagePipeDispatcher::EndSerializeAndCloseImplNoLock( start = SerializeBuffer(start, &serialized_write_buffer_); start = SerializeBuffer(start, &serialized_message_queue_); - serialization->shared_memory_handle_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->shared_memory_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(shared_buffer->PassPlatformHandle().release()); } else { serialization->shared_memory_handle_index = kInvalidMessagePipeHandleIndex; } - serialization->serialized_read_fds_length = serialized_read_fds_length_; - serialization->serialized_write_fds_length = serialized_write_fds_length_; - serialization->serialized_message_fds_length = serialized_message_fds_length_; + DCHECK(serialized_read_fds_length_ < std::numeric_limits<uint32_t>::max()); + serialization->serialized_read_fds_length = + static_cast<uint32_t>(serialized_read_fds_length_); + DCHECK(serialized_write_fds_length_ < std::numeric_limits<uint32_t>::max()); + serialization->serialized_write_fds_length = + static_cast<uint32_t>(serialized_write_fds_length_); + DCHECK(serialized_message_fds_length_ < std::numeric_limits<uint32_t>::max()); + serialization->serialized_message_fds_length = + static_cast<uint32_t>(serialized_message_fds_length_); if (serialized_fds_.empty()) { serialization->serialized_fds_index = kInvalidMessagePipeHandleIndex; } else { #if defined(OS_POSIX) - serialization->serialized_fds_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->serialized_fds_index = + static_cast<uint32_t>(platform_handles->size()); for (size_t i = 0; i < serialized_fds_.size(); ++i) platform_handles->push_back(PlatformHandle(serialized_fds_[i])); serialized_fds_.clear(); diff --git a/mojo/edk/system/platform_handle_dispatcher.cc b/mojo/edk/system/platform_handle_dispatcher.cc index ab0ac12..eadcb8e 100644 --- a/mojo/edk/system/platform_handle_dispatcher.cc +++ b/mojo/edk/system/platform_handle_dispatcher.cc @@ -7,6 +7,7 @@ #include <stddef.h> #include <algorithm> +#include <limits> #include <utility> #include "base/logging.h" @@ -16,10 +17,10 @@ namespace edk { namespace { -const size_t kInvalidPlatformHandleIndex = static_cast<size_t>(-1); +const uint32_t kInvalidPlatformHandleIndex = static_cast<uint32_t>(-1); struct MOJO_ALIGNAS(8) SerializedPlatformHandleDispatcher { - size_t platform_handle_index; // (Or |kInvalidPlatformHandleIndex|.) + uint32_t platform_handle_index; // (Or |kInvalidPlatformHandleIndex|.) }; } // namespace @@ -98,7 +99,9 @@ bool PlatformHandleDispatcher::EndSerializeAndCloseImplNoLock( SerializedPlatformHandleDispatcher* serialization = static_cast<SerializedPlatformHandleDispatcher*>(destination); if (platform_handle_.is_valid()) { - serialization->platform_handle_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->platform_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(platform_handle_.release()); } else { serialization->platform_handle_index = kInvalidPlatformHandleIndex; diff --git a/mojo/edk/system/shared_buffer_dispatcher.cc b/mojo/edk/system/shared_buffer_dispatcher.cc index 0da8bbe..510db85 100644 --- a/mojo/edk/system/shared_buffer_dispatcher.cc +++ b/mojo/edk/system/shared_buffer_dispatcher.cc @@ -7,6 +7,7 @@ #include <stddef.h> #include <stdint.h> +#include <algorithm> #include <limits> #include <utility> @@ -24,8 +25,8 @@ namespace edk { namespace { struct MOJO_ALIGNAS(8) SerializedSharedBufferDispatcher { - size_t num_bytes; - size_t platform_handle_index; + uint32_t num_bytes; + uint32_t platform_handle_index; }; } // namespace @@ -257,8 +258,12 @@ bool SharedBufferDispatcher::EndSerializeAndCloseImplNoLock( return false; } - serialization->num_bytes = shared_buffer_->GetNumBytes(); - serialization->platform_handle_index = platform_handles->size(); + DCHECK(shared_buffer_->GetNumBytes() < std::numeric_limits<uint32_t>::max()); + serialization->num_bytes = + static_cast<uint32_t>(shared_buffer_->GetNumBytes()); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->platform_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(platform_handle.release()); *actual_size = sizeof(SerializedSharedBufferDispatcher); |