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