Jump to content

Ntoskrnl.exe: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
The much-needed improvements
No edit summary
Line 59: Line 59:
| <code>Io</code> || I/O manager<ref>{{cite web | author=Microsoft Corporation | author-link=Microsoft Corporation | year=2009 | url=http://msdn.microsoft.com/en-us/library/ff551797.aspx | title=I/O Manager Routines | publisher=[[Microsoft Corporation]] | access-date=2009-06-13 }}</ref>
| <code>Io</code> || I/O manager<ref>{{cite web | author=Microsoft Corporation | author-link=Microsoft Corporation | year=2009 | url=http://msdn.microsoft.com/en-us/library/ff551797.aspx | title=I/O Manager Routines | publisher=[[Microsoft Corporation]] | access-date=2009-06-13 }}</ref>
|-
|-
| <code>Ke</code> || core kernel routines<ref>{{cite web | author=Microsoft Corporation | author-link=Microsoft Corporation | year=2009 | url=http://msdn.microsoft.com/en-us/library/ff542078.aspx | title=Core Kernel Library Support Routines | publisher=[[Microsoft Corporation]] | access-date=2009-06-13 }}</ref>
| <code>Ke</code> || Core kernel routines<ref>{{cite web | author=Microsoft Corporation | author-link=Microsoft Corporation | year=2009 | url=http://msdn.microsoft.com/en-us/library/ff542078.aspx | title=Core Kernel Library Support Routines | publisher=[[Microsoft Corporation]] | access-date=2009-06-13 }}</ref>
|-
|-
| <code>Ki</code> || routines in the kernel that are not exported for call from outside the kernel (i = internal)
| <code>Ki</code> || Routines in the kernel that are not exported for call from outside the kernel (i = internal)
|-
|-
| <code>Ks</code> || kernel streaming
| <code>Ks</code> || Kernel streaming
|-
|-
| <code>Ldr</code> || loader functions for PE file handling
| <code>Kx</code> || Interrupt handling, semaphores and context switching functions
|-
| <code>Ldr</code> || NT's PE Executables loader
|-
|-
| <code>Lpc</code> || [[Local Inter-Process Communication|Local Procedure Call]], an internal, undocumented, interprocess or user/kernel message passing mechanism
| <code>Lpc</code> || [[Local Inter-Process Communication|Local Procedure Call]], an internal, undocumented, interprocess or user/kernel message passing mechanism
Line 71: Line 73:
| <code>Lsa</code> || [[Local Security Authority Subsystem Service|Local Security Authority]]
| <code>Lsa</code> || [[Local Security Authority Subsystem Service|Local Security Authority]]
|-
|-
| <code>Mi</code> || memory management routines not exported for call outside the memory manager (i = internal)
| <code>Mi</code> || Memory management routines not exported for call outside the memory manager (i = internal)
|-
|-
| <code>Mm</code> || memory management
| <code>Mm</code> || Memory management
|-
|-
| <code>Nls</code> || Nls for Native Language Support (similar to code pages).
| <code>Nls</code> || Nls for Native Language Support (similar to code pages).
Line 79: Line 81:
| <code>Ob</code> || [[Object Manager]]
| <code>Ob</code> || [[Object Manager]]
|-
|-
| <code>Pfx</code> || prefix handling
| <code>Pfx</code> || Prefix handling
|-
|-
| <code>Po</code> || [[Plug and play|Plug-and-play]] and [[power management]]<ref>{{cite web | author=Microsoft Corporation | author-link=Microsoft Corporation | year=2009 | url=http://msdn.microsoft.com/en-us/library/ff559835.aspx | title=Power Manager Routines | publisher=[[Microsoft Corporation]] | access-date=2009-06-13 }}</ref>
| <code>Po</code> || [[Plug and play|Plug-and-play]] and [[power management]]<ref>{{cite web | author=Microsoft Corporation | author-link=Microsoft Corporation | year=2009 | url=http://msdn.microsoft.com/en-us/library/ff559835.aspx | title=Power Manager Routines | publisher=[[Microsoft Corporation]] | access-date=2009-06-13 }}</ref>
Line 89: Line 91:
| <code>Rtlp</code> || Runtime library private (for internal use only)
| <code>Rtlp</code> || Runtime library private (for internal use only)
|-
|-
| <code>Se</code> || security
| <code>Se</code> || Security
|-
|-
| <code>Vf</code> || [[Driver Verifier]]
| <code>Vf</code> || [[Driver Verifier]]

Revision as of 09:54, 9 March 2023

ntoskrnl.exe (short for Windows NT operating system kernel executable), also known as the kernel image, contains the kernel and executive layers of the Microsoft Windows NT kernel, and is responsible for hardware abstraction, process handling, and memory management. In addition to the kernel and executive mentioned earlier, it contains the cache manager, security reference monitor, memory manager, scheduler (Dispatcher), and blue screen of death (the prose and portions of the code).[1]

Overview

ntoskrnl.exe depends on bootvid.dll, hal.dll and kdcom.dll. However, it is not a native application. In other words, it is not linked against ntdll.dll. Instead, ntoskrnl.exe containing a standard "start" entry point that calls the architecture-independent kernel initialization function. Because it requires a static copy of the C Runtime objects, the executable is usually about 10 MB in size.

In Windows XP and earlier, the Windows installation source ships four kernel image files to support uniprocessor systems, symmetric multiprocessor (SMP) systems, CPUs with PAE, and CPUs without PAE. Windows setup decides whether the system is uniprocessor or multiprocessor, then, installs both the PAE and non-PAE variants of the kernel image for the decided kind. On a multiprocessor system, Setup installs ntkrnlmp.exe and ntkrpamp.exe but renames them to ntoskrnl.exe and ntkrnlpa.exe respectively.

Kernel image filenames
Filename Supports
SMP
Supports
PAE
ntoskrnl.exe No No
ntkrnlmp.exe Yes No
ntkrnlpa.exe No Yes
ntkrpamp.exe Yes Yes

Starting with Windows Vista, Microsoft began unifying the kernel images as multi-core CPUs took to the market and PAE became mandatory.

Routines in ntoskrnl use prefixes on their names to indicate in which component of ntoskrnl they are defined. The following table lists some of them.

NT function prefixes
Prefix Meaning
Cc File system cache[2]
Cm Configuration Manager, the kernel mode side of Windows Registry
Csr functions used to communicate with the Win32 subsystem process, csrss.exe (csrss stands for client/server runtime sub-system)
Dbg debugging aid functions, such as a software break point
Ex Windows executive, an "outer layer" of Ntoskrnl.exe
Exp Windows executive private (routines intended for the internal use of Windows Executive)
FsRtl file system runtime library[3]
Io I/O manager[4]
Ke Core kernel routines[5]
Ki Routines in the kernel that are not exported for call from outside the kernel (i = internal)
Ks Kernel streaming
Kx Interrupt handling, semaphores and context switching functions
Ldr NT's PE Executables loader
Lpc Local Procedure Call, an internal, undocumented, interprocess or user/kernel message passing mechanism
Lsa Local Security Authority
Mi Memory management routines not exported for call outside the memory manager (i = internal)
Mm Memory management
Nls Nls for Native Language Support (similar to code pages).
Ob Object Manager
Pfx Prefix handling
Po Plug-and-play and power management[6]
Ps Process and thread management
Rtl Runtime library, i.e., many utility functions that can be used by native applications, yet don't directly involve kernel support
Rtlp Runtime library private (for internal use only)
Se Security
Vf Driver Verifier
Vi Driver Verifier routines not exported for call outside the driver verifier
Zw Nt or Zw are system calls declared in ntdll.dll and ntoskrnl.exe. When called from ntdll.dll in user mode, these groups are almost exactly the same; they trap into kernel mode and call the equivalent function in ntoskrnl.exe via the SSDT. When calling the functions directly in ntoskrnl.exe (only possible in kernel mode), the Zw variants ensure kernel mode, whereas the Nt variants do not.[7]

Initialization

When the kernel receives control, it gets a struct-type pointer from bootloader. The pointer's destination contains information about the hardware, the path to the Windows Registry file, kernel parameters containing boot preferences or options that change the behavior of the kernel, path of the files loaded by the bootloader (SYSTEM Registry hive, nls for character encoding conversion, and vga font).[8] The definition of this structure can be retrieved by using the kernel debugger or downloading it from the Microsoft symbol database.[9][page needed]

In the x86 architecture, the kernel receives the system already in protected mode, with the GDT, IDT and TSS ready.[further explanation needed] But since it does not know the address of each one, it has to load them one by one to fill the PCR structure.[jargon]

The main entry point of ntoskrnl.exe performs some system dependent initialization then calls a system independent initialization then enters an idle loop.[contradictory]

Interrupt handling

Modern operating systems use interrupts instead of I/O port polling to wait for information from devices.

In the x86 architecture, interrupts are handled through the Interrupt Dispatch Table (IDT). When a device triggers an interrupt and the interrupt flag (IF) in the FLAGS register is set, the processor's hardware looks for an interrupt handler in the table entry corresponding to the interrupt number to which in turn has been translated from IRQ by PIC chips, or in more modern hardwares, APIC. Interrupt handlers usually save some subset of the state of registers before handling it and restore them back to their original values when done.

The interrupt table contains handlers for hardware interrupts, software interrupts, and exceptions. For some IA-32 versions of the kernel, one example of such a software interrupt handler (of which there are many) is in its IDT table entry 2E16 (hexadecimal; 46 in decimal), used in assembly language as INT 2EH for system calls. In the real implementation the entry points to an internal subroutine named (as per symbol information published by Microsoft) KiSystemService. For newer versions, different mechanisms making use of SYSENTER instruction and in x86-64 SYSCALL instruction are used instead.

One notable feature of NT's interrupt handling is that interrupts are usually conditionally masked based on their priority (called "IRQL"), instead of disabling all IRQs via the interrupt flag. This permits various kernel components to carry on critical operations without necessarily blocking services of peripherals and other devices.[10]

Memory manager

Microsoft Windows divides virtual address space into two regions. The lower part, starting at zero, is instantiated separately for each process and is accessible from both user and kernel mode. Application programs run in processes and supply code that runs in user mode. The upper part is accessible only from kernel mode, and with some exceptions, is instantiated just once, system-wide. Ntoskrnl.exe is mapped into this region, as are several other kernel mode components. This region also contains data used by kernel mode code, such as the kernel mode heaps and the file system cache.

Start and end of segments by access privilege[9]
Arch MmHighestUserAddress MmSystemRangeStart
x86[a] 0x7fffffff 0x80000000
ARM 0x7fffffff 0x80000000
x86-64 0x000007ff'ffffffff 0xffff8000'00000000

The entire physical memory (RAM) address range is broken into many small (usually 4 KB) blocks. A few of the properties of each block are stored in structures called page table entries, which are managed by the OS and accessed by the processor's hardware. Page tables are organized into a tree structure, and the physical page number of the top-level table is stored in control register 3 (CR3).

Registry

Windows Registry is a repository for configuration and settings information for the operating system and for other software, such as applications. It can be thought of as a filesystem optimized for small files.[11] However, it is not accessed through file system-like semantics, but rather through a specialized set of APIs, implemented in kernel mode and exposed to user mode.

The registry is stored on disk as several different files called "hives." One, the System hive, is loaded early in the boot sequence and provides configuration information required at that time. Additional registry hives, providing software-specific and user-specific data, are loaded during later phases of system initialization and during user login, respectively.

Drivers

The list of drivers to be loaded from the disk are retrieved from the Services key of the current control set's key in the SYSTEM registry hive. That key stores device drivers, kernel processes and user processes. They are all collectively called "services" and are all stored mixed on the same place.

During initialization or upon driver load request, the kernel traverses that tree looking for services tagged as kernel services.

See also

Notes

  1. ^ Tunable via /userva or /3gb switch.

References

  1. ^ Russinovich, M: Systems Internals Tips and Trivia, SysInternals Information
  2. ^ Microsoft Corporation (2009). "Cache Manager Routines". Microsoft Corporation. Retrieved 2009-06-13.
  3. ^ Microsoft Corporation (2009). "File System Runtime Library Routines". Microsoft Corporation. Retrieved 2009-06-13.
  4. ^ Microsoft Corporation (2009). "I/O Manager Routines". Microsoft Corporation. Retrieved 2009-06-13.
  5. ^ Microsoft Corporation (2009). "Core Kernel Library Support Routines". Microsoft Corporation. Retrieved 2009-06-13.
  6. ^ Microsoft Corporation (2009). "Power Manager Routines". Microsoft Corporation. Retrieved 2009-06-13.
  7. ^ The NT Insider (August 27, 2003). "Nt vs. Zw - Clearing Confusion On The Native API". OSR Online. 10 (4). OSR Open Systems Resources. Retrieved 2013-09-16.
  8. ^ "struct LOADER_PARAMETER_BLOCK". www.nirsoft.net.
  9. ^ a b Practical Reverse Engineering Using X86, X64, Arm, Windows Kernel, and Reversing Tools. John Wiley & Sons Inc. 2014. ISBN 978-1118787311.
  10. ^ CC Hameed (January 22, 2008). "What is IRQL and why is it important? | Ask the Performance Team Blog". Microsoft Corporation. Retrieved 2018-11-11.
  11. ^ Tanenbaum, Andrew S. (2008). Modern operating systems (3rd ed.). Upper Saddle River, N.J.: Pearson Prentice Hall. p. 829. ISBN 978-0136006633.

Further reading

  • Tanenbaum, Andrew S. (2008). Modern Operating Systems (3rd ed.). Upper Saddle River, N.J.: Pearson Prentice Hall. p. 829. ISBN 978-0136006633.
  • Bruce Dang; Alexandre Gazet; Elias Bachaalany (2014). Practical Reverse Engineering: x86, x64, ARM, Windows Kernel, Reversing Tools, and Obfuscation. Wiley. p. 384. ISBN 978-1118787311.

External links