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 |
|
|
exit(1); |
68 |
|
|
} |
69 |
|
|
// Do the actual conversion |
70 |
|
|
argv[i] = new char[size]; |
71 |
|
|
DWORD result = WideCharToMultiByte(CP_UTF8, |
72 |
|
|
0, |
73 |
|
|
wargv[i], |
74 |
|
|
-1, |
75 |
|
|
argv[i], |
76 |
|
|
size, |
77 |
|
|
nullptr, |
78 |
|
|
nullptr); |
79 |
|
|
if (result == 0) { |
80 |
|
|
// This should never happen. |
81 |
|
|
fprintf(stderr, "Could not convert arguments to utf8."); |
82 |
|
|
exit(1); |
83 |
|
|
} |
84 |
|
|
} |
85 |
|
|
argv[argc] = nullptr; |
86 |
|
|
// Now that conversion is done, we can finally start. |
87 |
|
|
return node::Start(argc, argv); |
88 |
|
|
} |
89 |
|
|
#else |
90 |
|
|
// UNIX |
91 |
|
|
#ifdef __linux__ |
92 |
|
|
#include <sys/auxv.h> |
93 |
|
|
#endif // __linux__ |
94 |
|
|
#if defined(__POSIX__) && defined(NODE_SHARED_MODE) |
95 |
|
|
#include <string.h> |
96 |
|
|
#include <signal.h> |
97 |
|
|
#endif |
98 |
|
|
|
99 |
|
|
namespace node { |
100 |
|
|
namespace per_process { |
101 |
|
|
extern bool linux_at_secure; |
102 |
|
|
} // namespace per_process |
103 |
|
|
} // namespace node |
104 |
|
|
|
105 |
|
5238 |
int main(int argc, char* argv[]) { |
106 |
|
|
#if defined(__POSIX__) && defined(NODE_SHARED_MODE) |
107 |
|
|
// In node::PlatformInit(), we squash all signal handlers for non-shared lib |
108 |
|
|
// build. In order to run test cases against shared lib build, we also need |
109 |
|
|
// to do the same thing for shared lib build here, but only for SIGPIPE for |
110 |
|
|
// now. If node::PlatformInit() is moved to here, then this section could be |
111 |
|
|
// removed. |
112 |
|
|
{ |
113 |
|
|
struct sigaction act; |
114 |
|
|
memset(&act, 0, sizeof(act)); |
115 |
|
|
act.sa_handler = SIG_IGN; |
116 |
|
|
sigaction(SIGPIPE, &act, nullptr); |
117 |
|
|
} |
118 |
|
|
#endif |
119 |
|
|
|
120 |
|
|
#if defined(__linux__) |
121 |
|
5238 |
node::per_process::linux_at_secure = getauxval(AT_SECURE); |
122 |
|
|
#endif |
123 |
|
|
// Disable stdio buffering, it interacts poorly with printf() |
124 |
|
|
// calls elsewhere in the program (e.g., any logging from V8.) |
125 |
|
5238 |
setvbuf(stdout, nullptr, _IONBF, 0); |
126 |
|
5238 |
setvbuf(stderr, nullptr, _IONBF, 0); |
127 |
|
5238 |
return node::Start(argc, argv); |
128 |
|
|
} |
129 |
|
|
#endif |