The Assembly Programming Master Book

In the previous section, I described page and segment addressing. How do these two addressing modes coexist in Windows? As it turns out, everything is simple. Selectors based on addresses of zero are loaded into the segment registers, and the segment size is 4 GB. After this approach is implemented, programmers can forget about the existence of segments and selectors, although this mechanism is still working from the processor's point of view. As for the main mechanism of forming addresses, it is based on page conversions. This memory model became known as the flat memory model. Logical addressing in such a model is defined only by a 32-bit offset. Until now, all the programs presented in this book were written for the flat memory model. At the same time, you assumed that the entire memory area addressed by the 32-bit address was entirely at your disposal. Naturally, you were right; however, this address was the logical address, which also undergoes page conversion; it would be a difficult task to say, into which physical cell it will fall.

Fig. 19.4 shows the logical address space of a process. Pay attention to the shared memory areas ( numbers 2, 4, and 5). What does this mean? This means that these memory areas are mapped to the same physical space. Consider these areas in more detail:

Figure 19.4: Address space of a process

To store something in the virtual address space, this space must be mapped to the physical memory. The physical memory page need not be present in RAM. The operating system stores part of the pages in the page file (PAGEFILE.SYS) or in memory-mapped files (see Chapter 18). When accessing the address related to the page stored on the disk, the so-called page fault is generated, which loads the page from the disk. So-called free pages participate in this mechanism. The system looks for a free page (which is not occupied by any process) and loads there the data from the page stored on the disk. After that, the page is occupied. If there are no free pages, the system looks for a page that it could flush to disk, frees it, and loads the required data there. Usually, however, the operating system ensures that free pages are available.

Категории