| 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/child_process_host_impl.h" | 5 #include "content/common/child_process_host_impl.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "ipc/attachment_broker_privileged_win.h" | 35 #include "ipc/attachment_broker_privileged_win.h" |
| 36 #endif // OS_LINUX | 36 #endif // OS_LINUX |
| 37 | 37 |
| 38 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 39 base::LazyInstance<IPC::AttachmentBrokerPrivilegedWin>::Leaky | 39 base::LazyInstance<IPC::AttachmentBrokerPrivilegedWin>::Leaky |
| 40 g_attachment_broker = LAZY_INSTANCE_INITIALIZER; | 40 g_attachment_broker = LAZY_INSTANCE_INITIALIZER; |
| 41 #endif // defined(OS_WIN) | 41 #endif // defined(OS_WIN) |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 #if defined(OS_MACOSX) | |
| 46 // Given |path| identifying a Mac-style child process executable path, adjusts | |
| 47 // it to correspond to |feature|. For a child process path such as | |
| 48 // ".../Chromium Helper.app/Contents/MacOS/Chromium Helper", the transformed | |
| 49 // path for feature "NP" would be | |
| 50 // ".../Chromium Helper NP.app/Contents/MacOS/Chromium Helper NP". The new | |
| 51 // path is returned. | |
| 52 base::FilePath TransformPathForFeature(const base::FilePath& path, | |
| 53 const std::string& feature) { | |
| 54 std::string basename = path.BaseName().value(); | |
| 55 | |
| 56 base::FilePath macos_path = path.DirName(); | |
| 57 const char kMacOSName[] = "MacOS"; | |
| 58 DCHECK_EQ(kMacOSName, macos_path.BaseName().value()); | |
| 59 | |
| 60 base::FilePath contents_path = macos_path.DirName(); | |
| 61 const char kContentsName[] = "Contents"; | |
| 62 DCHECK_EQ(kContentsName, contents_path.BaseName().value()); | |
| 63 | |
| 64 base::FilePath helper_app_path = contents_path.DirName(); | |
| 65 const char kAppExtension[] = ".app"; | |
| 66 std::string basename_app = basename; | |
| 67 basename_app.append(kAppExtension); | |
| 68 DCHECK_EQ(basename_app, helper_app_path.BaseName().value()); | |
| 69 | |
| 70 base::FilePath root_path = helper_app_path.DirName(); | |
| 71 | |
| 72 std::string new_basename = basename; | |
| 73 new_basename.append(1, ' '); | |
| 74 new_basename.append(feature); | |
| 75 std::string new_basename_app = new_basename; | |
| 76 new_basename_app.append(kAppExtension); | |
| 77 | |
| 78 base::FilePath new_path = root_path.Append(new_basename_app) | |
| 79 .Append(kContentsName) | |
| 80 .Append(kMacOSName) | |
| 81 .Append(new_basename); | |
| 82 | |
| 83 return new_path; | |
| 84 } | |
| 85 #endif // OS_MACOSX | |
| 86 | |
| 87 // Global atomic to generate child process unique IDs. | 45 // Global atomic to generate child process unique IDs. |
| 88 base::StaticAtomicSequenceNumber g_unique_id; | 46 base::StaticAtomicSequenceNumber g_unique_id; |
| 89 | 47 |
| 90 } // namespace | 48 } // namespace |
| 91 | 49 |
| 92 namespace content { | 50 namespace content { |
| 93 | 51 |
| 94 int ChildProcessHost::kInvalidUniqueID = -1; | 52 int ChildProcessHost::kInvalidUniqueID = -1; |
| 95 | 53 |
| 96 uint64 ChildProcessHost::kBrowserTracingProcessId = | 54 uint64 ChildProcessHost::kBrowserTracingProcessId = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 115 // Valgrind executable, which then crashes. However, it's almost safe to | 73 // Valgrind executable, which then crashes. However, it's almost safe to |
| 116 // assume that the updates won't happen while testing with Valgrind tools. | 74 // assume that the updates won't happen while testing with Valgrind tools. |
| 117 if (child_path.empty() && flags & CHILD_ALLOW_SELF && !RunningOnValgrind()) | 75 if (child_path.empty() && flags & CHILD_ALLOW_SELF && !RunningOnValgrind()) |
| 118 child_path = base::FilePath(base::kProcSelfExe); | 76 child_path = base::FilePath(base::kProcSelfExe); |
| 119 #endif | 77 #endif |
| 120 | 78 |
| 121 // On most platforms, the child executable is the same as the current | 79 // On most platforms, the child executable is the same as the current |
| 122 // executable. | 80 // executable. |
| 123 if (child_path.empty()) | 81 if (child_path.empty()) |
| 124 PathService::Get(CHILD_PROCESS_EXE, &child_path); | 82 PathService::Get(CHILD_PROCESS_EXE, &child_path); |
| 125 | |
| 126 #if defined(OS_MACOSX) | |
| 127 DCHECK(!(flags & CHILD_NO_PIE && flags & CHILD_ALLOW_HEAP_EXECUTION)); | |
| 128 | |
| 129 // If needed, choose an executable with special flags set that inform the | |
| 130 // kernel to enable or disable specific optional process-wide features. | |
| 131 if (flags & CHILD_NO_PIE) { | |
| 132 // "NP" is "No PIE". This results in Chromium Helper NP.app or | |
| 133 // Google Chrome Helper NP.app. | |
| 134 child_path = TransformPathForFeature(child_path, "NP"); | |
| 135 } else if (flags & CHILD_ALLOW_HEAP_EXECUTION) { | |
| 136 // "EH" is "Executable Heap". A non-executable heap is only available to | |
| 137 // 32-bit processes on Mac OS X 10.7. Most code can and should run with a | |
| 138 // non-executable heap, but the "EH" feature is provided to allow code | |
| 139 // intolerant of a non-executable heap to work properly on 10.7. This | |
| 140 // results in Chromium Helper EH.app or Google Chrome Helper EH.app. | |
| 141 child_path = TransformPathForFeature(child_path, "EH"); | |
| 142 } | |
| 143 #endif | |
| 144 | |
| 145 return child_path; | 83 return child_path; |
| 146 } | 84 } |
| 147 | 85 |
| 148 // static | 86 // static |
| 149 IPC::AttachmentBrokerPrivileged* ChildProcessHost::GetAttachmentBroker() { | 87 IPC::AttachmentBrokerPrivileged* ChildProcessHost::GetAttachmentBroker() { |
| 150 #if USE_ATTACHMENT_BROKER | 88 #if USE_ATTACHMENT_BROKER |
| 151 return &g_attachment_broker.Get(); | 89 return &g_attachment_broker.Get(); |
| 152 #else | 90 #else |
| 153 return nullptr; | 91 return nullptr; |
| 154 #endif // USE_ATTACHMENT_BROKER | 92 #endif // USE_ATTACHMENT_BROKER |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } | 312 } |
| 375 | 313 |
| 376 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( | 314 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( |
| 377 gfx::GpuMemoryBufferId id, | 315 gfx::GpuMemoryBufferId id, |
| 378 uint32 sync_point) { | 316 uint32 sync_point) { |
| 379 // Note: Nothing to do here as ownership of shared memory backed | 317 // Note: Nothing to do here as ownership of shared memory backed |
| 380 // GpuMemoryBuffers is passed with IPC. | 318 // GpuMemoryBuffers is passed with IPC. |
| 381 } | 319 } |
| 382 | 320 |
| 383 } // namespace content | 321 } // namespace content |
| OLD | NEW |