[10397] | 1 | /* $Id: windllbase.h,v 1.11 2004-01-15 10:39:06 sandervl Exp $ */
|
---|
[3059] | 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 |
|
---|
[21916] | 15 | #include "winimagebase.h"
|
---|
[3059] | 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 |
|
---|
[6015] | 32 | #define DLL_EXTENSION ".DLL"
|
---|
[4523] | 33 |
|
---|
[3059] | 34 | //odin.ini section names to lookup renamed dlls
|
---|
| 35 | //i.e. OLE32 -> OLE32OS2
|
---|
[6015] | 36 | #define DLLRENAMEWIN_SECTION "DLLRENAMEWIN"
|
---|
[3059] | 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
|
---|
[6015] | 47 | virtual ULONG AddRef(char *parentname = NULL);
|
---|
[3059] | 48 | #else
|
---|
| 49 | virtual ULONG AddRef();
|
---|
| 50 | #endif
|
---|
[6015] | 51 | virtual ULONG Release();
|
---|
[3059] | 52 |
|
---|
[6015] | 53 | char *getName() { return szModule; };
|
---|
[3059] | 54 |
|
---|
[3854] | 55 | //do not call the ATTACH_THREAD, DETACH_THREAD functions
|
---|
[6015] | 56 | void disableThreadLibraryCalls() { fSkipThreadEntryCalls = TRUE; };
|
---|
| 57 | void disableLibraryCalls() { fSkipEntryCalls = fSkipThreadEntryCalls = TRUE; };
|
---|
[3854] | 58 |
|
---|
[6015] | 59 | Win32DllBase *getNext() { return next; };
|
---|
| 60 | static Win32DllBase *getFirst();
|
---|
[3059] | 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 |
|
---|
[8923] | 68 | //Send DLL_PROCESS_DETACH message to all dlls for process that's about to end
|
---|
| 69 | static void detachProcessFromAllDlls();
|
---|
| 70 |
|
---|
[3059] | 71 | //Setup TLS structure for all dlls for a new thread
|
---|
| 72 | static void tlsAttachThreadToAllDlls();
|
---|
| 73 |
|
---|
| 74 | //Destroy TLS structure for all dlls for a thread that's about to die
|
---|
| 75 | static void tlsDetachThreadFromAllDlls();
|
---|
| 76 |
|
---|
[6015] | 77 | BOOL attachProcess();
|
---|
| 78 | BOOL detachProcess();
|
---|
| 79 | BOOL attachThread();
|
---|
| 80 | BOOL detachThread();
|
---|
[3059] | 81 |
|
---|
[6015] | 82 | //This counter is incremented when the dll has been loaded with LoadLibrary(Ex)
|
---|
[8923] | 83 | //(== not loaded on behalf of another dll or the main exe)
|
---|
[6015] | 84 | void incDynamicLib();
|
---|
| 85 | void decDynamicLib();
|
---|
| 86 | BOOL isDynamicLib() { return nrDynamicLibRef != 0; };
|
---|
[3059] | 87 |
|
---|
[10397] | 88 | WIN32DLLENTRY getEntryPoint() { return dllEntryPoint; };
|
---|
| 89 |
|
---|
[6015] | 90 | void setUnloadOrder(Win32ImageBase *parent);
|
---|
[3059] | 91 |
|
---|
[6015] | 92 | void updateDependencies();
|
---|
[3059] | 93 |
|
---|
[6015] | 94 | BOOL RemoveCircularDependency(Win32DllBase *parent);
|
---|
[3059] | 95 |
|
---|
[6015] | 96 | //Only called for kernel32
|
---|
| 97 | void DisableUnload() { fDisableUnload = TRUE; };
|
---|
| 98 |
|
---|
[8923] | 99 | BOOL IsUnloaded() { return fUnloaded; };
|
---|
| 100 |
|
---|
[3059] | 101 | static void deleteDynamicLibs();
|
---|
| 102 | static void deleteAll();
|
---|
| 103 |
|
---|
[6015] | 104 | static BOOL isSystemDll(char *szFileName);
|
---|
[3059] | 105 |
|
---|
[6015] | 106 | virtual BOOL isPe2LxDll() const = 0;
|
---|
| 107 | virtual BOOL isLxDll() const = 0;
|
---|
[3059] | 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);
|
---|
[3483] | 116 | static Win32DllBase *findModuleByAddr(ULONG address);
|
---|
[6015] | 117 | static Win32DllBase *findModuleByOS2Handle(HINSTANCE hinstance);
|
---|
[3059] | 118 |
|
---|
[10397] | 119 | static int enumDlls(HMODULE *lphModule, int countMax);
|
---|
| 120 |
|
---|
[8609] | 121 | #ifdef DEBUG
|
---|
[6015] | 122 | void printListOfDlls();
|
---|
[3059] | 123 | #endif
|
---|
| 124 |
|
---|
| 125 | protected:
|
---|
| 126 | #ifdef DEBUG
|
---|
[6015] | 127 | void printDependencies(char *parent);
|
---|
[3059] | 128 | #endif
|
---|
| 129 |
|
---|
[6015] | 130 | BOOL fSkipThreadEntryCalls, fUnloaded, fAttachedToProcess, fSkipEntryCalls;
|
---|
[3059] | 131 |
|
---|
[6015] | 132 | WIN32DLLENTRY dllEntryPoint;
|
---|
[3059] | 133 |
|
---|
[6015] | 134 | LONG referenced;
|
---|
[3059] | 135 |
|
---|
[6015] | 136 | //This counter is incremented when the dll has been loaded with LoadLibrary(Ex)
|
---|
[3059] | 137 | //(== not loaded on behalf of another dll or the main exe)
|
---|
[6015] | 138 | BOOL nrDynamicLibRef;
|
---|
[3059] | 139 |
|
---|
[6015] | 140 | BOOL fInserted; //inserted in dll list
|
---|
[3059] | 141 |
|
---|
[6015] | 142 | //This flag is set when a dll has been loaded with DosLoadModule
|
---|
| 143 | BOOL fDisableUnload;
|
---|
[3993] | 144 |
|
---|
| 145 | static Win32DllBase *head;
|
---|
[6015] | 146 | Win32DllBase *next;
|
---|
[3059] | 147 | private:
|
---|
| 148 | static Queue loadLibDlls;
|
---|
| 149 | };
|
---|
| 150 |
|
---|
| 151 | extern VMutex dlllistmutex; //protects linked lists of heaps
|
---|
| 152 |
|
---|
| 153 | #endif
|
---|