mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-21 00:07:36 +08:00
* dll_init.cc: Use fabort in favor of api_fatal and fork_info->abort where
appropriate throughout. (fabort): Define. (dll_list::topsort): Don't print sorting information. Fix formatting. (dll_list::topsort_visit): Fix formatting. (dll_list::load_after_fork_impl): Perform comment fixups. * sigproc.cc (child_info_fork::abort): (for now?) Always print cause of fork failure. * include/sys/strace.h (strace_vprintf): Remove _STRACE_NOTALL when printing. We really do want to see this.
This commit is contained in:
parent
f0968c1e7e
commit
2964913236
@ -1,3 +1,16 @@
|
|||||||
|
2011-08-03 Christopher Faylor <me.cygwin2011@cgf.cx>
|
||||||
|
|
||||||
|
* dll_init.cc: Use fabort in favor of api_fatal and fork_info->abort
|
||||||
|
where appropriate throughout.
|
||||||
|
(fabort): Define.
|
||||||
|
(dll_list::topsort): Don't print sorting information. Fix formatting.
|
||||||
|
(dll_list::topsort_visit): Fix formatting.
|
||||||
|
(dll_list::load_after_fork_impl): Perform comment fixups.
|
||||||
|
* sigproc.cc (child_info_fork::abort): (for now?) Always print cause of
|
||||||
|
fork failure.
|
||||||
|
* include/sys/strace.h (strace_vprintf): Remove _STRACE_NOTALL when
|
||||||
|
printing. We really do want to see this.
|
||||||
|
|
||||||
2011-08-03 Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
|
2011-08-03 Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
|
||||||
|
|
||||||
* cygtls.h (struct _local_storage): Add cw_timer member.
|
* cygtls.h (struct _local_storage): Add cw_timer member.
|
||||||
|
@ -28,6 +28,8 @@ details. */
|
|||||||
|
|
||||||
extern void __stdcall check_sanity_and_sync (per_process *);
|
extern void __stdcall check_sanity_and_sync (per_process *);
|
||||||
|
|
||||||
|
#define fabort fork_info->abort
|
||||||
|
|
||||||
dll_list dlls;
|
dll_list dlls;
|
||||||
|
|
||||||
muto dll_list::protect;
|
muto dll_list::protect;
|
||||||
@ -147,17 +149,17 @@ dll_list::alloc (HINSTANCE h, per_process *p, dll_type type)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (d->p.data_start != p->data_start)
|
if (d->p.data_start != p->data_start)
|
||||||
fork_info->abort ("data segment start: parent(%p) != child(%p)",
|
fabort ("data segment start: parent(%p) != child(%p)",
|
||||||
d->p.data_start, p->data_start);
|
d->p.data_start, p->data_start);
|
||||||
else if (d->p.data_end != p->data_end)
|
else if (d->p.data_end != p->data_end)
|
||||||
fork_info->abort ("data segment end: parent(%p) != child(%p)",
|
fabort ("data segment end: parent(%p) != child(%p)",
|
||||||
d->p.data_end, p->data_end);
|
d->p.data_end, p->data_end);
|
||||||
else if (d->p.bss_start != p->bss_start)
|
else if (d->p.bss_start != p->bss_start)
|
||||||
fork_info->abort ("data segment start: parent(%p) != child(%p)",
|
fabort ("data segment start: parent(%p) != child(%p)",
|
||||||
d->p.bss_start, p->bss_start);
|
d->p.bss_start, p->bss_start);
|
||||||
else if (d->p.bss_end != p->bss_end)
|
else if (d->p.bss_end != p->bss_end)
|
||||||
fork_info->abort ("bss segment end: parent(%p) != child(%p)",
|
fabort ("bss segment end: parent(%p) != child(%p)",
|
||||||
d->p.bss_end, p->bss_end);
|
d->p.bss_end, p->bss_end);
|
||||||
}
|
}
|
||||||
d->p = p;
|
d->p = p;
|
||||||
}
|
}
|
||||||
@ -256,9 +258,11 @@ dll_list::topsort ()
|
|||||||
d = &start;
|
d = &start;
|
||||||
while ((d = d->next))
|
while ((d = d->next))
|
||||||
{
|
{
|
||||||
debug_printf ("%W", d->modname);
|
#ifdef DEBUGGING
|
||||||
for (int i=1; i < -d->ndeps; i++)
|
paranoid_printf ("%W", d->modname);
|
||||||
debug_printf ("-> %W", d->deps[i-1]->modname);
|
for (int i = 1; i < -d->ndeps; i++)
|
||||||
|
paranoid_printf ("-> %W", d->deps[i - 1]->modname);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* It would be really nice to be able to keep this information
|
/* It would be really nice to be able to keep this information
|
||||||
around for next time, but we don't have an easy way to
|
around for next time, but we don't have an easy way to
|
||||||
@ -294,8 +298,8 @@ dll_list::topsort_visit (dll* d, bool seek_tail)
|
|||||||
if (d->ndeps > 0)
|
if (d->ndeps > 0)
|
||||||
{
|
{
|
||||||
d->ndeps = -d->ndeps;
|
d->ndeps = -d->ndeps;
|
||||||
for (long i=1; i < -d->ndeps; i++)
|
for (long i = 1; i < -d->ndeps; i++)
|
||||||
topsort_visit (d->deps[i-1], false);
|
topsort_visit (d->deps[i - 1], false);
|
||||||
|
|
||||||
append (d);
|
append (d);
|
||||||
}
|
}
|
||||||
@ -378,8 +382,8 @@ reserve_at (const PWCHAR name, DWORD here, DWORD dll_base, DWORD dll_size)
|
|||||||
MEMORY_BASIC_INFORMATION mb;
|
MEMORY_BASIC_INFORMATION mb;
|
||||||
|
|
||||||
if (!VirtualQuery ((void *) here, &mb, sizeof (mb)))
|
if (!VirtualQuery ((void *) here, &mb, sizeof (mb)))
|
||||||
api_fatal ("couldn't examine memory at %08lx while mapping %W, %E",
|
fabort ("couldn't examine memory at %08lx while mapping %W, %E",
|
||||||
here, name);
|
here, name);
|
||||||
if (mb.State != MEM_FREE)
|
if (mb.State != MEM_FREE)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -395,8 +399,8 @@ reserve_at (const PWCHAR name, DWORD here, DWORD dll_base, DWORD dll_size)
|
|||||||
|
|
||||||
size = end - here;
|
size = end - here;
|
||||||
if (!VirtualAlloc ((void *) here, size, MEM_RESERVE, PAGE_NOACCESS))
|
if (!VirtualAlloc ((void *) here, size, MEM_RESERVE, PAGE_NOACCESS))
|
||||||
api_fatal ("couldn't allocate memory %p(%d) for '%W' alignment, %E\n",
|
fabort ("couldn't allocate memory %p(%d) for '%W' alignment, %E\n",
|
||||||
here, size, name);
|
here, size, name);
|
||||||
return here;
|
return here;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,8 +409,8 @@ static void
|
|||||||
release_at (const PWCHAR name, DWORD here)
|
release_at (const PWCHAR name, DWORD here)
|
||||||
{
|
{
|
||||||
if (!VirtualFree ((void *) here, 0, MEM_RELEASE))
|
if (!VirtualFree ((void *) here, 0, MEM_RELEASE))
|
||||||
api_fatal ("couldn't release memory %p for '%W' alignment, %E\n",
|
fabort ("couldn't release memory %p for '%W' alignment, %E\n",
|
||||||
here, name);
|
here, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Step 1: Reserve memory for all DLL_LOAD dlls. This is to prevent
|
/* Step 1: Reserve memory for all DLL_LOAD dlls. This is to prevent
|
||||||
@ -423,8 +427,8 @@ dll_list::reserve_space ()
|
|||||||
{
|
{
|
||||||
for (dll* d = dlls.istart (DLL_LOAD); d; d = dlls.inext ())
|
for (dll* d = dlls.istart (DLL_LOAD); d; d = dlls.inext ())
|
||||||
if (!VirtualAlloc (d->handle, d->image_size, MEM_RESERVE, PAGE_NOACCESS))
|
if (!VirtualAlloc (d->handle, d->image_size, MEM_RESERVE, PAGE_NOACCESS))
|
||||||
fork_info->abort ("address space needed by '%W' (%08lx) is already occupied",
|
fabort ("address space needed by '%W' (%08lx) is already occupied",
|
||||||
d->modname, d->handle);
|
d->modname, d->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reload DLLs after a fork. Iterates over the list of dynamically loaded
|
/* Reload DLLs after a fork. Iterates over the list of dynamically loaded
|
||||||
@ -469,12 +473,13 @@ void dll_list::load_after_fork_impl (HANDLE parent, dll* d, int retries)
|
|||||||
dll's protective reservation from step 1
|
dll's protective reservation from step 1
|
||||||
*/
|
*/
|
||||||
if (!retries && !VirtualFree (d->handle, 0, MEM_RELEASE))
|
if (!retries && !VirtualFree (d->handle, 0, MEM_RELEASE))
|
||||||
api_fatal ("unable to release protective reservation for %W (%08lx), %E",
|
fabort ("unable to release protective reservation for %W (%08lx), %E",
|
||||||
d->modname, d->handle);
|
d->modname, d->handle);
|
||||||
|
|
||||||
HMODULE h = LoadLibraryExW (d->name, NULL, DONT_RESOLVE_DLL_REFERENCES);
|
HMODULE h = LoadLibraryExW (d->name, NULL, DONT_RESOLVE_DLL_REFERENCES);
|
||||||
if (!h)
|
if (!h)
|
||||||
api_fatal ("unable to create interim mapping for %W, %E", d->name);
|
fabort ("unable to create interim mapping for %W, %E",
|
||||||
|
d->name);
|
||||||
if (h != d->handle)
|
if (h != d->handle)
|
||||||
{
|
{
|
||||||
sigproc_printf ("%W loaded in wrong place: %08lx != %08lx",
|
sigproc_printf ("%W loaded in wrong place: %08lx != %08lx",
|
||||||
@ -483,14 +488,14 @@ void dll_list::load_after_fork_impl (HANDLE parent, dll* d, int retries)
|
|||||||
DWORD reservation = reserve_at (d->modname, (DWORD) h,
|
DWORD reservation = reserve_at (d->modname, (DWORD) h,
|
||||||
(DWORD) d->handle, d->image_size);
|
(DWORD) d->handle, d->image_size);
|
||||||
if (!reservation)
|
if (!reservation)
|
||||||
api_fatal ("unable to block off %p to prevent %W from loading there",
|
fabort ("unable to block off %p to prevent %W from loading there",
|
||||||
h, d->modname);
|
h, d->modname);
|
||||||
|
|
||||||
if (retries < DLL_RETRY_MAX)
|
if (retries < DLL_RETRY_MAX)
|
||||||
load_after_fork_impl (parent, d, retries+1);
|
load_after_fork_impl (parent, d, retries+1);
|
||||||
else
|
else
|
||||||
fork_info->abort ("unable to remap %W to same address as parent (%08lx) - try running rebaseall",
|
fabort ("unable to remap %W to same address as parent (%08lx) - try running rebaseall",
|
||||||
d->modname, d->handle);
|
d->modname, d->handle);
|
||||||
|
|
||||||
/* once the above returns all the dlls are mapped; release
|
/* once the above returns all the dlls are mapped; release
|
||||||
the reservation and continue unwinding */
|
the reservation and continue unwinding */
|
||||||
@ -504,34 +509,29 @@ void dll_list::load_after_fork_impl (HANDLE parent, dll* d, int retries)
|
|||||||
protective reservation (for well-behaved dlls) or unloading the
|
protective reservation (for well-behaved dlls) or unloading the
|
||||||
interim mapping (for rebased dlls) . The dll list is sorted in
|
interim mapping (for rebased dlls) . The dll list is sorted in
|
||||||
dependency order, so we shouldn't pull in any additional dlls
|
dependency order, so we shouldn't pull in any additional dlls
|
||||||
outside our control.
|
outside our control. */
|
||||||
|
|
||||||
It stinks that we can't invert the order of the initial LoadLibrary
|
|
||||||
and FreeLibrary since Microsoft documentation seems to imply that
|
|
||||||
should do what we want. However, once a library is loaded as
|
|
||||||
above, the second LoadLibrary will not execute its startup code
|
|
||||||
unless it is first unloaded. */
|
|
||||||
for (dll *d = dlls.istart (DLL_LOAD); d; d = dlls.inext ())
|
for (dll *d = dlls.istart (DLL_LOAD); d; d = dlls.inext ())
|
||||||
{
|
{
|
||||||
if (d->handle == d->preferred_base)
|
if (d->handle == d->preferred_base)
|
||||||
{
|
{
|
||||||
if (!VirtualFree (d->handle, 0, MEM_RELEASE))
|
if (!VirtualFree (d->handle, 0, MEM_RELEASE))
|
||||||
api_fatal ("unable to release protective reservation for %W (%08lx), %E",
|
fabort ("unable to release protective reservation for %W (%08lx), %E",
|
||||||
d->modname, d->handle);
|
d->modname, d->handle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Free the library using our parent's handle: it's identical
|
/* Free the library using our parent's handle: it's identical
|
||||||
to ours our we wouldn't have gotten this far */
|
to ours or we wouldn't have gotten this far */
|
||||||
if (!FreeLibrary (d->handle))
|
if (!FreeLibrary (d->handle))
|
||||||
api_fatal ("unable to unload interim mapping of %W, %E", d->modname);
|
fabort ("unable to unload interim mapping of %W, %E",
|
||||||
|
d->modname);
|
||||||
}
|
}
|
||||||
HMODULE h = LoadLibraryW (d->name);
|
HMODULE h = LoadLibraryW (d->name);
|
||||||
if (!h)
|
if (!h)
|
||||||
api_fatal ("unable to map %W, %E", d->name);
|
fabort ("unable to map %W, %E", d->name);
|
||||||
if (h != d->handle)
|
if (h != d->handle)
|
||||||
api_fatal ("unable to map %W to same address as parent: %p != %p",
|
fabort ("unable to map %W to same address as parent: %p != %p",
|
||||||
d->modname, d->handle, h);
|
d->modname, d->handle, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ void strace_printf (unsigned, const char *func, const char *, ...);
|
|||||||
#define strace_vprintf(what, fmt, arg) \
|
#define strace_vprintf(what, fmt, arg) \
|
||||||
((void) ({\
|
((void) ({\
|
||||||
if ((_STRACE_ ## what & _STRACE_SYSTEM) || strace.active ()) \
|
if ((_STRACE_ ## what & _STRACE_SYSTEM) || strace.active ()) \
|
||||||
strace.vprntf((_STRACE_ ## what) | _STRACE_NOTALL, __PRETTY_FUNCTION__, fmt, arg); \
|
strace.vprntf((_STRACE_ ## what), __PRETTY_FUNCTION__, fmt, arg); \
|
||||||
0; \
|
0; \
|
||||||
}))
|
}))
|
||||||
#endif /*NOSTRACE*/
|
#endif /*NOSTRACE*/
|
||||||
|
@ -944,7 +944,7 @@ child_info_fork::abort (const char *fmt, ...)
|
|||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start (ap, fmt);
|
va_start (ap, fmt);
|
||||||
strace_vprintf (SIGP, fmt, ap);
|
strace_vprintf (SYSTEM, fmt, ap);
|
||||||
ExitProcess (EXITCODE_FORK_FAILED);
|
ExitProcess (EXITCODE_FORK_FAILED);
|
||||||
}
|
}
|
||||||
if (retry > 0)
|
if (retry > 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user