Welcome to mirror list, hosted at ThFree Co, Russian Federation.

_cygwin_crt0_common.cc « lib « cygwin « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ca249c69b90c8d54c9165030ba05309aa7e75201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* common.cc: common crt0 function for cygwin crt0's.

   Copyright 2000 Cygnus Solutions.

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"
#include "crt0.h"
#include <reent.h>
#include <stdlib.h>

extern __declspec(dllimport) per_process __cygwin_user_data;

extern "C"
{
char **environ;
void cygwin_crt0 (MainFunc);
int cygwin_attach_dll (HMODULE, MainFunc);
int cygwin_attach_noncygwin_dll (HMODULE, MainFunc);
int main (int, char **, char **);
struct _reent *_impure_ptr;
int _fmode;

/* Set up pointers to various pieces so the dll can then use them,
   and then jump to the dll.  */

void
_cygwin_crt0_common (MainFunc f)
{
  /* 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.  */
  int onstack;

  /* The version numbers are the main source of compatibility checking.
     As a backup to them, we use the size of the per_process struct.  */
  __cygwin_user_data.magic_biscuit = sizeof (per_process);

  /* cygwin.dll version number in effect at the time the app was created.  */
  __cygwin_user_data.dll_major = CYGWIN_VERSION_DLL_MAJOR;
  __cygwin_user_data.dll_minor = CYGWIN_VERSION_DLL_MINOR;
  __cygwin_user_data.api_major = CYGWIN_VERSION_API_MAJOR;
  __cygwin_user_data.api_minor = CYGWIN_VERSION_API_MINOR;

  __cygwin_user_data.ctors = &__CTOR_LIST__;
  __cygwin_user_data.dtors = &__DTOR_LIST__;
  __cygwin_user_data.envptr = &environ;
  __cygwin_user_data.impure_ptr_ptr = &_impure_ptr;
  __cygwin_user_data.main = f;
  __cygwin_user_data.premain[0] = cygwin_premain0;
  __cygwin_user_data.premain[1] = cygwin_premain1;
  __cygwin_user_data.premain[2] = cygwin_premain2;
  __cygwin_user_data.premain[3] = cygwin_premain3;
  __cygwin_user_data.fmode_ptr = &_fmode;
  __cygwin_user_data.initial_sp = (char *) &onstack;

  /* Remember whatever the user linked his application with - or
     point to entries in the dll.  */
  __cygwin_user_data.malloc = &malloc;
  __cygwin_user_data.free = &free;
  __cygwin_user_data.realloc = &realloc;
  __cygwin_user_data.calloc = &calloc;

  /* Setup the module handle so fork can get the path name. */
  __cygwin_user_data.hmodule = GetModuleHandle (0);

  /* variables for fork */
  __cygwin_user_data.data_start = &_data_start__;
  __cygwin_user_data.data_end = &_data_end__;
  __cygwin_user_data.bss_start = &_bss_start__;
  __cygwin_user_data.bss_end = &_bss_end__;
}
} /* "C" */