22 uint32_t windows_version_bits = GetVersion();
23 int32_t minor_version = (windows_version_bits >> 8) & 0xff;
27 uint32_t major_version = (uint32_t)(uint8_t)windows_version_bits;
39 startup_frame[-1] = 0;
46 STARTUPINFOA startup_info;
47 startup_info.dwFlags = 0;
48 GetStartupInfoA(&startup_info);
51 int show_window = startup_info.dwFlags & STARTF_USESHOWWINDOW ? startup_info.wShowWindow :
SW_SHOWDEFAULT;
73 if (allocated_bytes < (next_handler_slot - handler_base + 1) *
sizeof(*next_handler_slot))
78 if (!resized_handlers)
87 next_handler_slot = resized_handlers + used_bytes /
sizeof(*resized_handlers);
91 *next_handler_slot = callback;
112 if (!handler_allocation)
118 *handler_allocation = NULL;
138 __builtin_unreachable();
146 __builtin_unreachable();
151void _doexit(int32_t status, int32_t quick_exit, int32_t return_to_caller)
155 TerminateProcess(GetCurrentProcess(), status);
182 if (return_to_caller)
194 for (
void (**initializer_slot)() = first; initializer_slot < last; initializer_slot = &initializer_slot[1])
196 void (*initializer)(void) = *initializer_slot;
212 __builtin_unreachable();
238 while (*cursor && *cursor !=
'"')
249 while ((uint8_t)*cursor >
' ')
253 while (*cursor && (uint8_t)*cursor <=
' ')
272 char **slot =
CRT_malloc((count + 1) *
sizeof(*slot));
280 size_t size =
_strlen(entry) + 1;
302 int32_t char_count_out;
310 _parse_cmdline(command_line, NULL, NULL, &argc_out, &char_count_out);
312 char **argv =
CRT_malloc(char_count_out + argc_out *
sizeof(*argv));
315 char *arg_buffer = (
char *)(argv + argc_out);
316 _parse_cmdline(command_line, argv, arg_buffer, &argc_out, &char_count_out);
318 int32_t result = argc_out - 1;
329void _parse_cmdline(
char *command_line,
char **argv,
char *arg_buffer, int32_t *argc_out, int32_t *char_count_out)
331 char *input = command_line;
332 char *output = arg_buffer;
341 while (*input && *input !=
'"')
349 *output++ = *input++;
366 char character = *input++;
368 *output++ = character;
378 if (character ==
'\0')
383 if (character ==
' ' || character ==
'\t')
392 bool in_quotes =
false;
395 while (*input ==
' ' || *input ==
'\t')
405 unsigned int backslashes = 0;
406 while (*input ==
'\\')
412 bool copy_character =
true;
415 if ((backslashes & 1) == 0)
417 if (in_quotes && input[1] ==
'"')
420 copy_character =
false;
421 in_quotes = !in_quotes;
426 while (backslashes > 0)
434 if (!*input || (!in_quotes && (*input ==
' ' || *input ==
'\t')))
472 wide = GetEnvironmentStringsW();
477 ansi = GetEnvironmentStrings();
484 wide = GetEnvironmentStringsW();
489 ansi = GetEnvironmentStrings();
499 const char *end = ansi;
506 size_t bytes = (size_t)(end - ansi) + 1;
510 FreeEnvironmentStringsA(ansi);
514 const WCHAR *end = wide;
521 int characters = (int)(end - wide) + 1;
522 int bytes = WideCharToMultiByte(CP_ACP, 0, wide, characters, NULL, 0, NULL, NULL);
527 if (copy && !WideCharToMultiByte(CP_ACP, 0, wide, characters, copy, bytes, NULL, NULL))
533 FreeEnvironmentStringsW(wide);
558 const uint32_t error_id = (uint32_t)runtime_error_id;
560 while (error_entry < g_crtRuntimeErrors + 18 && error_entry->
error_id !=
error_id)
575 char program_path[MAX_PATH];
577 if (!GetModuleFileNameA(NULL, program_path,
sizeof(program_path)))
578 CRT_strcpy(program_path,
"<program name unknown>");
580 char *display_path = program_path;
582 if (
_strlen(program_path) + 1 > 0x3c)
584 display_path = program_path +
_strlen(program_path) - 59;
590 CRT_strcpy(text,
"Runtime Error!\n\nProgram: ");
602 HWND owner_window = NULL;
606 HMODULE h_module = LoadLibraryA(
"user32.dll");
620 if (get_active_window)
622 owner_window = get_active_window();
628 if (get_last_active_popup)
629 owner_window = get_last_active_popup(owner_window);
#define g_pGetLastActivePopup
#define g_crtGetModuleHandleAPtr
#define CRT_FATAL_EXIT_STATUS
@ CRT_RUNTIME_ARGUMENT_SPACE
@ CRT_RUNTIME_ENVIRONMENT_SPACE
@ CRT_APPLICATION_CONSOLE
uint32_t CRT_msize(void *ptr)
int32_t _heap_init(int32_t mt_flag)
void * CRT_malloc(uint32_t size)
void * CRT_realloc(void *ptr, uint32_t size)
void(*)() CRT_onexit(void(*callback)())
char * CRT_strcat(char *dest, char const *src)
char * _strncpy(char *dest, char const *src, uint32_t count)
char * CRT_MoveBytesOverlapSafe(char *dest, char const *src, uint32_t count)
uint32_t _strlen(char const *str)
int32_t CRT_ismbblead(uint32_t character)
char * CRT_strcpy(char *dest, char const *src)
#define g_crtPreTerminators
#define g_crtExitProcessing
#define g_crtStartupFlags
#define g_crtEnvStringsMode
#define g_crtCommandLineBuffer
#define g_pCRT_ErrorHandler
#define g_crtFloatingPointInitializer
#define g_crtMultibyteClassTable
#define g_crtSubsystemInitializers
#define g_CRT_EnvironmentBlock
#define g_crtApplicationInitializers
#define g_crtExitInProgress
#define g_crtRuntimeErrors
#define g_crtRuntimeErrorBannerCallback
char * __crtGetEnvironmentStringsA()
int32_t CRT_atexit(CRT_ExitCallback callback)
void _parse_cmdline(char *command_line, char **argv, char *arg_buffer, int32_t *argc_out, int32_t *char_count_out)
void _doexit(int32_t status, int32_t quick_exit, int32_t return_to_caller)
void CRT_InitializeAndRunWinMain(int32_t *startup_frame)
void __amsg_exit(int32_t runtime_error)
void CRT_exit_immediate(int32_t status)
int32_t CRT_ShowMessageBoxA(LPCSTR lp_text, LPCSTR lp_caption, UINT u_type)
void CRT_initterm(void(**first)(), void(**last)())
void CRT_exit(int32_t status)
@ CRT_EXIT_TABLE_GROWTH_BYTES
@ CRT_EXIT_TABLE_INITIAL_BYTES
void CRT_WriteRuntimeErrorBanner()
void CRT_fast_error_exit(int32_t runtime_error)
char * CRT_SkipProgramNameInCmdLine()
void _NMSG_WRITE(int32_t runtime_error_id)
#define g_windowsVersionMinor
#define g_windowsVersionCombined
#define g_environmentBlock
void(* CRT_ExitCallback)(void)
#define g_atexitHandlerNext
#define g_windowsVersionMajor
#define g_atexitHandlerBase