Recent from talks
Contribute something
Nothing was collected or created yet.
Windows Native API
View on WikipediaThe topic of this article may not meet Wikipedia's general notability guideline. (February 2022) |
The Native API is a lightweight application programming interface (API) used by Windows NT's kernel and user mode applications. This API is used in the early stages of Windows NT startup process, when other components and APIs are still unavailable. Therefore, a few Windows components, such as the Client/Server Runtime Subsystem (CSRSS), are implemented using the Native API. The Native API is also used by subroutines such as those in kernel32.dll that implement the Windows API, the API based on which most of the Windows components are created.
Most of the Native API calls are implemented in ntoskrnl.exe and are exposed to user mode by ntdll.dll. The entry point of ntdll.dll is LdrInitializeThunk. Native API calls are handled by the kernel via the System Service Descriptor Table (SSDT).
Function groups
[edit]The Native API comprises many functions. They include C runtime functions that are needed for a very basic C runtime execution, such as strlen(), sprintf(), memcpy() and floor(). Other common procedures like malloc(), printf(), scanf() are missing (the first because it does not specify a heap to allocate memory from and the second and third because they use the console, accessed only via KERNEL32.DLL). The vast majority of other Native API routines, by convention, have a 2 or 3 letter prefix, which is:
- 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 execute an interrupt 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.[1] The Zw prefix does not stand for anything.[2]
- Rtl is the second largest group of ntdll calls. These comprise the (extended) C Run-Time Library, which includes many utility functions that can be used by native applications, yet don't directly involve kernel support.
- Csr are client-server functions that are used to communicate with the Win32 subsystem process, csrss.exe (csrss stands for client/server runtime sub-system).
- Dbg are debugging functions such as a software breakpoint.
- Ki are upcalls from kernel mode for events like APC dispatching.
- Ldr are loader functions for PE file handling and starting of new processes.
- Nls for National Language Support (similar to code pages).
- Pfx for prefix handling.
- Tp for threadpool handling.
user32.dll and gdi32.dll include several other calls that execute an interrupt into kernel mode. These were not part of the original Windows NT design, as can be seen in Windows NT 3.5. However, due to performance issues of hardware of that age, it was decided to move the graphics subsystem into kernel mode. As such, system call in the range of 0x1000-0x1FFF are satisfied by win32k.sys (instead of ntoskrnl.exe as done for 0-0x0FFF), and are declared in user32.dll and gdi32.dll. These functions have the NtUser and NtGdi prefix (e.g. NtUserLockWorkStation and NtGdiEnableEudc).
Uses
[edit]Uses of Native API functions includes but not limited to:
- Enabling and disabling privileges (RtlAdjustPrivilege)
- Creating remote threads within processes that are running in different session (RtlCreateUserThread)
- Running native applications (RtlCreateUserProcess)
- Performing a forced shutdown (NtShutdownSystem)
- Causing a BSOD in User mode (NtRaiseHardError)
- Displaying a string in Native Mode (NtDisplayString)
See also
[edit]References
[edit]- ^ 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.
- ^ Raymond Chen (2009). "The Old New Thing : What does the "Zw" prefix mean?". Microsoft Corporation. Retrieved 2009-06-13.
External links
[edit]- A website that documents most of the Native API functions Archived 2017-10-25 at the Wayback Machine
- Inside Native Applications
- Inside the Native API
- Open source native applications development framework
- Compiling Free Pascal programs for the native API
- Windows NT Native Tools - A free native applications development util
- Native shell - Windows command prompt which can start before Winlogon and Win32 subsystem Archived 2015-08-11 at the Wayback Machine
Windows Native API
View on GrokipediaIntroduction
Definition and Purpose
The Windows Native API is a lightweight, undocumented application programming interface (API) consisting of approximately 250-300 functions that provide direct access to kernel services in Windows NT-based operating systems, bypassing higher-level abstractions.[1][4] This API forms the foundational layer for system operations, enabling low-level interactions between user-mode components and the kernel without reliance on environment-specific subsystems. It serves as the underlying interface for documented higher-level APIs like Win32, which build upon its primitives to offer more abstracted functionality.[1] The primary purpose of the Native API is to act as the interface for user-mode applications and subsystems to invoke kernel-mode operations, particularly during the early stages of the Windows boot process when components such as the Win32 subsystem are not yet available.[1] For instance, native applications like disk-checking utilities execute in this phase to perform essential initialization tasks directly against kernel services. This design ensures that core system functions can operate independently of loaded environment layers, supporting reliable startup and maintenance operations.[1] Key characteristics of the Native API include its exports from thentdll.dll dynamic-link library in user mode, which provide stubs that transition to kernel-mode implementations.[4] Error handling is managed through NTSTATUS codes, which are 32-bit values structured with 2 bits for severity (e.g., success, informational, warning, error in bits 30-31), 12 bits for facility codes (bits 16-27) identifying the subsystem, and 16 bits for specific error codes (bits 0-15); for example, STATUS_SUCCESS is defined as 0x00000000.[5] These codes allow precise reporting of outcomes from kernel interactions.
The API's internal and undocumented nature is intentional, designed to maintain operating system stability by preventing external dependencies that could lead to compatibility breaks across Windows versions.[6] Microsoft does not guarantee consistency for undocumented interfaces, allowing internal modifications without impacting officially supported applications.[6] This approach prioritizes the robustness of the core OS while reserving the Native API for Microsoft's own subsystems and select low-level tools.[1]
