⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dllmain.c

📁 这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 *  ReactOS W32 Subsystem
 *  Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 ReactOS Team
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
/* $Id: dllmain.c 25118 2006-12-10 18:40:30Z ion $
 *
 *  Entry Point for win32k.sys
 */

#include <w32k.h>
#include <include/napi.h>

#define NDEBUG
#include <debug.h>

PGDI_HANDLE_TABLE INTERNAL_CALL GDIOBJ_iAllocHandleTable(OUT PSECTION_OBJECT *SectionObject);
BOOL INTERNAL_CALL GDI_CleanupForProcess (PGDI_HANDLE_TABLE HandleTable, struct _EPROCESS *Process);
/* FIXME */
PGDI_HANDLE_TABLE GdiHandleTable = NULL;
PSECTION_OBJECT GdiTableSection = NULL;

HANDLE GlobalUserHeap = NULL;
PSECTION_OBJECT GlobalUserHeapSection = NULL;

extern ULONG_PTR Win32kSSDT[];
extern UCHAR Win32kSSPT[];
extern ULONG Win32kNumberOfSysCalls;

NTSTATUS 
STDCALL
Win32kProcessCallback(struct _EPROCESS *Process,
                      BOOLEAN Create)
{
    PW32PROCESS Win32Process;
    DECLARE_RETURN(NTSTATUS);
    
    DPRINT("Enter Win32kProcessCallback\n");
    UserEnterExclusive();
    
    /* Get the Win32 Process */
    Win32Process = PsGetProcessWin32Process(Process);
    
    /* Allocate one if needed */
    if (!Win32Process)
    {
        /* FIXME - lock the process */
        Win32Process = ExAllocatePoolWithTag(NonPagedPool,
                                             sizeof(W32PROCESS),
                                             TAG('W', '3', '2', 'p'));

        if (Win32Process == NULL) RETURN( STATUS_NO_MEMORY);

        RtlZeroMemory(Win32Process, sizeof(W32PROCESS));
        
        PsSetProcessWin32Process(Process, Win32Process);
        /* FIXME - unlock the process */
    }

  if (Create)
    {
      ULONG ViewSize = 0;
      LARGE_INTEGER Offset;
      PVOID UserBase = NULL;
      NTSTATUS Status;
      extern PSECTION_OBJECT GlobalUserHeapSection;
      DPRINT("Creating W32 process PID:%d at IRQ level: %lu\n", Process->UniqueProcessId, KeGetCurrentIrql());

      /* map the global heap into the process */
      Offset.QuadPart = 0;
      Status = MmMapViewOfSection(GlobalUserHeapSection,
                                  PsGetCurrentProcess(),
                                  &UserBase,
                                  0,
                                  0,
                                  &Offset,
                                  &ViewSize,
                                  ViewUnmap,
                                  SEC_NO_CHANGE,
                                  PAGE_EXECUTE_READ); /* would prefer PAGE_READONLY, but thanks to RTL heaps... */
      if (!NT_SUCCESS(Status))
      {
          DPRINT1("Failed to map the global heap! 0x%x\n", Status);
          RETURN(Status);
      }
      Win32Process->HeapMappings.Next = NULL;
      Win32Process->HeapMappings.KernelMapping = (PVOID)GlobalUserHeap;
      Win32Process->HeapMappings.UserMapping = UserBase;
      Win32Process->HeapMappings.Count = 1;

      InitializeListHead(&Win32Process->ClassList);

      InitializeListHead(&Win32Process->MenuListHead);

      InitializeListHead(&Win32Process->PrivateFontListHead);
      ExInitializeFastMutex(&Win32Process->PrivateFontListLock);

      InitializeListHead(&Win32Process->DriverObjListHead);
      ExInitializeFastMutex(&Win32Process->DriverObjListLock);

      Win32Process->KeyboardLayout = W32kGetDefaultKeyLayout();

      if(Process->Peb != NULL)
      {
        /* map the gdi handle table to user land */
        Process->Peb->GdiSharedHandleTable = GDI_MapHandleTable(GdiTableSection, Process);
      }

      /* setup process flags */
      Win32Process->Flags = 0;
    }
  else
    {
      DPRINT("Destroying W32 process PID:%d at IRQ level: %lu\n", Process->UniqueProcessId, KeGetCurrentIrql());
      IntCleanupMenus(Process, Win32Process);
      IntCleanupCurIcons(Process, Win32Process);
      IntEngCleanupDriverObjs(Process, Win32Process);
      CleanupMonitorImpl();
      
      /* no process windows should exist at this point, or the function will assert! */
      DestroyProcessClasses(Win32Process);

      GDI_CleanupForProcess(GdiHandleTable, Process);

      co_IntGraphicsCheck(FALSE);

      /*
       * Deregister logon application automatically
       */
      if(LogonProcess == Win32Process)
      {
        LogonProcess = NULL;
      }

      if (Win32Process->ProcessInfo != NULL)
      {
          UserHeapFree(Win32Process->ProcessInfo);
          Win32Process->ProcessInfo = NULL;
      }
    }

  RETURN( STATUS_SUCCESS);
  
CLEANUP:
  UserLeave();
  DPRINT("Leave Win32kProcessCallback, ret=%i\n",_ret_);
  END_CLEANUP;
}


