OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "base/memory/ptr_util.h" | 5 #include "base/memory/ptr_util.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/posix/global_descriptors.h" | 7 #include "base/posix/global_descriptors.h" |
8 #include "content/browser/bootstrap_sandbox_manager_mac.h" | 8 #include "content/browser/bootstrap_sandbox_manager_mac.h" |
9 #include "content/browser/child_process_launcher.h" | 9 #include "content/browser/child_process_launcher.h" |
10 #include "content/browser/child_process_launcher_helper.h" | 10 #include "content/browser/child_process_launcher_helper.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 mojo::edk::ScopedPlatformHandle | 22 mojo::edk::ScopedPlatformHandle |
23 ChildProcessLauncherHelper::PrepareMojoPipeHandlesOnClientThread() { | 23 ChildProcessLauncherHelper::PrepareMojoPipeHandlesOnClientThread() { |
24 DCHECK_CURRENTLY_ON(client_thread_id_); | 24 DCHECK_CURRENTLY_ON(client_thread_id_); |
25 return mojo::edk::ScopedPlatformHandle(); | 25 return mojo::edk::ScopedPlatformHandle(); |
26 } | 26 } |
27 | 27 |
28 void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() { | 28 void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() { |
29 DCHECK_CURRENTLY_ON(client_thread_id_); | 29 DCHECK_CURRENTLY_ON(client_thread_id_); |
30 } | 30 } |
31 | 31 |
32 std::unique_ptr<FileDescriptorInfo> | 32 std::unique_ptr<PosixFileDescriptorInfo> |
33 ChildProcessLauncherHelper::GetFilesToMap() { | 33 ChildProcessLauncherHelper::GetFilesToMap() { |
34 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | 34 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
35 return CreateDefaultPosixFilesToMap( | 35 return CreateDefaultPosixFilesToMap( |
36 child_process_id(), mojo_client_handle(), | 36 child_process_id(), mojo_client_handle(), |
37 false /* include_service_required_files */, GetProcessType(), | 37 false /* include_service_required_files */, GetProcessType(), |
38 command_line()); | 38 command_line()); |
39 } | 39 } |
40 | 40 |
41 void ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread( | 41 void ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread( |
42 const FileMappedForLaunch& files_to_register, | 42 const FileMappedForLaunch& files_to_register, |
43 base::LaunchOptions* options) { | 43 base::LaunchOptions* options) { |
44 // Convert FD mapping to FileHandleMappingVector. | 44 // Convert FD mapping to FileHandleMappingVector. |
45 std::unique_ptr<base::FileHandleMappingVector> fds_to_map = | 45 options->fds_to_remap = files_to_register.GetMappingWithIDAdjustment( |
46 files_to_register.GetMappingWithIDAdjustment( | 46 base::GlobalDescriptors::kBaseDescriptor); |
47 base::GlobalDescriptors::kBaseDescriptor); | |
48 | 47 |
49 options->environ = delegate_->GetEnvironment(); | 48 options->environ = delegate_->GetEnvironment(); |
50 // fds_to_remap will de deleted in AfterLaunchOnLauncherThread() below. | |
51 options->fds_to_remap = fds_to_map.release(); | |
52 | 49 |
53 // Hold the MachBroker lock for the duration of LaunchProcess. The child will | 50 // Hold the MachBroker lock for the duration of LaunchProcess. The child will |
54 // send its task port to the parent almost immediately after startup. The Mach | 51 // send its task port to the parent almost immediately after startup. The Mach |
55 // message will be delivered to the parent, but updating the record of the | 52 // message will be delivered to the parent, but updating the record of the |
56 // launch will wait until after the placeholder PID is inserted below. This | 53 // launch will wait until after the placeholder PID is inserted below. This |
57 // ensures that while the child process may send its port to the parent prior | 54 // ensures that while the child process may send its port to the parent prior |
58 // to the parent leaving LaunchProcess, the order in which the record in | 55 // to the parent leaving LaunchProcess, the order in which the record in |
59 // MachBroker is updated is correct. | 56 // MachBroker is updated is correct. |
60 MachBroker* broker = MachBroker::GetInstance(); | 57 MachBroker* broker = MachBroker::GetInstance(); |
61 broker->GetLock().Acquire(); | 58 broker->GetLock().Acquire(); |
(...skipping 12 matching lines...) Expand all Loading... |
74 } | 71 } |
75 } | 72 } |
76 // options now owns the pre_exec_delegate which will be delete on | 73 // options now owns the pre_exec_delegate which will be delete on |
77 // AfterLaunchOnLauncherThread below. | 74 // AfterLaunchOnLauncherThread below. |
78 options->pre_exec_delegate = pre_exec_delegate.release(); | 75 options->pre_exec_delegate = pre_exec_delegate.release(); |
79 } | 76 } |
80 | 77 |
81 ChildProcessLauncherHelper::Process | 78 ChildProcessLauncherHelper::Process |
82 ChildProcessLauncherHelper::LaunchProcessOnLauncherThread( | 79 ChildProcessLauncherHelper::LaunchProcessOnLauncherThread( |
83 const base::LaunchOptions& options, | 80 const base::LaunchOptions& options, |
84 std::unique_ptr<FileDescriptorInfo> files_to_register, | 81 std::unique_ptr<PosixFileDescriptorInfo> files_to_register, |
85 bool* is_synchronous_launch, | 82 bool* is_synchronous_launch, |
86 int* launch_result) { | 83 int* launch_result) { |
87 *is_synchronous_launch = true; | 84 *is_synchronous_launch = true; |
88 ChildProcessLauncherHelper::Process process; | 85 ChildProcessLauncherHelper::Process process; |
89 process.process = base::LaunchProcess(*command_line(), options); | 86 process.process = base::LaunchProcess(*command_line(), options); |
90 *launch_result = process.process.IsValid() ? LAUNCH_RESULT_SUCCESS | 87 *launch_result = process.process.IsValid() ? LAUNCH_RESULT_SUCCESS |
91 : LAUNCH_RESULT_FAILURE; | 88 : LAUNCH_RESULT_FAILURE; |
92 return process; | 89 return process; |
93 } | 90 } |
94 | 91 |
95 void ChildProcessLauncherHelper::AfterLaunchOnLauncherThread( | 92 void ChildProcessLauncherHelper::AfterLaunchOnLauncherThread( |
96 const ChildProcessLauncherHelper::Process& process, | 93 const ChildProcessLauncherHelper::Process& process, |
97 const base::LaunchOptions& options) { | 94 const base::LaunchOptions& options) { |
98 delete options.fds_to_remap; | |
99 | |
100 std::unique_ptr<sandbox::PreExecDelegate> pre_exec_delegate = | 95 std::unique_ptr<sandbox::PreExecDelegate> pre_exec_delegate = |
101 base::WrapUnique(static_cast<sandbox::PreExecDelegate*>( | 96 base::WrapUnique(static_cast<sandbox::PreExecDelegate*>( |
102 options.pre_exec_delegate)); | 97 options.pre_exec_delegate)); |
103 | 98 |
104 MachBroker* broker = MachBroker::GetInstance(); | 99 MachBroker* broker = MachBroker::GetInstance(); |
105 if (process.process.IsValid()) { | 100 if (process.process.IsValid()) { |
106 broker->AddPlaceholderForPid(process.process.Pid(), child_process_id()); | 101 broker->AddPlaceholderForPid(process.process.Pid(), child_process_id()); |
107 } else { | 102 } else { |
108 if (pre_exec_delegate) { | 103 if (pre_exec_delegate) { |
109 BootstrapSandboxManager::GetInstance()->sandbox()->RevokeToken( | 104 BootstrapSandboxManager::GetInstance()->sandbox()->RevokeToken( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 base::File OpenFileToShare(const base::FilePath& path, | 159 base::File OpenFileToShare(const base::FilePath& path, |
165 base::MemoryMappedFile::Region* region) { | 160 base::MemoryMappedFile::Region* region) { |
166 // Not used yet (until required files are described in the service manifest on | 161 // Not used yet (until required files are described in the service manifest on |
167 // Mac). | 162 // Mac). |
168 NOTREACHED(); | 163 NOTREACHED(); |
169 return base::File(); | 164 return base::File(); |
170 } | 165 } |
171 | 166 |
172 } // namespace internal | 167 } // namespace internal |
173 } // namespace content | 168 } // namespace content |
OLD | NEW |