range.c (a0efbf16604770b9d805bcf210ec29942321134f) range.c (6dd726a2bf1b800289d90a84d5fcb5ce7b78a8e1)
1/*
2 * QEMU 64-bit address ranges
3 *
4 * Copyright (c) 2015-2016 Red Hat, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either

--- 8 unchanged lines hidden (view full) ---

17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#include "qemu/osdep.h"
22#include "qemu/range.h"
23
24/*
1/*
2 * QEMU 64-bit address ranges
3 *
4 * Copyright (c) 2015-2016 Red Hat, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either

--- 8 unchanged lines hidden (view full) ---

17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#include "qemu/osdep.h"
22#include "qemu/range.h"
23
24/*
25 * Operations on 64 bit address ranges.
26 * Notes:
27 * - ranges must not wrap around 0, but can include the last byte ~0x0LL.
28 * - this can not represent a full 0 to ~0x0LL range.
25 * Return -1 if @a < @b, 1 @a > @b, and 0 if they touch or overlap.
26 * Both @a and @b must not be empty.
29 */
27 */
30
31/* Return -1 if @a < @b, 1 if greater, and 0 if they touch or overlap. */
32static inline int range_compare(Range *a, Range *b)
33{
28static inline int range_compare(Range *a, Range *b)
29{
34 /* Zero a->end is 2**64, and therefore not less than any b->begin */
35 if (a->end && a->end < b->begin) {
30 assert(!range_is_empty(a) && !range_is_empty(b));
31
32 /* Careful, avoid wraparound */
33 if (b->lob && b->lob - 1 > a->upb) {
36 return -1;
37 }
34 return -1;
35 }
38 if (b->end && a->begin > b->end) {
36 if (a->lob && a->lob - 1 > b->upb) {
39 return 1;
40 }
41 return 0;
42}
43
44/* Insert @data into @list of ranges; caller no longer owns @data */
45GList *range_list_insert(GList *list, Range *data)
46{

--- 29 unchanged lines hidden ---
37 return 1;
38 }
39 return 0;
40}
41
42/* Insert @data into @list of ranges; caller no longer owns @data */
43GList *range_list_insert(GList *list, Range *data)
44{

--- 29 unchanged lines hidden ---