From 7b9e07899108fbd0198cfebde36d6b74777c7778 Mon Sep 17 00:00:00 2001 From: James Dansereau <106631954+jkdansereau@users.noreply.github.com> Date: Wed, 2 Sep 2026 23:03:46 -0400 Subject: [PATCH] linux-runtime: declare getenv()/realloc() for the strict-host build The N64 stub declares neither. MinGW's other CRT headers leak them; a strict host GCC (Linux/macOS, -std=gnu11) does not, so getenv()'s 64-bit char* return is assumed int and truncated -> configGetFrameDump (GE_PCDUMP path) dereferenced a low-32 pointer and segfaulted. Add K&R decls: pc_protos.h (D38 mechanism -> game TUs via ) and the port/shim/stdlib.h non-Windows branch (-> port TUs that #include ). K&R form stays compatible with the real prototypes; malloc/ calloc/free are already covered elsewhere so not repeated. --- port/include/pc_protos.h | 5 +++++ port/shim/stdlib.h | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/port/include/pc_protos.h b/port/include/pc_protos.h index 836819f9..6d4096e8 100644 --- a/port/include/pc_protos.h +++ b/port/include/pc_protos.h @@ -201,6 +201,11 @@ void fileUpdateSelectedBondInSave(); s32 fogGetPropDistColor(); void fogLoadLevelEnvironment(); void free(); +/* D38: the N64 stub declares neither, and unlike MinGW a strict + * host GCC does not leak them — so getenv()'s 64-bit pointer return is + * truncated to int (crashed configGetFrameDump on Linux). */ +char * getenv(); +void * realloc(); int frontGetPlayersFavoriteWeaponInHand(); void generate_player_thrown_grenade(); void generate_player_thrown_knife(); diff --git a/port/shim/stdlib.h b/port/shim/stdlib.h index 868956c1..5512a05f 100644 --- a/port/shim/stdlib.h +++ b/port/shim/stdlib.h @@ -17,4 +17,15 @@ #include "hoststdlib.h" #else #include "include/stdlib.h" +#if !defined(_WIN32) +/* The N64 stub declares only lldiv_t/ldiv_t + lldiv/ldiv. MinGW's other CRT + * headers leak getenv() etc.; a strict host GCC (Linux/macOS) does not, so + * getenv()'s 64-bit pointer return is assumed int and truncated (crashed + * configGetFrameDump). Declare the pointer-returning stragglers the port + + * game code use that nothing else declares. K&R form = compatible with any + * real prototype. (malloc/calloc/free are in port/include/pc_protos.h and + * a few port TUs' own local decls — not repeated here to avoid conflicts.) */ +extern char *getenv(); +extern void *realloc(); +#endif #endif