NTSTATUS 
STDCALL
Win32kThreadCallback(struct _ETHREAD *Thread,
                     PSW32THREADCALLOUTTYPE Type)
{
    struct _EPROCESS *Process;
    PW32THREAD Win32Thread;
    DECLARE_RETURN(NTSTATUS);
    
    DPRINT("Enter Win32kThreadCallback\n");
    UserEnterExclusive();

    Process = Thread->ThreadsProcess;
    
    /* Get the Win32 Thread */
    Win32Thread = PsGetThreadWin32Thread(Thread);
    
    /* Allocate one if needed */
    if (!Win32Thread)
    {
        /* FIXME - lock the process */
        Win32Thread = ExAllocatePoolWithTag(NonPagedPool,
                                            sizeof(W32THREAD),
                                            TAG('W', '3', '2', 't'));

        if (Win32Thread == NULL) RETURN( STATUS_NO_MEMORY);

        RtlZeroMemory(Win32Thread, sizeof(W32THREAD));
        
        PsSetThreadWin32Thread(Thread, Win32Thread);
        /* FIXME - unlock the process */
    }
  if (Type == PsW32ThreadCalloutInitialize)
    {
      HWINSTA hWinSta = NULL;
      HDESK hDesk = NULL;
      NTSTATUS Status;
      PUNICODE_STRING DesktopPath;
      PRTL_USER_PROCESS_PARAMETERS ProcessParams = (Process->Peb ? Process->Peb->ProcessParameters : NULL);

      DPRINT("Creating W32 thread TID:%d at IRQ level: %lu\n", Thread->Cid.UniqueThread, KeGetCurrentIrql());

      InitializeListHead(&Win32Thread->WindowListHead);
      InitializeListHead(&Win32Thread->W32CallbackListHead);

      /*
       * inherit the thread desktop and process window station (if not yet inherited) from the process startup
       * info structure. See documentation of CreateProcess()
       */
      DesktopPath = (ProcessParams ? ((ProcessParams->DesktopInfo.Length > 0) ? &ProcessParams->DesktopInfo : NULL) : NULL);
      Status = IntParseDesktopPath(Process,
                                   DesktopPath,
                                   &hWinSta,
                                   &hDesk);
      if(NT_SUCCESS(Status))
      {
        if(hWinSta != NULL)
        {
          if(Process != CsrProcess)
          {
            HWINSTA hProcessWinSta = (HWINSTA)InterlockedCompareExchangePointer((PVOID)&Process->Win32WindowStation, (PVOID)hWinSta, NULL);
            if(hProcessWinSta != NULL)
            {
              /* our process is already assigned to a different window station, we don't need the handle anymore */
              NtClose(hWinSta);
            }
          }
          else
          {
            NtClose(hWinSta);
          }
        }

        if (hDesk != NULL)
        {
          PDESKTOP_OBJECT DesktopObject;
          Win32Thread->Desktop = NULL;
          Status = ObReferenceObjectByHandle(hDesk,
                                             0,
                                             ExDesktopObjectType,
                                             KernelMode,
                                             (PVOID*)&DesktopObject,
                                             NULL);
          NtClose(hDesk);
          if(NT_SUCCESS(Status))
          {
            if (!IntSetThreadDesktop(DesktopObject,
                                     FALSE))
            {
              DPRINT1("Unable to set thread desktop\n");
            }
          }
          else
          {
            DPRINT1("Unable to reference thread desktop handle 0x%x\n", hDesk);
          }
        }
      }
      Win32Thread->IsExiting = FALSE;
      co_IntDestroyCaret(Win32Thread);
      Win32Thread->MessageQueue = MsqCreateMessageQueue(Thread);
      Win32Thread->KeyboardLayout = W32kGetDefaultKeyLayout();
      Win32Thread->MessagePumpHookValue = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -