Address Space of a Process

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:

  • Area 1This memory region is blocked. This area is intended for detecting zero pointers. This is especially true for the C language, in which the malloc function can return a zero pointer. An attempt to write anything by this address will result in an error message from the operating system.

  • Area 2This memory area was used in the operating systems of the Windows 9 x family. In Windows NT and later versions, this area is part of area 3. Address space for MS-DOS and 16-bit applications is allocated in this region.

  • Area 3This area of the address space, located between the 4 MB and the 2 GB boundaries (in Windows 2000 and later, this area starts at 1 MB), is the process address space. The process takes this area for code and data, including process-specific dynamic link libraries (DLLs). This area is not shared. However, there are some exceptions, which you have encountered already. It is possible to define a shared section, which means that some pages from this logical space will be mapped into the same physical area for different processes.

  • Area 4This is the reserved memory region used for internal implementation of the operating system.

  • Area 5This area contains memory-mapped files, system DLLs, and dynamic memory for 16-bit applications. For Windows 2000 and later, this area is included in the sixth area.

  • Area 6The last part of the address space is allocated for system components . Surprisingly, but in Windows 9 x , this area is not protected against access by user programs. In operating systems of the Windows NT family, this area is not accessible for executable processes.

image from book
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.



The Assembly Programming Master Book
The Assembly Programming Master Book
ISBN: 8170088178
EAN: 2147483647
Year: 2004
Pages: 140
Authors: Vlad Pirogov

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net