GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_main.cc Lines: 11 11 100.0 %
Date: 2020-05-27 22:15:15 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 <cstdio>
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
  // Windows Server 2012 (not R2) is supported until 10/10/2023, so we allow it
32
  // to run in the experimental support tier.
33
  if (!IsWindows8Point1OrGreater() &&
34
      !(IsWindowsServer() && IsWindows8OrGreater())) {
35
    fprintf(stderr, "This application is only supported on Windows 8.1, "
36
                    "Windows Server 2012 R2, or higher.");
37
    exit(ERROR_EXE_MACHINE_TYPE_MISMATCH);
38
  }
39
40
  // Convert argv to UTF8
41
  char** argv = new char*[argc + 1];
42
  for (int i = 0; i < argc; i++) {
43
    // Compute the size of the required buffer
44
    DWORD size = WideCharToMultiByte(CP_UTF8,
45
                                     0,
46
                                     wargv[i],
47
                                     -1,
48
                                     nullptr,
49
                                     0,
50
                                     nullptr,
51
                                     nullptr);
52
    if (size == 0) {
53
      // This should never happen.
54
      fprintf(stderr, "Could not convert arguments to utf8.");
55
      exit(1);
56
    }
57
    // Do the actual conversion
58
    argv[i] = new char[size];
59
    DWORD result = WideCharToMultiByte(CP_UTF8,
60
                                       0,
61
                                       wargv[i],
62
                                       -1,
63
                                       argv[i],
64
                                       size,
65
                                       nullptr,
66
                                       nullptr);
67
    if (result == 0) {
68
      // This should never happen.
69
      fprintf(stderr, "Could not convert arguments to utf8.");
70
      exit(1);
71
    }
72
  }
73
  argv[argc] = nullptr;
74
  // Now that conversion is done, we can finally start.
75
  return node::Start(argc, argv);
76
}
77
#else
78
// UNIX
79
#ifdef __linux__
80
#include <elf.h>
81
#ifdef __LP64__
82
#define Elf_auxv_t Elf64_auxv_t
83
#else
84
#define Elf_auxv_t Elf32_auxv_t
85
#endif  // __LP64__
86
extern char** environ;
87
#endif  // __linux__
88
#if defined(__POSIX__) && defined(NODE_SHARED_MODE)
89
#include <string.h>
90
#include <signal.h>
91
#endif
92
93
namespace node {
94
namespace per_process {
95
extern bool linux_at_secure;
96
}  // namespace per_process
97
}  // namespace node
98
99
4317
int main(int argc, char* argv[]) {
100
#if defined(__POSIX__) && defined(NODE_SHARED_MODE)
101
  // In node::PlatformInit(), we squash all signal handlers for non-shared lib
102
  // build. In order to run test cases against shared lib build, we also need
103
  // to do the same thing for shared lib build here, but only for SIGPIPE for
104
  // now. If node::PlatformInit() is moved to here, then this section could be
105
  // removed.
106
  {
107
    struct sigaction act;
108
    memset(&act, 0, sizeof(act));
109
    act.sa_handler = SIG_IGN;
110
    sigaction(SIGPIPE, &act, nullptr);
111
  }
112
#endif
113
114
#if defined(__linux__)
115
4317
  char** envp = environ;
116
303056
  while (*envp++ != nullptr) {}
117
4317
  Elf_auxv_t* auxv = reinterpret_cast<Elf_auxv_t*>(envp);
118
125193
  for (; auxv->a_type != AT_NULL; auxv++) {
119
64755
    if (auxv->a_type == AT_SECURE) {
120
4317
      node::per_process::linux_at_secure = auxv->a_un.a_val;
121
4317
      break;
122
    }
123
  }
124
#endif
125
  // Disable stdio buffering, it interacts poorly with printf()
126
  // calls elsewhere in the program (e.g., any logging from V8.)
127
4317
  setvbuf(stdout, nullptr, _IONBF, 0);
128
4317
  setvbuf(stderr, nullptr, _IONBF, 0);
129
4317
  return node::Start(argc, argv);
130
}
131
#endif