ntoskrnl.exe
(short for
Windows NT
Windows NT is a Proprietary software, proprietary Graphical user interface, graphical operating system produced by Microsoft as part of its Windows product line, the first version of which, Windows NT 3.1, was released on July 27, 1993. Original ...
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
kernel executable
In computer science, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded instruction (computer science), in ...
), also known as the kernel image, contains the
kernel and
executive
Executive ( exe., exec., execu.) may refer to:
Role or title
* Executive, a senior management role in an organization
** Chief executive officer (CEO), one of the highest-ranking corporate officers (executives) or administrators
** Executive dir ...
layers of the Microsoft
Windows NT kernel
The architecture of Windows NT, a line of operating systems produced and sold by Microsoft, is a layered design that consists of two main components, user mode and kernel mode. It is a preemptive, reentrant multitasking operating system, whic ...
, and is responsible for
hardware abstraction
Hardware abstractions are sets of routines in software that provide programs with access to hardware resources through programming interfaces. The programming interface allows all devices in a particular class ''C'' of hardware devices to be acc ...
,
process
A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic.
Things called a process include:
Business and management
* Business process, activities that produce a specific s ...
handling, and
memory management
Memory management (also dynamic memory management, dynamic storage allocation, or dynamic memory allocation) is a form of Resource management (computing), resource management applied to computer memory. The essential requirement of memory manag ...
. In addition to the kernel and executive layers, it contains the
cache
Cache, caching, or caché may refer to:
Science and technology
* Cache (computing), a technique used in computer storage for easier data access
* Cache (biology) or hoarding, a food storing behavior of animals
* Cache (archaeology), artifacts p ...
manager, security reference monitor, memory manager,
scheduler
A schedule (, ) or a timetable, as a basic time-management tool, consists of a list of times at which possible tasks, events, or actions are intended to take place, or of a sequence of events in the chronological order in which such things ...
(Dispatcher), and
blue screen of death
The blue screen of death (BSoD) or blue screen error, blue screen, fatal error, bugcheck, and officially known as a stop erroris a fatal system error, critical error screen displayed by the Microsoft Windows operating systems to indicate a cr ...
(the prose and portions of the code).
[Russinovich, M]
Systems Internals Tips and Trivia
''SysInternals Information''
Overview
x86 versions of
ntoskrnl.exe
depend on
bootvid.dll
,
hal.dll
and
kdcom.dll
(x64 variants of
ntoskrnl.exe
have these DLLs embedded in the kernel to improve performance). However, it is not a
native application
Native describes a computing system as operating directly with an underlying technology; with no intervening communication or translation layers.
Native software
Native software is built to be executed directly by processors that implement ...
thus it is not linked against
ntdll.dll
. Instead,
ntoskrnl.exe
has its own
entry point
In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.
To start a program's execution, the loader or operating system passes co ...
"KiSystemStartup" that calls the
architecture
Architecture is the art and technique of designing and building, as distinguished from the skills associated with construction. It is both the process and the product of sketching, conceiving, planning, designing, and construction, constructi ...
-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
Windows XP is a major release of Microsoft's Windows NT operating system. It was released to manufacturing on August 24, 2001, and later to retail on October 25, 2001. It is a direct successor to Windows 2000 for high-end and business users a ...
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.
Starting with Windows Vista, Microsoft began unifying the kernel images as
multi-core CPUs took to the market and PAE became mandatory.
Windows kernel's architecture is structured so that everything is easy to understand. Functions and global variables use the so called
Pascal Case
The writing format camel case (sometimes stylized autologically as camelCase or CamelCase, also known as camel caps or more formally as medial capitals) is the practice of writing phrases without spaces or punctuation and with capitalized wo ...
formatting with special (additional) prefixes in their names to differentiate parts of the kernel.
An example is IoCreateDevice and ObReferenceObjectByHandle. Both functions have different prefix names to differentiate critical managers within the kernel code: Io being used fo
I/O Managerfunctions and Ob for
Object Manager functions.
Variations of these prefixes exist for internal functions that are not being exported by the kernel, such as adding an i after the first letter (e.g.,
Ki
for “Kernel Internal”) or appending p to the full prefix (e.g.,
Psp
for “Process Support Internal”).
The following table lists all prefixes.
Initialization
When the kernel receives control, it gets a struct-type pointer from
bootloader
A bootloader, also spelled as boot loader or called bootstrap loader, is a computer program that is responsible for booting a computer and booting an operating system. If it also provides an interactive menu with multiple boot choices then it's o ...
. 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). The definition of this structure can be retrieved by using the kernel debugger or downloading it from the Microsoft symbol database.
In the
x86 architecture
x86 (also known as 80x86 or the 8086 family) is a family of complex instruction set computer (CISC) instruction set architectures initially developed by Intel, based on the 8086 microprocessor and its 8-bit-external-bus variant, the 8088. T ...
, the kernel receives the system already in protected mode, with the
GDT,
IDT and
TSS ready. But since it does not know the address of each one, it has to load them one by one to fill the
PCR structure.
The main entry point of
ntoskrnl.exe
performs some system dependent initialization then calls a system independent initialization then enters an idle loop.
Interrupt handling
Modern operating systems use interrupts instead of I/O port polling to wait for information from devices.
In the
x86 architecture
x86 (also known as 80x86 or the 8086 family) is a family of complex instruction set computer (CISC) instruction set architectures initially developed by Intel, based on the 8086 microprocessor and its 8-bit-external-bus variant, the 8088. T ...
, interrupts are handled through the Interrupt Dispatch Table (IDT). When a device triggers an interrupt ''and'' the
interrupt flag
The Interrupt flag (IF) is a flag bit in the CPU's FLAGS register, which determines whether or not the (CPU) will respond immediately to maskable hardware interrupts. If the flag is set to 1 maskable interrupts are enabled. If reset (set to 0) suc ...
(IF) in the
FLAGS register
The FLAGS processor register, register is the status register that contains the current state of an x86 CPU. The size and meanings of the flag bits are architecture dependent. It usually reflects the result of arithmetic operations as well as infor ...
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
IA-32 (short for "Intel Architecture, 32-bit", commonly called ''i386'') is the 32-bit version of the x86 instruction set architecture, designed by Intel and first implemented in the i386, 80386 microprocessor in 1985. IA-32 is the first incarn ...
versions of the kernel, one example of such a software interrupt handler (of which there are many) is in its IDT table entry 2E
16 (
hexadecimal
Hexadecimal (also known as base-16 or simply hex) is a Numeral system#Positional systems in detail, positional numeral system that represents numbers using a radix (base) of sixteen. Unlike the decimal system representing numbers using ten symbo ...
; 46 in
decimal
The decimal numeral system (also called the base-ten positional numeral system and denary or decanary) is the standard system for denoting integer and non-integer numbers. It is the extension to non-integer numbers (''decimal fractions'') of th ...
), used in
assembly language
In computing, assembly language (alternatively assembler language or symbolic machine code), often referred to simply as assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence bet ...
as
INT 2EH
for
system call
In computing, a system call (syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, accessing a hard disk drive ...
s. In the real implementation the entry points to an internal
subroutine
In computer programming, a function (also procedure, method, subroutine, routine, or subprogram) is a callable unit of software logic that has a well-defined interface and behavior and can be invoked multiple times.
Callable units provide a ...
named (as per
symbol
A symbol is a mark, Sign (semiotics), sign, or word that indicates, signifies, or is understood as representing an idea, physical object, object, or wikt:relationship, relationship. Symbols allow people to go beyond what is known or seen by cr ...
information published by Microsoft)
KiSystemService
. For newer versions, different mechanisms making use of
SYSENTER
instruction and in
x86-64
x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit extension of the x86 instruction set architecture, instruction set. It was announced in 1999 and first available in the AMD Opteron family in 2003. It introduces two new ope ...
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.
Memory manager
The entire physical memory (RAM) address range is broken into many small blocks also called pages, 4KB in size each, and mapped to virtual addresses. A few of the properties of each block are stored in structures called
page table
A page table is a data structure used by a virtual memory system in a computer to store mappings between virtual addresses and physical addresses. Virtual addresses are used by the program executed by the accessing process, while physical addr ...
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).
Microsoft Windows divides
virtual address space
In computing, a virtual address space (VAS) or address space is the set of ranges of virtual addresses that an operating system makes available to a process. The range of virtual addresses usually starts at a low address and can extend to the h ...
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.
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.
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
*
Architecture of Windows NT
The architecture of Windows NT, a line of operating systems produced and sold by Microsoft, is a layered design that consists of two main components, user mode and kernel mode. It is a preemptive, reentrant multitasking operating system, whi ...
*
Windows NT Startup Process
Notes
As mentioned i
Windows Internals Book 7th edition
the boot-time option increaseuserva
and corresponding header in executable image is required for this feature.
References
Further reading
*
*
External links
Inside the Windows Vista Kernel (TechNet Magazine)Driver Development Part 1: Introduction to Drivers
{{Windows Components
Windows NT kernel
Windows files