OS8 Address Spaces
Volume Number: 12
Issue Number: 11
Column Tag: Book Excerpt
Mac OS 8 Address Spaces and Memory Protection
By Tony Francis
[As you may have heard by now, Apple has made the announcement that Mac OS 8
(aka Copland) will be delivered in parts instead of one large release. The first of these
releases is slated for January, 1997. Some Mac OS 8 technologies previously
announced may not ever be part of any release - but many are and will be implemented
over the next 18 months. This month, we’re bringing you an excerpt from Mac OS 8
Revealed by Addison-Wesley. This book contains important information/background
about technologies that are definitely to come in one release or another. We at MacTech
felt is was important for you to see what is coming so that you could intelligently plan
for, discuss, and debate these new parts of the operating system. If you’d like to know
more about other technologies, Mac OS 8 Revealed is a good source of information -
just be aware of which technologies are coming in which timeframes (and if at all)
when you do your planning. - Ed. nst]
We are indebted to Addison Wesley Longman for permission to reproduce an edited
version of Chapter 3 from Mac OS 8 Revealed by Tony Francis. Copyright © 1996 by
Tony Francis. Addison-Wesley Publishing Company, One Jacob Way, Reading, MA
01867. 617/944-3700. Suggested retail price $34.95. Available at your local
bookstore, by calling 1-800-822-6339, or through Developer Depot™.
When a program is launched-for instance, when a user double-clicks its
icon-the operating system prepares the program code for execution, creates memory
areas for the code and its temporary data, and assigns locations for the code and data
within these memory areas. In this way, the program becomes instantiated as a process
on the computer. The memory areas created for a process lie within a 4-gigabyte (GB)
range of logical addresses. This range of addressable memory constitutes the address
space for that process.
Mac OS 8 maintains multiple simultaneous address spaces. A program can’t
reference any memory locations outside of its address space. Therefore, if code in a
given address space malfunctions, it can’t corrupt the data in a different address space.
Mac OS 8 provides other forms of memory protection, too. Mac OS 8 protects all code,
for example, by mapping it into read-only memory areas where it can’t be corrupted
by any errant code elsewhere in the system. Crucial system data is protected because
it’s stored in memory areas where operating system services-such as the
microkernel, device drivers, and the file system-have read/write permission to the
data, but application-level software has read-only permission. This greatly decreases
the ability of applications to cause a system-wide crash. Yet another kind of memory
protection, called guard pages, enhances system stability by limiting the amount of
damage that software can do if it attempts to read or write outside the memory area it’s
entitled to access.
Key Terms and Concepts
• A process is an instance of a program running at execution time. A process is
characterized by a set of one or more tasks and the operating system resources
necessary to support those tasks.
• A task is the basic unit of program execution in Mac OS 8. Every process has at
least one task. As you’ll read in the next chapter, each task is assigned a priority
and, when eligible for execution, is preemptively scheduled by the microkernel.
• A memory area is a range of logical addresses.
• Virtual memory is addressable memory beyond the limits of available physical
memory. Mac OS 8 extends physical memory by storing on a secondary storage
device, such as a hard disk, code and data not immediately required by the CPU.
• A logical address is a memory address used by code when it’s running. By
comparison, a physical address is a memory address represented by bits on a
physical address bus. Physical addresses are assigned to memory locations in
RAM chips and to various hardware devices. When executing code, the CPU
translates the logical addresses of an address space into physical addresses.
• An access permission stipulates whether other programs can read from or write
to a memory area.
• A guard page is a 4-kilobyte (K) range of logical addresses that excludes all
program access. Guard pages may appear at the beginnings and ends of memory
areas to help prevent code from inadvertently accessing the wrong memory areas.
If a programming error causes code to reference a guard page, the CPU generates
an exception before the erring code can adversely affect a contiguous memory
area.
Major Points of Interest
All code and data for a process exist within an address space. Because Mac OS 8
uses a 32-bit address space-which is the maximum size supported by the PowerPC
CPU-an address space can contain up to 232 addresses. In every address space, in
other words, addressable locations number up to 4GB.
A 4-GB address space encompasses far more memory addresses than are available
in physical memory on most computers. So Mac OS 8 uses a virtual memory system to
extend the range of addressable memory beyond what is available in physical memory.
The virtual memory system stores unused portions of code and data on a secondary
storage device, such as hard disk. The virtual memory system then transfers into
physical memory only those portions immediately needed by the CPU. (As you’ll see in
Chapter 6, the virtual memory system also makes efficient use of secondary storage by
using only enough disk space to support currently open programs.)
When launching a program, the operating system creates memory areas that
constitute only a small portion of an address space. The operating system creates a
memory area for the program code, and it creates an initial memory area for the
program to store the data-such as its global variables and dynamic data
structures-that it needs while it’s running. Other portions of an address space are
unavailable to the program because they’re used to store code (including code for the
microkernel and code for the libraries used by the program), or they’re reserved for
other uses by the operating system. From the 4GB of logical addresses in a single
address space, at least 1GB is available to programs for data storage.
As you’ll see in Chapter 7, the operating system dynamically creates and releases
memory areas as needed so that programs can store temporary data. The Dynamic
Storage-Allocation Services provided by Mac OS 8 also allow developers to create their
own memory areas suitable for special program needs.
For overall system stability, Mac OS 8 employs multiple address spaces. The data
referenced by a program in one address space is inaccessible to programs in other
address spaces. Therefore, programming errors affecting one address space are
isolated from all other address spaces. For example, suppose that a game program has a
programming error that corrupts portions of its address space, causing the game to