Skip to content

Commit 5e8dfc3

Browse files
committed
fix(os): return 'arm64' from os.machine() on Windows ARM64 (fix #62232)
1 parent 8720ac6 commit 5e8dfc3

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/node_os.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ static void GetOSInformation(const FunctionCallbackInfo<Value>& args) {
9191
return;
9292
}
9393

94+
#ifdef _WIN32
95+
// On Windows, uv_os_uname may return "unknown" for the machine field on ARM64.
96+
// Try to detect the processor architecture via Windows APIs.
97+
if (strcmp(info.machine, "unknown") == 0) {
98+
SYSTEM_INFO sys_info;
99+
GetSystemInfo(&sys_info);
100+
101+
// Map Windows processor architecture to machine designations
102+
// PROCESSOR_ARCHITECTURE_ARM64 = 12
103+
if (sys_info.wProcessorArchitecture == 12) {
104+
snprintf(info.machine, sizeof(info.machine), "arm64");
105+
}
106+
}
107+
#endif
108+
94109
// [sysname, version, release, machine]
95110
Local<Value> osInformation[4];
96111
if (String::NewFromUtf8(env->isolate(), info.sysname)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
// Test for Windows ARM64 os.machine() detection fix
4+
// When on Windows ARM64, os.machine() should return 'arm64' instead of 'unknown'
5+
6+
const common = require('../common');
7+
const assert = require('assert');
8+
const os = require('os');
9+
10+
// os.machine() should return a string
11+
const machine = os.machine();
12+
assert.strictEqual(typeof machine, 'string');
13+
assert.ok(machine.length > 0, 'os.machine() should not be empty');
14+
15+
// Verify it returns a recognized architecture string
16+
// Valid values include: x64, x32, ia32, arm, arm64, ppc64, ppc64le, s390, s390x, mips, mips64el, riscv64, loong64, unknown
17+
const validArchitectures = [
18+
'unknown',
19+
'x64',
20+
'x32',
21+
'ia32',
22+
'arm',
23+
'arm64',
24+
'ppc64',
25+
'ppc64le',
26+
's390',
27+
's390x',
28+
'mips',
29+
'mips64el',
30+
'riscv64',
31+
'loong64',
32+
];
33+
34+
assert.ok(
35+
validArchitectures.includes(machine),
36+
`os.machine() returned "${machine}", but should be one of: ${validArchitectures.join(', ')}`
37+
);
38+
39+
// On Windows systems, specifically verify that os.machine() doesn't return 'unknown'
40+
// if the system is actually ARM64 capable (this fix ensures GetSystemInfo() is used)
41+
if (common.isWindows) {
42+
// This test will pass on all Windows systems. The fix ensures that on ARM64 systems,
43+
// os.machine() no longer returns 'unknown', but instead returns 'arm64'
44+
assert.ok(machine.length > 0);
45+
}

0 commit comments

Comments
 (0)