| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/nacl/nacl_main_platform_delegate.h" | 5 #include "components/nacl/loader/nacl_main_platform_delegate.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/native_library.h" | 11 #include "base/native_library.h" |
| 12 #include "chrome/common/chrome_sandbox_type_mac.h" | 12 #include "components/nacl/common/nacl_delegate.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "components/nacl/common/nacl_sandbox_type_mac.h" |
| 14 #include "components/nacl/common/nacl_switches.h" |
| 14 #include "content/public/common/sandbox_init.h" | 15 #include "content/public/common/sandbox_init.h" |
| 15 | 16 |
| 16 NaClMainPlatformDelegate::NaClMainPlatformDelegate( | 17 NaClMainPlatformDelegate::NaClMainPlatformDelegate( |
| 17 const content::MainFunctionParams& parameters) | 18 const content::MainFunctionParams& parameters) |
| 18 : parameters_(parameters), sandbox_test_module_(NULL) { | 19 : parameters_(parameters), sandbox_test_module_(NULL) { |
| 19 } | 20 } |
| 20 | 21 |
| 21 NaClMainPlatformDelegate::~NaClMainPlatformDelegate() { | 22 NaClMainPlatformDelegate::~NaClMainPlatformDelegate() { |
| 22 } | 23 } |
| 23 | 24 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 DVLOG(1) << "Started NaClLdr with "; | 39 DVLOG(1) << "Started NaClLdr with "; |
| 39 const std::vector<std::string>& argstrings = command_line.argv(); | 40 const std::vector<std::string>& argstrings = command_line.argv(); |
| 40 for (std::vector<std::string>::const_iterator ii = argstrings.begin(); | 41 for (std::vector<std::string>::const_iterator ii = argstrings.begin(); |
| 41 ii != argstrings.end(); ++ii) | 42 ii != argstrings.end(); ++ii) |
| 42 DVLOG(1) << *ii; | 43 DVLOG(1) << *ii; |
| 43 | 44 |
| 44 // Be sure not to load the sandbox test DLL if the sandbox isn't on. | 45 // Be sure not to load the sandbox test DLL if the sandbox isn't on. |
| 45 // Comment-out guard and recompile if you REALLY want to test w/out the SB. | 46 // Comment-out guard and recompile if you REALLY want to test w/out the SB. |
| 46 // TODO(jvoung): allow testing without sandbox, but change expected ret vals. | 47 // TODO(jvoung): allow testing without sandbox, but change expected ret vals. |
| 47 if (!no_sandbox) { | 48 if (!no_sandbox) { |
| 48 base::FilePath test_dll_name = | 49 base::FilePath test_dll_name = command_line.GetSwitchValuePath( |
| 49 command_line.GetSwitchValuePath(switches::kTestNaClSandbox); | 50 switches::kTestNaClSandbox); |
| 50 if (!test_dll_name.empty()) { | 51 if (!test_dll_name.empty()) { |
| 51 sandbox_test_module_ = base::LoadNativeLibrary(test_dll_name, NULL); | 52 sandbox_test_module_ = base::LoadNativeLibrary(test_dll_name, NULL); |
| 52 CHECK(sandbox_test_module_); | 53 CHECK(sandbox_test_module_); |
| 53 } | 54 } |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 | 57 |
| 57 void NaClMainPlatformDelegate::EnableSandbox() { | 58 void NaClMainPlatformDelegate::EnableSandbox() { |
| 58 CHECK(content::InitializeSandbox(CHROME_SANDBOX_TYPE_NACL_LOADER, | 59 CHECK(content::InitializeSandbox(NACL_SANDBOX_TYPE_NACL_LOADER, |
| 59 base::FilePath())) | 60 base::FilePath())) |
| 60 << "Error initializing sandbox for " << switches::kNaClLoaderProcess; | 61 << "Error initializing sandbox for " << switches::kNaClLoaderProcess; |
| 61 } | 62 } |
| 62 | 63 |
| 63 bool NaClMainPlatformDelegate::RunSandboxTests() { | 64 bool NaClMainPlatformDelegate::RunSandboxTests() { |
| 64 // TODO(jvoung): Win and mac should share this identical code. | 65 // TODO(jvoung): Win and mac should share this identical code. |
| 65 bool result = true; | 66 bool result = true; |
| 66 if (sandbox_test_module_) { | 67 if (sandbox_test_module_) { |
| 67 RunNaClLoaderTests run_security_tests = | 68 RunNaClLoaderTests run_security_tests = |
| 68 reinterpret_cast<RunNaClLoaderTests>( | 69 reinterpret_cast<RunNaClLoaderTests>( |
| 69 base::GetFunctionPointerFromNativeLibrary(sandbox_test_module_, | 70 base::GetFunctionPointerFromNativeLibrary(sandbox_test_module_, |
| 70 kNaClLoaderTestCall)); | 71 kNaClLoaderTestCall)); |
| 71 if (run_security_tests) { | 72 if (run_security_tests) { |
| 72 DVLOG(1) << "Running NaCl Loader security tests"; | 73 DVLOG(1) << "Running NaCl Loader security tests"; |
| 73 result = (*run_security_tests)(); | 74 result = (*run_security_tests)(); |
| 74 } else { | 75 } else { |
| 75 VLOG(1) << "Failed to get NaCl sandbox test function"; | 76 VLOG(1) << "Failed to get NaCl sandbox test function"; |
| 76 result = false; | 77 result = false; |
| 77 } | 78 } |
| 78 base::UnloadNativeLibrary(sandbox_test_module_); | 79 base::UnloadNativeLibrary(sandbox_test_module_); |
| 79 sandbox_test_module_ = NULL; | 80 sandbox_test_module_ = NULL; |
| 80 } | 81 } |
| 81 return result; | 82 return result; |
| 82 } | 83 } |
| OLD | NEW |