13. Ranges of addresses¶
13.1. Introduction¶
.intro: This is the design of the Range module, which implements objects representing address ranges.
.readership: This document is intended for any MPS developer.
13.2. Requirements¶
.req.range: A range object must be able to represent an arbitrary
range of addresses that neither starts at NULL nor includes the
top grain of the address space.
.req.empty: A range object must be able to represent the empty range.
.req.stack-alloc: It must be possible to allocate range objects on the stack: that is, they do not require any heap resource.
13.3. Interface¶
-
RangeStruct *
Range¶
Range is the type of a range. It is an alias for RangeStruct*. RangeStruct is defined in the header so that it can be
inlined in client structures or allocated on the stack. Clients must
not depend on its implementation details.
Initialize a range object to represent the half-open address range
between base (inclusive) and limit (exclusive). It must be the
case that base <= limit. If base == limit then the range is
empty.
Initialize dest to be a copy of src.
Initialize a range object to represent the half-open address range
between base (inclusive) and base + size (exclusive). If
size == 0 then the range is empty.
Finish a range object. Because a range object uses no heap resources (.req.stack-alloc) it is not necessary to call this. However, clients may wish to do so in order to ensure that the range object is invalid.
Return the base of the range. (This is implemented as a macro, but there is a function too.)
Return the limit of the range. (This is implemented as a macro, but there is a function too.)
Return the size of the range. (This is implemented as a macro, but there is a function too. The macro evaluates its argument twice.)
Return TRUE if addr belongs to the range, or FALSE if it
does not. (This is implemented as a macro, but there is a function
too. The macro evaluates its arguments twice.)
Return TRUE if the range is empty (contains no addresses),
FALSE otherwise. (This is implemented as a macro, but there is a
function too. The macro evaluates its argument twice.)
Return TRUE if the base and limit of the range are both aligned to
the given alignment, or FALSE if either is not.
Return TRUE if the two ranges overlap (have at least one address
in common), or FALSE if they do not. Note that ranges [A, B) and
[B, C) do not overlap.
Return TRUE if all addresses in inner are also in outer,
or FALSE otherwise.