blob: b27779332884e2fde47495e571c76390b8d29bfd [file] [log] [blame] [raw]
#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\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"
"Compiled by GCC " __VERSION__ ", on " BUILD_DATE "\n";
static void init_console(const RTL_USER_PROCESS_PARAMETERS *process_parameters) {
int stdout_fd = (int)process_parameters->StandardOutput;
int stderr_fd = (int)process_parameters->StandardError;
if(stdout_fd) _set_stdout_fd(stdout_fd);
if(stderr_fd) _set_stderr_fd(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;
}