Core OS API Reference

Introduction to Core OS APIs

The Core OS APIs provide fundamental services and functionalities for interacting with the Windows operating system at its core. These APIs are essential for developing low-level system components, drivers, and applications that require deep integration with the operating system's kernel, memory management, process and thread management, and more.

This section covers key areas such as:

Key API Categories

Process and Thread Management

These APIs allow you to create, control, and manage processes and threads. Understanding these is crucial for concurrent programming and optimizing application performance.

API Function Description Module
CreateProcess Creates a new process and its primary thread. Kernel32.dll
OpenProcess Opens an existing process object. Kernel32.dll
CreateThread Creates a new thread. Kernel32.dll
TerminateProcess Terminates an existing process. Kernel32.dll
GetCurrentProcessId Retrieves the process identifier of the calling process. Kernel32.dll

Memory Management

APIs for managing virtual and physical memory, including allocation, protection, and deallocation.

API Function Description Module
VirtualAlloc Reserves, commits, or changes the state of a region of pages in the virtual address space of the calling process. Kernel32.dll
VirtualFree Releases, frees, or uncommits a range of pages in the virtual address space of the calling process. Kernel32.dll
HeapAlloc Allocates a block of memory from a process's heap. Kernel32.dll

Inter-Process Communication (IPC)

Mechanisms for enabling different processes to communicate and synchronize their actions.

API Function Description Module
CreatePipe Creates an anonymous pipe, a unidirectional data flow. Kernel32.dll
CreateFileMapping Creates or opens a named or unnamed file mapping object. Kernel32.dll
MapViewOfFile Maps a view of a file mapping into the address space of the calling process. Kernel32.dll

Code Example: Creating a New Process

Here's a basic C++ example demonstrating how to create a new process using the CreateProcess API:


#include <windows.h>
#include <iostream>

int main() {
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    ZeroMemory(&pi, sizeof(pi));

    // Path to the executable you want to run
    const char* programPath = "C:\\Windows\\System32\\notepad.exe";

    // Start the child process.
    if (!CreateProcess(
        programPath,   // No module name (use command line)
        NULL,          // Command line
        NULL,          // Process handle not inheritable
        NULL,          // Thread handle not inheritable
        FALSE,         // Set handle inheritance to FALSE
        0,             // No creation flags
        NULL,          // Use parent's environment block
        NULL,          // Use parent's starting directory
        &si,           // Pointer to STARTUPINFO structure
        &pi)           // Pointer to PROCESS_INFORMATION structure
    ) {
        std::cerr << "CreateProcess failed (" << GetLastError() << ")." << std::endl;
        return 1;
    }

    // Wait until child process exits.
    WaitForSingleObject(pi.hProcess, INFINITE);

    // Close process and thread handles.
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);

    std::cout << "Notepad process created and waited for." << std::endl;

    return 0;
}