| 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 "chrome/browser/nacl_host/nacl_process_host.h" | 5 #include "chrome/browser/nacl_host/nacl_process_host.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "ipc/ipc_channel_posix.h" | 54 #include "ipc/ipc_channel_posix.h" |
| 55 #elif defined(OS_WIN) | 55 #elif defined(OS_WIN) |
| 56 #include <windows.h> | 56 #include <windows.h> |
| 57 | 57 |
| 58 #include "base/process_util.h" | 58 #include "base/process_util.h" |
| 59 #include "base/threading/thread.h" | 59 #include "base/threading/thread.h" |
| 60 #include "base/win/scoped_handle.h" | 60 #include "base/win/scoped_handle.h" |
| 61 #include "chrome/browser/nacl_host/nacl_broker_service_win.h" | 61 #include "chrome/browser/nacl_host/nacl_broker_service_win.h" |
| 62 #include "chrome/common/nacl_debug_exception_handler_win.h" | 62 #include "chrome/common/nacl_debug_exception_handler_win.h" |
| 63 #include "content/public/common/sandbox_init.h" | 63 #include "content/public/common/sandbox_init.h" |
| 64 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 64 #endif | 65 #endif |
| 65 | 66 |
| 66 using content::BrowserThread; | 67 using content::BrowserThread; |
| 67 using content::ChildProcessData; | 68 using content::ChildProcessData; |
| 68 using content::ChildProcessHost; | 69 using content::ChildProcessHost; |
| 69 using ppapi::proxy::SerializedHandle; | 70 using ppapi::proxy::SerializedHandle; |
| 70 | 71 |
| 71 namespace { | 72 namespace { |
| 72 | 73 |
| 73 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
| 74 bool RunningOnWOW64() { | 75 bool RunningOnWOW64() { |
| 75 return (base::win::OSInfo::GetInstance()->wow64_status() == | 76 return (base::win::OSInfo::GetInstance()->wow64_status() == |
| 76 base::win::OSInfo::WOW64_ENABLED); | 77 base::win::OSInfo::WOW64_ENABLED); |
| 77 } | 78 } |
| 78 #endif | 79 |
| 80 // NOTE: changes to this class need to be reviewed by the security team. |
| 81 class NaClSandboxedProcessLauncherDelegate |
| 82 : public content::SandboxedProcessLauncherDelegate { |
| 83 public: |
| 84 NaClSandboxedProcessLauncherDelegate() {} |
| 85 virtual ~NaClSandboxedProcessLauncherDelegate() {} |
| 86 |
| 87 virtual void PostSpawnTarget(base::ProcessHandle process) { |
| 88 #if !defined(NACL_WIN64) |
| 89 // For Native Client sel_ldr processes on 32-bit Windows, reserve 1 GB of |
| 90 // address space to prevent later failure due to address space fragmentation |
| 91 // from .dll loading. The NaCl process will attempt to locate this space by |
| 92 // scanning the address space using VirtualQuery. |
| 93 // TODO(bbudge) Handle the --no-sandbox case. |
| 94 // http://code.google.com/p/nativeclient/issues/detail?id=2131 |
| 95 const SIZE_T kOneGigabyte = 1 << 30; |
| 96 void* nacl_mem = VirtualAllocEx(process, |
| 97 NULL, |
| 98 kOneGigabyte, |
| 99 MEM_RESERVE, |
| 100 PAGE_NOACCESS); |
| 101 if (!nacl_mem) { |
| 102 DLOG(WARNING) << "Failed to reserve address space for Native Client"; |
| 103 } |
| 104 #endif // !defined(NACL_WIN64) |
| 105 } |
| 106 }; |
| 107 |
| 108 #endif // OS_WIN |
| 79 | 109 |
| 80 void SetCloseOnExec(NaClHandle fd) { | 110 void SetCloseOnExec(NaClHandle fd) { |
| 81 #if defined(OS_POSIX) | 111 #if defined(OS_POSIX) |
| 82 int flags = fcntl(fd, F_GETFD); | 112 int flags = fcntl(fd, F_GETFD); |
| 83 CHECK_NE(flags, -1); | 113 CHECK_NE(flags, -1); |
| 84 int rc = fcntl(fd, F_SETFD, flags | FD_CLOEXEC); | 114 int rc = fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
| 85 CHECK_EQ(rc, 0); | 115 CHECK_EQ(rc, 0); |
| 86 #endif | 116 #endif |
| 87 } | 117 } |
| 88 | 118 |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 // On Windows we might need to start the broker process to launch a new loader | 595 // On Windows we might need to start the broker process to launch a new loader |
| 566 #if defined(OS_WIN) | 596 #if defined(OS_WIN) |
| 567 if (RunningOnWOW64()) { | 597 if (RunningOnWOW64()) { |
| 568 if (!NaClBrokerService::GetInstance()->LaunchLoader( | 598 if (!NaClBrokerService::GetInstance()->LaunchLoader( |
| 569 weak_factory_.GetWeakPtr(), channel_id)) { | 599 weak_factory_.GetWeakPtr(), channel_id)) { |
| 570 LOG(ERROR) << "NaCl process launch failed: broker service did not launch " | 600 LOG(ERROR) << "NaCl process launch failed: broker service did not launch " |
| 571 "process"; | 601 "process"; |
| 572 return false; | 602 return false; |
| 573 } | 603 } |
| 574 } else { | 604 } else { |
| 575 process_->Launch(base::FilePath(), cmd_line.release()); | 605 process_->Launch(new NaClSandboxedProcessLauncherDelegate, |
| 606 cmd_line.release()); |
| 576 } | 607 } |
| 577 #elif defined(OS_POSIX) | 608 #elif defined(OS_POSIX) |
| 578 process_->Launch(nacl_loader_prefix.empty(), // use_zygote | 609 process_->Launch(nacl_loader_prefix.empty(), // use_zygote |
| 579 base::EnvironmentVector(), | 610 base::EnvironmentVector(), |
| 580 cmd_line.release()); | 611 cmd_line.release()); |
| 581 #endif | 612 #endif |
| 582 | 613 |
| 583 return true; | 614 return true; |
| 584 } | 615 } |
| 585 | 616 |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 } else { | 970 } else { |
| 940 NaClStartDebugExceptionHandlerThread( | 971 NaClStartDebugExceptionHandlerThread( |
| 941 process_handle.Take(), info, | 972 process_handle.Take(), info, |
| 942 base::MessageLoopProxy::current(), | 973 base::MessageLoopProxy::current(), |
| 943 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 974 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
| 944 weak_factory_.GetWeakPtr())); | 975 weak_factory_.GetWeakPtr())); |
| 945 return true; | 976 return true; |
| 946 } | 977 } |
| 947 } | 978 } |
| 948 #endif | 979 #endif |
| OLD | NEW |