1 | /* $Id: windllbase.h,v 1.8 2001-06-15 09:42:48 bird Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Win32 Dll base class
|
---|
5 | *
|
---|
6 | * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 | #ifndef __WINDLLBASE_H__
|
---|
13 | #define __WINDLLBASE_H__
|
---|
14 |
|
---|
15 | #include <winimagebase.h>
|
---|
16 | #include <odinlx.h>
|
---|
17 | #include <vmutex.h>
|
---|
18 |
|
---|
19 | #ifndef HINSTANCE
|
---|
20 | #define HINSTANCE ULONG
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | #define DLL_PROCESS_ATTACH 1
|
---|
24 | #define DLL_THREAD_ATTACH 2
|
---|
25 | #define DLL_THREAD_DETACH 3
|
---|
26 | #define DLL_PROCESS_DETACH 0
|
---|
27 |
|
---|
28 | #define DONT_RESOLVE_DLL_REFERENCES 0x00000001
|
---|
29 | #define LOAD_LIBRARY_AS_DATAFILE 0x00000002
|
---|
30 | #define LOAD_WITH_ALTERED_SEARCH_PATH 0x00000008
|
---|
31 |
|
---|
32 | #define DLL_EXTENSION ".DLL"
|
---|
33 |
|
---|
34 | //odin.ini section names to lookup renamed dlls
|
---|
35 | //i.e. OLE32 -> OLE32OS2
|
---|
36 | #define DLLRENAMEWIN_SECTION "DLLRENAMEWIN"
|
---|
37 | //i.e. OLE32OS2 -> OLE32
|
---|
38 | #define DLLRENAMEOS2_SECTION "DLLRENAMEOS2"
|
---|
39 |
|
---|
40 | class Win32DllBase : public virtual Win32ImageBase
|
---|
41 | {
|
---|
42 | public:
|
---|
43 | Win32DllBase(HINSTANCE hInstance, WIN32DLLENTRY DllEntryPoint, Win32ImageBase *parent = NULL);
|
---|
44 | virtual ~Win32DllBase();
|
---|
45 |
|
---|
46 | #ifdef DEBUG
|
---|
47 | virtual ULONG AddRef(char *parentname = NULL);
|
---|
48 | #else
|
---|
49 | virtual ULONG AddRef();
|
---|
50 | #endif
|
---|
51 | virtual ULONG Release();
|
---|
52 |
|
---|
53 | char *getName() { return szModule; };
|
---|
54 |
|
---|
55 | //do not call the ATTACH_THREAD, DETACH_THREAD functions
|
---|
56 | void disableThreadLibraryCalls() { fSkipThreadEntryCalls = TRUE; };
|
---|
57 | void disableLibraryCalls() { fSkipEntryCalls = fSkipThreadEntryCalls = TRUE; };
|
---|
58 |
|
---|
59 | Win32DllBase *getNext() { return next; };
|
---|
60 | static Win32DllBase *getFirst();
|
---|
61 |
|
---|
62 | //Send DLL_THREAD_ATTACH message to all dlls for a new thread
|
---|
63 | static void attachThreadToAllDlls();
|
---|
64 |
|
---|
65 | //Send DLL_THREAD_DETACH message to all dlls for thread that's about to die
|
---|
66 | static void detachThreadFromAllDlls();
|
---|
67 |
|
---|
68 | //Setup TLS structure for all dlls for a new thread
|
---|
69 | static void tlsAttachThreadToAllDlls();
|
---|
70 |
|
---|
71 | //Destroy TLS structure for all dlls for a thread that's about to die
|
---|
72 | static void tlsDetachThreadFromAllDlls();
|
---|
73 |
|
---|
74 | BOOL attachProcess();
|
---|
75 | BOOL detachProcess();
|
---|
76 | BOOL attachThread();
|
---|
77 | BOOL detachThread();
|
---|
78 |
|
---|
79 | //This counter is incremented when the dll has been loaded with LoadLibrary(Ex)
|
---|
80 | //(== not loaded on behalf of another dll or the main exe)
|
---|
81 | void incDynamicLib();
|
---|
82 | void decDynamicLib();
|
---|
83 | BOOL isDynamicLib() { return nrDynamicLibRef != 0; };
|
---|
84 |
|
---|
85 | void setUnloadOrder(Win32ImageBase *parent);
|
---|
86 |
|
---|
87 | void updateDependencies();
|
---|
88 |
|
---|
89 | BOOL RemoveCircularDependency(Win32DllBase *parent);
|
---|
90 |
|
---|
91 | //Only called for kernel32
|
---|
92 | void DisableUnload() { fDisableUnload = TRUE; };
|
---|
93 |
|
---|
94 | static void deleteDynamicLibs();
|
---|
95 | static void deleteAll();
|
---|
96 |
|
---|
97 | static BOOL isSystemDll(char *szFileName);
|
---|
98 |
|
---|
99 | virtual BOOL isPe2LxDll() const = 0;
|
---|
100 | virtual BOOL isLxDll() const = 0;
|
---|
101 | virtual BOOL isDll();
|
---|
102 |
|
---|
103 | static void renameDll(char *dllname, BOOL fWinToOS2=TRUE);
|
---|
104 | static void setDefaultRenaming();
|
---|
105 |
|
---|
106 | static Win32DllBase *findModule(char *dllname, BOOL fRenameFirst = FALSE);
|
---|
107 | static Win32DllBase *findModule(HINSTANCE hinstance);
|
---|
108 | static Win32DllBase *findModule(WIN32DLLENTRY DllEntryPoint);
|
---|
109 | static Win32DllBase *findModuleByAddr(ULONG address);
|
---|
110 | static Win32DllBase *findModuleByOS2Handle(HINSTANCE hinstance);
|
---|
111 |
|
---|
112 | #ifdef DEBUG_ENABLELOG_LEVEL2
|
---|
113 | void printListOfDlls();
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | protected:
|
---|
117 | #ifdef DEBUG
|
---|
118 | void printDependencies(char *parent);
|
---|
119 | #endif
|
---|
120 |
|
---|
121 | BOOL fSkipThreadEntryCalls, fUnloaded, fAttachedToProcess, fSkipEntryCalls;
|
---|
122 |
|
---|
123 | WIN32DLLENTRY dllEntryPoint;
|
---|
124 |
|
---|
125 | LONG referenced;
|
---|
126 |
|
---|
127 | //This counter is incremented when the dll has been loaded with LoadLibrary(Ex)
|
---|
128 | //(== not loaded on behalf of another dll or the main exe)
|
---|
129 | BOOL nrDynamicLibRef;
|
---|
130 |
|
---|
131 | BOOL fInserted; //inserted in dll list
|
---|
132 |
|
---|
133 | //This flag is set when a dll has been loaded with DosLoadModule
|
---|
134 | BOOL fDisableUnload;
|
---|
135 |
|
---|
136 | static Win32DllBase *head;
|
---|
137 | Win32DllBase *next;
|
---|
138 | private:
|
---|
139 | static Queue loadLibDlls;
|
---|
140 | };
|
---|
141 |
|
---|
142 | extern VMutex dlllistmutex; //protects linked lists of heaps
|
---|
143 |
|
---|
144 | #endif
|
---|