source: trunk/src/kernel32/windllbase.h@ 10010

Last change on this file since 10010 was 8923, checked in by sandervl, 23 years ago

added method to detach process from all dlls

File size: 4.3 KB
Line 
1/* $Id: windllbase.h,v 1.10 2002-07-26 10:48:40 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#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
40class Win32DllBase : public virtual Win32ImageBase
41{
42public:
43 Win32DllBase(HINSTANCE hInstance, WIN32DLLENTRY DllEntryPoint, Win32ImageBase *parent = NULL);
44virtual ~Win32DllBase();
45
46#ifdef DEBUG
47virtual ULONG AddRef(char *parentname = NULL);
48#else
49virtual ULONG AddRef();
50#endif
51virtual 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; };
60static Win32DllBase *getFirst();
61
62//Send DLL_THREAD_ATTACH message to all dlls for a new thread
63static void attachThreadToAllDlls();
64
65//Send DLL_THREAD_DETACH message to all dlls for thread that's about to die
66static void detachThreadFromAllDlls();
67
68//Send DLL_PROCESS_DETACH message to all dlls for process that's about to end
69static void detachProcessFromAllDlls();
70
71//Setup TLS structure for all dlls for a new thread
72static void tlsAttachThreadToAllDlls();
73
74//Destroy TLS structure for all dlls for a thread that's about to die
75static void tlsDetachThreadFromAllDlls();
76
77 BOOL attachProcess();
78 BOOL detachProcess();
79 BOOL attachThread();
80 BOOL detachThread();
81
82 //This counter is incremented when the dll has been loaded with LoadLibrary(Ex)
83 //(== not loaded on behalf of another dll or the main exe)
84 void incDynamicLib();
85 void decDynamicLib();
86 BOOL isDynamicLib() { return nrDynamicLibRef != 0; };
87
88 void setUnloadOrder(Win32ImageBase *parent);
89
90 void updateDependencies();
91
92 BOOL RemoveCircularDependency(Win32DllBase *parent);
93
94 //Only called for kernel32
95 void DisableUnload() { fDisableUnload = TRUE; };
96
97 BOOL IsUnloaded() { return fUnloaded; };
98
99static void deleteDynamicLibs();
100static void deleteAll();
101
102static BOOL isSystemDll(char *szFileName);
103
104virtual BOOL isPe2LxDll() const = 0;
105virtual BOOL isLxDll() const = 0;
106virtual BOOL isDll();
107
108static void renameDll(char *dllname, BOOL fWinToOS2=TRUE);
109static void setDefaultRenaming();
110
111static Win32DllBase *findModule(char *dllname, BOOL fRenameFirst = FALSE);
112static Win32DllBase *findModule(HINSTANCE hinstance);
113static Win32DllBase *findModule(WIN32DLLENTRY DllEntryPoint);
114static Win32DllBase *findModuleByAddr(ULONG address);
115static Win32DllBase *findModuleByOS2Handle(HINSTANCE hinstance);
116
117#ifdef DEBUG
118 void printListOfDlls();
119#endif
120
121protected:
122#ifdef DEBUG
123 void printDependencies(char *parent);
124#endif
125
126 BOOL fSkipThreadEntryCalls, fUnloaded, fAttachedToProcess, fSkipEntryCalls;
127
128 WIN32DLLENTRY dllEntryPoint;
129
130 LONG referenced;
131
132 //This counter is incremented when the dll has been loaded with LoadLibrary(Ex)
133 //(== not loaded on behalf of another dll or the main exe)
134 BOOL nrDynamicLibRef;
135
136 BOOL fInserted; //inserted in dll list
137
138 //This flag is set when a dll has been loaded with DosLoadModule
139 BOOL fDisableUnload;
140
141static Win32DllBase *head;
142 Win32DllBase *next;
143private:
144static Queue loadLibDlls;
145};
146
147extern VMutex dlllistmutex; //protects linked lists of heaps
148
149#endif
Note: See TracBrowser for help on using the repository browser.