Use KeStackAttachProcess/KeUnstackDetachProcess instead of KeAttachProcess/KeDetachProcess.
Modified: trunk/reactos/drivers/video/videoprt/int10.c
Modified: trunk/reactos/drivers/video/videoprt/videoprt.c
Modified: trunk/reactos/drivers/video/videoprt/videoprt.h

Modified: trunk/reactos/drivers/video/videoprt/int10.c
--- trunk/reactos/drivers/video/videoprt/int10.c	2005-06-14 18:39:12 UTC (rev 15914)
+++ trunk/reactos/drivers/video/videoprt/int10.c	2005-06-14 20:24:02 UTC (rev 15915)
@@ -36,11 +36,11 @@
    PVOID MemoryAddress;
    NTSTATUS Status;
    PKPROCESS CallingProcess;
-   PKPROCESS PrevAttachedProcess;
+   KAPC_STATE ApcState;
 
    DPRINT("IntInt10AllocateBuffer\n");
 
-   IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
+   IntAttachToCSRSS(&CallingProcess, &ApcState);
 
    MemoryAddress = (PVOID)0x20000;
    Status = ZwAllocateVirtualMemory(NtCurrentProcess(), &MemoryAddress, 0,
@@ -49,7 +49,7 @@
    if (!NT_SUCCESS(Status))
    {
       DPRINT("- ZwAllocateVirtualMemory failed\n");
-      IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
+      IntDetachFromCSRSS(&CallingProcess, &ApcState);
       return ERROR_NOT_ENOUGH_MEMORY;
    }
 
@@ -58,7 +58,7 @@
       ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress, Length,
          MEM_RELEASE);
       DPRINT("- Unacceptable memory allocated\n");
-      IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
+      IntDetachFromCSRSS(&CallingProcess, &ApcState);
       return ERROR_NOT_ENOUGH_MEMORY;
    }
 
@@ -69,7 +69,7 @@
    DPRINT("- Offset: %x\n", (ULONG)MemoryAddress & 0xF);
    DPRINT("- Length: %x\n", *Length);
 
-   IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
+   IntDetachFromCSRSS(&CallingProcess, &ApcState);
 
    return NO_ERROR;
 }
@@ -83,16 +83,16 @@
    PVOID MemoryAddress = (PVOID)((Seg << 4) | Off);
    NTSTATUS Status;
    PKPROCESS CallingProcess;
-   PKPROCESS PrevAttachedProcess;
+   KAPC_STATE ApcState;
 
    DPRINT("IntInt10FreeBuffer\n");
    DPRINT("- Segment: %x\n", Seg);
    DPRINT("- Offset: %x\n", Off);
 
-   IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
+   IntAttachToCSRSS(&CallingProcess, &ApcState);
    Status = ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress, 0,
       MEM_RELEASE);
-   IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
+   IntDetachFromCSRSS(&CallingProcess, &ApcState);
 
    return Status;
 }
@@ -106,7 +106,7 @@
    IN ULONG Length)
 {
    PKPROCESS CallingProcess;
-   PKPROCESS PrevAttachedProcess;
+   KAPC_STATE ApcState;
 
    DPRINT("IntInt10ReadMemory\n");
    DPRINT("- Segment: %x\n", Seg);
@@ -114,9 +114,9 @@
    DPRINT("- Buffer: %x\n", Buffer);
    DPRINT("- Length: %x\n", Length);
 
-   IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
+   IntAttachToCSRSS(&CallingProcess, &ApcState);
    RtlCopyMemory(Buffer, (PVOID)((Seg << 4) | Off), Length);
-   IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
+   IntDetachFromCSRSS(&CallingProcess, &ApcState);
 
    return NO_ERROR;
 }
@@ -130,7 +130,7 @@
    IN ULONG Length)
 {
    PKPROCESS CallingProcess;
-   PKPROCESS PrevAttachedProcess;
+   KAPC_STATE ApcState;
 
    DPRINT("IntInt10WriteMemory\n");
    DPRINT("- Segment: %x\n", Seg);
@@ -138,9 +138,9 @@
    DPRINT("- Buffer: %x\n", Buffer);
    DPRINT("- Length: %x\n", Length);
 
-   IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
+   IntAttachToCSRSS(&CallingProcess, &ApcState);
    RtlCopyMemory((PVOID)((Seg << 4) | Off), Buffer, Length);
-   IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
+   IntDetachFromCSRSS(&CallingProcess, &ApcState);
 
    return NO_ERROR;
 }
@@ -153,11 +153,11 @@
    KV86M_REGISTERS Regs;
    NTSTATUS Status;
    PKPROCESS CallingProcess;
-   PKPROCESS PrevAttachedProcess;
+   KAPC_STATE ApcState;
 
    DPRINT("IntInt10CallBios\n");
 
-   IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
+   IntAttachToCSRSS(&CallingProcess, &ApcState);
 
    memset(&Regs, 0, sizeof(Regs));
    DPRINT("- Input register Eax: %x\n", BiosArguments->Eax);
@@ -189,7 +189,7 @@
    BiosArguments->SegDs = Regs.Ds;
    BiosArguments->SegEs = Regs.Es;
 
