Managing Memory with the PAL
Memory is a fundamental computational resource, and not surprisingly, the PAL provides memory allocation as a service to the SSCLI. The four Win32 routines,
VirtualQuery, form the basis for this service and are what lie beneath the intricate memory management
mechanisms that we examined in Chapter 7. In the Unix PAL, the logical implementation choice would seem to be to use the
mmap functions as a basis for these APIs. This is, in fact, ultimately the choice, although a few problems had to be solved along the way to get the code to work, mostly having to do with the lower-level nature of
mmap has the ability to allocate memory in a way that maps nicely to
VirtualAlloc, there is no standard equivalent to
VirtualQuery. What is ore problematical is that some implementations of
mmap are unable to provide memory at a specific virtual address and, instead, assign the address unilaterally. (The hint parameter, which is provided in the API for this purpose, is honored by most implementations but not all.)
VirtualAlloc, of course, has a nearly opposite usage: allocation either happens at the location specified or the request fails.
The SSCLI depends on the
VirtualAlloc approach, since several of its algorithms use structures that have known starting addresses to simplify address calculations. Because of this, and because of the lack of
VirtualQuery functionality, the PAL implements extra infrastructure ...