aboutsummaryrefslogtreecommitdiff
path: root/mojo/public/cpp/bindings/lib/message_buffer.cc
diff options
context:
space:
mode:
authorLuis Hector Chavez <lhchavez@google.com>2017-07-26 17:38:05 +0000
committerLuis Hector Chavez <lhchavez@google.com>2017-07-26 17:38:05 +0000
commit21a249e4d9cb0b2ec6f0ff84ed5f7939ea67ac52 (patch)
treed380c2689495d31fd250cf8f1d0ceebbdd4cf250 /mojo/public/cpp/bindings/lib/message_buffer.cc
parent8ac9103e05b66812c25348943383f9365d1ce3e0 (diff)
downloadlibmojo-21a249e4d9cb0b2ec6f0ff84ed5f7939ea67ac52.tar.gz
Revert "libmojo: Uprev the library to r456626 from Chromium"
This reverts commit 8ac9103e05b66812c25348943383f9365d1ce3e0. Reason for revert: Broke the mac_sdk Exempt-From-Owner-Approval: Fixing mac_sdk Change-Id: I0b74d1abaa66933a93fd6f82ff018e8948c1204e
Diffstat (limited to 'mojo/public/cpp/bindings/lib/message_buffer.cc')
-rw-r--r--mojo/public/cpp/bindings/lib/message_buffer.cc37
1 files changed, 28 insertions, 9 deletions
diff --git a/mojo/public/cpp/bindings/lib/message_buffer.cc b/mojo/public/cpp/bindings/lib/message_buffer.cc
index cc12ef6..af79cfd 100644
--- a/mojo/public/cpp/bindings/lib/message_buffer.cc
+++ b/mojo/public/cpp/bindings/lib/message_buffer.cc
@@ -13,35 +13,54 @@ namespace internal {
MessageBuffer::MessageBuffer(size_t capacity, bool zero_initialized) {
DCHECK_LE(capacity, std::numeric_limits<uint32_t>::max());
+ data_num_bytes_ = static_cast<uint32_t>(capacity);
MojoResult rv = AllocMessage(capacity, nullptr, 0,
MOJO_ALLOC_MESSAGE_FLAG_NONE, &message_);
CHECK_EQ(rv, MOJO_RESULT_OK);
- void* buffer = nullptr;
- if (capacity != 0) {
- rv = GetMessageBuffer(message_.get(), &buffer);
+ if (capacity == 0) {
+ buffer_ = nullptr;
+ } else {
+ rv = GetMessageBuffer(message_.get(), &buffer_);
CHECK_EQ(rv, MOJO_RESULT_OK);
if (zero_initialized)
- memset(buffer, 0, capacity);
+ memset(buffer_, 0, capacity);
}
- Initialize(buffer, capacity);
}
MessageBuffer::MessageBuffer(ScopedMessageHandle message, uint32_t num_bytes) {
message_ = std::move(message);
+ data_num_bytes_ = num_bytes;
- void* buffer = nullptr;
- if (num_bytes != 0) {
- MojoResult rv = GetMessageBuffer(message_.get(), &buffer);
+ if (num_bytes == 0) {
+ buffer_ = nullptr;
+ } else {
+ MojoResult rv = GetMessageBuffer(message_.get(), &buffer_);
CHECK_EQ(rv, MOJO_RESULT_OK);
}
- Initialize(buffer, num_bytes);
}
MessageBuffer::~MessageBuffer() {}
+void* MessageBuffer::Allocate(size_t delta) {
+ delta = internal::Align(delta);
+
+ DCHECK_LE(delta, static_cast<size_t>(data_num_bytes_));
+ DCHECK_GT(bytes_claimed_ + static_cast<uint32_t>(delta), bytes_claimed_);
+
+ uint32_t new_bytes_claimed = bytes_claimed_ + static_cast<uint32_t>(delta);
+ if (new_bytes_claimed > data_num_bytes_) {
+ NOTREACHED();
+ return nullptr;
+ }
+
+ char* start = static_cast<char*>(buffer_) + bytes_claimed_;
+ bytes_claimed_ = new_bytes_claimed;
+ return static_cast<void*>(start);
+}
+
void MessageBuffer::NotifyBadMessage(const std::string& error) {
DCHECK(message_.is_valid());
MojoResult result = mojo::NotifyBadMessage(message_.get(), error);