Cygwin: strptime: add release note
[newlib-cygwin.git] / winsup / cygwin / lib / _cygwin_crt0_common.cc
blobd356a50fba72dca62f05feb176ca3f6e9907f32a
1 /* _cygwin_crt0_common.cc: common crt0 function for cygwin crt0's.
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
9 #include "winsup.h"
10 #include "crt0.h"
11 #include "cygwin-cxx.h"
13 /* Weaken these declarations so the references don't pull in C++ dependencies
14 unnecessarily. */
15 #define WEAK __attribute__ ((weak))
17 #define REAL_ZNWX "__real__Znwm"
18 #define REAL_ZNAX "__real__Znam"
19 #define REAL_ZNWX_NOTHROW_T "__real__ZnwmRKSt9nothrow_t"
20 #define REAL_ZNAX_NOTHROW_T "__real__ZnamRKSt9nothrow_t"
21 #define REAL_ZDLPV _SYMSTR (__real__ZdlPv)
22 #define REAL_ZDAPV _SYMSTR (__real__ZdaPv)
23 #define REAL_ZDLPV_NOTHROW_T _SYMSTR (__real__ZdlPvRKSt9nothrow_t)
24 #define REAL_ZDAPV_NOTHROW_T _SYMSTR (__real__ZdaPvRKSt9nothrow_t)
26 /* Use asm names to bypass the --wrap that is being applied to redirect all other
27 references to these operators toward the redirectors in the Cygwin DLL; this
28 way we can record what definitions were visible at final link time but still
29 send all calls to the redirectors. */
30 extern WEAK void *operator new(std::size_t sz) noexcept (false)
31 __asm__ (REAL_ZNWX);
32 extern WEAK void *operator new[](std::size_t sz) noexcept (false)
33 __asm__ (REAL_ZNAX);
34 extern WEAK void operator delete(void *p) noexcept (true)
35 __asm__ (REAL_ZDLPV);
36 extern WEAK void operator delete[](void *p) noexcept (true)
37 __asm__ (REAL_ZDAPV);
38 extern WEAK void *operator new(std::size_t sz, const std::nothrow_t &nt) noexcept (true)
39 __asm__ (REAL_ZNWX_NOTHROW_T);
40 extern WEAK void *operator new[](std::size_t sz, const std::nothrow_t &nt) noexcept (true)
41 __asm__ (REAL_ZNAX_NOTHROW_T);
42 extern WEAK void operator delete(void *p, const std::nothrow_t &nt) noexcept (true)
43 __asm__ (REAL_ZDLPV_NOTHROW_T);
44 extern WEAK void operator delete[](void *p, const std::nothrow_t &nt) noexcept (true)
45 __asm__ (REAL_ZDAPV_NOTHROW_T);
47 /* Avoid an info message from linker when linking applications. */
48 extern __declspec(dllimport) struct _reent *_impure_ptr;
50 /* Initialised in _cygwin_dll_entry. */
51 extern int __dynamically_loaded;
53 #undef environ
55 extern "C"
57 int _fmode;
59 extern char __RUNTIME_PSEUDO_RELOC_LIST__;
60 extern char __RUNTIME_PSEUDO_RELOC_LIST_END__;
61 extern char __image_base__;
62 #define _image_base__ __image_base__
64 struct per_process_cxx_malloc __cygwin_cxx_malloc =
66 &(operator new), &(operator new[]),
67 &(operator delete), &(operator delete[]),
68 &(operator new), &(operator new[]),
69 &(operator delete), &(operator delete[])
72 /* Set up pointers to various pieces so the dll can then use them,
73 and then jump to the dll. */
75 int
76 _cygwin_crt0_common (MainFunc f, per_process *u)
78 per_process *newu = (per_process *) cygwin_internal (CW_USER_DATA);
79 bool uwasnull;
81 /* u is non-NULL if we are in a DLL, and NULL in the main exe.
82 newu is the Cygwin DLL's internal per_process and never NULL. */
83 if (u != NULL)
84 uwasnull = false; /* Caller allocated space for per_process structure. */
85 else
87 u = newu; /* Using DLL built-in per_process. */
88 uwasnull = true; /* Remember for later. */
91 /* The version numbers are the main source of compatibility checking.
92 As a backup to them, we use the size of the per_process struct. */
93 u->magic_biscuit = sizeof (per_process);
95 /* cygwin.dll version number in effect at the time the app was created. */
96 u->dll_major = CYGWIN_VERSION_DLL_MAJOR;
97 u->dll_minor = CYGWIN_VERSION_DLL_MINOR;
98 u->api_major = CYGWIN_VERSION_API_MAJOR;
99 u->api_minor = CYGWIN_VERSION_API_MINOR;
101 u->ctors = &__CTOR_LIST__;
102 u->dtors = &__DTOR_LIST__;
103 if (uwasnull)
104 _impure_ptr = u->impure_ptr; /* Use field initialized in newer DLLs. */
105 else
106 u->impure_ptr_ptr = &_impure_ptr; /* Older DLLs need this. */
108 u->main = f;
110 /* These functions are executed prior to main. They are just stubs unless the
111 user overrides them. */
112 u->premain[0] = cygwin_premain0;
113 u->premain[1] = cygwin_premain1;
114 u->premain[2] = cygwin_premain2;
115 u->premain[3] = cygwin_premain3;
116 u->fmode_ptr = &_fmode;
118 /* Unused */
119 u->initial_sp = NULL;
121 /* Remember whatever the user linked his application with - or
122 point to entries in the dll. */
123 u->malloc = &malloc;
124 u->free = &free;
125 u->realloc = &realloc;
126 u->calloc = &calloc;
127 u->posix_memalign = &posix_memalign;
129 /* Likewise for the C++ memory operators, if any, but not if we
130 were dlopen()'d, as we might get dlclose()'d and that would
131 leave stale function pointers behind. */
132 if (newu && newu->cxx_malloc && !__dynamically_loaded)
134 /* Inherit what we don't override. */
135 #define CONDITIONALLY_OVERRIDE(MEMBER) \
136 if (!__cygwin_cxx_malloc.MEMBER) \
137 __cygwin_cxx_malloc.MEMBER = newu->cxx_malloc->MEMBER;
138 CONDITIONALLY_OVERRIDE(oper_new);
139 CONDITIONALLY_OVERRIDE(oper_new__);
140 CONDITIONALLY_OVERRIDE(oper_delete);
141 CONDITIONALLY_OVERRIDE(oper_delete__);
142 CONDITIONALLY_OVERRIDE(oper_new_nt);
143 CONDITIONALLY_OVERRIDE(oper_new___nt);
144 CONDITIONALLY_OVERRIDE(oper_delete_nt);
145 CONDITIONALLY_OVERRIDE(oper_delete___nt);
146 /* Now update the resulting set into the global redirectors. */
147 *newu->cxx_malloc = __cygwin_cxx_malloc;
150 /* Setup the module handle so fork can get the path name. */
151 u->hmodule = GetModuleHandle (0);
153 /* variables for fork */
154 u->data_start = &__data_start__;
155 u->data_end = &__data_end__;
156 u->bss_start = &__bss_start__;
157 u->bss_end = &__bss_end__;
158 u->pseudo_reloc_start = &__RUNTIME_PSEUDO_RELOC_LIST__;
159 u->pseudo_reloc_end = &__RUNTIME_PSEUDO_RELOC_LIST_END__;
160 u->image_base = &_image_base__;
161 /* This is actually a dummy call to force the linker to load this
162 symbol for older apps which need it. Unfortunately, ld for x86_64
163 still emits this symbol when linking against static libs which
164 require pseudo relocation, so we can't drop this call and the
165 dummy function just yet. */
166 _pei386_runtime_relocator (NULL);
167 return 1;
169 } /* "C" */