From 8355a95407026e043dc5786b9810dcd72bc47809 Mon Sep 17 00:00:00 2001 From: Tom Najdek Date: Sat, 2 Aug 2025 15:59:48 +0200 Subject: [PATCH] Warn users running non-ARM version on ARM CPU on Linux (#5461) --- chrome/content/zotero/xpcom/zotero.js | 49 +++++++++++++++++++++++++++ chrome/content/zotero/zoteroPane.js | 4 +-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index c402e8aff9..0e68211fa7 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1419,6 +1419,55 @@ const { CommandLineOptions } = ChromeUtils.importESModule("chrome://zotero/conte return false; } } + + this.isLinux64EmulatedOnArm = function () { + if (!this.isLinux) { + return false; + } + + // We only check if x86_64 build is running on ARM + if (this.arch !== "x86_64") { + return false; + } + + try { + const { ctypes } = ChromeUtils.importESModule( + "resource://gre/modules/ctypes.sys.mjs" + ); + + let utsname = ctypes.StructType("utsname", [ + { sysname: ctypes.ArrayType(ctypes.char, 65) }, + { nodename: ctypes.ArrayType(ctypes.char, 65) }, + { release: ctypes.ArrayType(ctypes.char, 65) }, + { version: ctypes.ArrayType(ctypes.char, 65) }, + { machine: ctypes.ArrayType(ctypes.char, 65) }, + { domainname: ctypes.ArrayType(ctypes.char, 65) } + ]); + + let libc = ctypes.open("libc.so.6"); + let unameC = libc.declare( + "uname", + ctypes.default_abi, + ctypes.int, + utsname.ptr + ); + + let buf = utsname(); + if (unameC(buf.address()) !== 0) { + libc.close(); + return false; + } + + let machine = buf.machine.readString().trim(); // e.g., "x86_64", "aarch64" + libc.close(); + + return ["aarch64", "arm64"].includes(machine.toLowerCase()); + } + catch (e) { + Zotero.logError(e); + return false; + } + }; /** * Get versions, platform, etc. diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 5d92745e19..e1b4e56505 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -6590,9 +6590,9 @@ var ZoteroPane = new function () { } const isWow64 = (await Services.sysinfo.processInfo).isWow64; - const isX64OnArm = Zotero.isWin64EmulatedOnArm(); + const isX64OnArm = Zotero.isWin64EmulatedOnArm() || Zotero.isLinux64EmulatedOnArm(); - if (Zotero.isWin && (isWow64 || isX64OnArm)) { + if ((Zotero.isWin && isWow64) || isX64OnArm) { let panel = document.getElementById('architecture-warning-container'); let action = document.getElementById('architecture-warning-action'); let close = document.getElementById('architecture-warning-close');