-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAddressRangeFilter.h
65 lines (53 loc) · 1.39 KB
/
AddressRangeFilter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2019 Intel Corporation
*
* Authors: Huang Ying <ying.huang@intel.com>
* Jin Yao <yao.jin@intel.com>
*/
#ifndef __ADDRESS_RANGE_FILTER__HH__
#define __ADDRESS_RANGE_FILTER__HH__
#include <iterator>
#include <type_traits>
#include <map>
#include <string>
class AddressRangeFilter
{
struct Range {
unsigned long size;
};
class Key
{
public:
unsigned long pid;
unsigned long start;
public:
Key(unsigned long p, unsigned long s) :
pid(p), start(s) {}
Key(void) :
pid(0), start(0) {}
bool operator<(const Key& src) const
{
if (pid == src.pid)
return start < src.start;
else
return pid < src.pid;
}
};
typedef std::map<Key, Range>::iterator Iterator;
public:
bool search_address(int pid, unsigned long addr);
void insert_range(int pid, unsigned long start, unsigned long size);
void clear(void);
void show(void);
private:
Iterator search_range(int pid, unsigned long addr,
Iterator *lower_p, Iterator *upper_p);
void insert_new_range(int pid, unsigned long start, unsigned long size);
void remove_ranges(Iterator rm_start, Iterator rm_end,
int pid, unsigned long new_start, unsigned long new_end);
private:
std::map<Key, Range> rmap;
};
#endif /* __ADDRESS_RANGE_FILTER__HH__ */