| 1 | /* $Id: windllbase.h,v 1.4 2000-07-18 18:37:29 sandervl 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 | //odin.ini section names to lookup renamed dlls
|
|---|
| 33 | //i.e. OLE32 -> OLE32OS2
|
|---|
| 34 | #define DLLRENAMEWIN_SECTION "DLLRENAMEWIN"
|
|---|
| 35 | //i.e. OLE32OS2 -> OLE32
|
|---|
| 36 | #define DLLRENAMEOS2_SECTION "DLLRENAMEOS2"
|
|---|
| 37 |
|
|---|
| 38 | class Win32DllBase : public virtual Win32ImageBase
|
|---|
| 39 | {
|
|---|
| 40 | public:
|
|---|
| 41 | Win32DllBase(HINSTANCE hInstance, WIN32DLLENTRY DllEntryPoint, Win32ImageBase *parent = NULL);
|
|---|
| 42 | virtual ~Win32DllBase();
|
|---|
| 43 |
|
|---|
| 44 | #ifdef DEBUG
|
|---|
| 45 | virtual ULONG AddRef(char *parentname = NULL);
|
|---|
| 46 | #else
|
|---|
| 47 | virtual ULONG AddRef();
|
|---|
| 48 | #endif
|
|---|
| 49 | virtual ULONG Release();
|
|---|
| 50 |
|
|---|
| 51 | char *getName() { return szModule; };
|
|---|
| 52 |
|
|---|
| 53 | //do not call the ATTACH_THREAD, DETACH_THREAD functions
|
|---|
| 54 | void disableThreadLibraryCalls() { fSkipThreadEntryCalls = TRUE; };
|
|---|
| 55 |
|
|---|
| 56 | Win32DllBase *getNext() { return next; };
|
|---|
| 57 | static Win32DllBase *getFirst();
|
|---|
| 58 |
|
|---|
| 59 | //Send DLL_THREAD_ATTACH message to all dlls for a new thread
|
|---|
| 60 | static void attachThreadToAllDlls();
|
|---|
| 61 |
|
|---|
| 62 | //Send DLL_THREAD_DETACH message to all dlls for thread that's about to die
|
|---|
| 63 | static void detachThreadFromAllDlls();
|
|---|
| 64 |
|
|---|
| 65 | //Setup TLS structure for all dlls for a new thread
|
|---|
| 66 | static void tlsAttachThreadToAllDlls();
|
|---|
| 67 |
|
|---|
| 68 | //Destroy TLS structure for all dlls for a thread that's about to die
|
|---|
| 69 | static void tlsDetachThreadFromAllDlls();
|
|---|
| 70 |
|
|---|
| 71 | BOOL attachProcess();
|
|---|
| 72 | BOOL detachProcess();
|
|---|
| 73 | BOOL attachThread();
|
|---|
| 74 | BOOL detachThread();
|
|---|
| 75 |
|
|---|
| 76 | //This counter is incremented when the dll has been loaded with LoadLibrary(Ex)
|
|---|
| 77 | //(== not loaded on behalf of another dll or the main exe)
|
|---|
| 78 | void incDynamicLib();
|
|---|
| 79 | void decDynamicLib();
|
|---|
| 80 | BOOL isDynamicLib() { return nrDynamicLibRef != 0; };
|
|---|
| 81 |
|
|---|
| 82 | void setUnloadOrder(Win32ImageBase *parent);
|
|---|
| 83 |
|
|---|
| 84 | void updateDependencies();
|
|---|
| 85 |
|
|---|
| 86 | BOOL RemoveCircularDependency(Win32DllBase *parent);
|
|---|
| 87 |
|
|---|
| 88 | // Loaded by DosLoadModule
|
|---|
| 89 | virtual void setLoadLibrary() { fLoadLibrary = TRUE; };
|
|---|
| 90 |
|
|---|
| 91 | // isLoaded returns TRUE when a dll has been loaded with DosLoadModule
|
|---|
| 92 | virtual BOOL isLoaded() { return fLoadLibrary; };
|
|---|
| 93 |
|
|---|
| 94 | //Should only be called to make sure DosLoadModule is called at least
|
|---|
| 95 | //once for a dll (to make sure OS/2 doesn't unload the dll when it's
|
|---|
| 96 | //still needed)
|
|---|
| 97 | virtual void loadLibrary();
|
|---|
| 98 |
|
|---|
| 99 | //Only called for kernel32
|
|---|
| 100 | void DisableUnload() { fDisableUnload = TRUE; };
|
|---|
| 101 |
|
|---|
| 102 | static void deleteDynamicLibs();
|
|---|
| 103 | static void deleteAll();
|
|---|
| 104 |
|
|---|
| 105 | static BOOL isSystemDll(char *szFileName);
|
|---|
| 106 |
|
|---|
| 107 | virtual BOOL isLxDll() = 0;
|
|---|
| 108 | virtual BOOL isDll();
|
|---|
| 109 |
|
|---|
| 110 | static void renameDll(char *dllname, BOOL fWinToOS2=TRUE);
|
|---|
| 111 | static void setDefaultRenaming();
|
|---|
| 112 |
|
|---|
| 113 | static Win32DllBase *findModule(char *dllname, BOOL fRenameFirst = FALSE);
|
|---|
| 114 | static Win32DllBase *findModule(HINSTANCE hinstance);
|
|---|
| 115 | static Win32DllBase *findModule(WIN32DLLENTRY DllEntryPoint);
|
|---|
| 116 | static Win32DllBase *findModuleByAddr(ULONG address);
|
|---|
| 117 |
|
|---|
| 118 | #ifdef DEBUG_ENABLELOG_LEVEL2
|
|---|
| 119 | void printListOfDlls();
|
|---|
| 120 | #endif
|
|---|
| 121 |
|
|---|
| 122 | protected:
|
|---|
| 123 | #ifdef DEBUG
|
|---|
| 124 | void printDependencies(char *parent);
|
|---|
| 125 | #endif
|
|---|
| 126 |
|
|---|
| 127 | BOOL fSkipThreadEntryCalls, fUnloaded, fAttachedToProcess;
|
|---|
| 128 |
|
|---|
| 129 | WIN32DLLENTRY dllEntryPoint;
|
|---|
| 130 |
|
|---|
| 131 | LONG referenced;
|
|---|
| 132 |
|
|---|
| 133 | //This counter is incremented when the dll has been loaded with LoadLibrary(Ex)
|
|---|
| 134 | //(== not loaded on behalf of another dll or the main exe)
|
|---|
| 135 | BOOL nrDynamicLibRef;
|
|---|
| 136 |
|
|---|
| 137 | BOOL fInserted; //inserted in dll list
|
|---|
| 138 |
|
|---|
| 139 | //This flag is set when a dll has been loaded with DosLoadModule
|
|---|
| 140 | BOOL fLoadLibrary;
|
|---|
| 141 | BOOL fDisableUnload;
|
|---|
| 142 |
|
|---|
| 143 | private:
|
|---|
| 144 | static Queue loadLibDlls;
|
|---|
| 145 | static Win32DllBase *head;
|
|---|
| 146 | Win32DllBase *next;
|
|---|
| 147 | };
|
|---|
| 148 |
|
|---|
| 149 | extern VMutex dlllistmutex; //protects linked lists of heaps
|
|---|
| 150 |
|
|---|
| 151 | #endif
|
|---|