OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "sandbox/win/src/process_thread_interception.h" | 5 #include "sandbox/win/src/process_thread_interception.h" |
6 | 6 |
7 #include "sandbox/win/src/crosscall_client.h" | 7 #include "sandbox/win/src/crosscall_client.h" |
8 #include "sandbox/win/src/ipc_tags.h" | 8 #include "sandbox/win/src/ipc_tags.h" |
9 #include "sandbox/win/src/policy_params.h" | 9 #include "sandbox/win/src/policy_params.h" |
10 #include "sandbox/win/src/policy_target.h" | 10 #include "sandbox/win/src/policy_target.h" |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 if (ERROR_SUCCESS != answer.win32_result) | 394 if (ERROR_SUCCESS != answer.win32_result) |
395 return FALSE; | 395 return FALSE; |
396 | 396 |
397 return TRUE; | 397 return TRUE; |
398 } while (false); | 398 } while (false); |
399 | 399 |
400 ::SetLastError(original_error); | 400 ::SetLastError(original_error); |
401 return FALSE; | 401 return FALSE; |
402 } | 402 } |
403 | 403 |
| 404 HANDLE WINAPI TargetCreateThread(CreateThreadFunction orig_CreateThread, |
| 405 LPSECURITY_ATTRIBUTES thread_attributes, SIZE_T stack_size, |
| 406 LPTHREAD_START_ROUTINE start_address, PVOID parameter, |
| 407 DWORD creation_flags, LPDWORD thread_id) { |
| 408 HANDLE hThread = NULL; |
| 409 |
| 410 TargetServices* target_services = SandboxFactory::GetTargetServices(); |
| 411 if (NULL == target_services || |
| 412 target_services->GetState()->IsCsrssConnected()) { |
| 413 hThread = orig_CreateThread(thread_attributes, stack_size, |
| 414 start_address, parameter, creation_flags, thread_id); |
| 415 if (hThread) { |
| 416 return hThread; |
| 417 } |
| 418 } |
| 419 |
| 420 if (NULL == target_services) |
| 421 return NULL; |
| 422 |
| 423 // We don't trust that the IPC can work this early. |
| 424 if (!target_services->GetState()->InitCalled()) |
| 425 return NULL; |
| 426 |
| 427 DWORD original_error = ::GetLastError(); |
| 428 |
| 429 do { |
| 430 if (NULL != thread_id && |
| 431 !ValidParameter(thread_id, sizeof(*thread_id), WRITE)) |
| 432 break; |
| 433 |
| 434 void* memory = GetGlobalIPCMemory(); |
| 435 if (NULL == memory) |
| 436 break; |
| 437 |
| 438 SharedMemIPCClient ipc(memory); |
| 439 CrossCallReturn answer = { 0 }; |
| 440 |
| 441 ResultCode code = CrossCall(ipc, IPC_CREATETHREAD_TAG, |
| 442 (LPVOID)thread_attributes, (LPVOID)stack_size, |
| 443 (LPVOID)start_address, (LPVOID)parameter, |
| 444 (DWORD)creation_flags, &answer); |
| 445 |
| 446 if (SBOX_ALL_OK != code) |
| 447 break; |
| 448 |
| 449 if (ERROR_SUCCESS != answer.win32_result) { |
| 450 return NULL; |
| 451 } |
| 452 |
| 453 if (thread_id != NULL) { |
| 454 *thread_id = GetThreadId(answer.handle); |
| 455 } |
| 456 |
| 457 ::SetLastError(answer.win32_result); |
| 458 return answer.handle; |
| 459 } while (false); |
| 460 |
| 461 ::SetLastError(original_error); |
| 462 return NULL; |
| 463 } |
| 464 |
404 } // namespace sandbox | 465 } // namespace sandbox |
OLD | NEW |