Microsoft’s Early Beginnings
Transcript
The year is 1975. A 21-year -old Paul Allen is walking through the Harvard Square when something catches his attention. It's an issue of the magazine Popular Electronics. The cover stars a computer called the Altair 8800, a personal computer released just the year before by Micro Instrumentation and Telemetry Systems Incorporated. Let's just call them MITS. Allen buys the magazine and heads back to his best friend's dorm. That friend was Bill Gates. The two had been considering
starting a software development company for years. The problem was that, at the time, consumer-grade computers did not exist. Manufacturers only produced systems for large companies and research labs at astronomical prices. So when Allen saw that MITS managed to release a computer system at a price the market could afford, he knew they had an opportunity at hand. The two decided that they should land a deal with the company for the development of an implementation of BASIC for the system. Gates called Ed Roberts, the CEO of MITS, to tell him they already had a working interpreter, which they actually did not. Roberts had already received other calls from people with the same claim, so he knew it was likely a bluff. He told them that the first group to show up in Albuquerque with a working demo on the Altair would get the contract. Two months later, Paul Allen went alone to the meeting with the completed software and the presentation was successful. They were the
first to show a demo. Another month later, Allen and Gates founded Microsoft. Over the years, they secured many more contracts, and in 1980, the revenue was of $8 million or about $31 million in today's currency. At the time, IBM was working on their next personal computer, the IBM PC. Yeah, really original name. Being on a tight deadline and failing to secure a contract with another developer, the company insisted that Microsoft should be the one to code the operating system for the computer. To save themselves a lot of time, Microsoft ended up buying an already existing system called 86-DOS, which they modified and licensed to IBM as MS-DOS. Microsoft ended up releasing Windows in 1985. It was a graphical interface running on top of DOS. This later evolved into Windows 95, Windows XP, and eventually all modern versions of Windows. Okay, but enough of the history lessons. That's not what you're here for. Before we dive headfirst into the subject, let me clarify a
couple of concepts that are crucial for you to understand the rest of this video. We'll briefly cover the following things. How the memory is isolated, how the CPU deals with permissions, and how it keeps track of code. Let's start with memory. I'll assume that you at least understand number systems, such as binary and hexadecimal, and that traditional computers deal with data as bits. When dealing with larger chunks of data, we have other measurements. The more common unit we use is the byte. It represents 8 bits. Another popular unit is the word. It represents 16 bits. Other variants of it are the double and quadruple word, these being 2 and 4 times the size of a word respectively. These measurements are often used in general, so it's worth learning what they mean. Once a program has been executed and is loaded into the memory, we call it a process. Processes are how the system isolates the resources of each running application. The most important example of such an
isolation is the address space. Fundamentally, physical memory is accessed byte by byte, but there are many issues with letting processes freely navigate physical memory. For one, it would be a nightmare to manage. For two, it would be unsafe. Any program could read and write anything. These two reasons are mostly why modern operating systems utilize virtual memory. Hey, editing aXXo here. So I realize I already made a full video on this subject, so if you don't understand certain things from this segment, then I recommend you go check out that video by clicking the card at the top right corner or the link in the description. I also made a post on my website for both the video you're watching right now and this video in question if you prefer a written format. Alright, let's get back to the video now. Virtual memory constricts each process into its own address space. Addresses act as indexes into tables describing the chunks of memory associated to each
application. We call these chunks pages. Usually, four levels of tables are used. Every table contains 512 entries, each pointing to a table in the lower level. The only exception to this are the tables in the final level, which instead store the index into the exact physical memory page. Nine bits of virtual addresses are used to index into the first level of tables. The next nine indexes into the second level, and so on, until the last 12 bits. These bits offset into the
specific page. Memory pages are usually of 4 kilobytes, aligned to the power of two in size. I say usually because it is possible for the system to index them as what we call huge and giant pages, which are of 2 megabytes and 1 gigabyte of size respectively. Although, this is beyond the scope of this video. Assuming they are always of 4096 bytes, the use of the 12 final bits in the virtual addresses to index into the pages makes sense because 2 to the power of 12 is 4096. The number of
entries into the memory tables is not random. Each entry is of 64 bits. This means that every table is of exactly 4096 bytes in size. That's the size of a memory page. The table entries don't use their full 64 bits to point to the next tables or pages. This allows for their remaining bits to be used to specify additional information such as whether or not the described pages should be executable or writable. While virtual memory isolates programs into their own address space, it's still possible
for their page tables to point to the same physical pages if they need to share memory. In fact, the system uses this to share dynamic libraries between programs and save on physical memory. To ensure that one program may not modify the code of a shared library, a bit in the page table entries is set to specify that the concerned pages use copy-on -write. When a program writes to such a page, the system will copy its contents into a fresh physical page and change the page table entry of the writing program to point to it. Now the writer process has its own copy of the code it modified and won't affect the execution of other programs which depends on the same library. We'll expand upon libraries later into this video. Windows even maps most of its system code into the upper portion of every application's virtual memory. Although the mapped pages have the kernel bit set, making them only accessible when the CPU is in privileged mode. The idea is that this system runs in
permission levels. The lower the level, the more permissions the running code will have. This is often illustrated as protection rings like here. In modern systems, the rings 1 and 2 are not used. The main property of protection rings is that they lock sensitive instructions and data behind the appropriate levels, including separating the user and their kernel address space. In the before mentioned system code that's mapped in every application, the pages will cause an exception to occur if they are accessed while the CPU is running into ring 3. This will essentially crash the program. Traditionally, we call ring 3 the user mode and ring 0 the kernel mode. So that user mode programs can still execute privileged operations like creating a process, Windows leverages system calls. The user mode code sets up the arguments describing the operation the system should run and invokes the syscall instruction. Basically, before invoking this instruction, the code will specify what operation it
wants the system to complete using a service number. It's essentially an index the system will use to get a specific function to handle the operation from a table called the system service dispatch table, or SSDT. The code that will handle this is part of the system code I mentioned that's mapped into the upper portion of every application's memory. We call it the system call handler. The syscall instruction will put the CPU in kernel mode and jump to this handler. Moving away from memory, let's briefly cover CPUs. They exist in many architectures. I won't get into all the differences between architectures, but note that throughout this video, anytime I refer to processor-related features, I only consider x86_64 architecture. At a high level, you can understand a CPU as one big component composed of many units. What you're seeing here is a very simplified overview of these units. I'm only showing the most relevant parts. The L3 is a large cache shared
between all of the cores. Each core has both an L2 and an L1 cache as well. The lower the cache number, the smaller in size it is, but also the faster it is to perform operations with it. Caches are used to store frequently used data and instructions. Note that CPUs usually have more than a single L2 and L1 cache, each for a specific purpose. Within cores is a control unit. It is responsible for fetching instructions from the code and directing them to the appropriate execution unit. In this case, there's only one execution unit, the ALU. It stands for arithmetic logical unit and handles arithmetic operations. Modern CPUs include other execution units, but I want to keep things simple. The MMU, or memory management unit, is the component responsible for handling memory that includes virtual memory. Lastly, registers are small storage units used to store data needed within the current execution context. In 64-bit computers, their size goes from 64 bits up to
512 bits. They are the fastest way a CPU can handle memory. What you see here are the most commonly used ones. These are the labels we refer to them as. RIP, or the instruction pointer, points to the current instruction that the concerned core is currently executing. In this case, there are two cores, so this hypothetical CPU could simultaneously execute two instructions at once. Other registers, such as RAX or RCX, do not have the special use. Machine code can even refer to lower portions of
the same set of registers when necessary. For instance, EAX would access only the first 32 bits of the RAX register. Although they don't have a mandatory use case, basic conventions exist for how they are used. For instance, RAX is often employed to store the return value of a function. The CPU uses RFLAGS as a bitfield to specify certain conditions and configuration. For instance, the sixth bit in it represents the zero flag. After testing a register, if this bit is set to 1, then the value it
stores is 0. Note that for some reason, only the EFLAGS part of the register is accessible in user mode. The remaining bits are reserved for future use. Segment registers were introduced in the past to handle segmentation. All you need to know is that, with the advent of virtual memory, this mechanism was rendered obsolete. Operating systems now use them to store useful pointers and system-related structures. This is something we'll expand upon later. There are many other registers I didn't mention. Most of them are used by the system for configuration purposes. For instance, the CR3 register, which is used to store the current program's first level of tables for translating virtual addresses. Every process contains threads. These are basically execution contexts, meaning they each represent a state of the CPU. They are associated to the specific register values present in the CPU when executing the instructions associated to them. Threads can be handled simultaneously on a
multicore processor. Finally, let's cover the thread stack. It's a fixed size, read and writable chunk of memory every thread has dedicated to it. They use it to handle local variables and arguments that functions are using. In a data structures class, you'd be told that a stack is the last in the first out data structure, meaning that the last element to be added would be the first one to be removed. Although on modern systems, the thread stack doesn't have to be accessed in this order, but typically each function reserves its own portion of it which only it uses. We call this portion a stack frame. Two registers are associated to the stack. RSP, the stack pointer, and RBP, the base pointer. The stack pointer simply points to the top of the stack, while the base pointer points to the base of the current stack frame. For example, after calling foo, this code would first push the address where the code must return to afterwards, then the base
pointer of the previous function's stack frame. Set the base pointer to the current stack pointer, use 4 bytes to make space for the integer, and finally add the value 5 to that location after zeroing it out. Zeroing out a stack value is important because there could be unexpected data left there from previous stack frames. Functions aren't all invoked in the same way though. There exist different calling conventions for different use cases. We won't bother with them in this video, but it's important that you know this detail. Once the code is done, it simply pops the old base pointer, thus setting it back to the old stack frame's value. Now the stack pointer would point to the return address, and thus when executing a return instruction, the code would pop this value back into the instruction pointer, thus going back after the call to foo. Because the stack is fixed in size, you wouldn't use it to store large data such as an image. Instead, you'd use something called
the heap, but we won't cover this for now. Great, now that we got all of this out of the way, we should be ready to begin. Imagine you have some program on your desktop, say notepad. The executable file stored on your disk representing that application uses a format called portable executable, or PE for short. We call it portable because it supports multiple architectures. If you were to analyze it with some specialized tool, close to its beginning, you'd find a header called the DOS stub.
It's a small 16-bit program that would be run when executing the file on an old DOS system. Usually, its code simply prints the following message. This program cannot be run in DOS mode. Most of your applications hold this old piece of history. Microsoft decided to put it there for backwards compatibility. These two words are something you'll hear a lot when working with Windows. Right before the DOS stub is the DOS header. It's the very first chunk of information in PE files. It contains values specifying how far we need to go to avoid the DOS stub and find the NT headers. These consist of two very important headers called the file header and the optional header. The file header holds information such as the architecture the executable is for and when the file was created. As for the optional header, do not be misled by its name. It's actually pretty important as it stores information such as where the code even begins. After all of these headers is the section
table. A section is a portion of an executable dedicated to storing some data. This can be executable code, information about the functions the program needs to import from libraries or even resources such as images. The purpose of the section table is to list all of these sections using entries which specifies their name, sizes and attributes. The attributes specify whether the data should be readable, writable and or executable. This is for security reasons. By default, you wouldn't want the code section to be writable for instance. When you execute an application, the system will make sure to set up the address space accordingly. Then say some executed code tried to write into a non-writable section like the code section, an access violation exception would occur and the program would crash. Some sections with specific names are almost always present in any executable. Some examples are the .text section, it's used to store the executable code. The .data section,
it's used to store the data that should be writable. And the .rdata section, it's used to store data that should only be readable. There's a handful more examples I could give but most of them will only be relevant to us later into this video. So what happens when you double click that notepad application? The program that handles this action is explorer.exe. That's what displays your desktop, taskbar and file explorer. If you were to terminate that program, your desktop, taskbar and any explorer window you will have open will vanish. I know, because that's exactly what I just did. Please, someone help. Jokes aside, when you execute notepad, under the hood, explorer.exe will call the function CreateProcess. It's a utility that's part of the Windows API. A massive set of utilities that programmers can use to interact with the operating system in a very simple way. This API is not all stored in one big ass library. It's instead fragmented into different files that
programs can either statically or dynamically link. Statically linking a library is basically just slapping all of its contents straight into your executable. Dynamic linking exists to avoid wasting space when multiple programs require the same library. To make this possible, files called dynamically linked libraries or for short DLLs are stored on the disk. When running executables, the system will make sure that these libraries are available in memory and map them into the processes which require them. The three most important DLLs associated to the Windows API are kernel32.dll, kernelbase.dll and
ntdll.dll. kernel32.dll is the legacy version of kernelbase.dll. Kernelbase is intended to be the modern replacement for kernel32, but it was kept for backwards compatibility. Nowadays, its functions mostly are just forwards to the functions in kernelbase, so we'll just ignore it. Before we dive into CreateProcess, I think we should get a small overview of Windows. Threads are scheduled by Windows, meaning the system makes decisions for when and for how long each should run.
The thing that handles the scheduling is intuitively called the scheduler. It is part of a bigger group of Windows components called the kernel. What you see here is an illustration of the Windows architecture. This red bar divides the user and the kernel mode parts of Windows. In user mode, you find user processes. These processes depend on subsystem DLLs. These are libraries like kernel32 and kernelbase. We call them subsystems because they each expose some subset of the Windows API. For
instance, the subsystem DLL user32 provides functions to manage graphical interfaces and user inputs. Down the line, almost all functions in subsystems end up invoking some functions in NTDLL. NTDLL holds three variants of functions, each having a specific prefix. The NT or native functions are essentially system call wrappers. The Zw functions implement the same system calls as their NT equivalent, but for kernel code to use in certain cases. The Rtl or runtime library functions are helper
functions that may or may not perform system calls. The reason programs rarely directly invoke NTDLL routines is for simplicity. The wrappers provided by the other DLLs often include additional features such as argument parsing, validation, or error handling. Service processes are processes which generally aren't executing within the context of some logged-in user. An example of a service process is Windows Defender, the antivirus. System processes are fixed processes with a specific system-related purpose. An example of this is the logon manager, which handles logins and logouts. As for the kernel mode side of Windows, the executive is its higher level. It contains components such as the memory manager and the object manager. We'll be discussing these further later on. The kernel includes its lower level features such as the scheduler. Device drivers include drivers such as your graphics card driver. And finally, the hardware abstraction layer, or for
short, HAL, is the lowest part of Windows. It's the actual hardware-specific implementation of the system and will vary significantly between architectures. It's also the one we worry the least about as a user. With this overview out of the way, we can go back to what CreateProcess does. Quick recap, we saw that explorer.exe was responsible for displaying your desktop and executing the programs you double-click. To do so, it invokes the CreateProcess function from kernelbase.dll. On its own, this function doesn't really do much. Instead, it's another function that it calls named CreateProcessInternalW that sets things into motion. This function gathers and formats all of the required arguments to
then invoke NtCreateUserProcess from NTDLL. That's the system call which will hand control to the system so it can create the process. The system call handler and the functions which process the specific operations are all stored in the file ntoskrnl.exe. This file stores most of the Windows executive and kernel. You can find in this file a function with the same name as the one invoked from NTDLL, which the dispatcher will invoke. As a matter of fact, you can even find the said dispatcher under the name KiSystemCall64. The shadow in this one's name is to differentiate it from the original version. It mitigates the Meltdown hardware vulnerability, but that's a subject for another video. KiSystemCall64's code first executes the swapgs assembly instruction. This swaps the current value of the GS segment register with the value of the IA32_KERNEL_GS_BASE MSR. This model-specific register points to a per-processor kernel structure known as the Processor Control Region, or KPCR. Per
-processor means that each core inside of your CPU has one associated to it. It contains important core -specific data, which we'll explore later, and contains another structure known as the Processor Control Block, or KPRCB. Next up, the code backs up the old stack pointer and makes it point to the kernel stack associated to the current processor. Indeed, to isolate kernel mode from user mode, even a special kernel stack is used. Afterwards, it also stores the original value of the base pointer and makes it point into the stack. Down the line, the handler falls into another function called KiSystemServiceStart. This is the part that will actually invoke the appropriate system call. It first accesses the service descriptor table, a structure containing information regarding the system service dispatch table, or SSDT. The SSDT contains offsets to the actual system call functions. It is simply indexed using the system call number specified from user mode. The specific
function is then invoked. Based on certain flags, some logging routines may also be executed with the system call. Once the operation completed, a count for the amount of system calls executed inside of the Processor Control Block is incremented. The registers that were saved on the stack are loaded back into their original value, the gs segment is swapped back, and finally the sysret instruction is executed. Most if not all of the code in ntoskrnl.exe is undocumented. This makes understanding it hard. Thanks to community efforts and some reverse engineering, I'm able to provide you with a decent overview of its contents. Any external help or information I may have used will be mentioned and credited at the end of this video and into the description. Back to the syscall NtCreateUserProcess. Simplifying its code is not as straightforward as it was with the system call handler. While every creation of a process ends up calling the same mandatory functions, it's
far more complex and contains many more conditions. All to say, don't take everything I say for granted. In my case, I hooked the system call handler so it would break only when a system call with the service number of NtCreateUserProcess is triggered and the process owning the thread is explorer.exe. Then I simply opened the file explorer and executed notepad.exe so I could trace what the system call does. It begins by opening the executable file by calling IoCreateFileEx. Then it creates a section object to map the file into memory by calling MmCreateSpecialImageSection.
Before I can explain what a section object is, I need to explain what even are Windows objects. They are a representation of resources currently in use that the system needs to keep track of such as processes, files, threads, etc. Different types of objects contain different information specific to the kind of resource they represent, but they all are prefixed by an object header. Essentially, there's an executive component known as the object manager. It is responsible for managing the lifetime of Windows objects. Object headers contain details such as the reference count and handle count. When such counts reach zero, the object manager will get rid of the concerned objects unless it's specified as permanent through the flags member. Windows objects are not directly accessible from user mode for security reasons. If a process wants to interact with another process, for example, it will need to open a handle to it. This handle has permissions and behaves as a
key for the using process to interact with the target process through the Windows API. All the handles a process has open are stored in a table linked to it. Every time some code is done using a handle, it must close it so the object manager can be aware when objects are not needed anymore using the CloseHandle function. When working from kernel mode, however, since objects are directly accessible, handles are not necessary. As an alternative to still be able to specify that an object is needed, the reference count is used instead. Kernel mode code will invoke the function ObReferenceObject to increase the object's reference count and ObDereferenceObject to decrease it. Windows objects have a security descriptor associated with them. This is a structure that describes security information such as the owner of said object. It also points to two access control lists or ACLs. These are structures followed by zero or more access control entries or ACEs for short.
Both of these ACLs have a different purpose. The system access control list or SACL describes what operations and by whom should generate audit logs. On the other hand, the discretionary access control list or DACL describes who has what permission over the object. The structure for ACEs looks something like this. I say something like because I couldn't find an actual basic definition anywhere. I had to base myself off of Windows debugger outputs. The type of an ACE can range between many different values. The more interesting types are access allowed which grants access to a user and access denied which denies access to a user. The mask is what specifies the permissions the ACE grants or denies. Each bit within the mask specifies a different permission. The first 16 bits are object specific permissions. The next 8 are for standard access rights like delete, modify access descriptors, change owner, etc. The 4 bits after that we can ignore and the final 4 are
for generic rights such as read write execute or all. The SID or security identifier is used to specify which user is affected by the ACE. This is a unique identifier the system uses to identify any entity which the system can authenticate. When displayed as a string, an SID looks like this. While this is the standard format in which SIDs are displayed as strings, the S indicating that this is indeed an SID and the hyphens separating the different parts of it are only present for readability. SIDs aren't stored as strings. In the string format, this part is the revision number. It's supposed to specify the version of SID being used. As of 2026, this version number can only be 1. Next is the authority. It is a number stored over 48 bits which specifies the component that issued the SID. An authority of 5 means that it was created by the Windows security subsystem. This number is mostly present for parsing purposes so that the code can identify the format of the
remainder of the SID. Afterwards comes the subauthorities. While all of these are considered to be subauthorities some subauthorities like the 21 in this case are followed by a specific kind of value. In this case, it is a domain ID and an RID. On a standalone computer, like yours probably is, the domain ID is just a unique identifier associated with your device. But on a network using Active Directory, this will be the ID of the domain that handles security information of the entity identified by the SID. If you have no clue what I'm talking about when I mention Active Directory, then don't worry, it is really not important for this video. The RID I mentioned stands for relative identifier. It usually comes last and identifies the specific entity that's part of the sub-authority. Back to the section objects, they exist in two types. File-backed and page-backed. File-backed section objects, as their name implies, represent a file to be mapped into
memory. I've made some C++ code to exemplify such a use. Almost all of the function calls here, such as CreateFileA, GetFileSize or CreateFileMappingA are Windows API functions. The first thing I would like to point out are these two conditions. Their purpose is to verify that the function is executed successfully by checking the value of the handle they returned. What I want to specifically highlight is that both check for a different value. On one hand, with CreateFile, we compare the handle with the value INVALID_HANDLE_VALUE, which is defined as negative one. On the other hand, with CreateFileMappingA the handle is just compared with nullptr, which is just 0. This is just one of the inconsistencies in the Windows API, and it's why you should always carefully read documentation for such functions. You can find that through simple Google searches and specifically on Microsoft's Learn website. The second thing I want to mention is the reason for
the suffix A at the end of some functions. Every time a Windows API routine takes in a string as an argument, Microsoft makes available at least two variants of said function, one with an A as a suffix and one with a W. The difference has to do with character encoding. The W variants use wide strings which are now the standard in Windows, but for simplicity and backwards compatibility reasons, they maintain the A variants for regular strings. These A variants usually convert the strings you input into wide strings before working with them or issuing a system call. They also make sure to convert the outputs as well if they contain strings. With this out of the way, the CreateFile can be used to open or create files and get a handle to them. In this case, the code is intended to open an existing file called example.txt with read and write permissions. After making sure the returned handle is valid, it gets the size of said file and creates the file-backed section object
using CreateFileMapping. Don't be deceived by its name or description. Under the hood, it calls NtCreateSection and returns its handle. After checking that the section object was successfully created, the code calls MapViewOfFile. This will tell the system to map the pages of memory representing the file into the process's address space. It can now directly interact with it. The contents of the example.txt was a simple hello world which gets printed into the console. Before ending everything, the code writes back goodbye world and calls FlushViewOfFile. This will write the modified pages back into the file. Finally, it unmaps the memory and closes the handles that were opened. On the other hand, page-backed section objects don't represent any particular file. They're just useful to share memory between different processes. I've got some code to show you, but in this example, it consists of two different applications. This code creates a section, only this
time it doesn't provide it a file handle, thus making it page-backed. So we can find said section from the other process, a name is specified. While the object header structure doesn't hold a variable for the name of objects, when one is specified, an additional header is placed before this header called the object name info header. The code then maps a view of the page and writes the string hello world to it. The second code opens a handle to the existing section by specifying its name, maps a view of the page and then prints its contents. Executing both programs results in the second one printing hello world. Back to NtCreateUserProcess, after opening the file and creating a section object, it calls PspAllocateProcess. This function is responsible for creating the executive process object or EPROCESS. This might be one of the most important kernel objects to know as it represents the processes. It points to data such as the handles table and the process ID. At its very top
is another structure called the KPROCESS. It exists to separate the data that is specifically used by the kernel from the rest that the executive cares about. PspAllocateProcess creates it by invoking ObCreateObjectEx. That's the object manager function to create objects. It will then fill its values and assign it an access token. Access tokens are like keys with permissions associated to them. When you log into your account, the LSASS process assigns one to your session and processes which you subsequently execute are given a copy of it. After assigning the token, among other things, PspAllocateProcess creates the process's address space by calling MmCreateProcessAddressSpace. This function first initializes the working set list of the process. A working set is a set of all the memory pages which the process currently has loaded into physical memory. Every process has a minimum amount of pages Windows guarantees will be in the working set and a maximum. While processes have a working
set, the kernel has one for its own memory called the system working set and there is also one for every session called the session working set. Sessions aren't a super important topic to understand so I'll be brief about it. Essentially, every time you log into your desktop or even remote connect to it, a session is created and associated to this logon. Actually, before you even actually log in and are in the lock screen, a session is already created. Within a session, there are window stations. Each of those holds desktops and the state of your clipboard. Each desktop contains windows, menus and hooks. The system has a session zero existent at all times for system processes. The primary purpose for sessions is to provide an isolation for the different interfaces. Next up, after creating the working set, it allocates its virtual address descriptors or VADs. VADs are trees in which each node describes a region of memory that was allocated. To allocate memory from an
application, you can invoke the function VirtualAlloc from the Windows API. You can optionally specify at which virtual address you'd like the allocation to reside, its size, its type and its protections. The allocation type is actually a set of bit flags to which the two main options you can set are MEM_COMMIT and MEM_RESERVE. When applying MEM_RESERVE alone, the memory region you're allocating will be reserved, but the memory won't actually be charged to the system. Trying to write to this region will lead to a memory access violation unless you apply MEM_COMMIT. You can apply both at once, which will reserve and charge the region. In both cases, a node describing the region will be inserted into some VAD, but no page table entries will be created yet. When the region is accessed, a page fault will occur and the system will walk through the appropriate VAD to look for the entry. If it finds one and the page is committed, then the entry is created. If an entry already
existed, then the VAD would not be walked, of course. Back to MmCreateProcessAddressSpace, after creating the VADs, the section created earlier in NtCreateUserProcess to read the executable is mapped into the address space. Back into PspAllocateProcess, a structure called the Process Environment Block or PEB is created and initialized in the same address space. Its purpose is similar to that of EPROCESS in terms of its contents, except it's for the user mode routines. It holds information such as the list of loaded DLLs, the base address of the image, and flags such as whether or not the program is being debugged. MmCreateProcessAddressSpace also maps NTDLL into the process. Now, the final step, at least in the kernel, is to create the initial thread to run the application. First, PspAllocateThread is called. Similar to the process equivalent, it will create the executive object for the new thread, the ETHREAD. It sets up the user stack for this new thread and
allocates its thread environment block, the TEB. Just like the PEB, it is used to store information about the thread for the user mode code to use. Every thread has its own TEB. Then, KeInitThread is called. This will set up the KTHREAD structure that is part of the ETHREAD object, create a kernel stack, and initialize the thread context. We'll explore further the thread context when discussing the scheduler, but for now, just know it is stored on the kernel stack. Back into NtCreateUserProcess, PspInsertProcess is invoked to create and return a handle into the new process. Followed by PspInsertThread, this performs further scheduling-related initialization and calls KeStartThread. KeStartThread also does some scheduling initialization, along with incrementing the thread count inside of the EPROCESS object, and inserting the new thread into its list. Back into PspInsertThread, a handle to the new thread is created for the process, and finally, KeReadyThread is invoked. This will simply
put the thread in a deferred ready state. This makes the thread ready to run on a specific core, but not yet running. We'll discuss thread states when we get to scheduling. At this point, NtCreateUserProcess will return to CreateProcessInternalW the user mode function that was responsible for initiating the system call. The function now sends a message to the ClientServerRuntimeSubsystem for it to register the process by invoking CsrClientCallServer. This message contains information such as the process and thread handles, the address of the PEB, and the section object handle. The ClientServerRuntimeSubsystem or CSRSS is a system process that's constantly running on your system. It keeps a list of all of the processes and their threads running within its session, with handles open to them. In order to send a message, the function uses something called an Advanced Local Procedure Call, or ALPC. It is an undocumented inter-process communication protocol, as I
won't dive into how it works. If you want, I made a fork of some guy's repository, which gives a very clear example of a client and server using the protocol to send and receive an ALPC message. The final step of CreateProcessInternalW is to resume the thread, which has been in a suspended state until this point. The thread begins its execution into the kernel function KxStartUserThread. This name is aliased as KiStartUserThread in Microsoft documentation, but the actual symbol is prefixed with Kx. To put it simply, functions prefixed with Kx are processor architecture specific. This means that their implementation will vary from one architecture to another. Usually, a trap frame will already have been constructed on the kernel stack after a thread transition from user mode to kernel mode using a system call, for example. In this case, the function manually builds one, as the thread has never gone through this process. Essentially, a trap frame is just a structure

Ask anything
We've read this whole study set, so questions about it get the best answers.