2000-02-17 20:38:33 +01:00
|
|
|
/* dll_init.h
|
|
|
|
|
2009-06-06 13:47:29 +02:00
|
|
|
Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008,
|
|
|
|
2009 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
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. */
|
|
|
|
|
2000-07-15 04:48:11 +02:00
|
|
|
struct per_module
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-07-15 04:48:11 +02:00
|
|
|
char ***envptr;
|
|
|
|
void (**ctors)(void);
|
|
|
|
void (**dtors)(void);
|
|
|
|
void *data_start;
|
|
|
|
void *data_end;
|
|
|
|
void *bss_start;
|
|
|
|
void *bss_end;
|
|
|
|
int (*main)(int, char **, char **);
|
|
|
|
per_module &operator = (per_process *p)
|
|
|
|
{
|
|
|
|
envptr = p->envptr;
|
|
|
|
ctors = p->ctors;
|
|
|
|
dtors = p->dtors;
|
|
|
|
data_start = p->data_start;
|
|
|
|
data_end = p->data_end;
|
|
|
|
bss_start = p->bss_start;
|
|
|
|
bss_end = p->bss_end;
|
|
|
|
main = p->main;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
void run_ctors ();
|
|
|
|
void run_dtors ();
|
2000-02-17 20:38:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-07-15 04:48:11 +02:00
|
|
|
typedef enum
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-07-15 04:48:11 +02:00
|
|
|
DLL_NONE,
|
|
|
|
DLL_LINK,
|
|
|
|
DLL_LOAD,
|
|
|
|
DLL_ANY
|
|
|
|
} dll_type;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-07-15 04:48:11 +02:00
|
|
|
struct dll
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-07-15 04:48:11 +02:00
|
|
|
struct dll *next, *prev;
|
|
|
|
per_module p;
|
|
|
|
HMODULE handle;
|
|
|
|
int count;
|
2009-08-21 23:32:06 +02:00
|
|
|
bool has_dtors;
|
2000-07-15 04:48:11 +02:00
|
|
|
dll_type type;
|
2009-06-08 05:53:40 +02:00
|
|
|
WCHAR name[1];
|
2000-07-15 04:48:11 +02:00
|
|
|
void detach ();
|
|
|
|
int init ();
|
2009-08-21 23:32:06 +02:00
|
|
|
void run_dtors ()
|
|
|
|
{
|
|
|
|
if (has_dtors)
|
|
|
|
{
|
|
|
|
has_dtors = 0;
|
|
|
|
p.run_dtors ();
|
|
|
|
}
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
};
|
|
|
|
|
2000-07-15 04:48:11 +02:00
|
|
|
#define MAX_DLL_BEFORE_INIT 100
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-07-15 04:48:11 +02:00
|
|
|
class dll_list
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-07-15 04:48:11 +02:00
|
|
|
dll *end;
|
|
|
|
dll *hold;
|
|
|
|
dll_type hold_type;
|
2000-02-17 20:38:33 +01:00
|
|
|
public:
|
2000-07-15 04:48:11 +02:00
|
|
|
dll start;
|
|
|
|
int tot;
|
|
|
|
int loaded_dlls;
|
|
|
|
int reload_on_fork;
|
2008-08-13 10:25:44 +02:00
|
|
|
dll *operator [] (const PWCHAR name);
|
2000-07-15 04:48:11 +02:00
|
|
|
dll *alloc (HINSTANCE, per_process *, dll_type);
|
2002-11-14 05:29:39 +01:00
|
|
|
void detach (void *);
|
2000-07-15 04:48:11 +02:00
|
|
|
void init ();
|
2009-06-08 05:53:40 +02:00
|
|
|
void load_after_fork (HANDLE);
|
2000-07-15 04:48:11 +02:00
|
|
|
dll *inext ()
|
|
|
|
{
|
|
|
|
while ((hold = hold->next))
|
|
|
|
if (hold_type == DLL_ANY || hold->type == hold_type)
|
|
|
|
break;
|
|
|
|
return hold;
|
|
|
|
}
|
2001-11-03 04:32:27 +01:00
|
|
|
dll *istart (dll_type t)
|
|
|
|
{
|
|
|
|
hold_type = t;
|
|
|
|
hold = &start;
|
|
|
|
return inext ();
|
|
|
|
}
|
2008-08-04 17:55:32 +02:00
|
|
|
friend void dll_global_dtors ();
|
2000-02-17 20:38:33 +01:00
|
|
|
};
|
|
|
|
|
2000-07-15 04:48:11 +02:00
|
|
|
extern dll_list dlls;
|
2005-04-14 19:34:03 +02:00
|
|
|
void dll_global_dtors ();
|