-   IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
+   IntDetachFromCSRSS(&CallingProcess, &ApcState);
 
    return Status;
 }
@@ -208,7 +208,7 @@
    KV86M_REGISTERS Regs;
    NTSTATUS Status;
    PKPROCESS CallingProcess;
-   PKPROCESS PrevAttachedProcess;
+   KAPC_STATE ApcState;
 
    DPRINT("VideoPortInt10\n");
 
@@ -217,7 +217,7 @@
       return ERROR_INVALID_PARAMETER;
    }
 
-   IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
+   IntAttachToCSRSS(&CallingProcess, &ApcState);
 
    memset(&Regs, 0, sizeof(Regs));
    DPRINT("- Input register Eax: %x\n", BiosArguments->Eax);
@@ -243,7 +243,7 @@
    BiosArguments->Edi = Regs.Edi;
    BiosArguments->Ebp = Regs.Ebp;
 
-   IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
+   IntDetachFromCSRSS(&CallingProcess, &ApcState);
 
    return Status;
 }

Modified: trunk/reactos/drivers/video/videoprt/videoprt.c
--- trunk/reactos/drivers/video/videoprt/videoprt.c	2005-06-14 18:39:12 UTC (rev 15914)
+++ trunk/reactos/drivers/video/videoprt/videoprt.c	2005-06-14 20:24:02 UTC (rev 15915)
@@ -22,7 +22,6 @@
  */
 
 #include "videoprt.h"
-#include "internal/ps.h"
 
 /* GLOBAL VARIABLES ***********************************************************/
 
@@ -495,34 +494,21 @@
 }
 
 VOID FASTCALL
-IntAttachToCSRSS(PKPROCESS *CallingProcess, PKPROCESS *PrevAttachedProcess)
+IntAttachToCSRSS(PKPROCESS *CallingProcess, PKAPC_STATE ApcState)
 {
-   *CallingProcess = &PsGetCurrentProcess()->Pcb;
+   *CallingProcess = (PKPROCESS)PsGetCurrentProcess();
    if (*CallingProcess != Csrss)
    {
-      if (&PsGetCurrentThread()->ThreadsProcess->Pcb != *CallingProcess)
-      {
-         *PrevAttachedProcess = *CallingProcess;
-         KeDetachProcess();
-      }
-      else
-      {
-         *PrevAttachedProcess = NULL;
-      }
-      KeAttachProcess(Csrss);
+      KeStackAttachProcess(Csrss, ApcState);
    }
 }
 
 VOID FASTCALL
-IntDetachFromCSRSS(PKPROCESS *CallingProcess, PKPROCESS *PrevAttachedProcess)
+IntDetachFromCSRSS(PKPROCESS *CallingProcess, PKAPC_STATE ApcState)
 {
    if (*CallingProcess != Csrss)
    {
-      KeDetachProcess();
-      if (NULL != *PrevAttachedProcess)
-      {
-         KeAttachProcess(*PrevAttachedProcess);
-      }
+      KeUnstackDetachProcess(ApcState);
    }
 }
 
@@ -853,7 +839,7 @@
 {
    static PVOID RomImageBuffer = NULL;
    PKPROCESS CallingProcess;
-   PKPROCESS PrevAttachedProcess;
+   KAPC_STATE ApcState;
 
    DPRINT("VideoPortGetRomImage(HwDeviceExtension 0x%X Length 0x%X)\n",
           HwDeviceExtension, Length);
@@ -890,9 +876,9 @@
          return NULL;
       }
 
-      IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
+      IntAttachToCSRSS(&CallingProcess, &ApcState);
       RtlCopyMemory(RomImageBuffer, (PUCHAR)0xC0000, Length);
-      IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
+      IntDetachFromCSRSS(&CallingProcess, &ApcState);
 
       return RomImageBuffer;
    }

Modified: trunk/reactos/drivers/video/videoprt/videoprt.h
--- trunk/reactos/drivers/video/videoprt/videoprt.h	2005-06-14 18:39:12 UTC (rev 15914)
+++ trunk/reactos/drivers/video/videoprt/videoprt.h	2005-06-14 20:24:02 UTC (rev 15915)
@@ -29,6 +29,8 @@
 #include <ddk/ntddvdeo.h>
 #include <ddk/ntapi.h>
 #include <ddk/ntagp.h>
+/* For process attaching functions */
+#include <ddk/ntifs.h>
 #define NDEBUG
 #include <debug.h>
 
@@ -201,10 +203,10 @@
    IN PUCHAR FunctionName);
 
 VOID FASTCALL
-IntAttachToCSRSS(PKPROCESS *CallingProcess, PKPROCESS *PrevAttachedProcess);
+IntAttachToCSRSS(PKPROCESS *CallingProcess, PKAPC_STATE ApcState);
 
 VOID FASTCALL
-IntDetachFromCSRSS(PKPROCESS *CallingProcess, PKPROCESS *PrevAttachedProcess);
+IntDetachFromCSRSS(PKPROCESS *CallingProcess, PKAPC_STATE ApcState);
 
 NTSTATUS STDCALL
 IntVideoPortCreateAdapterDeviceObject(