summaryrefslogtreecommitdiffstats
path: root/chrome/nacl/nacl_main_platform_delegate_mac.mm
blob: 19e7df7165bf23d1447c4436a589c7c3d55a4bfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/nacl/nacl_main_platform_delegate.h"

#import <Cocoa/Cocoa.h>
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/logging.h"
#include "base/native_library.h"
#include "chrome/common/chrome_switches.h"
#include "content/common/sandbox_mac.h"

NaClMainPlatformDelegate::NaClMainPlatformDelegate(
    const MainFunctionParams& parameters)
    : parameters_(parameters), sandbox_test_module_(NULL) {
}

NaClMainPlatformDelegate::~NaClMainPlatformDelegate() {
}

// TODO(jvoung): see if this old comment (from renderer_main_platform...)
// is relevant to the nacl loader.
// TODO(mac-port): Any code needed to initialize a process for purposes of
// running a NaClLoader needs to also be reflected in chrome_main.cc for
// --single-process support.
void NaClMainPlatformDelegate::PlatformInitialize() {
}

void NaClMainPlatformDelegate::PlatformUninitialize() {
}

void NaClMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
  const CommandLine& command_line = parameters_.command_line_;

  DVLOG(1) << "Started NaClLdr with ";
  const std::vector<std::string>& argstrings = command_line.argv();
  for (std::vector<std::string>::const_iterator ii = argstrings.begin();
       ii != argstrings.end(); ++ii)
    DVLOG(1) << *ii;

  // Be sure not to load the sandbox test DLL if the sandbox isn't on.
  // Comment-out guard and recompile if you REALLY want to test w/out the SB.
  // TODO(jvoung): allow testing without sandbox, but change expected ret vals.
  if (!no_sandbox) {
    FilePath test_dll_name =
      command_line.GetSwitchValuePath(switches::kTestNaClSandbox);
    if (!test_dll_name.empty()) {
      sandbox_test_module_ = base::LoadNativeLibrary(test_dll_name);
      CHECK(sandbox_test_module_);
    }
  }
}

void NaClMainPlatformDelegate::EnableSandbox() {
  CommandLine* parsed_command_line = CommandLine::ForCurrentProcess();
  SandboxInitWrapper sandbox_wrapper;
  bool sandbox_initialized_ok =
       sandbox_wrapper.InitializeSandbox(*parsed_command_line,
                                         switches::kNaClLoaderProcess);
  CHECK(sandbox_initialized_ok) << "Error initializing sandbox for "
                                << switches::kNaClLoaderProcess;
}

bool NaClMainPlatformDelegate::RunSandboxTests() {
  // TODO(jvoung): Win and mac should share this identical code.
  bool result = true;
  if (sandbox_test_module_) {
    RunNaClLoaderTests run_security_tests =
      reinterpret_cast<RunNaClLoaderTests>(
        base::GetFunctionPointerFromNativeLibrary(sandbox_test_module_,
                                                  kNaClLoaderTestCall));
    if (run_security_tests) {
      DVLOG(1) << "Running NaCl Loader security tests";
      result = (*run_security_tests)();
    } else {
      VLOG(1) << "Failed to get NaCl sandbox test function";
      result = false;
    }
    base::UnloadNativeLibrary(sandbox_test_module_);
    sandbox_test_module_ = NULL;
  }
  return result;
}