2000-07-01 11:51:55 +08:00
|
|
|
/* common.cc: common crt0 function for cygwin crt0's.
|
|
|
|
|
2001-09-12 04:01:02 +08:00
|
|
|
Copyright 2000, 2001 Red Hat, Inc.
|
2000-07-01 11:51:55 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
2000-09-08 23:54:36 +08:00
|
|
|
#include "perprocess.h"
|
|
|
|
#include "cygwin/version.h"
|
2000-07-01 11:51:55 +08:00
|
|
|
#include "crt0.h"
|
|
|
|
#include <reent.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2000-07-17 08:24:56 +08:00
|
|
|
#undef environ
|
|
|
|
|
2000-07-01 11:51:55 +08:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
char **environ;
|
|
|
|
int cygwin_attach_dll (HMODULE, MainFunc);
|
|
|
|
int cygwin_attach_noncygwin_dll (HMODULE, MainFunc);
|
|
|
|
int main (int, char **, char **);
|
|
|
|
struct _reent *_impure_ptr;
|
|
|
|
int _fmode;
|
2002-12-10 06:49:12 +08:00
|
|
|
void _pei386_runtime_relocator ();
|
2000-07-01 11:51:55 +08:00
|
|
|
|
|
|
|
/* Set up pointers to various pieces so the dll can then use them,
|
|
|
|
and then jump to the dll. */
|
|
|
|
|
2000-07-08 12:36:27 +08:00
|
|
|
int __stdcall
|
|
|
|
_cygwin_crt0_common (MainFunc f, per_process *u)
|
2000-07-01 11:51:55 +08:00
|
|
|
{
|
|
|
|
/* This is used to record what the initial sp was. The value is needed
|
|
|
|
when copying the parent's stack to the child during a fork. */
|
2000-07-08 12:36:27 +08:00
|
|
|
DWORD newu;
|
|
|
|
int uwasnull;
|
|
|
|
|
|
|
|
if (u != NULL)
|
|
|
|
uwasnull = 0; /* Caller allocated space for per_process structure */
|
|
|
|
else if ((newu = cygwin_internal (CW_USER_DATA)) == (DWORD) -1)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u = (per_process *) newu; /* Using DLL built-in per_process */
|
|
|
|
uwasnull = 1; /* Remember for later */
|
|
|
|
}
|
2000-07-01 11:51:55 +08:00
|
|
|
|
|
|
|
/* The version numbers are the main source of compatibility checking.
|
|
|
|
As a backup to them, we use the size of the per_process struct. */
|
2000-07-08 12:36:27 +08:00
|
|
|
u->magic_biscuit = sizeof (per_process);
|
2000-07-01 11:51:55 +08:00
|
|
|
|
|
|
|
/* cygwin.dll version number in effect at the time the app was created. */
|
2000-07-08 12:36:27 +08:00
|
|
|
u->dll_major = CYGWIN_VERSION_DLL_MAJOR;
|
|
|
|
u->dll_minor = CYGWIN_VERSION_DLL_MINOR;
|
|
|
|
u->api_major = CYGWIN_VERSION_API_MAJOR;
|
|
|
|
u->api_minor = CYGWIN_VERSION_API_MINOR;
|
|
|
|
|
|
|
|
u->ctors = &__CTOR_LIST__;
|
|
|
|
u->dtors = &__DTOR_LIST__;
|
2000-07-15 10:48:11 +08:00
|
|
|
u->envptr = &environ;
|
2000-07-08 12:36:27 +08:00
|
|
|
if (uwasnull)
|
|
|
|
_impure_ptr = u->impure_ptr; /* Use field initialized in newer DLLs. */
|
|
|
|
else
|
|
|
|
u->impure_ptr_ptr = &_impure_ptr; /* Older DLLs need this. */
|
2000-11-13 12:06:41 +08:00
|
|
|
|
2000-07-08 12:36:27 +08:00
|
|
|
u->forkee = 0; /* This should only be set in dcrt0.cc
|
|
|
|
when the process is actually forked */
|
|
|
|
u->main = f;
|
2000-07-01 11:51:55 +08:00
|
|
|
|
2000-07-08 12:36:27 +08:00
|
|
|
/* These functions are executed prior to main. They are just stubs unless the
|
|
|
|
user overrides them. */
|
|
|
|
u->premain[0] = cygwin_premain0;
|
|
|
|
u->premain[1] = cygwin_premain1;
|
|
|
|
u->premain[2] = cygwin_premain2;
|
|
|
|
u->premain[3] = cygwin_premain3;
|
|
|
|
u->fmode_ptr = &_fmode;
|
|
|
|
u->initial_sp = (char *) __builtin_frame_address (1);
|
2000-07-01 11:51:55 +08:00
|
|
|
|
|
|
|
/* Remember whatever the user linked his application with - or
|
|
|
|
point to entries in the dll. */
|
2000-07-08 12:36:27 +08:00
|
|
|
u->malloc = &malloc;
|
|
|
|
u->free = &free;
|
|
|
|
u->realloc = &realloc;
|
|
|
|
u->calloc = &calloc;
|
2000-07-01 11:51:55 +08:00
|
|
|
|
|
|
|
/* Setup the module handle so fork can get the path name. */
|
2000-07-08 12:36:27 +08:00
|
|
|
u->hmodule = GetModuleHandle (0);
|
2000-07-01 11:51:55 +08:00
|
|
|
|
|
|
|
/* variables for fork */
|
2000-07-08 12:36:27 +08:00
|
|
|
u->data_start = &_data_start__;
|
|
|
|
u->data_end = &_data_end__;
|
|
|
|
u->bss_start = &_bss_start__;
|
|
|
|
u->bss_end = &_bss_end__;
|
2002-12-10 06:49:12 +08:00
|
|
|
|
|
|
|
_pei386_runtime_relocator ();
|
2000-07-08 12:36:27 +08:00
|
|
|
return 1;
|
2000-07-01 11:51:55 +08:00
|
|
|
}
|
|
|
|
} /* "C" */
|