[Cpp]
# Ifdef ALLOC_PRAGMA
# Pragma alloc_text (INIT, DriverEntry)
# Pragma alloc_text (PAGE, PreCreate)
# Endif
The kernel loader loads all the code parts and global data to the non-Paging memory. In addition, the loader loads the executable file of the entire driver at a time, including the related DLL. After the driver is loaded, the kernel loader closes the driver file and you can even delete the currently running driver file.
However, you can tell the loader which part of the driver you want to drive is pagination. The so-called pagination means that the Page may be swapped out of memory (Page out)
The paging memory is virtual memory, which may not always be physically available.
The main way to implement virtual memory in the operating system is through the paging mechanism. In Win32, physical address space, two-dimensional virtual address space, and actual memory address are three different concepts. The operating system uses segments to select Sub-nodes to create a two-dimensional virtual address space. Each process has a 4 GB address space, then, the memory management device of the operating system maps each process to different parts of the one-dimensional physical address space, but because most of our machines do not have 4 GB memory, the actual memory space is a subset of the physical address space.
The page manager divides the address space into 4 K pages (different from the IntelX86 system). When a process accesses a page, the operating system first searches for the page in the Cache, if the page is not in memory, a PageFault is generated, and the process is blocked until the page to be accessed is transferred from the external memory to the memory.
We know that high-priority interruptions can still occur when handling low-priority interruptions. Since the page missing process is also an interruption process, there is a problem, that is, the priority of page missing interruptions and other interruptions. If there is another page-missing interruption that is higher than the page-missing interruption priority, the kernel will crash. Therefore, at the DISPATCH_LEVEL or above, the paging memory is definitely not used. If the paging memory is used, page disconnection may occur. As mentioned above, this will cause the kernel to crash.
Simply put, if you write a high driver level or a hardware driver, the Code must always be in the memory, so no special declaration is required.
If you think that some functions can be transferred from memory to hardware temporary files, you can declare that they are paging without affecting the program running.
Codes that do not need to be retained after initialization can be declared as follows
[Cpp]
# Pragma alloc_text (INIT, DriverEntry)