01519 :
01520
01521 This function sets
the state of a process object.
01522
01523 Arguments:
01524
01525 ProcessHandle - Supplies a handle to a process object.
01526
01527 ProcessInformationClass - Supplies
the class of information being
01528 set.
01529
01530 ProcessInformation - Supplies a pointer to a record that contains
the
01531 information to set.
01532
01533 ProcessInformationLength - Supplies
the length of
the record that contains
01534
the information to set.
01535
01536 Return Value:
01537
01538 TBS
01539
01540 --*/
01541
01542 {
01543
01544
PEPROCESS Process;
01545
PETHREAD Thread;
01546
KPROCESSOR_MODE PreviousMode;
01547
NTSTATUS st;
01548 KPRIORITY BasePriority;
01549 ULONG BoostValue;
01550 ULONG DefaultHardErrorMode;
01551 PVOID
DebugPort;
01552 PVOID ExceptionPort;
01553 HANDLE DebugPortHandle;
01554 BOOLEAN EnableAlignmentFaultFixup;
01555 HANDLE ExceptionPortHandle;
01556 ULONG ProbeAlignment;
01557 HANDLE PrimaryTokenHandle;
01558 BOOLEAN HasPrivilege =
FALSE;
01559 BOOLEAN IsChildToken =
FALSE;
01560 PLIST_ENTRY Next;
01561 UCHAR MemoryPriority;
01562 PROCESS_PRIORITY_CLASS LocalPriorityClass;
01563 PROCESS_FOREGROUND_BACKGROUND LocalForeground;
01564 HANDLE Wx86Info;
01565 KAFFINITY Affinity, AffinityWithMasks;
01566 ULONG_PTR BigAffinity;
01567 ULONG DisableBoost;
01568 BOOLEAN bDisableBoost;
01569 PPROCESS_DEVICEMAP_INFORMATION DeviceMapInfo;
01570 HANDLE
DirectoryHandle;
01571 PROCESS_SESSION_INFORMATION SessionInfo;
01572 ULONG BytesCopied;
01573 PACCESS_TOKEN
Token;
01574
01575
PAGED_CODE();
01576
01577
01578
01579
01580
01581 PreviousMode = KeGetPreviousMode();
01582
if (PreviousMode !=
KernelMode) {
01583
01584
if (ProcessInformationClass == ProcessBasePriority) {
01585 ProbeAlignment =
sizeof(KPRIORITY);
01586
01587 }
else if (ProcessInformationClass == ProcessEnableAlignmentFaultFixup) {
01588 ProbeAlignment =
sizeof(BOOLEAN);
01589 }
else if (ProcessInformationClass == ProcessForegroundInformation) {
01590 ProbeAlignment =
sizeof(PROCESS_FOREGROUND_BACKGROUND);
01591 }
else if (ProcessInformationClass == ProcessPriorityClass) {
01592 ProbeAlignment =
sizeof(BOOLEAN);
01593 }
else if (ProcessInformationClass == ProcessAffinityMask) {
01594 ProbeAlignment =
sizeof (ULONG_PTR);
01595 }
else {
01596 ProbeAlignment =
sizeof(ULONG);
01597 }
01598
01599
try {
01600
ProbeForRead(
01601 ProcessInformation,
01602 ProcessInformationLength,
01603 ProbeAlignment
01604 );
01605 } except(EXCEPTION_EXECUTE_HANDLER) {
01606
return GetExceptionCode();
01607 }
01608 }
01609
01610
01611
01612
01613
01614
switch ( ProcessInformationClass ) {
01615
01616
case ProcessWorkingSetWatch:
01617 {
01618 PPAGEFAULT_HISTORY WorkingSetCatcher;
01619
01620 st =
ObReferenceObjectByHandle(
01621 ProcessHandle,
01622 PROCESS_SET_INFORMATION,
01623 PsProcessType,
01624 PreviousMode,
01625 (PVOID *)&Process,
01626 NULL
01627 );
01628
01629
if ( !
NT_SUCCESS(st) ) {
01630
return st;
01631 }
01632
01633 WorkingSetCatcher =
ExAllocatePool(NonPagedPool,WS_CATCH_SIZE);
01634
if ( !WorkingSetCatcher ) {
01635
ObDereferenceObject(Process);
01636
return STATUS_NO_MEMORY;
01637 }
01638
01639
PsWatchEnabled =
TRUE;
01640 WorkingSetCatcher->CurrentIndex = 0;
01641 WorkingSetCatcher->MaxIndex =
MAX_WS_CATCH_INDEX;
01642
01643 st =
PsLockProcess(Process,PreviousMode,PsLockPollOnTimeout);
01644
01645
if ( st != STATUS_SUCCESS ) {
01646
ExFreePool(WorkingSetCatcher);
01647
ObDereferenceObject( Process );
01648
return STATUS_PROCESS_IS_TERMINATING;
01649 }
01650
01651
if ( Process->WorkingSetWatch ) {
01652
PsUnlockProcess(Process);
01653
ExFreePool(WorkingSetCatcher);
01654
ObDereferenceObject(Process);
01655
return STATUS_PORT_ALREADY_SET;
01656 }
01657
01658
KeInitializeSpinLock(&WorkingSetCatcher->SpinLock);
01659 Process->WorkingSetWatch = WorkingSetCatcher;
01660
01661
PsUnlockProcess(Process);
01662
01663
ObDereferenceObject(Process);
01664
01665
return STATUS_SUCCESS;
01666 }
01667
01668
case ProcessBasePriority:
01669 {
01670
01671
01672
01673
01674
01675
01676
if ( ProcessInformationLength !=
sizeof(KPRIORITY) ) {
01677
return STATUS_INFO_LENGTH_MISMATCH;
01678 }
01679
01680
try {
01681 BasePriority = *(KPRIORITY *)ProcessInformation;
01682 } except(EXCEPTION_EXECUTE_HANDLER) {
01683
return GetExceptionCode();
01684 }
01685
01686
if ( BasePriority & 0x80000000 ) {
01687 MemoryPriority =
MEMORY_PRIORITY_FOREGROUND;
01688 BasePriority &= ~0x80000000;
01689 }
01690
else {
01691 MemoryPriority =
MEMORY_PRIORITY_BACKGROUND;
01692 }
01693
01694
if ( BasePriority > HIGH_PRIORITY ||
01695 BasePriority <= LOW_PRIORITY ) {
01696
01697
return STATUS_INVALID_PARAMETER;
01698 }
01699
01700 st =
ObReferenceObjectByHandle(
01701 ProcessHandle,
01702 PROCESS_SET_INFORMATION,
01703 PsProcessType,
01704 PreviousMode,
01705 (PVOID *)&Process,
01706 NULL
01707 );
01708
01709
if ( !
NT_SUCCESS(st) ) {
01710
return st;
01711 }
01712
01713
01714
if ( BasePriority > Process->Pcb.BasePriority ) {
01715
01716
01717
01718
01719
01720
01721
01722 HasPrivilege =
SeCheckPrivilegedObject(
01723 SeIncreaseBasePriorityPrivilege,
01724 ProcessHandle,
01725 PROCESS_SET_INFORMATION,
01726 PreviousMode
01727 );
01728
01729
if (!HasPrivilege) {
01730
01731
ObDereferenceObject(Process);
01732
return STATUS_PRIVILEGE_NOT_HELD;
01733 }
01734 }
01735
01736
KeSetPriorityProcess(&Process->Pcb,BasePriority);
01737
MmSetMemoryPriorityProcess(Process, MemoryPriority);
01738
ObDereferenceObject(Process);
01739
01740
return STATUS_SUCCESS;
01741 }
01742
01743
case ProcessPriorityClass:
01744 {
01745
if ( ProcessInformationLength !=
sizeof(PROCESS_PRIORITY_CLASS) ) {
01746
return STATUS_INFO_LENGTH_MISMATCH;
01747 }
01748
01749
try {
01750 LocalPriorityClass = *(PPROCESS_PRIORITY_CLASS)ProcessInformation;
01751 } except(EXCEPTION_EXECUTE_HANDLER) {
01752
return GetExceptionCode();
01753 }
01754
01755
if ( LocalPriorityClass.PriorityClass > PROCESS_PRIORITY_CLASS_ABOVE_NORMAL ) {
01756
return STATUS_INVALID_PARAMETER;
01757 }
01758
01759 st =
ObReferenceObjectByHandle(
01760 ProcessHandle,
01761 PROCESS_SET_INFORMATION,
01762 PsProcessType,
01763 PreviousMode,
01764 (PVOID *)&Process,
01765 NULL
01766 );
01767
01768
if ( !
NT_SUCCESS(st) ) {
01769
return st;
01770 }
01771
01772
01773
if ( LocalPriorityClass.PriorityClass != Process->PriorityClass &&
01774 LocalPriorityClass.PriorityClass == PROCESS_PRIORITY_CLASS_REALTIME ) {
01775
01776
01777
01778
01779
01780
01781
01782 HasPrivilege =
SeCheckPrivilegedObject(
01783 SeIncreaseBasePriorityPrivilege,
01784 ProcessHandle,
01785 PROCESS_SET_INFORMATION,
01786 PreviousMode
01787 );
01788
01789
if (!HasPrivilege) {
01790
01791
ObDereferenceObject(Process);
01792
return STATUS_PRIVILEGE_NOT_HELD;
01793 }
01794 }
01795
01796
01797
01798
01799
01800
if ( Process->Job ) {
01801
KeEnterCriticalRegion();
01802
ExAcquireResourceShared(&Process->Job->JobLock, TRUE);
01803
01804
if ( Process->Job->LimitFlags & JOB_OBJECT_LIMIT_PRIORITY_CLASS ) {
01805 LocalPriorityClass.PriorityClass = Process->Job->PriorityClass;
01806 }
01807
01808
ExReleaseResource(&Process->Job->JobLock);
01809
KeLeaveCriticalRegion();
01810 }
01811
01812 Process->PriorityClass = LocalPriorityClass.PriorityClass;
01813
01814
PsSetProcessPriorityByClass(Process, LocalPriorityClass.Foreground ?
01815 PsProcessPriorityForeground : PsProcessPriorityBackground);
01816
01817
ObDereferenceObject(Process);
01818
01819
return STATUS_SUCCESS;
01820 }
01821
01822
case ProcessForegroundInformation:
01823 {
01824
01825
if ( ProcessInformationLength !=
sizeof(PROCESS_FOREGROUND_BACKGROUND) ) {
01826
return STATUS_INFO_LENGTH_MISMATCH;
01827 }
01828
01829
try {
01830 LocalForeground = *(PPROCESS_FOREGROUND_BACKGROUND)ProcessInformation;
01831 } except(EXCEPTION_EXECUTE_HANDLER) {
01832
return GetExceptionCode();
01833 }
01834
01835 st =
ObReferenceObjectByHandle(
01836 ProcessHandle,
01837 PROCESS_SET_INFORMATION,
01838 PsProcessType,
01839 PreviousMode,
01840 (PVOID *)&Process,
01841 NULL
01842 );
01843
01844
if ( !
NT_SUCCESS(st) ) {
01845
return st;
01846 }
01847
01848
01849
PsSetProcessPriorityByClass(Process, LocalForeground.Foreground ?
01850 PsProcessPriorityForeground : PsProcessPriorityBackground);
01851
01852
ObDereferenceObject(Process);
01853
01854
return STATUS_SUCCESS;
01855 }
01856
01857
case ProcessRaisePriority:
01858 {
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
if ( ProcessInformationLength !=
sizeof(ULONG) ) {
01869
return STATUS_INFO_LENGTH_MISMATCH;
01870 }
01871
01872
try {
01873 BoostValue = *(PULONG)ProcessInformation;
01874 } except(EXCEPTION_EXECUTE_HANDLER) {
01875
return GetExceptionCode();
01876 }
01877
01878 st =
ObReferenceObjectByHandle(
01879 ProcessHandle,
01880 PROCESS_SET_INFORMATION,
01881 PsProcessType,
01882 PreviousMode,
01883 (PVOID *)&Process,
01884 NULL
01885 );
01886
01887
if ( !
NT_SUCCESS(st) ) {
01888
return st;
01889 }
01890
01891
01892
01893
01894
01895
01896
01897 st =
PsLockProcess(Process,KernelMode,PsLockReturnTimeout);
01898
01899
if ( st != STATUS_SUCCESS ) {
01900
ObDereferenceObject( Process );
01901
return( st );
01902 }
01903
01904 Next = Process->ThreadListHead.Flink;
01905
01906
while ( Next != &Process->ThreadListHead) {
01907 Thread = (
PETHREAD)(CONTAINING_RECORD(Next,
ETHREAD,ThreadListEntry));
01908
KeBoostPriorityThread(&Thread->Tcb,(KPRIORITY)BoostValue);
01909 Next = Next->Flink;
01910 }
01911
01912
PsUnlockProcess(Process);
01913
01914
ObDereferenceObject(Process);
01915
01916
return STATUS_SUCCESS;
01917 }
01918
01919
case ProcessDefaultHardErrorMode:
01920 {
01921
if ( ProcessInformationLength !=
sizeof(ULONG) ) {
01922
return STATUS_INFO_LENGTH_MISMATCH;
01923 }
01924
01925
try {
01926 DefaultHardErrorMode = *(PULONG)ProcessInformation;
01927 } except(EXCEPTION_EXECUTE_HANDLER) {
01928
return GetExceptionCode();
01929 }
01930
01931 st =
ObReferenceObjectByHandle(
01932 ProcessHandle,
01933 PROCESS_SET_INFORMATION,
01934 PsProcessType,
01935 PreviousMode,
01936 (PVOID *)&Process,
01937 NULL
01938 );
01939
01940
if ( !
NT_SUCCESS(st) ) {
01941
return st;
01942 }
01943
01944 Process->DefaultHardErrorProcessing = DefaultHardErrorMode;
01945
if (DefaultHardErrorMode & PROCESS_HARDERROR_ALIGNMENT_BIT) {
01946
KeSetAutoAlignmentProcess(&Process->Pcb,TRUE);
01947 }
01948
else {
01949
KeSetAutoAlignmentProcess(&Process->Pcb,FALSE);
01950 }
01951
01952
ObDereferenceObject(Process);
01953
01954
return STATUS_SUCCESS;
01955 }
01956
01957
case ProcessQuotaLimits:
01958 {
01959
return PspSetQuotaLimits(
01960 ProcessHandle,
01961 ProcessInformationClass,
01962 ProcessInformation,
01963 ProcessInformationLength,
01964 PreviousMode
01965 );
01966 }
01967
01968
case ProcessDebugPort :
01969 {
01970
if ( ProcessInformationLength !=
sizeof(HANDLE) ) {
01971
return STATUS_INFO_LENGTH_MISMATCH;
01972 }
01973
01974
try {
01975 DebugPortHandle = *(PHANDLE) ProcessInformation;
01976 } except(EXCEPTION_EXECUTE_HANDLER) {
01977
return GetExceptionCode();
01978 }
01979
01980
if ( DebugPortHandle ) {
01981 st =
ObReferenceObjectByHandle (
01982 DebugPortHandle,
01983 0,
01984 LpcPortObjectType,
01985 PreviousMode,
01986 (PVOID *)&DebugPort,
01987 NULL
01988 );
01989
if ( !
NT_SUCCESS(st) ) {
01990
return st;
01991 }
01992 }
else {
01993
return STATUS_INVALID_PARAMETER;
01994 }
01995
01996 st =
ObReferenceObjectByHandle(
01997 ProcessHandle,
01998 PROCESS_SET_PORT,
01999 PsProcessType,
02000 PreviousMode,
02001 (PVOID *)&Process,
02002 NULL
02003 );
02004
02005
if ( !
NT_SUCCESS(st) ) {
02006
if (
DebugPort ) {
02007
ObDereferenceObject(DebugPort);
02008 }
02009
return st;
02010 }
02011
02012
02013
02014
02015
02016
02017
if ( InterlockedCompareExchangePointer(&Process->DebugPort,DebugPort,NULL) ==
NULL ) {
02018
02019
if ( (Process->ExitTime.QuadPart != 0 ||
KeReadStateProcess(&Process->Pcb) !=
FALSE) ) {
02020
DebugPort = InterlockedExchangePointer(&Process->DebugPort,NULL);
02021
if (
DebugPort ) {
02022
ObDereferenceObject(DebugPort);
02023 }
02024
ObDereferenceObject( Process );
02025
return STATUS_PROCESS_IS_TERMINATING;
02026 }
02027 }
02028
else {
02029
ObDereferenceObject(Process);
02030
ObDereferenceObject(DebugPort);
02031
return STATUS_PORT_ALREADY_SET;
02032 }
02033
02034
KeAttachProcess (&Process->Pcb);
02035
if (Process->Peb !=
NULL) {
02036 Process->Peb->BeingDebugged = (BOOLEAN)(Process->DebugPort !=
NULL ?
TRUE :
FALSE);
02037
#if defined(_WIN64)
02038
if (Process->Wow64Process !=
NULL) {
02039 PPEB32 Peb32 = (PPEB32)Process->Wow64Process->Wow64;
02040
if (Peb32 !=
NULL) {
02041 Peb32->BeingDebugged = Process->Peb->BeingDebugged;
02042 }
02043 }
02044
#endif
02045
}
02046
KeDetachProcess();
02047
02048
02049
ObDereferenceObject(Process);
02050
02051
return STATUS_SUCCESS;
02052 }
02053
02054
case ProcessExceptionPort :
02055 {
02056
if ( ProcessInformationLength !=
sizeof(HANDLE) ) {
02057
return STATUS_INFO_LENGTH_MISMATCH;
02058 }
02059
02060
try {
02061 ExceptionPortHandle = *(PHANDLE) ProcessInformation;
02062 } except(EXCEPTION_EXECUTE_HANDLER) {
02063
return GetExceptionCode();
02064 }
02065
02066 st =
ObReferenceObjectByHandle (
02067 ExceptionPortHandle,
02068 0,
02069 LpcPortObjectType,
02070 PreviousMode,
02071 (PVOID *)&ExceptionPort,
02072 NULL
02073 );
02074
if ( !
NT_SUCCESS(st) ) {
02075
return st;
02076 }
02077
02078 st =
ObReferenceObjectByHandle(
02079 ProcessHandle,
02080 PROCESS_SET_PORT,
02081 PsProcessType,
02082 PreviousMode,
02083 (PVOID *)&Process,
02084 NULL
02085 );
02086
02087
if ( !
NT_SUCCESS(st) ) {
02088
ObDereferenceObject(ExceptionPort);
02089
return st;
02090 }
02091
02092 st =
PsLockProcess(Process,PreviousMode,PsLockPollOnTimeout);
02093
02094
if ( st != STATUS_SUCCESS ) {
02095
ObDereferenceObject(ExceptionPort);
02096
ObDereferenceObject( Process );
02097
return STATUS_PROCESS_IS_TERMINATING;
02098 }
02099
02100
if ( Process->ExceptionPort ) {
02101
ObDereferenceObject(Process);
02102
ObDereferenceObject(ExceptionPort);
02103
PsUnlockProcess(Process);
02104
return STATUS_PORT_ALREADY_SET;
02105 }
else {
02106 Process->ExceptionPort = ExceptionPort;
02107 }
02108
PsUnlockProcess(Process);
02109
02110
ObDereferenceObject(Process);
02111
02112
return STATUS_SUCCESS;
02113 }
02114
02115
case ProcessAccessToken :
02116 {
02117
02118
if ( ProcessInformationLength !=
sizeof(PROCESS_ACCESS_TOKEN) ) {
02119
return STATUS_INFO_LENGTH_MISMATCH;
02120 }
02121
02122
try {
02123 PrimaryTokenHandle = ((PROCESS_ACCESS_TOKEN *)ProcessInformation)->Token;
02124
02125 } except(EXCEPTION_EXECUTE_HANDLER) {
02126
return GetExceptionCode();
02127 }
02128
02129
02130 st =
PspSetPrimaryToken(
02131 ProcessHandle,
02132 PrimaryTokenHandle,
02133 NULL );
02134
02135
return st;
02136 }
02137
02138
02139
case ProcessLdtInformation:
02140
02141 st =
ObReferenceObjectByHandle(
02142 ProcessHandle,
02143 PROCESS_SET_INFORMATION | PROCESS_VM_WRITE,
02144 PsProcessType,
02145 PreviousMode,
02146 (PVOID *)&Process,
02147 NULL
02148 );
02149
02150
if ( !
NT_SUCCESS(st) ) {
02151
return st;
02152 }
02153
02154
try {
02155 st =
PspSetLdtInformation(
02156 Process,
02157 ProcessInformation,
02158 ProcessInformationLength
02159 );
02160 } except (EXCEPTION_EXECUTE_HANDLER) {
02161 st = STATUS_SUCCESS;
02162 }
02163
02164
ObDereferenceObject(Process);
02165
return st;
02166
02167
case ProcessLdtSize:
02168
02169 st =
ObReferenceObjectByHandle(
02170 ProcessHandle,
02171 PROCESS_SET_INFORMATION | PROCESS_VM_WRITE,
02172 PsProcessType,
02173 PreviousMode,
02174 (PVOID *)&Process,
02175 NULL
02176 );
02177
02178
if ( !
NT_SUCCESS(st) ) {
02179
return st;
02180 }
02181
02182
try {
02183
02184 st =
PspSetLdtSize(
02185 Process,
02186 ProcessInformation,
02187 ProcessInformationLength
02188 );
02189
02190 } except(EXCEPTION_EXECUTE_HANDLER) {
02191
02192 st = GetExceptionCode();
02193
02194 }
02195
02196
ObDereferenceObject(Process);
02197
return st;
02198
02199
case ProcessIoPortHandlers:
02200
02201 st =
ObReferenceObjectByHandle(
02202 ProcessHandle,
02203 PROCESS_SET_INFORMATION,
02204 PsProcessType,
02205 PreviousMode,
02206 (PVOID *)&Process,
02207 NULL
02208 );
02209
02210
if ( !
NT_SUCCESS(st) ) {
02211
return st;
02212 }
02213
02214 st =
PspSetProcessIoHandlers(
02215 Process,
02216 ProcessInformation,
02217 ProcessInformationLength
02218 );
02219
02220
ObDereferenceObject(Process);
02221
return st;
02222
02223
case ProcessUserModeIOPL:
02224
02225
02226
02227
02228
02229
02230
02231
if (!
SeSinglePrivilegeCheck(RtlConvertLongToLuid(
02232 SE_TCB_PRIVILEGE),
02233 PreviousMode )) {
02234
02235
return STATUS_PRIVILEGE_NOT_HELD;
02236
02237 }
02238
02239 st =
ObReferenceObjectByHandle(
02240 ProcessHandle,
02241 PROCESS_SET_INFORMATION,
02242 PsProcessType,
02243 PreviousMode,
02244 (PVOID *)&Process,
02245 NULL
02246 );
02247
02248
if (
NT_SUCCESS(st) ) {
02249
02250
#ifdef i386
02251
Ke386SetIOPL(&Process->Pcb);
02252
#endif
02253
02254
ObDereferenceObject(Process);
02255 }
02256
02257
return st;
02258
02259
02260
02261
02262
02263
case ProcessEnableAlignmentFaultFixup:
02264
02265
if ( ProcessInformationLength !=
sizeof(BOOLEAN) ) {
02266
return STATUS_INFO_LENGTH_MISMATCH;
02267 }
02268
02269
try {
02270 EnableAlignmentFaultFixup = *(PBOOLEAN)ProcessInformation;
02271
02272 } except(EXCEPTION_EXECUTE_HANDLER) {
02273
return GetExceptionCode();
02274 }
02275
02276 st =
ObReferenceObjectByHandle(
02277 ProcessHandle,
02278 PROCESS_SET_INFORMATION,
02279 PsProcessType,
02280 PreviousMode,
02281 (PVOID *)&Process,
02282 NULL
02283 );
02284
02285
if ( !
NT_SUCCESS(st) ) {
02286
return st;
02287 }
02288
02289
if ( EnableAlignmentFaultFixup ) {
02290 Process->DefaultHardErrorProcessing |= PROCESS_HARDERROR_ALIGNMENT_BIT;
02291 }
02292
else {
02293 Process->DefaultHardErrorProcessing &= ~PROCESS_HARDERROR_ALIGNMENT_BIT;
02294 }
02295
02296
KeSetAutoAlignmentProcess( &(Process->Pcb), EnableAlignmentFaultFixup );
02297
ObDereferenceObject(Process);
02298
return STATUS_SUCCESS;
02299
02300
02301
#ifndef i386
02302
case ProcessWx86Information :
02303
if ( ProcessInformationLength !=
sizeof(HANDLE) ) {
02304
return STATUS_INFO_LENGTH_MISMATCH;
02305 }
02306
02307
try {
02308 Wx86Info = *(PHANDLE) ProcessInformation;
02309 }
02310 except(EXCEPTION_EXECUTE_HANDLER) {
02311
return GetExceptionCode();
02312 }
02313
02314 st =
ObReferenceObjectByHandle(
02315 ProcessHandle,
02316 PROCESS_SET_INFORMATION,
02317 PsProcessType,
02318 PreviousMode,
02319 (PVOID *)&Process,
02320 NULL
02321 );
02322
02323
if (!
NT_SUCCESS(st)) {
02324
return st;
02325 }
02326
02327
02328
02329
02330
02331
02332
if ((ULONG_PTR)Wx86Info !=
sizeof(WX86TIB)) {
02333
if ((ULONG_PTR)Wx86Info != 0 || Process !=
PsGetCurrentProcess()) {
02334
ObDereferenceObject( Process );
02335
return STATUS_INVALID_PARAMETER;
02336 }
02337
02338 Wx86Info =
NULL;
02339 }
02340
02341
02342 Process->VdmObjects = Wx86Info;
02343
02344
02345
02346
02347
02348
02349
if (Wx86Info ==
NULL) {
02350
NTSTATUS xst;
02351 PTEB Teb;
02352 PLIST_ENTRY Next;
02353 PWX86TIB Wx86Tib;
02354 PVOID BaseAddress;
02355 SIZE_T StackSize;
02356
02357 st =
PsLockProcess(Process,PreviousMode,PsLockPollOnTimeout);
02358
if ( st != STATUS_SUCCESS ) {
02359
ObDereferenceObject(Process);
02360
return STATUS_PROCESS_IS_TERMINATING;
02361 }
02362
02363 Next = Process->ThreadListHead.Flink;
02364
02365
while ( Next != &Process->ThreadListHead) {
02366
02367 Thread = (
PETHREAD)(CONTAINING_RECORD(Next,
ETHREAD,ThreadListEntry));
02368
if ( !
IS_SYSTEM_THREAD(Thread) ) {
02369
if ( Thread->Tcb.Teb ) {
02370 Teb = (PTEB)Thread->Tcb.Teb;
02371
try {
02372 Wx86Tib = Teb->Vdm;
02373 Teb->Vdm = 0;
02374
ProbeForRead(Wx86Tib,
sizeof(WX86TIB),
sizeof(ULONG));
02375
if (Wx86Tib && Wx86Tib->Size ==
sizeof(WX86TIB)) {
02376 StackSize = 0;
02377 BaseAddress = Wx86Tib->DeallocationStack;
02378 ZwFreeVirtualMemory(ProcessHandle,
02379 &BaseAddress,
02380 &StackSize,
02381 MEM_RELEASE
02382 );
02383
02384
if (Teb->Wx86Thread.DeallocationCpu) {
02385 BaseAddress = Teb->Wx86Thread.DeallocationCpu;
02386 Teb->Wx86Thread.DeallocationCpu = 0;
02387 StackSize = 0;
02388 st = ZwFreeVirtualMemory(ProcessHandle,
02389 &BaseAddress,
02390 &StackSize,
02391 MEM_RELEASE
02392 );
02393 }
02394 }
02395 }
02396 except(EXCEPTION_EXECUTE_HANDLER) {
02397 ;
02398 }
02399 }
02400 }
02401 Next = Next->Flink;
02402 }
02403
02404
PsUnlockProcess(Process);
02405 }
02406
02407
ObDereferenceObject(Process);
02408
return STATUS_SUCCESS;
02409
#endif
02410
02411
case ProcessAffinityMask:
02412
02413
#ifdef _WIN64
02414
if ( ProcessInformationLength !=
sizeof(ULONG_PTR) ) {
02415
02416
02417
02418
02419
C_ASSERT(
sizeof(KAFFINITY) !=
sizeof(ULONG_PTR) );
02420
return STATUS_INFO_LENGTH_MISMATCH;
02421 }
02422
#else
02423
if ( ProcessInformationLength !=
sizeof(KAFFINITY) ) {
02424
return STATUS_INFO_LENGTH_MISMATCH;
02425 }
02426
#endif
02427
02428
try {
02429 BigAffinity = *(PULONG_PTR)ProcessInformation;
02430 Affinity = (KAFFINITY)BigAffinity;
02431
02432 }
02433 except(EXCEPTION_EXECUTE_HANDLER) {
02434
return GetExceptionCode();
02435 }
02436
02437 AffinityWithMasks = Affinity &
KeActiveProcessors;
02438
02439
if ( !Affinity || ( AffinityWithMasks != Affinity ) ) {
02440
return STATUS_INVALID_PARAMETER;
02441 }
02442
02443 st =
ObReferenceObjectByHandle(
02444 ProcessHandle,
02445 PROCESS_SET_INFORMATION,
02446 PsProcessType,
02447 PreviousMode,
02448 (PVOID *)&Process,
02449 NULL
02450 );
02451
02452
if ( !
NT_SUCCESS(st) ) {
02453
return st;
02454 }
02455
02456
02457
02458
02459
02460
if ( Process->Job ) {
02461
KeEnterCriticalRegion();
02462
ExAcquireResourceShared(&Process->Job->JobLock, TRUE);
02463
02464
if ( Process->Job->LimitFlags & JOB_OBJECT_LIMIT_AFFINITY ) {
02465 AffinityWithMasks = Process->Job->Affinity;
02466 }
02467
02468
ExReleaseResource(&Process->Job->JobLock);
02469
KeLeaveCriticalRegion();
02470 }
02471
02472
02473 {
02474
NTSTATUS xst;
02475 PLIST_ENTRY Next;
02476
PETHREAD OriginalThread;
02477
02478
02479
02480
02481
02482
02483
02484
02485 xst =
PsLockProcess(Process,PreviousMode,PsLockPollOnTimeout);
02486
02487
if ( xst != STATUS_SUCCESS ) {
02488
ObDereferenceObject( Process );
02489
return STATUS_PROCESS_IS_TERMINATING;
02490 }
02491
02492 Process->Pcb.Affinity = AffinityWithMasks;
02493
02494 Next = Process->ThreadListHead.Flink;
02495
02496
while ( Next != &Process->ThreadListHead) {
02497
02498 Thread = (
PETHREAD)(CONTAINING_RECORD(Next,
ETHREAD,ThreadListEntry));
02499
KeSetAffinityThread(&Thread->Tcb,AffinityWithMasks);
02500 Next = Next->Flink;
02501 }
02502
02503
PsUnlockProcess(Process);
02504 }
02505
ObDereferenceObject(Process);
02506
return STATUS_SUCCESS;
02507
02508
case ProcessPriorityBoost:
02509
if ( ProcessInformationLength !=
sizeof(ULONG) ) {
02510
return STATUS_INFO_LENGTH_MISMATCH;
02511 }
02512
02513
try {
02514 DisableBoost = *(PULONG)ProcessInformation;
02515 } except(EXCEPTION_EXECUTE_HANDLER) {
02516
return GetExceptionCode();
02517 }
02518
02519 bDisableBoost = (DisableBoost ?
TRUE :
FALSE);
02520
02521 st =
ObReferenceObjectByHandle(
02522 ProcessHandle,
02523 PROCESS_SET_INFORMATION,
02524 PsProcessType,
02525 PreviousMode,
02526 (PVOID *)&Process,
02527 NULL
02528 );
02529
02530
if ( !
NT_SUCCESS(st) ) {
02531
return st;
02532 }
02533
02534 {
02535
NTSTATUS xst;
02536 PLIST_ENTRY Next;
02537
PETHREAD OriginalThread;
02538
02539
02540
02541
02542
02543
02544
02545
02546 xst =
PsLockProcess(Process,PreviousMode,PsLockPollOnTimeout);
02547
02548
if ( xst != STATUS_SUCCESS ) {
02549
ObDereferenceObject( Process );
02550
return STATUS_PROCESS_IS_TERMINATING;
02551 }
02552
02553 Process->Pcb.DisableBoost = bDisableBoost;
02554
02555 Next = Process->ThreadListHead.Flink;
02556
02557
while ( Next != &Process->ThreadListHead) {
02558
02559 Thread = (
PETHREAD)(CONTAINING_RECORD(Next,
ETHREAD,ThreadListEntry));
02560
KeSetDisableBoostThread(&Thread->Tcb,bDisableBoost);
02561 Next = Next->Flink;
02562 }
02563
02564
PsUnlockProcess(Process);
02565 }
02566
ObDereferenceObject(Process);
02567
return STATUS_SUCCESS;
02568
02569
case ProcessDeviceMap:
02570 DeviceMapInfo = (PPROCESS_DEVICEMAP_INFORMATION)ProcessInformation;
02571
if ( ProcessInformationLength !=
sizeof(DeviceMapInfo->Set) ) {
02572
return STATUS_INFO_LENGTH_MISMATCH;
02573 }
02574
02575
try {
02576
DirectoryHandle = DeviceMapInfo->Set.DirectoryHandle;
02577 } except(EXCEPTION_EXECUTE_HANDLER) {
02578
return GetExceptionCode();
02579 }
02580
02581 st =
ObReferenceObjectByHandle(
02582 ProcessHandle,
02583 PROCESS_SET_INFORMATION,
02584 PsProcessType,
02585 PreviousMode,
02586 (PVOID *)&Process,
02587 NULL
02588 );
02589
02590
if ( !
NT_SUCCESS(st) ) {
02591
return st;
02592 }
02593
02594
02595
02596
02597
02598
02599
02600
02601 st =
PsLockProcess(Process,PreviousMode,PsLockPollOnTimeout);
02602
02603
if ( st != STATUS_SUCCESS ) {
02604
ObDereferenceObject( Process );
02605
return STATUS_PROCESS_IS_TERMINATING;
02606 }
02607
02608 st =
ObSetDeviceMap( Process, DirectoryHandle );
02609
PsUnlockProcess(Process);
02610
ObDereferenceObject(Process);
02611
return st;
02612
02613
case ProcessSessionInformation :
02614
02615
02616
02617
02618
if ( ProcessInformationLength != (ULONG)
sizeof(PROCESS_SESSION_INFORMATION) ) {
02619
return STATUS_INFO_LENGTH_MISMATCH;
02620 }
02621
02622
try {
02623 SessionInfo = *(PPROCESS_SESSION_INFORMATION) ProcessInformation;
02624 } except(EXCEPTION_EXECUTE_HANDLER) {
02625
return GetExceptionCode();
02626 }
02627
02628
02629
02630
02631
if ( !
SeSinglePrivilegeCheck(SeTcbPrivilege,PreviousMode) ) {
02632
return( STATUS_PRIVILEGE_NOT_HELD );
02633 }
02634
02635
02636
02637
02638 st =
ObReferenceObjectByHandle(
02639 ProcessHandle,
02640 PROCESS_SET_INFORMATION | PROCESS_SET_SESSIONID,
02641 PsProcessType,
02642 PreviousMode,
02643 (PVOID *)&Process,
02644 NULL
02645 );
02646
if ( !
NT_SUCCESS(st) ) {
02647
return st;
02648 }
02649
02650
02651
02652
02653
02654
02655
02656
Token =
PsReferencePrimaryToken( Process );
02657
SeSetSessionIdToken( Token, SessionInfo.SessionId );
02658
PsDereferencePrimaryToken( Token );
02659
02660
02661
02662
02663
02664
02665 Process->SessionId = SessionInfo.SessionId;
02666
02667
02668 st =
PsLockProcess(Process,PreviousMode,PsLockPollOnTimeout);
02669
02670
if ( st != STATUS_SUCCESS ) {
02671
ObDereferenceObject(Process);
02672
return STATUS_PROCESS_IS_TERMINATING;
02673 }
02674
02675
02676
02677
02678
if (Process->Peb !=
NULL) {
02679
02680
02681
KeAttachProcess (&Process->Pcb);
02682
02683
02684
02685
02686
02687 Process->Peb->SessionId = Process->SessionId;
02688
02689
KeDetachProcess();
02690
02691 }
02692
02693
PsUnlockProcess(Process);
02694
ObDereferenceObject(Process);
02695
02696
return( st );
02697
02698
default:
02699
return STATUS_INVALID_INFO_CLASS;
02700 }
02701
02702 }