Maystyle :
Admin : New post
Guestbook
Local
media
Catergories
Recent Articles
Recent Comments
Recent Trackbacks
Calendar
Tag
Archive
Link
Search
 
  커널 모드 시스템 서비스 디스패칭 
작성일시 : 2007. 11. 26. 16:14 | 분류 : Windows Server/Kernel

커널에서는 IDT와 비슷한 시스템 서비스 디스패치 테이블을 가지고 있다.

그림에서 보는 것 처럼 시스템 서비스 디스패처 (KiSystemService)는 스레드의 사용자 모드 스택으로 부터 자신의 커널 모드 스택에 호출자의 매개 변수들을 복사하고, 그 뒤 시스템 서비스를 실행한다. 시스템 서비스에 넘겨진 매개변수가 사용자 공간의 버퍼를 가르킨다면, 이들 버퍼들이 액세스 가능한지 검사한 후에 커널 모드 코드가 이 버퍼에서 데이터를 읽어 오거나 쓰게 할 수 있다.

각 스레드는 자신의 시스템 서비스 테이블에 대한 포인터를 가진다. Windows는 두개의 내장 시스템 서비스 테이블을 가지지만, 4개 까지 지원이 가능하다.
시스템 서비스 디스패처는 2비트 필드를 테이블 인덱스로 해석하여 32비트 시스템 서비스 번호에서 요청된 서비스를 포함하는 테이블이 어떤 것인지 결정한다. 시스템 서비스 번호 아래 12 비트는 테이블 인덱스에 의해 지정된 테이블에 인덱스로 ㅈ공되는데, 해당 필드들은 아래 그림과 같다.

A primary default array table, KeServiceDescriptorTable, defines the core executive system services implemented in Ntosrknl.exe.

The other table array, KeServiceDescriptorTableShadow, includes the Windows USER and GDI services implemented in the kernel-mode part of the Windows subsystem, Win32k.sys.

The first time a Windows thread calls a Windows USER or GDI service, the address of the thread's system service table is changed to point to a table that includes the Windows USER and GDI services. The KeAddSystemServiceTable function allows Win32k.sys and other device drivers to add system service tables. If you install Internet Information Services (IIS) on Windows 2000, its support driver (Spud.sys) upon loading defines an additional service table, leaving only one left for definition by third parties.

With the exception of the Win32k.sys service table, a service table added with KeAddSystemServiceTable is copied into both the KeServiceDescriptorTable array and the KeServiceDescriptorTableShadow array.

Windows supports the addition of only two system service tables beyond the core and Win32 tables.

As shown in 3-16 the Windows WriteFile function in Kernel32.dll calls the NtWriteFile function in Ntdll.dll, which in turn executes the appropriate instruction to cause a system service trap, passing the system service number representing NtWriteFile. The system service dispatcher (function KiSystemService in Ntoskrnl.exe) then calls the real NtWriteFile to process the I/O request. For Windows USER and GDI functions, the system service dispatch calls functions in the loadable kernel-mode part of the Windows subsystem, Win32k.sys.

|