]>
git.proxmox.com Git - qemu.git/blob - include/qemu/range.h
7 * Operations on 64 bit address ranges.
9 * - ranges must not wrap around 0, but can include the last byte ~0x0LL.
10 * - this can not represent a full 0 to ~0x0LL range.
13 /* A structure representing a range of addresses. */
15 uint64_t begin
; /* First byte of the range, or 0 if empty. */
16 uint64_t end
; /* 1 + the last byte. 0 if range empty or ends at ~0x0LL. */
18 typedef struct Range Range
;
20 /* Get last byte of a range from offset + length.
21 * Undefined for ranges that wrap around 0. */
22 static inline uint64_t range_get_last(uint64_t offset
, uint64_t len
)
24 return offset
+ len
- 1;
27 /* Check whether a given range covers a given byte. */
28 static inline int range_covers_byte(uint64_t offset
, uint64_t len
,
31 return offset
<= byte
&& byte
<= range_get_last(offset
, len
);
34 /* Check whether 2 given ranges overlap.
35 * Undefined if ranges that wrap around 0. */
36 static inline int ranges_overlap(uint64_t first1
, uint64_t len1
,
37 uint64_t first2
, uint64_t len2
)
39 uint64_t last1
= range_get_last(first1
, len1
);
40 uint64_t last2
= range_get_last(first2
, len2
);
42 return !(last2
< first1
|| last1
< first2
);