GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/node_main.cc Lines: 11 11 100.0 %
Date: 2017-12-18 Branches: 5 6 83.3 %

Line Branch Exec Source
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
#include "node.h"
23
#include <stdio.h>
24
25
#ifdef _WIN32
26
#include <windows.h>
27
#include <VersionHelpers.h>
28
#include <WinError.h>
29
30
int wmain(int argc, wchar_t *wargv[]) {
31
  if (!IsWindows7OrGreater()) {
32
    fprintf(stderr, "This application is only supported on Windows 7, "
33
                    "Windows Server 2008 R2, or higher.");
34
    exit(ERROR_EXE_MACHINE_TYPE_MISMATCH);
35
  }
36
37
  // Convert argv to to UTF8
38
  char** argv = new char*[argc + 1];
39
  for (int i = 0; i < argc; i++) {
40
    // Compute the size of the required buffer
41
    DWORD size = WideCharToMultiByte(CP_UTF8,
42
                                     0,
43
                                     wargv[i],
44
                                     -1,
45
                                     nullptr,
46
                                     0,
47
                                     nullptr,
48
                                     nullptr);
49
    if (size == 0) {
50
      // This should never happen.
51
      fprintf(stderr, "Could not convert arguments to utf8.");
52
      exit(1);
53
    }
54
    // Do the actual conversion
55
    argv[i] = new char[size];
56
    DWORD result = WideCharToMultiByte(CP_UTF8,
57
                                       0,
58
                                       wargv[i],
59
                                       -1,
60
                                       argv[i],
61
                                       size,
62
                                       nullptr,
63
                                       nullptr);
64
    if (result == 0) {
65
      // This should never happen.
66
      fprintf(stderr, "Could not convert arguments to utf8.");
67
      exit(1);
68
    }
69
  }
70
  argv[argc] = nullptr;
71
  // Now that conversion is done, we can finally start.
72
  return node::Start(argc, argv);
73
}
74
#else
75
// UNIX
76
#ifdef __linux__
77
#include <elf.h>
78
#ifdef __LP64__
79
#define Elf_auxv_t Elf64_auxv_t
80
#else
81
#define Elf_auxv_t Elf32_auxv_t
82
#endif  // __LP64__
83
extern char** environ;
84
#endif  // __linux__
85
86
namespace node {
87
  extern bool linux_at_secure;
88
}  // namespace node
89
90
3391
int main(int argc, char *argv[]) {
91
#if defined(__linux__)
92
3391
  char** envp = environ;
93
3391
  while (*envp++ != nullptr) {}
94
3391
  Elf_auxv_t* auxv = reinterpret_cast<Elf_auxv_t*>(envp);
95
50865
  for (; auxv->a_type != AT_NULL; auxv++) {
96
50865
    if (auxv->a_type == AT_SECURE) {
97
3391
      node::linux_at_secure = auxv->a_un.a_val;
98
3391
      break;
99
    }
100
  }
101
#endif
102
  // Disable stdio buffering, it interacts poorly with printf()
103
  // calls elsewhere in the program (e.g., any logging from V8.)
104
3391
  setvbuf(stdout, nullptr, _IONBF, 0);
105
3391
  setvbuf(stderr, nullptr, _IONBF, 0);
106
3391
  return node::Start(argc, argv);
107
}
108
#endif