Update comments.

This commit is contained in:
Christopher Faylor 2000-07-16 04:10:33 +00:00
parent 92e30b7535
commit c77c441991

View File

@ -16,10 +16,6 @@ extern void __stdcall check_sanity_and_sync (per_process *);
dll_list NO_COPY dlls; dll_list NO_COPY dlls;
static NO_COPY int in_forkee = 0; static NO_COPY int in_forkee = 0;
/* local variables */
//-----------------------------------------------------------------------------
static int dll_global_dtors_recorded = 0; static int dll_global_dtors_recorded = 0;
/* Run destructors for all DLLs on exit. */ /* Run destructors for all DLLs on exit. */
@ -95,7 +91,7 @@ dll_list::operator[] (const char *name)
#define RETRIES 100 #define RETRIES 100
/* Allocate space for a dll struct after the just-loaded dll. */ /* Allocate space for a dll struct contiguous with the just-loaded dll. */
dll * dll *
dll_list::alloc (HINSTANCE h, per_process *p, dll_type type) dll_list::alloc (HINSTANCE h, per_process *p, dll_type type)
{ {
@ -119,29 +115,32 @@ dll_list::alloc (HINSTANCE h, per_process *p, dll_type type)
if (!VirtualQuery (s, &m, sizeof (m))) if (!VirtualQuery (s, &m, sizeof (m)))
return NULL; /* Can't do it. */ return NULL; /* Can't do it. */
if (m.State == MEM_FREE) if (m.State == MEM_FREE)
break; break; /* Found some free space */
s = (char *) m.BaseAddress + m.RegionSize; s = (char *) m.BaseAddress + m.RegionSize;
} }
/* Couldn't find any. Uh oh. FIXME: Issue an error? */ /* Couldn't find any. Uh oh. FIXME: Issue an error? */
if (i == RETRIES) if (i == RETRIES)
return NULL; /* Oh well */ return NULL; /* Oh well. Couldn't locate free space. */
SYSTEM_INFO s1; SYSTEM_INFO s1;
GetSystemInfo (&s1); GetSystemInfo (&s1);
/* Need to do the shared memory thing since W95 can't allocate in /* Ensure that this is rounded to the nearest page boundary.
the shared memory region otherwise. */ FIXME: Should this be ensured by VirtualQuery? */
DWORD n = (DWORD) m.BaseAddress; DWORD n = (DWORD) m.BaseAddress;
DWORD r = n % s1.dwAllocationGranularity; DWORD r = n % s1.dwAllocationGranularity;
if (r) if (r)
n = ((n - r) + s1.dwAllocationGranularity); n = ((n - r) + s1.dwAllocationGranularity);
/* First reserve the area of memory, then commit it. */
if (VirtualAlloc ((void *) n, sizeof (dll), MEM_RESERVE, PAGE_READWRITE)) if (VirtualAlloc ((void *) n, sizeof (dll), MEM_RESERVE, PAGE_READWRITE))
d = (dll *) VirtualAlloc ((void *) n, sizeof (dll), MEM_COMMIT, PAGE_READWRITE); d = (dll *) VirtualAlloc ((void *) n, sizeof (dll), MEM_COMMIT, PAGE_READWRITE);
/* Did we succeed? */
if (d == NULL) if (d == NULL)
{ { /* Nope. */
#ifdef DEBUGGING #ifdef DEBUGGING
system_printf ("VirtualAlloc failed for %p, %E", n); system_printf ("VirtualAlloc failed for %p, %E", n);
#endif #endif
@ -189,7 +188,7 @@ dll_list::detach (dll *d)
} }
} }
/* Initialization called by dll_crt0_1. */ /* Initialization for all linked DLLs, called by dll_crt0_1. */
void void
dll_list::init () dll_list::init ()
{ {
@ -256,7 +255,6 @@ release_upto (const char *name, DWORD here)
} }
} }
#define MAX_DLL_SIZE (sizeof (dll))
/* Reload DLLs after a fork. Iterates over the list of dynamically loaded DLLs /* Reload DLLs after a fork. Iterates over the list of dynamically loaded DLLs
and attempts to load them in the same place as they were loaded in the parent. */ and attempts to load them in the same place as they were loaded in the parent. */
void void
@ -271,9 +269,10 @@ dll_list::load_after_fork (HANDLE parent, dll *first)
{ {
DWORD nb; DWORD nb;
/* Read the dll structure from the parent. */ /* Read the dll structure from the parent. */
if (!ReadProcessMemory (parent, next, &d, MAX_DLL_SIZE, &nb) || if (!ReadProcessMemory (parent, next, &d, sizeof (dll), &nb) ||
nb != MAX_DLL_SIZE) nb != sizeof (dll))
return; return;
/* We're only interested in dynamically loaded dlls. /* We're only interested in dynamically loaded dlls.
Hopefully, this function wouldn't even have been called unless Hopefully, this function wouldn't even have been called unless
the parent had some of those. */ the parent had some of those. */
@ -286,7 +285,7 @@ dll_list::load_after_fork (HANDLE parent, dll *first)
It sort of stinks that we can't invert the order of the FreeLibrary It sort of stinks that we can't invert the order of the FreeLibrary
and LoadLibrary since Microsoft documentation seems to imply that that and LoadLibrary since Microsoft documentation seems to imply that that
should do what we want. However, since the library was loaded above, should do what we want. However, since the library was loaded above,
The second LoadLibrary does not execute it's startup code unless it the second LoadLibrary does not execute it's startup code unless it
is first unloaded. */ is first unloaded. */
if (h == d.handle) if (h == d.handle)
{ {