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 "content/common/sandbox_win.h" | 5 #include "content/common/sandbox_win.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 return sandbox::SBOX_ALL_OK == result; | 646 return sandbox::SBOX_ALL_OK == result; |
647 } | 647 } |
648 | 648 |
649 base::Process StartSandboxedProcess( | 649 base::Process StartSandboxedProcess( |
650 SandboxedProcessLauncherDelegate* delegate, | 650 SandboxedProcessLauncherDelegate* delegate, |
651 base::CommandLine* cmd_line) { | 651 base::CommandLine* cmd_line) { |
652 const base::CommandLine& browser_command_line = | 652 const base::CommandLine& browser_command_line = |
653 *base::CommandLine::ForCurrentProcess(); | 653 *base::CommandLine::ForCurrentProcess(); |
654 std::string type_str = cmd_line->GetSwitchValueASCII(switches::kProcessType); | 654 std::string type_str = cmd_line->GetSwitchValueASCII(switches::kProcessType); |
655 | 655 |
656 TRACE_EVENT_BEGIN_ETW("StartProcessWithAccess", 0, type_str); | 656 TRACE_EVENT1("startup", "StartProcessWithAccess", "type", type_str); |
657 | 657 |
658 // Propagate the --allow-no-job flag if present. | 658 // Propagate the --allow-no-job flag if present. |
659 if (browser_command_line.HasSwitch(switches::kAllowNoSandboxJob) && | 659 if (browser_command_line.HasSwitch(switches::kAllowNoSandboxJob) && |
660 !cmd_line->HasSwitch(switches::kAllowNoSandboxJob)) { | 660 !cmd_line->HasSwitch(switches::kAllowNoSandboxJob)) { |
661 cmd_line->AppendSwitch(switches::kAllowNoSandboxJob); | 661 cmd_line->AppendSwitch(switches::kAllowNoSandboxJob); |
662 } | 662 } |
663 | 663 |
664 ProcessDebugFlags(cmd_line); | 664 ProcessDebugFlags(cmd_line); |
665 | 665 |
666 // Prefetch hints on windows: | 666 // Prefetch hints on windows: |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 policy->SetStderrHandle(GetStdHandle(STD_ERROR_HANDLE)); | 788 policy->SetStderrHandle(GetStdHandle(STD_ERROR_HANDLE)); |
789 #endif | 789 #endif |
790 | 790 |
791 if (delegate) { | 791 if (delegate) { |
792 bool success = true; | 792 bool success = true; |
793 delegate->PreSpawnTarget(policy, &success); | 793 delegate->PreSpawnTarget(policy, &success); |
794 if (!success) | 794 if (!success) |
795 return base::Process(); | 795 return base::Process(); |
796 } | 796 } |
797 | 797 |
798 TRACE_EVENT_BEGIN_ETW("StartProcessWithAccess::LAUNCHPROCESS", 0, 0); | 798 TRACE_EVENT_BEGIN0("startup", "StartProcessWithAccess::LAUNCHPROCESS"); |
799 | 799 |
800 PROCESS_INFORMATION temp_process_info = {}; | 800 PROCESS_INFORMATION temp_process_info = {}; |
801 result = g_broker_services->SpawnTarget( | 801 result = g_broker_services->SpawnTarget( |
802 cmd_line->GetProgram().value().c_str(), | 802 cmd_line->GetProgram().value().c_str(), |
803 cmd_line->GetCommandLineString().c_str(), | 803 cmd_line->GetCommandLineString().c_str(), policy, &temp_process_info); |
804 policy, &temp_process_info); | |
805 DWORD last_error = ::GetLastError(); | 804 DWORD last_error = ::GetLastError(); |
806 base::win::ScopedProcessInformation target(temp_process_info); | 805 base::win::ScopedProcessInformation target(temp_process_info); |
807 | 806 |
808 TRACE_EVENT_END_ETW("StartProcessWithAccess::LAUNCHPROCESS", 0, 0); | 807 TRACE_EVENT_END0("startup", "StartProcessWithAccess::LAUNCHPROCESS"); |
809 | 808 |
810 if (sandbox::SBOX_ALL_OK != result) { | 809 if (sandbox::SBOX_ALL_OK != result) { |
811 if (result == sandbox::SBOX_ERROR_GENERIC) | 810 if (result == sandbox::SBOX_ERROR_GENERIC) |
812 DPLOG(ERROR) << "Failed to launch process"; | 811 DPLOG(ERROR) << "Failed to launch process"; |
813 else if (result == sandbox::SBOX_ERROR_CREATE_PROCESS) { | 812 else if (result == sandbox::SBOX_ERROR_CREATE_PROCESS) { |
814 // TODO(shrikant): Remove this special case handling after determining | 813 // TODO(shrikant): Remove this special case handling after determining |
815 // cause for lowbox/createprocess errors. | 814 // cause for lowbox/createprocess errors. |
816 sandbox::PolicyBase* policy_base = | 815 sandbox::PolicyBase* policy_base = |
817 static_cast<sandbox::PolicyBase*>(policy); | 816 static_cast<sandbox::PolicyBase*>(policy); |
818 UMA_HISTOGRAM_SPARSE_SLOWLY(policy_base->GetLowBoxSid() ? | 817 UMA_HISTOGRAM_SPARSE_SLOWLY(policy_base->GetLowBoxSid() ? |
819 "Process.Sandbox.Lowbox.Launch.Error" : | 818 "Process.Sandbox.Lowbox.Launch.Error" : |
820 "Process.Sandbox.Launch.Error", | 819 "Process.Sandbox.Launch.Error", |
821 last_error); | 820 last_error); |
822 } else | 821 } else |
823 DLOG(ERROR) << "Failed to launch process. Error: " << result; | 822 DLOG(ERROR) << "Failed to launch process. Error: " << result; |
824 | 823 |
825 policy->Release(); | 824 policy->Release(); |
826 return base::Process(); | 825 return base::Process(); |
827 } | 826 } |
828 policy->Release(); | 827 policy->Release(); |
829 | 828 |
830 if (delegate) | 829 if (delegate) |
831 delegate->PostSpawnTarget(target.process_handle()); | 830 delegate->PostSpawnTarget(target.process_handle()); |
832 | 831 |
833 CHECK(ResumeThread(target.thread_handle()) != -1); | 832 CHECK(ResumeThread(target.thread_handle()) != -1); |
834 TRACE_EVENT_END_ETW("StartProcessWithAccess", 0, type_str); | |
835 return base::Process(target.TakeProcessHandle()); | 833 return base::Process(target.TakeProcessHandle()); |
836 } | 834 } |
837 | 835 |
838 bool BrokerDuplicateHandle(HANDLE source_handle, | 836 bool BrokerDuplicateHandle(HANDLE source_handle, |
839 DWORD target_process_id, | 837 DWORD target_process_id, |
840 HANDLE* target_handle, | 838 HANDLE* target_handle, |
841 DWORD desired_access, | 839 DWORD desired_access, |
842 DWORD options) { | 840 DWORD options) { |
843 // If our process is the target just duplicate the handle. | 841 // If our process is the target just duplicate the handle. |
844 if (::GetCurrentProcessId() == target_process_id) { | 842 if (::GetCurrentProcessId() == target_process_id) { |
(...skipping 22 matching lines...) Expand all Loading... |
867 } | 865 } |
868 | 866 |
869 return false; | 867 return false; |
870 } | 868 } |
871 | 869 |
872 bool BrokerAddTargetPeer(HANDLE peer_process) { | 870 bool BrokerAddTargetPeer(HANDLE peer_process) { |
873 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK; | 871 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK; |
874 } | 872 } |
875 | 873 |
876 } // namespace content | 874 } // namespace content |
OLD | NEW |