OSDN Git Service

Revert previous checkins as they introduced a bug when running zsh.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / dll_init.h
1 /* dll_init.h
2
3    Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008,
4    2009 Red Hat, Inc.
5
6 This file is part of Cygwin.
7
8 This software is a copyrighted work licensed under the terms of the
9 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
10 details. */
11
12 struct per_module
13 {
14   char ***envptr;
15   void (**ctors)(void);
16   void (**dtors)(void);
17   void *data_start;
18   void *data_end;
19   void *bss_start;
20   void *bss_end;
21   int (*main)(int, char **, char **);
22   per_module &operator = (per_process *p)
23   {
24     envptr = p->envptr;
25     ctors = p->ctors;
26     dtors = p->dtors;
27     data_start = p->data_start;
28     data_end = p->data_end;
29     bss_start = p->bss_start;
30     bss_end = p->bss_end;
31     main = p->main;
32     return *this;
33   }
34   void run_ctors ();
35   void run_dtors ();
36 };
37
38
39 typedef enum
40 {
41   DLL_NONE,
42   DLL_LINK,
43   DLL_LOAD,
44   DLL_ANY
45 } dll_type;
46
47 struct dll
48 {
49   struct dll *next, *prev;
50   per_module p;
51   HMODULE handle;
52   int count;
53   bool has_dtors;
54   dll_type type;
55   WCHAR name[1];
56   void detach ();
57   int init ();
58   void run_dtors ()
59   {
60     if (has_dtors)
61       {
62         has_dtors = 0;
63         p.run_dtors ();
64       }
65   }
66 };
67
68 #define MAX_DLL_BEFORE_INIT     100
69
70 class dll_list
71 {
72   dll *end;
73   dll *hold;
74   dll_type hold_type;
75   static muto protect;
76 public:
77   dll start;
78   int tot;
79   int loaded_dlls;
80   int reload_on_fork;
81   dll *operator [] (const PWCHAR name);
82   dll *alloc (HINSTANCE, per_process *, dll_type);
83   dll *find (void *);
84   void detach (void *);
85   void init ();
86   void load_after_fork (HANDLE);
87   dll *inext ()
88   {
89     while ((hold = hold->next))
90       if (hold_type == DLL_ANY || hold->type == hold_type)
91         break;
92     return hold;
93   }
94
95   dll *istart (dll_type t)
96   {
97     hold_type = t;
98     hold = &start;
99     return inext ();
100   }
101   void guard(bool lockit)
102   {
103     if (lockit)
104       protect.acquire ();
105     else
106       protect.release ();
107   }
108   friend void dll_global_dtors ();
109   dll_list () { protect.init ("dll_list"); }
110 };
111
112 extern dll_list dlls;
113 void dll_global_dtors ();
114
115 /* These probably belong in a newlib header but we can keep them here
116    for now.  */
117 extern "C" int __cxa_atexit(void (*)(void*), void*, void*);
118 extern "C" int __cxa_finalize(void*);