about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-12-21 15:51:55 +0100
committerptitSeb <sebastien.chev@gmail.com>2023-12-21 15:51:55 +0100
commit715ce5dbe987c103eeebbda470325866dc614b16 (patch)
tree51c1006e0e8992081a0b6abe21918cc3897a9c16
parent7d0f8078807c9a0d5f4416566da343de419015bf (diff)
downloadbox64-715ce5dbe987c103eeebbda470325866dc614b16.tar.gz
box64-715ce5dbe987c103eeebbda470325866dc614b16.zip
Introduce new BOX64_MAXCPU to cap the number of cpu core exposed, and created profile for wine, wine64 and GridAutosport using it
-rw-r--r--docs/USAGE.md5
-rw-r--r--src/include/debug.h1
-rw-r--r--src/main.c14
-rw-r--r--src/tools/my_cpuid.c4
-rw-r--r--src/tools/rcfile.c1
-rw-r--r--src/wrapped/wrappedlibc.c13
-rw-r--r--system/box64.box64rc15
7 files changed, 48 insertions, 5 deletions
diff --git a/docs/USAGE.md b/docs/USAGE.md
index ebbc7f81..5d3d0772 100644
--- a/docs/USAGE.md
+++ b/docs/USAGE.md
@@ -231,6 +231,11 @@ Handling of x87 80bits long double
 * 0 : Try to handle 80bits long double as precise as possible (Default)

 * 1 : Handle them as double

 

+#### BOX64_MAXCPU

+Maximum CPU Core exposed

+* 0 : Don't cap the number of cpu core exposed (Default)

+* XXX : Cap the maximum CPU Core exposed to XXX (usefull with wine64 or GridAutosport for example)

+

 #### BOX64_SYNC_ROUNDING *

 Box64 will sync rounding mode with fesetround/fegetround.

 * 0 : Disable rounding mode syncing. (Default.)

diff --git a/src/include/debug.h b/src/include/debug.h
index 948b29e4..4ce68cb9 100644
--- a/src/include/debug.h
+++ b/src/include/debug.h
@@ -10,6 +10,7 @@ extern int box64_dynarec;
 extern uintptr_t box64_pagesize;
 extern uintptr_t box64_load_addr;
 extern int box64_dynarec_test;
+extern int box64_maxcpu;
 #ifdef DYNAREC
 extern int box64_dynarec_dump;
 extern int box64_dynarec_trace;
diff --git a/src/main.c b/src/main.c
index db33d9a2..bb8181dd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -49,6 +49,7 @@ int box64_nosandbox = 0;
 int box64_inprocessgpu = 0;
 int box64_malloc_hack = 0;
 int box64_dynarec_test = 0;
+int box64_maxcpu = 0;
 #ifdef DYNAREC
 int box64_dynarec = 1;
 int box64_dynarec_dump = 0;
@@ -971,6 +972,19 @@ void LoadLogEnv()
         if(box64_showbt)
             printf_log(LOG_INFO, "Show a Backtrace when a Segfault signal is caught\n");
     }
+    p = getenv("BOX64_MAXCPU");
+    if(p) {
+        int maxcpu = 0;
+        if(sscanf(p, "%d", &maxcpu)==1)
+                box64_maxcpu = maxcpu;
+        if(box64_maxcpu<0)
+            box64_maxcpu = 0;
+        if(box64_maxcpu) {
+            printf_log(LOG_NONE, "Will not expose more than %d cpu cores\n", box64_maxcpu);
+        } else {
+            printf_log(LOG_NONE, "Will not limit the number of cpu cores exposed\n");
+        }
+    }
     box64_pagesize = sysconf(_SC_PAGESIZE);
     if(!box64_pagesize)
         box64_pagesize = 4096;
diff --git a/src/tools/my_cpuid.c b/src/tools/my_cpuid.c
index 258fb990..5352d0cf 100644
--- a/src/tools/my_cpuid.c
+++ b/src/tools/my_cpuid.c
@@ -83,8 +83,8 @@ int getNCpu()
 {
     if(!nCPU)
         grabNCpu();
-    if(box64_wine && nCPU>64)
-        return 64;
+    if(box64_maxcpu && nCPU>box64_maxcpu)
+        return box64_maxcpu;
     return nCPU;
 }
 
