From f0222daf5d662e58356bf3922ecc7fc98196cae2 Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Mon, 14 Feb 2005 21:00:05 +0000 Subject: [PATCH] 1. a few previous mode fixes 2. implemented NtSetDefaultHardErrorPort() with help of pseudo code from windowsitlibrary.com svn path=/trunk/; revision=13576 --- reactos/ntoskrnl/ke/alert.c | 7 ++++-- reactos/ntoskrnl/ke/apc.c | 9 +++++--- reactos/ntoskrnl/ke/error.c | 43 ++++++++++++++++++++++++++++++++++--- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/reactos/ntoskrnl/ke/alert.c b/reactos/ntoskrnl/ke/alert.c index 6dcc12cec1e..8fa0783baba 100644 --- a/reactos/ntoskrnl/ke/alert.c +++ b/reactos/ntoskrnl/ke/alert.c @@ -107,13 +107,16 @@ NtAlertResumeThread(IN HANDLE ThreadHandle, NTSTATUS STDCALL NtAlertThread (IN HANDLE ThreadHandle) { + KPROCESSOR_MODE PreviousMode; PETHREAD Thread; NTSTATUS Status; + + PreviousMode = ExGetPreviousMode(); Status = ObReferenceObjectByHandle(ThreadHandle, THREAD_SUSPEND_RESUME, PsThreadType, - ExGetPreviousMode(), + PreviousMode, (PVOID*)&Thread, NULL); if (!NT_SUCCESS(Status)) @@ -125,7 +128,7 @@ NtAlertThread (IN HANDLE ThreadHandle) * ZwAlertThread was called? * -Gunnar */ - KeAlertThread((PKTHREAD)Thread, UserMode); + KeAlertThread((PKTHREAD)Thread, PreviousMode); ObDereferenceObject(Thread); return(STATUS_SUCCESS); diff --git a/reactos/ntoskrnl/ke/apc.c b/reactos/ntoskrnl/ke/apc.c index 437de014465..9c7c0bcf08f 100644 --- a/reactos/ntoskrnl/ke/apc.c +++ b/reactos/ntoskrnl/ke/apc.c @@ -1,4 +1,4 @@ -/* $Id:$ +/* $Id$ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -517,13 +517,16 @@ NtQueueApcThread(HANDLE ThreadHandle, PKAPC Apc; PETHREAD Thread; + KPROCESSOR_MODE PreviousMode; NTSTATUS Status; + + PreviousMode = ExGetPreviousMode(); /* Get ETHREAD from Handle */ Status = ObReferenceObjectByHandle(ThreadHandle, THREAD_SET_CONTEXT, PsThreadType, - KeGetPreviousMode(), + PreviousMode, (PVOID)&Thread, NULL); @@ -552,7 +555,7 @@ NtQueueApcThread(HANDLE ThreadHandle, KiFreeApcRoutine, NULL, ApcRoutine, - UserMode, + PreviousMode, NormalContext); if (!KeInsertQueueApc(Apc, SystemArgument1, SystemArgument2, IO_NO_INCREMENT)) { Status = STATUS_UNSUCCESSFUL; diff --git a/reactos/ntoskrnl/ke/error.c b/reactos/ntoskrnl/ke/error.c index a86185086ee..121c432becc 100644 --- a/reactos/ntoskrnl/ke/error.c +++ b/reactos/ntoskrnl/ke/error.c @@ -1,4 +1,4 @@ -/* $Id:$ +/* $Id$ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -15,6 +15,10 @@ /* FUNCTIONS ***************************************************************/ +BOOLEAN ExReadyForErrors = FALSE; +PEPORT ExpDefaultErrorPort = NULL; +PEPROCESS ExpDefaultErrorPortProcess = NULL; + /* * @unimplemented */ @@ -54,8 +58,41 @@ NtRaiseHardError(IN NTSTATUS Status, NTSTATUS STDCALL NtSetDefaultHardErrorPort(IN HANDLE PortHandle) { - UNIMPLEMENTED; - return(STATUS_NOT_IMPLEMENTED); + KPROCESSOR_MODE PreviousMode; + NTSTATUS Status; + + PreviousMode = ExGetPreviousMode(); + + if(!SeSinglePrivilegeCheck(SeTcbPrivilege, + PreviousMode)) + { + DPRINT1("NtSetDefaultHardErrorPort: Caller requires the SeTcbPrivilege privilege!\n"); + return STATUS_PRIVILEGE_NOT_HELD; + } + + /* serialization shouldn't be required here as it usually is just called once + during startup */ + + if(!ExReadyForErrors) + { + Status = ObReferenceObjectByHandle(PortHandle, + 0, + LpcPortObjectType, + PreviousMode, + (PVOID*)&ExpDefaultErrorPort, + NULL); + if(NT_SUCCESS(Status)) + { + ExpDefaultErrorPortProcess = PsGetCurrentProcess(); + ExReadyForErrors = TRUE; + } + } + else + { + Status = STATUS_UNSUCCESSFUL; + } + + return Status; } /* EOF */