Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1447)

Unified Diff: mojo/public/cpp/bindings/lib/validation_context.h

Issue 2660733002: Mojo C++ bindings: introduce an optional array to store transferred interface IDs in messages. (Closed)
Patch Set: . Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/lib/validation_context.h
diff --git a/mojo/public/cpp/bindings/lib/validation_context.h b/mojo/public/cpp/bindings/lib/validation_context.h
index f8fe58ea22f330b5c017f58dff5ab7acb02a487b..ed6c6542e7e021deea7fe8a70112da4dda11b883 100644
--- a/mojo/public/cpp/bindings/lib/validation_context.h
+++ b/mojo/public/cpp/bindings/lib/validation_context.h
@@ -28,6 +28,8 @@ class MOJO_CPP_BINDINGS_EXPORT ValidationContext {
public:
// [data, data + data_num_bytes) specifies the initial valid memory range.
// [0, num_handles) specifies the initial valid range of handle indices.
+ // [0, num_associated_endpoint_handles) specifies the initial valid range of
+ // associated endpoint handle indices.
//
// If provided, |message| and |description| provide additional information
// to use when reporting validation errors. In addition if |message| is
@@ -36,6 +38,7 @@ class MOJO_CPP_BINDINGS_EXPORT ValidationContext {
ValidationContext(const void* data,
size_t data_num_bytes,
size_t num_handles,
+ size_t num_associated_endpoint_handles,
Message* message = nullptr,
const base::StringPiece& description = "",
int stack_depth = 0);
@@ -77,6 +80,28 @@ class MOJO_CPP_BINDINGS_EXPORT ValidationContext {
return true;
}
+ // Claims the specified encoded associated endpoint handle.
+ // The method succeeds if:
+ // - |encoded_handle|'s value is |kEncodedInvalidHandleValue|.
+ // - the handle is contained inside the valid range of associated endpoint
+ // handle indices. In this case, the valid range is shinked to begin right
+ // after the claimed handle.
+ bool ClaimAssociatedEndpointHandle(
+ const AssociatedEndpointHandle_Data& encoded_handle) {
+ uint32_t index = encoded_handle.value;
+ if (index == kEncodedInvalidHandleValue)
+ return true;
+
+ if (index < associated_endpoint_handle_begin_ ||
+ index >= associated_endpoint_handle_end_)
+ return false;
+
+ // |index| + 1 shouldn't overflow, because |index| is not the max value of
+ // uint32_t (it is less than |associated_endpoint_handle_end_|).
+ associated_endpoint_handle_begin_ = index + 1;
+ return true;
+ }
+
// Returns true if the specified range is not empty, and the range is
// contained inside the valid memory range.
bool IsValidRange(const void* position, uint32_t num_bytes) const {
@@ -128,6 +153,11 @@ class MOJO_CPP_BINDINGS_EXPORT ValidationContext {
uint32_t handle_begin_;
uint32_t handle_end_;
+ // [associated_endpoint_handle_begin_, associated_endpoint_handle_end_) is the
+ // valid associated endpoint handle index range.
+ uint32_t associated_endpoint_handle_begin_;
+ uint32_t associated_endpoint_handle_end_;
+
int stack_depth_;
DISALLOW_COPY_AND_ASSIGN(ValidationContext);
« no previous file with comments | « mojo/public/cpp/bindings/lib/serialization_context.cc ('k') | mojo/public/cpp/bindings/lib/validation_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698