diff --git a/src/tools/rcfile.c b/src/tools/rcfile.c
index b08622f8..39fba1df 100644
--- a/src/tools/rcfile.c
+++ b/src/tools/rcfile.c
@@ -109,6 +109,7 @@ ENTRYBOOL(BOX64_EXIT, want_exit)                        \
 ENTRYBOOL(BOX64_LIBCEF, box64_libcef)                   \
 ENTRYBOOL(BOX64_SDL2_JGUID, box64_sdl2_jguid)           \
 ENTRYINT(BOX64_MALLOC_HACK, box64_malloc_hack, 0, 2, 2) \
+ENTRYINTPOS(BOX64_MAXCPU, box64_maxcpu)                 \
 ENTRYSTRING_(BOX64_ENV, new_env)                        \
 
 #ifdef HAVE_TRACE
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c
index 1dcf17d6..cb329c33 100644
--- a/src/wrapped/wrappedlibc.c
+++ b/src/wrapped/wrappedlibc.c
@@ -1723,6 +1723,15 @@ EXPORT int32_t my_open64(x64emu_t* emu, void* pathname, int32_t flags, uint32_t
         lseek(tmp, 0, SEEK_SET);
         return tmp;
     }
+    if(box64_maxcpu && (!strcmp(pathname, "/sys/devices/system/cpu/present") || !strcmp(pathname, "/sys/devices/system/cpu/online")) && (getNCpu()>=box64_maxcpu)) {
+        // special case for cpu present (to limit to 64 cores)
+        int tmp = shm_open(TMP_CPUPRESENT, O_RDWR | O_CREAT, S_IRWXU);
+        if(tmp<0) return open64(pathname, mode); // error fallback
+        shm_unlink(TMP_CPUPRESENT);    // remove the shm file, but it will still exist because it's currently in use
+        CreateCPUPresentFile(tmp);
+        lseek(tmp, 0, SEEK_SET);
+        return tmp;
+    }
     #endif
     return open64(pathname, flags, mode);
 }
@@ -1748,7 +1757,7 @@ EXPORT FILE* my_fopen64(x64emu_t* emu, const char* path, const char* mode)
         lseek(tmp, 0, SEEK_SET);
         return fdopen(tmp, mode);
     }
-    if(box64_wine && (!strcmp(path, "/sys/devices/system/cpu/present") || !strcmp(path, "/sys/devices/system/cpu/online")) && (getNCpu()>=64)) {
+    if(box64_maxcpu && (!strcmp(path, "/sys/devices/system/cpu/present") || !strcmp(path, "/sys/devices/system/cpu/online")) && (getNCpu()>=box64_maxcpu)) {
         // special case for cpu present (to limit to 64 cores)
         int tmp = shm_open(TMP_CPUPRESENT, O_RDWR | O_CREAT, S_IRWXU);
         if(tmp<0) return fopen64(path, mode); // error fallback
@@ -2263,8 +2272,6 @@ EXPORT int32_t my___cxa_thread_atexit_impl(x64emu_t* emu, void* dtor, void* obj,
     //printf_log(LOG_INFO, "Warning, call to __cxa_thread_atexit_impl(%p, %p, %p) ignored\n", dtor, obj, dso);
     AddCleanup1Arg(emu, dtor, obj, dso);
     return 0;
-
-    return 0;
 }
 
 EXPORT int32_t my___register_atfork(x64emu_t *emu, void* prepare, void* parent, void* child, void* handle)
diff --git a/system/box64.box64rc b/system/box64.box64rc
index 2837fae1..8a69d4a0 100644
--- a/system/box64.box64rc
+++ b/system/box64.box64rc
@@ -59,6 +59,15 @@ BOX64_DYNAREC_ALIGNED_ATOMICS=1
 [geekbench6]
 BOX64_ENV=BOX64_DYNAREC_STRONGMEM=3
 
+[GridAutosport]
+BOX64_DYNAREC_STRONGMEM=1
+BOX64_NOSANDBOX=1
+BOX64_DYNAREC_ALIGNED_ATOMICS=1
+BOX64_SHOWSEGV=1
+BOX64_SHOWBT=1
+BOX64_MAXCPU=16
+
+
 [heroic]
 BOX64_NOSANDBOX=1
 BOX64_INPROCESSGPU=1
@@ -151,6 +160,12 @@ BOX64_MALLOC_HACK=2
 BOX64_NOSANDBOX=1
 BOX64_INPROCESSGPU=1
 
+[wine]
+BOX64_MAXCPU=32
+
+[wine64]
+BOX64_MAXCPU=64
+
 #
 # Wine process
 #