00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
#include "ki.h"
00029
00030
00031
00032
00033
00034
#undef ALIGN_UP
00035
#undef ALIGN_DOWN
00036 #define ALIGN_DOWN(address,amt) ((ULONG)(address) & ~(( amt ) - 1))
00037 #define ALIGN_UP(address,amt) (ALIGN_DOWN( (address + (amt) - 1), (amt) ))
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
VOID
00064
KiSetIoMap(
00065 IN PKIPI_CONTEXT SignalDone,
00066 IN PVOID MapSource,
00067 IN PVOID MapNumber,
00068 IN PVOID Parameter3
00069 );
00070
00071
VOID
00072
KiLoadIopmOffset(
00073 IN PKIPI_CONTEXT SignalDone,
00074 IN PVOID Parameter1,
00075 IN PVOID Parameter2,
00076 IN PVOID Parameter3
00077 );
00078
00079 BOOLEAN
00080 Ke386SetIoAccessMap (
00081 ULONG MapNumber,
00082 PKIO_ACCESS_MAP IoAccessMap
00083 )
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 {
00113
00114
PKPROCESS CurrentProcess;
00115 KIRQL OldIrql;
00116 PKPRCB Prcb;
00117 PVOID pt;
00118 KAFFINITY TargetProcessors;
00119
00120
00121
00122
00123
00124
if ((MapNumber > IOPM_COUNT) || (MapNumber == IO_ACCESS_MAP_NONE)) {
00125
return FALSE;
00126 }
00127
00128
00129
00130
00131
00132
KiLockContextSwap(&OldIrql);
00133
00134
00135
00136
00137
00138
00139 Prcb =
KeGetCurrentPrcb();
00140
00141
#if !defined(NT_UP)
00142
00143 TargetProcessors =
KeActiveProcessors & ~Prcb->SetMember;
00144
if (TargetProcessors != 0) {
00145
KiIpiSendPacket(TargetProcessors,
00146
KiSetIoMap,
00147 IoAccessMap,
00148 (PVOID)MapNumber,
00149
NULL);
00150 }
00151
00152
#endif
00153
00154
00155
00156
00157
00158 pt = &(
KiPcr()->TSS->IoMaps[MapNumber-1].IoMap);
00159 RtlMoveMemory(pt, (PVOID)IoAccessMap, IOPM_SIZE);
00160 CurrentProcess = Prcb->CurrentThread->ApcState.Process;
00161
KiPcr()->TSS->IoMapBase = CurrentProcess->IopmOffset;
00162
00163
00164
00165
00166
00167
00168
#if !defined(NT_UP)
00169
00170
if (TargetProcessors != 0) {
00171
KiIpiStallOnPacketTargets(TargetProcessors);
00172 }
00173
00174
#endif
00175
00176
00177
00178
00179
00180
KiUnlockContextSwap(OldIrql);
00181
return TRUE;
00182 }
00183
00184
#if !defined(NT_UP)
00185
00186
00187
VOID
00188 KiSetIoMap(
00189 IN PKIPI_CONTEXT SignalDone,
00190 IN PVOID MapSource,
00191 IN PVOID MapNumber,
00192 IN PVOID Parameter3
00193 )
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 {
00213
00214
PKPROCESS CurrentProcess;
00215 PKPRCB Prcb;
00216 PVOID pt;
00217
00218
00219
00220
00221
00222 Prcb =
KeGetCurrentPrcb();
00223 pt = &(
KiPcr()->TSS->IoMaps[((ULONG) MapNumber)-1].IoMap);
00224 RtlMoveMemory(pt, MapSource, IOPM_SIZE);
00225 CurrentProcess = Prcb->CurrentThread->ApcState.Process;
00226
KiPcr()->TSS->IoMapBase = CurrentProcess->IopmOffset;
00227
KiIpiSignalPacketDone(SignalDone);
00228
return;
00229 }
00230
00231
#endif
00232
00233
00234 BOOLEAN
00235 Ke386QueryIoAccessMap (
00236 ULONG MapNumber,
00237 PKIO_ACCESS_MAP IoAccessMap
00238 )
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 {
00263
00264 ULONG i;
00265 PVOID Map;
00266 KIRQL OldIrql;
00267 PUCHAR p;
00268
00269
00270
00271
00272
00273
if (MapNumber > IOPM_COUNT) {
00274
return FALSE;
00275 }
00276
00277
00278
00279
00280
00281
KiLockContextSwap(&OldIrql);
00282
00283
00284
00285
00286
00287
if (MapNumber == IO_ACCESS_MAP_NONE) {
00288
00289
00290
00291
00292
00293 p = (PUCHAR)IoAccessMap;
00294
for (i = 0; i < IOPM_SIZE; i++) {
00295 p[i] = (UCHAR)-1;
00296 }
00297
00298 }
else {
00299
00300
00301
00302
00303
00304 Map = (PVOID)&(
KiPcr()->TSS->IoMaps[MapNumber-1].IoMap);
00305 RtlMoveMemory((PVOID)IoAccessMap, Map, IOPM_SIZE);
00306 }
00307
00308
00309
00310
00311
00312
KiUnlockContextSwap(OldIrql);
00313
return TRUE;
00314 }
00315
00316
00317 BOOLEAN
00318 Ke386IoSetAccessProcess (
00319
PKPROCESS Process,
00320 ULONG MapNumber
00321 )
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 {
00346
00347
USHORT MapOffset;
00348 KIRQL OldIrql;
00349 PKPRCB Prcb;
00350 KAFFINITY TargetProcessors;
00351
00352
00353
00354
00355
00356
if (MapNumber > IOPM_COUNT) {
00357
return FALSE;
00358 }
00359
00360 MapOffset = KiComputeIopmOffset(MapNumber);
00361
00362
00363
00364
00365
00366
KiLockContextSwap(&OldIrql);
00367
00368
00369
00370
00371
00372
00373 Process->IopmOffset = MapOffset;
00374
00375 TargetProcessors = Process->
ActiveProcessors;
00376 Prcb =
KeGetCurrentPrcb();
00377
if (TargetProcessors & Prcb->SetMember) {
00378
KiPcr()->TSS->IoMapBase = MapOffset;
00379 }
00380
00381
00382
00383
00384
00385
00386
#if !defined(NT_UP)
00387
00388 TargetProcessors = TargetProcessors & ~Prcb->SetMember;
00389
if (TargetProcessors != 0) {
00390
KiIpiSendPacket(TargetProcessors,
00391
KiLoadIopmOffset,
00392
NULL,
00393
NULL,
00394
NULL);
00395
00396
KiIpiStallOnPacketTargets(TargetProcessors);
00397 }
00398
00399
#endif
00400
00401
00402
00403
00404
00405
KiUnlockContextSwap(OldIrql);
00406
return TRUE;
00407 }
00408
00409
#if !defined(NT_UP)
00410
00411
00412
VOID
00413 KiLoadIopmOffset(
00414 IN PKIPI_CONTEXT SignalDone,
00415 IN PVOID Parameter1,
00416 IN PVOID Parameter2,
00417 IN PVOID Parameter3
00418 )
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437 {
00438
00439
PKPROCESS CurrentProcess;
00440 PKPRCB Prcb;
00441
00442
00443
00444
00445
00446 Prcb =
KeGetCurrentPrcb();
00447 CurrentProcess = Prcb->CurrentThread->ApcState.Process;
00448
KiPcr()->TSS->IoMapBase = CurrentProcess->IopmOffset;
00449
KiIpiSignalPacketDone(SignalDone);
00450
return;
00451 }
00452
00453
#endif
00454
00455
00456
VOID
00457 Ke386SetIOPL(
00458 IN
PKPROCESS Process
00459 )
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490 {
00491
00492
PKTHREAD Thread;
00493
PKPROCESS Process2;
00494 PKTRAP_FRAME TrapFrame;
00495 CONTEXT Context;
00496
00497
00498
00499
00500
00501 Thread =
KeGetCurrentThread();
00502 Process2 = Thread->
ApcState.
Process;
00503
00504 Process2->Iopl = 1;
00505 Thread->
Iopl = 1;
00506
00507
00508
00509
00510
00511 TrapFrame = (PKTRAP_FRAME)((PUCHAR)Thread->
InitialStack -
00512
ALIGN_UP(
sizeof(KTRAP_FRAME),KTRAP_FRAME_ALIGN) -
00513
sizeof(FX_SAVE_AREA));
00514
00515 Context.ContextFlags =
CONTEXT_CONTROL;
00516
KeContextFromKframes(TrapFrame,
00517
NULL,
00518 &Context);
00519
00520 Context.EFlags |= (EFLAGS_IOPL_MASK & -1);
00521
00522
KeContextToKframes(TrapFrame,
00523
NULL,
00524 &Context,
00525
CONTEXT_CONTROL,
00526
UserMode);
00527
00528
return;
00529 }