Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

libmgmt.c File Reference

#include "precomp.h"

Go to the source code of this file.

Functions

int GetHmodTableIndex (PUNICODE_STRING pstrLibName)
VOID AddHmodDependency (int iatom)
VOID RemoveHmodDependency (int iatom)
HANDLE xxxLoadHmodIndex (int iatom, BOOL bWx86KnownDll)
VOID xxxDoSysExpunge (PTHREADINFO pti)

Variables

int catomSysTableEntries
ATOM aatomSysLoaded [CLIBS]
int acatomSysUse [CLIBS]
int acatomSysDepends [CLIBS]


Function Documentation

VOID AddHmodDependency int  iatom  ) 
 

Definition at line 136 of file libmgmt.c.

References acatomSysDepends, catomSysTableEntries, and VOID().

Referenced by _SetWinEventHook(), and zzzSetWindowsHookEx().

00138 { 00139 UserAssert(iatom >= 0); 00140 if (iatom < catomSysTableEntries) { 00141 acatomSysDepends[iatom]++; 00142 } 00143 }

int GetHmodTableIndex PUNICODE_STRING  pstrLibName  ) 
 

Definition at line 53 of file libmgmt.c.

References aatomSysLoaded, acatomSysDepends, acatomSysUse, catomSysTableEntries, CLIBS, FALSE, ProbeAndReadUnicodeString, ProbeForReadUnicodeStringBuffer, UserAddAtom(), and UserDeleteAtom().

Referenced by _SetWinEventHook(), and zzzSetWindowsHookEx().

00055 { 00056 int i; 00057 ATOM atom; 00058 UNICODE_STRING strLibName; 00059 00060 /* 00061 * Probe string 00062 */ 00063 try { 00064 strLibName = ProbeAndReadUnicodeString(pstrLibName); 00065 ProbeForReadUnicodeStringBuffer(strLibName); 00066 atom = UserAddAtom(strLibName.Buffer, FALSE); 00067 } except (W32ExceptionHandler(FALSE, RIP_WARNING)) { 00068 return -1; 00069 } 00070 00071 /* 00072 * If we can't add the atom we're hosed 00073 * so return an error. 00074 */ 00075 if (atom == 0) { 00076 return -1; 00077 } 00078 00079 /* 00080 * Search for atom index 00081 */ 00082 for (i = 0; i < catomSysTableEntries && aatomSysLoaded[i] != atom; i++) 00083 ; 00084 00085 if (i == catomSysTableEntries) { 00086 00087 /* 00088 * Find empty entry for atom 00089 */ 00090 for (i = 0; i < catomSysTableEntries && aatomSysLoaded[i]; i++) 00091 ; 00092 00093 /* 00094 * Check if no empty entry found 00095 */ 00096 if (i == catomSysTableEntries) { 00097 if (i == CLIBS) { 00098 UserDeleteAtom(atom); 00099 RIPERR0(ERROR_NOT_ENOUGH_MEMORY, 00100 RIP_WARNING, 00101 "Memory allocation failed in GetHmodTableIndex"); 00102 00103 return -1; 00104 } 00105 00106 /* 00107 * Increase table size 00108 */ 00109 catomSysTableEntries++; 00110 } 00111 00112 /* 00113 * Set entry 00114 */ 00115 aatomSysLoaded[i] = atom; 00116 acatomSysUse[i] = 0; 00117 acatomSysDepends[i] = 0; 00118 } else { 00119 UserDeleteAtom(atom); 00120 } 00121 00122 return i; 00123 }

VOID RemoveHmodDependency int  iatom  ) 
 

Definition at line 158 of file libmgmt.c.

References aatomSysLoaded, acatomSysDepends, acatomSysUse, catomSysTableEntries, gcSysExpunge, gdwSysExpungeMask, and VOID().

Referenced by DestroyEventHook(), and FreeHook().

00160 { 00161 00162 UserAssert(iatom >= 0); 00163 if (iatom < catomSysTableEntries && 00164 --acatomSysDepends[iatom] == 0) { 00165 00166 if (acatomSysUse[iatom]) { 00167 00168 /* 00169 * Cause each thread to check for expunged dlls 00170 * the next time they awake. 00171 */ 00172 gcSysExpunge++; 00173 gdwSysExpungeMask |= (1 << iatom); 00174 } else { 00175 aatomSysLoaded[iatom] = 0; 00176 } 00177 } 00178 }

VOID xxxDoSysExpunge PTHREADINFO  pti  ) 
 

Definition at line 253 of file libmgmt.c.

References aatomSysLoaded, acatomSysDepends, acatomSysUse, tagPROCESSINFO::ahmodLibLoaded, catomSysTableEntries, CLEARHMODLOADED, ClientFreeLibrary(), tagPROCESSINFO::cSysExpunge, gcSysExpunge, gdwSysExpungeMask, tagTHREADINFO::ppi, TESTHMODLOADED, UserDeleteAtom(), and VOID().

