blob: 7e57ea74b74404946d9403952f21200706f62770 [file] [log] [blame] [raw]
/* A part of the Native C Library for Windows NT
Copyright 2007-2015 PC GO Ld.
Copyright 2015-2024 Rivoreo
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/
#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-2024 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 (smss.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 ?
(__init_keyboard() < 0 ? TTY_FD_INVALID : 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;
}