blob: 080fa95b4035b81f2ab3258572735b2cf0be2374 [file] [log] [blame]
sewardjc5fc8662014-03-20 23:00:09 +00001
2/*--------------------------------------------------------------------*/
3/*--- A mapping where the keys exactly cover the address space. ---*/
4/*--- pub_tool_rangemap.h ---*/
5/*--------------------------------------------------------------------*/
6
7/*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
10
Elliott Hughesed398002017-06-21 14:41:24 -070011 Copyright (C) 2014-2017 Mozilla Foundation
sewardjc5fc8662014-03-20 23:00:09 +000012
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 02111-1307, USA.
27
28 The GNU General Public License is contained in the file COPYING.
29*/
30
31/* Contributed by Julian Seward <jseward@acm.org> */
32
33#ifndef __PUB_TOOL_RANGEMAP_H
34#define __PUB_TOOL_RANGEMAP_H
35
36//--------------------------------------------------------------------
37// PURPOSE: a mapping from the host machine word (UWord) ranges to
38// arbitrary other UWord values. The set of ranges exactly covers all
39// possible UWord values.
40// --------------------------------------------------------------------
41
42/* It's an abstract type. */
43typedef struct _RangeMap RangeMap;
44
45/* Create a new RangeMap, using given allocation and free functions.
florianb9d8fbb2014-09-14 22:19:52 +000046 alloc_fn must not return NULL (that is, if it returns it must have
sewardjc5fc8662014-03-20 23:00:09 +000047 succeeded.) The new array will contain a single range covering the
florianb9d8fbb2014-09-14 22:19:52 +000048 entire key space, which will be bound to the value |initialVal|.
49 This function never returns NULL. */
Elliott Hughesed398002017-06-21 14:41:24 -070050RangeMap* VG_(newRangeMap) ( Alloc_Fn_t alloc_fn,
sewardjc5fc8662014-03-20 23:00:09 +000051 const HChar* cc,
Elliott Hughesed398002017-06-21 14:41:24 -070052 Free_Fn_t free_fn,
sewardjc5fc8662014-03-20 23:00:09 +000053 UWord initialVal );
54
55/* Free all memory associated with a RangeMap. */
56void VG_(deleteRangeMap) ( RangeMap* );
57
58/* Bind the range [key_min, key_max] to val, overwriting any other
59 bindings existing in the range. Asserts if key_min > key_max. If
60 as a result of this addition, there come to be multiple adjacent
61 ranges with the same value, these ranges are merged together. Note
62 that this is slow: O(N) in the number of existing ranges. */
63void VG_(bindRangeMap) ( RangeMap* rm,
64 UWord key_min, UWord key_max, UWord val );
65
66/* Looks up |key| in the array and returns the associated value and
67 the key bounds. Can never fail since the RangeMap covers the
68 entire key space. This is fast: O(log N) in the number of
69 ranges. */
70void VG_(lookupRangeMap) ( /*OUT*/UWord* key_min, /*OUT*/UWord* key_max,
florian518850b2014-10-22 22:25:30 +000071 /*OUT*/UWord* val, const RangeMap* rm, UWord key );
sewardjc5fc8662014-03-20 23:00:09 +000072
73/* How many elements are there in the map? */
florianca631452015-08-05 13:23:11 +000074UInt VG_(sizeRangeMap) ( const RangeMap* rm );
sewardjc5fc8662014-03-20 23:00:09 +000075
76/* Get the i'th component */
77void VG_(indexRangeMap) ( /*OUT*/UWord* key_min, /*OUT*/UWord* key_max,
florian518850b2014-10-22 22:25:30 +000078 /*OUT*/UWord* val, const RangeMap* rm, Word ix );
sewardjc5fc8662014-03-20 23:00:09 +000079
80#endif // __PUB_TOOL_RANGEMAP_H
81
82/*--------------------------------------------------------------------*/
83/*--- end pub_tool_rangemap.h ---*/
84/*--------------------------------------------------------------------*/