OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
5 #include "base/callback.h" | 8 #include "base/callback.h" |
6 #include "base/logging.h" | 9 #include "base/logging.h" |
7 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
8 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
9 #include "sandbox/win/src/sharedmem_ipc_server.h" | 12 #include "sandbox/win/src/crosscall_params.h" |
10 #include "sandbox/win/src/sharedmem_ipc_client.h" | 13 #include "sandbox/win/src/crosscall_server.h" |
11 #include "sandbox/win/src/sandbox.h" | 14 #include "sandbox/win/src/sandbox.h" |
12 #include "sandbox/win/src/sandbox_types.h" | 15 #include "sandbox/win/src/sandbox_types.h" |
13 #include "sandbox/win/src/crosscall_params.h" | 16 #include "sandbox/win/src/sharedmem_ipc_client.h" |
14 #include "sandbox/win/src/crosscall_server.h" | 17 #include "sandbox/win/src/sharedmem_ipc_server.h" |
15 | 18 |
16 namespace { | 19 namespace { |
17 // This handle must not be closed. | 20 // This handle must not be closed. |
18 volatile HANDLE g_alive_mutex = NULL; | 21 volatile HANDLE g_alive_mutex = NULL; |
19 } | 22 } |
20 | 23 |
21 namespace sandbox { | 24 namespace sandbox { |
22 | 25 |
23 SharedMemIPCServer::ServerControl::ServerControl() { | 26 SharedMemIPCServer::ServerControl::ServerControl() { |
24 } | 27 } |
(...skipping 30 matching lines...) Expand all Loading... |
55 if (!thread_provider_->UnRegisterWaits(this)) { | 58 if (!thread_provider_->UnRegisterWaits(this)) { |
56 // Better to leak than to crash. | 59 // Better to leak than to crash. |
57 return; | 60 return; |
58 } | 61 } |
59 STLDeleteElements(&server_contexts_); | 62 STLDeleteElements(&server_contexts_); |
60 | 63 |
61 if (client_control_) | 64 if (client_control_) |
62 ::UnmapViewOfFile(client_control_); | 65 ::UnmapViewOfFile(client_control_); |
63 } | 66 } |
64 | 67 |
65 bool SharedMemIPCServer::Init(void* shared_mem, uint32 shared_size, | 68 bool SharedMemIPCServer::Init(void* shared_mem, |
66 uint32 channel_size) { | 69 uint32_t shared_size, |
| 70 uint32_t channel_size) { |
67 // The shared memory needs to be at least as big as a channel. | 71 // The shared memory needs to be at least as big as a channel. |
68 if (shared_size < channel_size) { | 72 if (shared_size < channel_size) { |
69 return false; | 73 return false; |
70 } | 74 } |
71 // The channel size should be aligned. | 75 // The channel size should be aligned. |
72 if (0 != (channel_size % 32)) { | 76 if (0 != (channel_size % 32)) { |
73 return false; | 77 return false; |
74 } | 78 } |
75 | 79 |
76 // Calculate how many channels we can fit in the shared memory. | 80 // Calculate how many channels we can fit in the shared memory. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 160 } |
157 } | 161 } |
158 } | 162 } |
159 | 163 |
160 // Fills up the list of arguments (args and ipc_params) for an IPC call. | 164 // Fills up the list of arguments (args and ipc_params) for an IPC call. |
161 bool GetArgs(CrossCallParamsEx* params, IPCParams* ipc_params, | 165 bool GetArgs(CrossCallParamsEx* params, IPCParams* ipc_params, |
162 void* args[kMaxIpcParams]) { | 166 void* args[kMaxIpcParams]) { |
163 if (kMaxIpcParams < params->GetParamsCount()) | 167 if (kMaxIpcParams < params->GetParamsCount()) |
164 return false; | 168 return false; |
165 | 169 |
166 for (uint32 i = 0; i < params->GetParamsCount(); i++) { | 170 for (uint32_t i = 0; i < params->GetParamsCount(); i++) { |
167 uint32 size; | 171 uint32_t size; |
168 ArgType type; | 172 ArgType type; |
169 args[i] = params->GetRawParameter(i, &size, &type); | 173 args[i] = params->GetRawParameter(i, &size, &type); |
170 if (args[i]) { | 174 if (args[i]) { |
171 ipc_params->args[i] = type; | 175 ipc_params->args[i] = type; |
172 switch (type) { | 176 switch (type) { |
173 case WCHAR_TYPE: { | 177 case WCHAR_TYPE: { |
174 scoped_ptr<base::string16> data(new base::string16); | 178 scoped_ptr<base::string16> data(new base::string16); |
175 if (!params->GetParameterStr(i, data.get())) { | 179 if (!params->GetParameterStr(i, data.get())) { |
176 args[i] = 0; | 180 args[i] = 0; |
177 ReleaseArgs(ipc_params, args); | 181 ReleaseArgs(ipc_params, args); |
178 return false; | 182 return false; |
179 } | 183 } |
180 args[i] = data.release(); | 184 args[i] = data.release(); |
181 break; | 185 break; |
182 } | 186 } |
183 case UINT32_TYPE: { | 187 case UINT32_TYPE: { |
184 uint32 data; | 188 uint32_t data; |
185 if (!params->GetParameter32(i, &data)) { | 189 if (!params->GetParameter32(i, &data)) { |
186 ReleaseArgs(ipc_params, args); | 190 ReleaseArgs(ipc_params, args); |
187 return false; | 191 return false; |
188 } | 192 } |
189 IPCInt ipc_int(data); | 193 IPCInt ipc_int(data); |
190 args[i] = ipc_int.AsVoidPtr(); | 194 args[i] = ipc_int.AsVoidPtr(); |
191 break; | 195 break; |
192 } | 196 } |
193 case VOIDPTR_TYPE : { | 197 case VOIDPTR_TYPE : { |
194 void* data; | 198 void* data; |
(...skipping 18 matching lines...) Expand all Loading... |
213 } | 217 } |
214 } | 218 } |
215 return true; | 219 return true; |
216 } | 220 } |
217 | 221 |
218 bool SharedMemIPCServer::InvokeCallback(const ServerControl* service_context, | 222 bool SharedMemIPCServer::InvokeCallback(const ServerControl* service_context, |
219 void* ipc_buffer, | 223 void* ipc_buffer, |
220 CrossCallReturn* call_result) { | 224 CrossCallReturn* call_result) { |
221 // Set the default error code; | 225 // Set the default error code; |
222 SetCallError(SBOX_ERROR_INVALID_IPC, call_result); | 226 SetCallError(SBOX_ERROR_INVALID_IPC, call_result); |
223 uint32 output_size = 0; | 227 uint32_t output_size = 0; |
224 // Parse, verify and copy the message. The handler operates on a copy | 228 // Parse, verify and copy the message. The handler operates on a copy |
225 // of the message so the client cannot play dirty tricks by changing the | 229 // of the message so the client cannot play dirty tricks by changing the |
226 // data in the channel while the IPC is being processed. | 230 // data in the channel while the IPC is being processed. |
227 scoped_ptr<CrossCallParamsEx> params( | 231 scoped_ptr<CrossCallParamsEx> params( |
228 CrossCallParamsEx::CreateFromBuffer(ipc_buffer, | 232 CrossCallParamsEx::CreateFromBuffer(ipc_buffer, |
229 service_context->channel_size, | 233 service_context->channel_size, |
230 &output_size)); | 234 &output_size)); |
231 if (!params.get()) | 235 if (!params.get()) |
232 return false; | 236 return false; |
233 | 237 |
234 uint32 tag = params->GetTag(); | 238 uint32_t tag = params->GetTag(); |
235 static_assert(0 == INVALID_TYPE, "incorrect type enum"); | 239 static_assert(0 == INVALID_TYPE, "incorrect type enum"); |
236 IPCParams ipc_params = {0}; | 240 IPCParams ipc_params = {0}; |
237 ipc_params.ipc_tag = tag; | 241 ipc_params.ipc_tag = tag; |
238 | 242 |
239 void* args[kMaxIpcParams]; | 243 void* args[kMaxIpcParams]; |
240 if (!GetArgs(params.get(), &ipc_params, args)) | 244 if (!GetArgs(params.get(), &ipc_params, args)) |
241 return false; | 245 return false; |
242 | 246 |
243 IPCInfo ipc_info = {0}; | 247 IPCInfo ipc_info = {0}; |
244 ipc_info.ipc_tag = tag; | 248 ipc_info.ipc_tag = tag; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 server_pong->Set(::CreateEventW(NULL, FALSE, FALSE, NULL)); | 421 server_pong->Set(::CreateEventW(NULL, FALSE, FALSE, NULL)); |
418 if (!::DuplicateHandle(::GetCurrentProcess(), server_pong->Get(), | 422 if (!::DuplicateHandle(::GetCurrentProcess(), server_pong->Get(), |
419 target_process_, client_pong, kDesiredAccess, FALSE, | 423 target_process_, client_pong, kDesiredAccess, FALSE, |
420 0)) { | 424 0)) { |
421 return false; | 425 return false; |
422 } | 426 } |
423 return true; | 427 return true; |
424 } | 428 } |
425 | 429 |
426 } // namespace sandbox | 430 } // namespace sandbox |
OLD | NEW |