00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
#include "precomp.h"
00014
#pragma hdrstop
00015
00016
00017
00018
00019
00020
00021
00022
00023 int catomSysTableEntries;
00024
00025
00026
00027
00028
00029 ATOM
aatomSysLoaded[
CLIBS];
00030
00031
00032
00033
00034 int acatomSysUse[
CLIBS];
00035
00036
00037
00038
00039 int acatomSysDepends[
CLIBS];
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 int GetHmodTableIndex(
00054 PUNICODE_STRING pstrLibName)
00055 {
00056
int i;
00057 ATOM atom;
00058 UNICODE_STRING strLibName;
00059
00060
00061
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
00073
00074
00075
if (atom == 0) {
00076
return -1;
00077 }
00078
00079
00080
00081
00082
for (i = 0; i <
catomSysTableEntries &&
aatomSysLoaded[i] != atom; i++)
00083 ;
00084
00085
if (i ==
catomSysTableEntries) {
00086
00087
00088
00089
00090
for (i = 0; i <
catomSysTableEntries &&
aatomSysLoaded[i]; i++)
00091 ;
00092
00093
00094
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
00108
00109
catomSysTableEntries++;
00110 }
00111
00112
00113
00114
00115
aatomSysLoaded[i] = atom;
00116
acatomSysUse[i] = 0;
00117
acatomSysDepends[i] = 0;
00118 }
else {
00119
UserDeleteAtom(atom);
00120 }
00121
00122
return i;
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 VOID AddHmodDependency(
00137
int iatom)
00138 {
00139 UserAssert(iatom >= 0);
00140
if (iatom <
catomSysTableEntries) {
00141
acatomSysDepends[iatom]++;
00142 }
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 VOID RemoveHmodDependency(
00159
int iatom)
00160 {
00161
00162 UserAssert(iatom >= 0);
00163
if (iatom <
catomSysTableEntries &&
00164 --
acatomSysDepends[iatom] == 0) {
00165
00166
if (
acatomSysUse[iatom]) {
00167
00168
00169
00170
00171
00172
gcSysExpunge++;
00173
gdwSysExpungeMask |= (1 << iatom);
00174 }
else {
00175
aatomSysLoaded[iatom] = 0;
00176 }
00177 }
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 HANDLE
xxxLoadHmodIndex(
00193
int iatom,
00194 BOOL bWx86KnownDll)
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
00213
00214
RtlInitUnicodeString(&strLibrary, pszLibName);
00215 hmod =
ClientLoadLibrary(&strLibrary, bWx86KnownDll);
00216
00217
if (hmod !=
NULL) {
00218
00219
00220
00221
00222
if (!
TESTHMODLOADED(ptiCurrent, iatom)) {
00223
00224
00225
00226
acatomSysUse[iatom]++;
00227
SETHMODLOADED(ptiCurrent, iatom, hmod);
00228
00229 }
else {
00230
00231
00232
00233
00234
00235
ClientFreeLibrary(ptiCurrent->
ppi->
ahmodLibLoaded[iatom]);
00236 }
00237 }
00238
00239
return hmod;
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 VOID xxxDoSysExpunge(
00254
PTHREADINFO pti)
00255 {
00256
int i;
00257
00258
00259
00260
00261 pti->
ppi->
cSysExpunge =
gcSysExpunge;
00262
00263
00264
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
00274
00275
00276
CLEARHMODLOADED(pti, i);
00277
00278
00279
00280
00281
00282
00283
if (--
acatomSysUse[i] == 0) {
00284
UserDeleteAtom(
aatomSysLoaded[i]);
00285
aatomSysLoaded[i] = 0;
00286
gdwSysExpungeMask &= ~(1 << i);
00287 }
00288
00289
00290
00291
00292
ClientFreeLibrary(hmodFree);
00293 }
00294 }
00295 }