Referenced by xxxInternalGetMessage(), and xxxSleepThread().

00255 { 00256 int i; 00257 00258 /* 00259 * Clear this first before we potentially leave the critical section. 00260 */ 00261 pti->ppi->cSysExpunge = gcSysExpunge; 00262 00263 /* 00264 * Scan for libraries that have been freed 00265 */ 00266 for (i = 0; i < catomSysTableEntries; i++) { 00267 if ((acatomSysDepends[i] == 0) && (aatomSysLoaded[i] != 0) && 00268 TESTHMODLOADED(pti, i)) { 00269 00270 HANDLE hmodFree = pti->ppi->ahmodLibLoaded[i]; 00271 00272 /* 00273 * Clear this hmod for this process before we leave the 00274 * critical section. 00275 */ 00276 CLEARHMODLOADED(pti, i); 00277 00278 /* 00279 * Decrement the count of processes that have loaded this 00280 * .dll. If there are no more, then destroy the reference 00281 * to this .dll. 00282 */ 00283 if (--acatomSysUse[i] == 0) { 00284 UserDeleteAtom(aatomSysLoaded[i]); 00285 aatomSysLoaded[i] = 0; 00286 gdwSysExpungeMask &= ~(1 << i); 00287 } 00288 00289 /* 00290 * Call back the client to free the library... 00291 */ 00292 ClientFreeLibrary(hmodFree); 00293 } 00294 } 00295 }

HANDLE xxxLoadHmodIndex int  iatom,
BOOL  bWx86KnownDll
 

Definition at line 192 of file libmgmt.c.

References aatomSysLoaded, acatomSysUse, tagPROCESSINFO::ahmodLibLoaded, catomSysTableEntries, ClientFreeLibrary(), ClientLoadLibrary(), gptiRit, MAX_PATH, NULL, tagTHREADINFO::ppi, PtiCurrent, RtlInitUnicodeString(), SETHMODLOADED, TESTHMODLOADED, and UserGetAtomName().

Referenced by xxxCallHook2(), and xxxGetEventProc().

00195 { 00196 WCHAR pszLibName[MAX_PATH]; 00197 HANDLE hmod; 00198 UNICODE_STRING strLibrary; 00199 PTHREADINFO ptiCurrent = PtiCurrent(); 00200 00201 UserAssert((!gptiRit || gptiRit->ppi != PtiCurrent()->ppi) && 00202 "Shouldn't load global hooks on system process - gptiRit->ppi is the system process"); 00203 00204 if (iatom >= catomSysTableEntries) { 00205 RIPERR0(ERROR_INVALID_PARAMETER, RIP_WARNING, "Index out of range"); 00206 return NULL; 00207 } 00208 00209 UserGetAtomName(aatomSysLoaded[iatom], pszLibName, sizeof(pszLibName)/sizeof(WCHAR)); 00210 00211 /* 00212 * Call back the client to load the library. 00213 */ 00214 RtlInitUnicodeString(&strLibrary, pszLibName); 00215 hmod = ClientLoadLibrary(&strLibrary, bWx86KnownDll); 00216 00217 if (hmod != NULL) { 00218 /* 00219 * Check to make sure another thread hasn't loaded this library 00220 * while we were outside the critical section. 00221 */ 00222 if (!TESTHMODLOADED(ptiCurrent, iatom)) { 00223 /* 00224 * Go ahead and bump the reference count. 00225 */ 00226 acatomSysUse[iatom]++; 00227 SETHMODLOADED(ptiCurrent, iatom, hmod); 00228 00229 } else { 00230 /* 00231 * Another thread loaded it while we were outside the 00232 * critical section. Unload it so the system's 00233 * reference count is correct. 00234 */ 00235 ClientFreeLibrary(ptiCurrent->ppi->ahmodLibLoaded[iatom]); 00236 } 00237 } 00238 00239 return hmod; 00240 }


Variable Documentation

ATOM aatomSysLoaded[CLIBS]
 

Definition at line 29 of file libmgmt.c.

Referenced by GetHmodTableIndex(), RemoveHmodDependency(), xxxDoSysExpunge(), and xxxLoadHmodIndex().

int acatomSysDepends[CLIBS]
 

Definition at line 39 of file libmgmt.c.

Referenced by AddHmodDependency(), GetHmodTableIndex(), RemoveHmodDependency(), and xxxDoSysExpunge().

int acatomSysUse[CLIBS]
 

Definition at line 34 of file libmgmt.c.

Referenced by GetHmodTableIndex(), RemoveHmodDependency(), xxxDoSysExpunge(), and xxxLoadHmodIndex().

int catomSysTableEntries
 

Definition at line 23 of file libmgmt.c.

Referenced by AddHmodDependency(), GetHmodTableIndex(), RemoveHmodDependency(), xxxDoSysExpunge(), and xxxLoadHmodIndex().


Generated on Sat May 15 19:44:32 2004 for test by doxygen 1.3.7