OSDN Git Service

* path.cc (conv_path_list): Take cygwin_conv_path_t as third parameter.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / dll_init.h
index a7601e7..d1be162 100644 (file)
@@ -1,6 +1,7 @@
 /* dll_init.h
 
-   Copyright 1998, 1999, 2000, 2001 Red Hat, Inc.
+   Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008,
+   2009 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -49,11 +50,24 @@ struct dll
   per_module p;
   HMODULE handle;
   int count;
+  bool has_dtors;
   dll_type type;
-  int namelen;
-  char name[NT_MAX_PATH];
+  long ndeps;
+  dll** deps;
+  PWCHAR modname;
+  DWORD image_size;
+  void* preferred_base;
+  WCHAR name[1];
   void detach ();
   int init ();
+  void run_dtors ()
+  {
+    if (has_dtors)
+      {
+       has_dtors = 0;
+       p.run_dtors ();
+      }
+  }
 };
 
 #define MAX_DLL_BEFORE_INIT     100
@@ -63,16 +77,25 @@ class dll_list
   dll *end;
   dll *hold;
   dll_type hold_type;
+  static muto protect;
 public:
   dll start;
-  int tot;
   int loaded_dlls;
   int reload_on_fork;
-  dll *operator [] (const char *name);
+  dll *operator [] (const PWCHAR name);
   dll *alloc (HINSTANCE, per_process *, dll_type);
+  dll *find (void *);
   void detach (void *);
   void init ();
-  void load_after_fork (HANDLE, dll *);
+  void load_after_fork (HANDLE);
+  void reserve_space ();
+  void load_after_fork_impl (HANDLE, dll* which, int retries);
+  dll *find_by_modname (const PWCHAR name);
+  void populate_deps (dll* d);
+  void topsort ();
+  void topsort_visit (dll* d, bool goto_tail);
+  void append (dll* d);
+
   dll *inext ()
   {
     while ((hold = hold->next))
@@ -80,14 +103,46 @@ public:
        break;
     return hold;
   }
+
   dll *istart (dll_type t)
   {
     hold_type = t;
     hold = &start;
     return inext ();
   }
+  void guard(bool lockit)
+  {
+    if (lockit)
+      protect.acquire ();
+    else
+      protect.release ();
+  }
   friend void dll_global_dtors ();
+  dll_list () { protect.init ("dll_list"); }
+};
+
+/* References:
+   http://msdn.microsoft.com/en-us/windows/hardware/gg463125
+   http://msdn.microsoft.com/en-us/library/ms809762.aspx
+*/
+struct pefile
+{
+  IMAGE_DOS_HEADER dos_hdr;
+
+  char* rva (long offset) { return (char*) this + offset; }
+  PIMAGE_NT_HEADERS32 pe_hdr () { return (PIMAGE_NT_HEADERS32) rva (dos_hdr.e_lfanew); }
+  PIMAGE_OPTIONAL_HEADER32 optional_hdr () { return &pe_hdr ()->OptionalHeader; }
+  PIMAGE_DATA_DIRECTORY idata_dir (DWORD which)
+  {
+    PIMAGE_OPTIONAL_HEADER32 oh = optional_hdr ();
+    return (which < oh->NumberOfRvaAndSizes)? oh->DataDirectory + which : 0;
+  }
 };
 
 extern dll_list dlls;
 void dll_global_dtors ();
+
+/* These probably belong in a newlib header but we can keep them here
+   for now.  */
+extern "C" int __cxa_atexit(void (*)(void*), void*, void*);
+extern "C" int __cxa_finalize(void*);