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

Side by Side Diff: mojo/public/cpp/bindings/lib/validation_util.cc

Issue 2203953003: [not for commit (yet)] inline more things but doesn't seem to improve perf Base URL: https://chromium.googlesource.com/chromium/src.git@85_3_inline_validation_context
Patch Set: Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/public/cpp/bindings/lib/validation_util.h" 5 #include "mojo/public/cpp/bindings/lib/validation_util.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 // to. 61 // to.
62 if (!inlined && !validation_context->ClaimMemory(data, kUnionDataSize)) { 62 if (!inlined && !validation_context->ClaimMemory(data, kUnionDataSize)) {
63 ReportValidationError(validation_context, 63 ReportValidationError(validation_context,
64 VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); 64 VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE);
65 return false; 65 return false;
66 } 66 }
67 67
68 return true; 68 return true;
69 } 69 }
70 70
71 bool ValidateMessageIsRequestWithoutResponse(
72 const Message* message,
73 ValidationContext* validation_context) {
74 if (message->has_flag(Message::kFlagIsResponse) ||
75 message->has_flag(Message::kFlagExpectsResponse)) {
76 ReportValidationError(validation_context,
77 VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
78 return false;
79 }
80 return true;
81 }
82
83 bool ValidateMessageIsRequestExpectingResponse(
84 const Message* message,
85 ValidationContext* validation_context) {
86 if (message->has_flag(Message::kFlagIsResponse) ||
87 !message->has_flag(Message::kFlagExpectsResponse)) {
88 ReportValidationError(validation_context,
89 VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
90 return false;
91 }
92 return true;
93 }
94
95 bool ValidateMessageIsResponse(const Message* message,
96 ValidationContext* validation_context) {
97 if (message->has_flag(Message::kFlagExpectsResponse) ||
98 !message->has_flag(Message::kFlagIsResponse)) {
99 ReportValidationError(validation_context,
100 VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
101 return false;
102 }
103 return true;
104 }
105
106 bool ValidateControlRequest(const Message* message, 71 bool ValidateControlRequest(const Message* message,
107 ValidationContext* validation_context) { 72 ValidationContext* validation_context) {
108 switch (message->header()->name) { 73 switch (message->header()->name) {
109 case kRunMessageId: 74 case kRunMessageId:
110 return ValidateMessageIsRequestExpectingResponse(message, 75 return ValidateMessageIsRequestExpectingResponse(message,
111 validation_context) && 76 validation_context) &&
112 ValidateMessagePayload<RunMessageParams_Data>(message, 77 ValidateMessagePayload<RunMessageParams_Data>(message,
113 validation_context); 78 validation_context);
114 case kRunOrClosePipeMessageId: 79 case kRunOrClosePipeMessageId:
115 return ValidateMessageIsRequestWithoutResponse(message, 80 return ValidateMessageIsRequestWithoutResponse(message,
116 validation_context) && 81 validation_context) &&
117 ValidateMessagePayload<RunOrClosePipeMessageParams_Data>( 82 ValidateMessagePayload<RunOrClosePipeMessageParams_Data>(
118 message, validation_context); 83 message, validation_context);
119 } 84 }
120 return false; 85 return false;
121 } 86 }
122 87
123 bool ValidateControlResponse(const Message* message, 88 bool ValidateControlResponse(const Message* message,
124 ValidationContext* validation_context) { 89 ValidationContext* validation_context) {
125 if (!ValidateMessageIsResponse(message, validation_context)) 90 if (!ValidateMessageIsResponse(message, validation_context))
126 return false; 91 return false;
127 switch (message->header()->name) { 92 switch (message->header()->name) {
128 case kRunMessageId: 93 case kRunMessageId:
129 return ValidateMessagePayload<RunResponseMessageParams_Data>( 94 return ValidateMessagePayload<RunResponseMessageParams_Data>(
130 message, validation_context); 95 message, validation_context);
131 } 96 }
132 return false; 97 return false;
133 } 98 }
134 99
135 bool IsHandleOrInterfaceValid(const AssociatedInterface_Data& input) {
136 return IsValidInterfaceId(input.interface_id);
137 }
138
139 bool IsHandleOrInterfaceValid(const AssociatedInterfaceRequest_Data& input) {
140 return IsValidInterfaceId(input.interface_id);
141 }
142
143 bool IsHandleOrInterfaceValid(const Interface_Data& input) {
144 return input.handle.is_valid();
145 }
146
147 bool IsHandleOrInterfaceValid(const Handle_Data& input) {
148 return input.is_valid();
149 }
150
151 bool ValidateHandleOrInterfaceNonNullable(
152 const AssociatedInterface_Data& input,
153 const char* error_message,
154 ValidationContext* validation_context) {
155 if (IsHandleOrInterfaceValid(input))
156 return true;
157
158 ReportValidationError(validation_context,
159 VALIDATION_ERROR_UNEXPECTED_INVALID_INTERFACE_ID,
160 error_message);
161 return false;
162 }
163
164 bool ValidateHandleOrInterfaceNonNullable(
165 const AssociatedInterfaceRequest_Data& input,
166 const char* error_message,
167 ValidationContext* validation_context) {
168 if (IsHandleOrInterfaceValid(input))
169 return true;
170
171 ReportValidationError(validation_context,
172 VALIDATION_ERROR_UNEXPECTED_INVALID_INTERFACE_ID,
173 error_message);
174 return false;
175 }
176
177 bool ValidateHandleOrInterfaceNonNullable(
178 const Interface_Data& input,
179 const char* error_message,
180 ValidationContext* validation_context) {
181 if (IsHandleOrInterfaceValid(input))
182 return true;
183
184 ReportValidationError(validation_context,
185 VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
186 error_message);
187 return false;
188 }
189
190 bool ValidateHandleOrInterfaceNonNullable(
191 const Handle_Data& input,
192 const char* error_message,
193 ValidationContext* validation_context) {
194 if (IsHandleOrInterfaceValid(input))
195 return true;
196
197 ReportValidationError(validation_context,
198 VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
199 error_message);
200 return false;
201 }
202
203 bool ValidateHandleOrInterface(const AssociatedInterface_Data& input,
204 ValidationContext* validation_context) {
205 if (!IsMasterInterfaceId(input.interface_id))
206 return true;
207
208 ReportValidationError(validation_context,
209 VALIDATION_ERROR_ILLEGAL_INTERFACE_ID);
210 return false;
211 }
212
213 bool ValidateHandleOrInterface(const AssociatedInterfaceRequest_Data& input,
214 ValidationContext* validation_context) {
215 if (!IsMasterInterfaceId(input.interface_id))
216 return true;
217
218 ReportValidationError(validation_context,
219 VALIDATION_ERROR_ILLEGAL_INTERFACE_ID);
220 return false;
221 }
222
223 bool ValidateHandleOrInterface(const Interface_Data& input,
224 ValidationContext* validation_context) {
225 if (validation_context->ClaimHandle(input.handle))
226 return true;
227
228 ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_HANDLE);
229 return false;
230 }
231
232 bool ValidateHandleOrInterface(const Handle_Data& input,
233 ValidationContext* validation_context) {
234 if (validation_context->ClaimHandle(input))
235 return true;
236
237 ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_HANDLE);
238 return false;
239 }
240
241 } // namespace internal 100 } // namespace internal
242 } // namespace mojo 101 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698