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
17 int (*main
)(int, char **, char **);
18 per_module
&operator = (per_process
*p
)
22 data_start
= p
->data_start
;
23 data_end
= p
->data_end
;
24 bss_start
= p
->bss_start
;
37 DLL_SELF
, /* main-program.exe, cygwin1.dll */
45 struct dll
*next
, *prev
;
56 FILE_INTERNAL_INFORMATION fii
;
57 PWCHAR forkable_ntname
;
58 WCHAR ntname
[1]; /* must be the last data member */
62 bool stat_real_file_once ();
63 void nominate_forkable (PCWCHAR
);
64 bool create_forkable ();
73 PWCHAR
forkedntname ()
75 return forkable_ntname
&& *forkable_ntname
? forkable_ntname
: ntname
;
79 #define MAX_DLL_BEFORE_INIT 100
83 bool forkables_supported ()
85 return cygwin_shared
->forkable_hardlink_support
>= 0;
87 DWORD forkables_dirx_size
;
88 bool forkables_created
;
89 PWCHAR forkables_dirx_ntname
;
90 PWCHAR forkables_mutex_name
;
91 HANDLE forkables_mutex
;
93 dll
*find_by_forkedntname (PCWCHAR ntname
);
94 size_t forkable_ntnamesize (dll_type
, PCWCHAR fullntname
, PCWCHAR modname
);
95 void prepare_forkables_nomination ();
96 void update_forkables_needs ();
97 bool update_forkables ();
98 bool create_forkables ();
99 void denominate_forkables ();
101 void try_remove_forkables (PWCHAR dirbuf
, size_t dirlen
, size_t dirbufsize
);
102 void set_forkables_inheritance (bool);
103 void request_forkables ();
109 /* Use this buffer under loader lock conditions only. */
110 static WCHAR NO_COPY nt_max_path_buffer
[NT_MAX_PATH
];
112 static HANDLE
ntopenfile (PCWCHAR ntname
, NTSTATUS
*pstatus
= NULL
,
113 ULONG openopts
= 0, ACCESS_MASK access
= 0,
114 HANDLE rootDir
= NULL
);
115 static bool read_fii (HANDLE fh
, PFILE_INTERNAL_INFORMATION pfii
);
116 static PWCHAR
form_ntname (PWCHAR ntbuf
, size_t bufsize
, PCWCHAR name
);
117 static PWCHAR
form_shortname (PWCHAR shortbuf
, size_t bufsize
, PCWCHAR name
);
118 static PWCHAR
nt_max_path_buf ()
120 return nt_max_path_buffer
;
122 static PCWCHAR
buffered_shortname (PCWCHAR name
)
124 form_shortname (nt_max_path_buffer
, NT_MAX_PATH
, name
);
125 return nt_max_path_buffer
;
128 dll
*main_executable
;
132 dll
*operator [] (PCWCHAR ntname
);
133 dll
*alloc (HINSTANCE
, per_process
*, dll_type
);
135 void detach (void *);
137 void load_after_fork (HANDLE
);
138 void reserve_space ();
139 void load_after_fork_impl (HANDLE
, dll
* which
, int retries
);
140 dll
*find_by_modname (PCWCHAR modname
);
141 void populate_deps (dll
* d
);
143 void topsort_visit (dll
* d
, bool goto_tail
);
144 void append (dll
* d
);
146 void release_forkables ();
147 void cleanup_forkables ();
148 bool setup_forkables (bool with_forkables
)
150 if (!forkables_supported ())
151 return true; /* no need to retry fork */
152 if (forkables_created
)
153 /* Once created, use forkables in current
154 process chain on first fork try already. */
155 with_forkables
= true;
157 request_forkables ();
158 return with_forkables
;
163 while ((hold
= hold
->next
))
164 if (hold_type
== DLL_ANY
|| hold
->type
== hold_type
)
169 dll
*istart (dll_type t
)
175 void guard(bool lockit
)
182 friend void dll_global_dtors ();
183 dll_list () { protect
.init ("dll_list"); }
187 http://msdn.microsoft.com/en-us/windows/hardware/gg463125
188 http://msdn.microsoft.com/en-us/library/ms809762.aspx
192 IMAGE_DOS_HEADER dos_hdr
;
194 char* rva (ptrdiff_t offset
) { return (char*) this + offset
; }
195 PIMAGE_NT_HEADERS
pe_hdr () { return (PIMAGE_NT_HEADERS
) rva (dos_hdr
.e_lfanew
); }
196 PIMAGE_OPTIONAL_HEADER
optional_hdr () { return &pe_hdr ()->OptionalHeader
; }
197 PIMAGE_DATA_DIRECTORY
idata_dir (DWORD which
)
199 PIMAGE_OPTIONAL_HEADER oh
= optional_hdr ();
200 return (which
< oh
->NumberOfRvaAndSizes
)? oh
->DataDirectory
+ which
: 0;
204 extern dll_list dlls
;
205 void dll_global_dtors ();
207 /* These probably belong in a newlib header but we can keep them here
209 extern "C" int __cxa_atexit(void (*)(void*), void*, void*);
210 extern "C" int __cxa_finalize(void*);