GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_main.cc Lines: 2 2 100.0 %
Date: 2022-11-05 03:21:31 Branches: 0 0 - %

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
#define SKIP_CHECK_VAR "NODE_SKIP_PLATFORM_CHECK"
31
#define SKIP_CHECK_SIZE 1
32
#define SKIP_CHECK_VALUE "1"
33
34
int wmain(int argc, wchar_t* wargv[]) {
35
  // Windows Server 2012 (not R2) is supported until 10/10/2023, so we allow it
36
  // to run in the experimental support tier.
37
  char buf[SKIP_CHECK_SIZE + 1];
38
  if (!IsWindows8Point1OrGreater() &&
39
      !(IsWindowsServer() && IsWindows8OrGreater()) &&
40
      (GetEnvironmentVariableA(SKIP_CHECK_VAR, buf, sizeof(buf)) !=
41
       SKIP_CHECK_SIZE ||
42
       strncmp(buf, SKIP_CHECK_VALUE, SKIP_CHECK_SIZE + 1) != 0)) {
43
    fprintf(stderr, "Node.js is only supported on Windows 8.1, Windows "
44
                    "Server 2012 R2, or higher.\n"
45
                    "Setting the " SKIP_CHECK_VAR " environment variable "
46
                    "to 1 skips this\ncheck, but Node.js might not execute "
47
                    "correctly. Any issues encountered on\nunsupported "
48
                    "platforms will not be fixed.");
49
    exit(ERROR_EXE_MACHINE_TYPE_MISMATCH);
50
  }
51
52
  // Convert argv to UTF8
53
  char** argv = new char*[argc + 1];
54
  for (int i = 0; i < argc; i++) {
55
    // Compute the size of the required buffer
56
    DWORD size = WideCharToMultiByte(CP_UTF8,
57
                                     0,
58
                                     wargv[i],
59
                                     -1,
60
                                     nullptr,
61
                                     0,
62
                                     nullptr,
63
                                     nullptr);
64
    if (size == 0) {
65
      // This should never happen.
66
      fprintf(stderr, "Could not convert arguments to utf8.");
67
      // TODO(joyeecheung): should be ExitCode::kInvalidCommandLineArgument,
68
      // but we are not ready to expose that to node.h yet.
69
      exit(1);
70
    }
71
    // Do the actual conversion
72
    argv[i] = new char[size];
73
    DWORD result = WideCharToMultiByte(CP_UTF8,
74
                                       0,
75
                                       wargv[i],
76
                                       -1,
77
                                       argv[i],
78
                                       size,
79
                                       nullptr,
80
                                       nullptr);
81
    if (result == 0) {
82
      // This should never happen.
83
      fprintf(stderr, "Could not convert arguments to utf8.");
84
      // TODO(joyeecheung): should be ExitCode::kInvalidCommandLineArgument,
85
      // but we are not ready to expose that to node.h yet.
86
      exit(1);
87
    }
88
  }
89
  argv[argc] = nullptr;
90
  // Now that conversion is done, we can finally start.
91
  return node::Start(argc, argv);
92
}
93
#else
94
// UNIX
95
96
5645
int main(int argc, char* argv[]) {
97
5645
  return node::Start(argc, argv);
98
}
99
#endif