From 0dd05169eef718cc589a5690753066de4d34107b Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Wed, 6 Nov 2024 21:00:49 -0800 Subject: [PATCH] add ability to override entry point type --- src/base/base_entry_point.c | 21 +++++++++++++++------ src/base/base_entry_point.h | 8 +++++++- src/os/core/linux/os_core_linux.c | 2 +- src/os/core/os_core.h | 4 ++++ src/os/core/win32/os_core_win32.c | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/base/base_entry_point.c b/src/base/base_entry_point.c index 7562f8b8..f7632494 100644 --- a/src/base/base_entry_point.c +++ b/src/base/base_entry_point.c @@ -4,21 +4,21 @@ global U64 global_update_tick_idx = 0; internal void -main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **arguments, U64 arguments_count) +main_thread_base_entry_point(EntryPoint entry_point, int argc, char **argv) { Temp scratch = scratch_begin(0, 0); ThreadNameF("[main thread]"); //- rjf: set up telemetry #if PROFILE_TELEMETRY - local_persist U8 tm_data[MB(64)]; + local_persist char tm_data[MB(64)]; tmLoadLibrary(TM_RELEASE); tmSetMaxThreadCount(256); - tmInitialize(sizeof(tm_data), (char *)tm_data); + tmInitialize(sizeof(tm_data), tm_data); #endif //- rjf: parse command line - String8List command_line_argument_strings = os_string_list_from_argcv(scratch.arena, (int)arguments_count, arguments); + String8List command_line_argument_strings = os_string_list_from_argcv(scratch.arena, argc, argv); CmdLine cmdline = cmd_line_from_string_list(scratch.arena, command_line_argument_strings); //- rjf: begin captures @@ -27,6 +27,10 @@ main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **argum { ProfBeginCapture(arguments[0]); } + +#if PROFILE_TELEMETRY + tmMessage(0, TMMF_ICON_NOTE, BUILD_TITLE); +#endif //- rjf: initialize all included layers #if defined(ASYNC_H) && !defined(ASYNC_INIT_MANUAL) @@ -83,16 +87,21 @@ main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **argum #if defined(RADDBG_CORE_H) && !defined(RD_INIT_MANUAL) rd_init(&cmdline); #endif - + //- rjf: call into entry point +#if BASE_ENTRY_POINT_ARGCV + scratch_end(scratch); // release command line memory + entry_point(argc, argv); +#else entry_point(&cmdline); + scratch_end(scratch); +#endif //- rjf: end captures if(capture) { ProfEndCapture(); } - scratch_end(scratch); } internal void diff --git a/src/base/base_entry_point.h b/src/base/base_entry_point.h index dc739fce..01c83199 100644 --- a/src/base/base_entry_point.h +++ b/src/base/base_entry_point.h @@ -4,7 +4,13 @@ #ifndef BASE_ENTRY_POINT_H #define BASE_ENTRY_POINT_H -internal void main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **arguments, U64 arguments_count); +#if BASE_ENTRY_POINT_ARGCV +typedef void (*EntryPoint)(int argc, char **argv); +#else +typedef void (*EntryPoint)(CmdLine *cmdline); +#endif + +internal void main_thread_base_entry_point(EntryPoint entry_point, int argc, char **argv); internal void supplement_thread_base_entry_point(void (*entry_point)(void *params), void *params); internal U64 update_tick_idx(void); internal B32 update(void); diff --git a/src/os/core/linux/os_core_linux.c b/src/os/core/linux/os_core_linux.c index 3ef0a306..3f6ad20c 100644 --- a/src/os/core/linux/os_core_linux.c +++ b/src/os/core/linux/os_core_linux.c @@ -1259,5 +1259,5 @@ main(int argc, char **argv) } //- rjf: call into "real" entry point - main_thread_base_entry_point(entry_point, argv, (U64)argc); + main_thread_base_entry_point(entry_point, argc, argv); } diff --git a/src/os/core/os_core.h b/src/os/core/os_core.h index 79876e45..a752981f 100644 --- a/src/os/core/os_core.h +++ b/src/os/core/os_core.h @@ -342,7 +342,11 @@ internal OS_Guid os_make_guid(void); // into the standard codebase program entry points, named "entry_point". #if BUILD_ENTRY_DEFINING_UNIT +# if BASE_ENTRY_POINT_ARGCV +internal void entry_point(int argc, char **argv); +# else internal void entry_point(CmdLine *cmdline); #endif +#endif #endif // OS_CORE_H diff --git a/src/os/core/win32/os_core_win32.c b/src/os/core/win32/os_core_win32.c index 7a850674..c4d3a9a8 100644 --- a/src/os/core/win32/os_core_win32.c +++ b/src/os/core/win32/os_core_win32.c @@ -1678,7 +1678,7 @@ w32_entry_point_caller(int argc, WCHAR **wargv) os_w32_state.entity_arena = arena_alloc(); //- rjf: call into "real" entry point - main_thread_base_entry_point(entry_point, argv, (U64)argc); + main_thread_base_entry_point(entry_point, argc, argv); } #if BUILD_CONSOLE_INTERFACE