Skip to content

Commit 7f73091

Browse files
committed
tweak(server/launcher): detect and cleanly fail on unsupported CPUs
There's a fair amount of old x86 CPUs floating around and every so often someone hits an 'illegal instruction' crash which is a bit confusing. See: - https://forum.cfx.re/t/4947054 - https://forum.cfx.re/t/4837037/4 - https://forum.cfx.re/t/4777623 and so on.
1 parent daf4cef commit 7f73091

6 files changed

Lines changed: 45 additions & 1 deletion

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,6 @@
277277
[submodule "vendor/nljson"]
278278
path = vendor/nljson
279279
url = https://github.com/nlohmann/json.git
280+
[submodule "vendor/cpu_features"]
281+
path = vendor/cpu_features
282+
url = https://github.com/google/cpu_features.git

code/server/launcher/premake5.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
links { "Shared", "CitiCore" }
66

7-
add_dependencies { 'vendor:fmtlib', 'vendor:breakpad' }
7+
add_dependencies { 'vendor:fmtlib', 'vendor:breakpad', 'vendor:cpu_features' }
88

99
if os.istarget('windows') then
1010
links { "psapi", "wininet", "winhttp" }

code/server/launcher/src/Main.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <pthread.h>
1515
#endif
1616

17+
#include "cpuinfo_x86.h"
18+
1719
bool InitializeExceptionHandler(int argc, char* argv[]);
1820

1921
int main(int argc, char* argv[])
@@ -27,6 +29,18 @@ int main(int argc, char* argv[])
2729
}
2830
#endif
2931

32+
#ifdef CPU_FEATURES_ARCH_X86
33+
auto x86info = cpu_features::GetX86Info();
34+
if (!x86info.features.popcnt)
35+
{
36+
fmt::printf("The Cfx.re Platform Server requires support for x86-64-v2 instructions (such as POPCNT).\n");
37+
fmt::printf("Your current CPU (\"%s\") does not appear to support this. Supported CPUs include most CPUs from around 2010 or newer.\n", x86info.brand_string);
38+
fmt::printf("\n");
39+
fmt::printf("Exiting.\n");
40+
return 1;
41+
}
42+
#endif
43+
3044
if (InitializeExceptionHandler(argc, argv))
3145
{
3246
return 0;

code/vendor/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,6 @@ vendor_component 'dspfilters'
104104
vendor_component 'speexdsp'
105105
vendor_component 'wil'
106106
vendor_component 'v8-93'
107+
vendor_component 'cpu_features'
107108
vendor_component 'citizen_enet'
108109
vendor_component 'citizen_util'

code/vendor/cpu_features.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
return {
2+
include = function()
3+
includedirs "../vendor/cpu_features/include/"
4+
end,
5+
6+
run = function()
7+
language "C"
8+
kind "StaticLib"
9+
10+
defines { "STACK_LINE_READER_BUFFER_SIZE=1024" }
11+
12+
files_project "../vendor/cpu_features/" {
13+
"src/**.c",
14+
}
15+
16+
if not os.istarget('linux') then
17+
removefiles "../vendor/cpu_features/src/hwcaps.c"
18+
else
19+
defines {
20+
"HAVE_STRONG_GETAUXVAL",
21+
"HAVE_DLFCN_H"
22+
}
23+
end
24+
end
25+
}

vendor/cpu_features

Submodule cpu_features added at 4e191a4

0 commit comments

Comments
 (0)