diff options
| author | Yang Liu <liuyang22@iscas.ac.cn> | 2025-10-17 19:01:37 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-17 13:01:37 +0200 |
| commit | 88aefd44adea974b5f6f5b393141b1e165f403c3 (patch) | |
| tree | ee8d627af35c0838fcb73d9720747e24e10e8306 | |
| parent | c8f6041ab0cecf777aea51303efb08cf0781b2ce (diff) | |
| download | box64-88aefd44adea974b5f6f5b393141b1e165f403c3.tar.gz box64-88aefd44adea974b5f6f5b393141b1e165f403c3.zip | |
[ENV] Added a new BOX64_ARCH option (#3076)
| -rw-r--r-- | docs/USAGE.md | 179 | ||||
| -rw-r--r-- | docs/box64.pod | 10 | ||||
| -rw-r--r-- | docs/gen/gen.py | 4 | ||||
| -rw-r--r-- | docs/gen/usage.json | 28 | ||||
| -rw-r--r-- | src/include/env.h | 1 | ||||
| -rw-r--r-- | src/tools/env.c | 50 |
6 files changed, 177 insertions, 95 deletions
diff --git a/docs/USAGE.md b/docs/USAGE.md index d9a26546..f8caf164 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -217,91 +217,6 @@ Use hardware counter for rdtsc if available. * 0: Use hardware counter for rdtsc opcode if available. [Default] * 1: Use hardware counter for rdtsc if and only if precision is at least 1GHz. -## Libraries - -### BOX64_ADDLIBS - -Add extras to the needed libraries list, rarely needed. - - * XXXX: Add library XXXX to the needed libraries list. - * XXXX:YYYY:ZZZZ: Add library XXXX, YYYY and ZZZZ to the needed libraries list. - -### BOX64_ALLOWMISSINGLIBS - -Allow missing libraries to be ignored. - - * 0: Do not allow missing libraries. [Default] - * 1: Allow missing libraries. - -### BOX64_EMULATED_LIBS - -Force the use of emulated libraries. - - * XXXX: Force the use of emulated library XXXX. - * XXXX:YYYY:ZZZZ: Force the use of emulated libraries XXXX, YYYY and ZZZZ. - -### BOX64_LD_LIBRARY_PATH - -Path to look for x86_64 libraries. - - * XXXX: Add path XXXX to the library path. - -### BOX64_LD_PRELOAD - -Force loading libraries with the binary. - - * XXXX: Force the loading of library XXXX. - * XXXX:YYYY: Force the loading of libraries XXXX and YYYY. - -### BOX64_LIBGL - -Set the name for libGL. - - * libXXXX: Set the name for libGL to libXXXX. - * /path/to/libXXXX: Set the name and path for libGL to /path/to/libXXXX, you can also use SDL_VIDEO_GL_DRIVER. - -### BOX64_NOGTK - -Do not load wrapped GTK libraries. - - * 0: Load wrapped GTK libraries. [Default] - * 1: Do not load wrapped GTK libraries. - -### BOX64_NOPULSE - -Do not load PulseAudio libraries (both native and x86_64). - - * 0: Load PulseAudio libraries. [Default] - * 1: Do not load PulseAudio libraries. - -### BOX64_NOVULKAN - -Do not load Vulkan libraries. - - * 0: Load Vulkan libraries. [Default] - * 1: Do not load Vulkan libraries, both native and x86_64. - -### BOX64_PREFER_EMULATED - -Prefer emulated libraries over native ones. - - * 0: Prefer native libraries over emulated ones. [Default] - * 1: Prefer emulated libraries over native ones. - -### BOX64_PREFER_WRAPPED - -Prefer wrapped libs first even if the lib is specified with absolute path. - - * 0: Prefer libs with absolute path over wrapped ones. [Default] - * 1: Prefer wrapped libs first even if the lib is specified with absolute path. - -### BOX64_WRAP_EGL - -Prefer wrapped libs for EGL and GLESv2. - - * 0: Prefer emulated libs for EGL and GLESv2. [Default] - * 1: Prefer wrapped libs for EGL and GLESv2. - ## Arguments ### BOX64_ARGS @@ -348,6 +263,15 @@ Add --no-sandbox argument to the guest program. ## Compatibility +### BOX64_ARCH + +Specify the architecture in rcfiles to which the current entry applies. This option only takes effect when used inside rcfiles. + + * `arm64`: Only apply current entry for AArch64. + * `la64`: Only apply current entry for LoongArch64. + * `rv64`: Only apply current entry for RISC-V. + * `<empty>`: Apply current entry for all architectures, will be replaced by more specific entries. [Default] + ### BOX64_AVX Expose AVX extension to CPUID and cpuinfo file. Default value is 2 on Arm64 because it's fully implemented in DynaRec, 0 otherwise. Availble in WowBox64. @@ -766,3 +690,88 @@ Add an environment variable. * XXXX=yyyy: Add environment variable XXXX with value yyyy. +## Libraries + +### BOX64_ADDLIBS + +Add extras to the needed libraries list, rarely needed. + + * XXXX: Add library XXXX to the needed libraries list. + * XXXX:YYYY:ZZZZ: Add library XXXX, YYYY and ZZZZ to the needed libraries list. + +### BOX64_ALLOWMISSINGLIBS + +Allow missing libraries to be ignored. + + * 0: Do not allow missing libraries. [Default] + * 1: Allow missing libraries. + +### BOX64_EMULATED_LIBS + +Force the use of emulated libraries. + + * XXXX: Force the use of emulated library XXXX. + * XXXX:YYYY:ZZZZ: Force the use of emulated libraries XXXX, YYYY and ZZZZ. + +### BOX64_LD_LIBRARY_PATH + +Path to look for x86_64 libraries. + + * XXXX: Add path XXXX to the library path. + +### BOX64_LD_PRELOAD + +Force loading libraries with the binary. + + * XXXX: Force the loading of library XXXX. + * XXXX:YYYY: Force the loading of libraries XXXX and YYYY. + +### BOX64_LIBGL + +Set the name for libGL. + + * libXXXX: Set the name for libGL to libXXXX. + * /path/to/libXXXX: Set the name and path for libGL to /path/to/libXXXX, you can also use SDL_VIDEO_GL_DRIVER. + +### BOX64_NOGTK + +Do not load wrapped GTK libraries. + + * 0: Load wrapped GTK libraries. [Default] + * 1: Do not load wrapped GTK libraries. + +### BOX64_NOPULSE + +Do not load PulseAudio libraries (both native and x86_64). + + * 0: Load PulseAudio libraries. [Default] + * 1: Do not load PulseAudio libraries. + +### BOX64_NOVULKAN + +Do not load Vulkan libraries. + + * 0: Load Vulkan libraries. [Default] + * 1: Do not load Vulkan libraries, both native and x86_64. + +### BOX64_PREFER_EMULATED + +Prefer emulated libraries over native ones. + + * 0: Prefer native libraries over emulated ones. [Default] + * 1: Prefer emulated libraries over native ones. + +### BOX64_PREFER_WRAPPED + +Prefer wrapped libs first even if the lib is specified with absolute path. + + * 0: Prefer libs with absolute path over wrapped ones. [Default] + * 1: Prefer wrapped libs first even if the lib is specified with absolute path. + +### BOX64_WRAP_EGL + +Prefer wrapped libs for EGL and GLESv2. + + * 0: Prefer emulated libs for EGL and GLESv2. [Default] + * 1: Prefer wrapped libs for EGL and GLESv2. + diff --git a/docs/box64.pod b/docs/box64.pod index a95613a5..f20e9f9d 100644 --- a/docs/box64.pod +++ b/docs/box64.pod @@ -65,6 +65,16 @@ Allow missing libraries to be ignored. * 1 : Allow missing libraries. +=item B<BOX64_ARCH> =I<`arm64`|`la64`|`rv64`|`<empty>`> + +Specify the architecture in rcfiles to which the current entry applies. This option only takes effect when used inside rcfiles. + + * `arm64` : Only apply current entry for AArch64. + * `la64` : Only apply current entry for LoongArch64. + * `rv64` : Only apply current entry for RISC-V. + * `<empty>` : Apply current entry for all architectures, will be replaced by more specific entries. [Default] + + =item B<BOX64_ARGS> =I<XXXX|XXXX YYYY ZZZZ> Arguments to pass to the guest program, only valid if there is no existing arguments. diff --git a/docs/gen/gen.py b/docs/gen/gen.py index e17b67fc..6dd77d84 100644 --- a/docs/gen/gen.py +++ b/docs/gen/gen.py @@ -63,8 +63,8 @@ This configuration will apply the specified settings application-wide to any exe for entry in data: categories[entry["category"]].append(entry) - # Put "Performance" at the top - sorted_categories = sorted(categories.items(), key=lambda x: x[0] != "Performance") + # Put "Performance" at the top, then sort the rest alphabetically + sorted_categories = sorted(categories.items(), key=lambda x: (x[0] != "Performance", x[0])) for category, entries in sorted_categories: md_file.write(f"## {category}\n\n") for entry in entries: diff --git a/docs/gen/usage.json b/docs/gen/usage.json index 53cc74b5..f96bb1c5 100644 --- a/docs/gen/usage.json +++ b/docs/gen/usage.json @@ -36,6 +36,34 @@ ] }, { + "name": "BOX64_ARCH", + "description": "Specify the architecture in rcfiles to which the current entry applies. This option only takes effect when used inside rcfiles.", + "category": "Compatibility", + "wine": false, + "options": [ + { + "key": "`arm64`", + "description": "Only apply current entry for AArch64.", + "default": false + }, + { + "key": "`la64`", + "description": "Only apply current entry for LoongArch64.", + "default": false + }, + { + "key": "`rv64`", + "description": "Only apply current entry for RISC-V.", + "default": false + }, + { + "key": "`<empty>`", + "description": "Apply current entry for all architectures, will be replaced by more specific entries.", + "default": true + } + ] + }, + { "name": "BOX64_ARGS", "description": "Arguments to pass to the guest program, only valid if there is no existing arguments.", "category": "Arguments", diff --git a/src/include/env.h b/src/include/env.h index 3e6a7342..6b793881 100644 --- a/src/include/env.h +++ b/src/include/env.h @@ -33,6 +33,7 @@ extern char* ftrace_name; #define ENVSUPER1() \ STRING(BOX64_ADDLIBS, addlibs, 0) \ BOOLEAN(BOX64_ALLOWMISSINGLIBS, allow_missing_libs, 0, 0) \ + STRING(BOX64_ARCH, arch, 0) \ STRING(BOX64_ARGS, args, 0) \ STRING(BOX64_BASH, bash, 0) \ BOOLEAN(BOX64_CEFDISABLEGPU, cefdisablegpu, 0, 0) \ diff --git a/src/tools/env.c b/src/tools/env.c index d81d6f6d..4e41ed74 100644 --- a/src/tools/env.c +++ b/src/tools/env.c @@ -288,19 +288,53 @@ static void freeEnv(box64env_t* env) #undef STRING } +#ifdef ARM64 +#define ENV_ARCH "arm64" +#elif defined(RV64) +#define ENV_ARCH "rv64" +#elif defined(LA64) +#define ENV_ARCH "la64" +#else +#warning "Unknown architecture for ENV_ARCH" +#define ENV_ARCH "unknown" +#endif + static void pushNewEntry(const char* name, box64env_t* env, int gen) { + if (env->is_arch_overridden && *env->arch == '\0') env->is_arch_overridden = 0; + + // Arch specific but not match, ignore + if (env->is_arch_overridden && strcasecmp(env->arch, ENV_ARCH)) { + freeEnv(env); + return; + } khint_t k; kh_box64env_entry_t* khp = gen ? box64env_entries_gen : box64env_entries; k = kh_get(box64env_entry, khp, name); + // No entry exist, add a new one if (k == kh_end(khp)) { int ret; k = kh_put(box64env_entry, khp, box_strdup(name), &ret); - } else { + box64env_t* p = &kh_value(khp, k); + memcpy(p, env, sizeof(box64env_t)); + return; + } + + // Entry exists, replace it if the new one is arch specific + if (env->is_arch_overridden && !strcasecmp(env->arch, ENV_ARCH)) { freeEnv(&kh_value(khp, k)); + box64env_t* p = &kh_value(khp, k); + memcpy(p, env, sizeof(box64env_t)); + return; } + + // Entry exists, the new one is generic, replace it only if existing one is also generic box64env_t* p = &kh_value(khp, k); - memcpy(p, env, sizeof(box64env_t)); + if (!p->is_arch_overridden) { + freeEnv(p); + box64env_t* p = &kh_value(khp, k); + memcpy(p, env, sizeof(box64env_t)); + } } #ifdef ANDROID @@ -612,12 +646,12 @@ void LoadEnvVariables() box64env.is_##name##_overridden = 1; \ box64env.is_any_overridden = 1; \ } -#define STRING(NAME, name, wine) \ - p = GETENV(#NAME, wine); \ - if (p) { \ - box64env.name = strdup(p); \ - box64env.is_##name##_overridden = 1; \ - box64env.is_any_overridden = 1; \ +#define STRING(NAME, name, wine) \ + p = GETENV(#NAME, wine); \ + if (p && strcasecmp(#NAME, "BOX64_ARCH")) { \ + box64env.name = strdup(p); \ + box64env.is_##name##_overridden = 1; \ + box64env.is_any_overridden = 1; \ } ENVSUPER() #undef INTEGER |