| #include "version.h" |
| #include "build-version.h" |
| #include <windows.h> |
| #include <nt.h> |
| #include <unistd.h> |
| |
| void __initenv_from_wenvblock(const wchar_t *); |
| |
| static const char version[] = "Native C Library for Windows NT\n" |
| "Version " VERSION " (" PKGVERSION ")\n" |
| "Copyright 2007-2015 PC GO Ld.\n" |
| "Copyright 2015-2017 Rivoreo\n\n" |
| "This is free software published under GNU GPL 2;\nsee the source code for more details.\n" |
| "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\nPARTICULAR PURPOSE.\n\n" |
| #ifdef __GUNC__ |
| "Compiled by GCC " __VERSION__ ", on " BUILD_DATE "\n" |
| #endif |
| ; |
| |
| static void init_console(const RTL_USER_PROCESS_PARAMETERS *process_parameters) { |
| int stdin_fd = (int)process_parameters->StandardInput; |
| int stdout_fd = (int)process_parameters->StandardOutput; |
| int stderr_fd = (int)process_parameters->StandardError; |
| |
| /* The standard handles for init process (sess.exe) are 0; in this |
| * case we set the internal file descriptors to default state, which |
| * is reading from /Device/KeyboardClass0 and writing via |
| * NtDisplayString. */ |
| _set_stdin_fd(stdin_fd == 0 ? TTY_FD_DEFAULT : stdin_fd); |
| _set_stdout_fd(stdout_fd == 0 ? TTY_FD_DEFAULT : stdout_fd); |
| _set_stderr_fd(stderr_fd == 0 ? TTY_FD_DEFAULT : stderr_fd); |
| } |
| |
| int __stdcall DllMainCRTStartup(void *dll, unsigned long int reason, void *reserved) { |
| PROCESS_BASIC_INFORMATION pbi; |
| NtQueryInformationProcess((void *)-1, ProcessBasicInformation, &pbi, sizeof pbi, NULL); |
| RTL_USER_PROCESS_PARAMETERS *process_parameters = RtlNormalizeProcessParams(pbi.PebBaseAddress->ProcessParameters); |
| if(dll == pbi.PebBaseAddress) { |
| init_console(process_parameters); |
| write(STDOUT_FILENO, version, sizeof version - 1); |
| _exit(0); |
| return 0; |
| } |
| if(reason == DLL_PROCESS_ATTACH) { |
| init_console(process_parameters); |
| __initenv_from_wenvblock(process_parameters->Environment); |
| } |
| return 1; |
| } |