Page 369 - DCAP103_Principle of operating system
P. 369
Principles of Operating Systems
Notes file has not yet been updated. Care is also taken that if another process opens the file for normal
reading, it sees the current pages in RAM, not stale pages from the disk.
Figure 12.10: Mapped Regions with their Shadow Pages on Disk. The lib.dll File
is Mapped into Two Address Spaces at the Same Time.
It is worth noting that there is a problem if two programs share a DLL file and one of them
changes the file’s static data. If no special action is taken, the other one will see the changed
data, which is probably not what is desired. The problem is solved by mapping all pages in as
read only by secretly noting that some are really writable. When a write happens to a page that
is mapped read only but is really writable, a private copy of the page is made and mapped in.
Now it can be written safely without affecting other users or the original copy on disk. This
technique is called copy-on-write.
Also it is worth noting that if program text is mapped into two address spaces at different
addresses, a certain problem arises with addressing. What happens if the first instruction is
JMP 300? If process one maps the program in at address 65,536, the code can easily be patched
to read JMP 65836. But what happens if a second process now maps it in at 131,072? The JMP
65836 will go to address 65,836 instead of 131,372 and the program will fail. The solution is to
use only relative offsets, not absolute virtual addresses in code that is to be shared. Fortunately,
most machines have instructions using relative offsets as well as instructions using absolute
addresses. Compilers can use the relative offset instructions, but they have to know in advance
whether to use them or the absolute ones. The relative ones are not used all the time because
the resulting code is usually less efficient. Usually, a compiler flag tells them which to use. The
technique of making it possible to place a piece of code at any virtual address without relocation
is called position independent code.
Years ago, when 16 bit (or 20 bit) virtual address spaces were standard, but machines had
megabytes of physical memory, all kinds of tricks were thought of to allow programs to use
more physical memory than to fit in the address space. Often these tricks went under the name
of bank switching, in which a program could substitute some block of memory above the 16-bit
or 20-bit limit for a block of its own memory. When 32-bit machines were introduced, people
362 LOVELY PROFESSIONAL UNIVERSITY