forked from toshipiazza/drcfg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfg_impl.cpp
64 lines (56 loc) · 1.26 KB
/
cfg_impl.cpp
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
#include "cfg_impl.h"
#include "droption.h"
#include <unordered_map>
#include <unordered_set>
#include <mutex>
using nlohmann::json;
static droption_t<bool> racy
(DROPTION_SCOPE_CLIENT, "racy", false,
"unused option", "");
static std::unordered_map<uintptr_t, std::unordered_set<uintptr_t>> cbr;
static std::mutex mtx;
void
safe_insert(uintptr_t src, uintptr_t trg)
{
/*
if (!racy.get_value()) {
std::lock_guard<std::mutex> g(mtx);
cbr[src].insert(trg);
} else
*/
cbr[src].insert(trg);
}
static json
construct_json_impl()
{
json j;
std::transform(std::begin(cbr), std::end(cbr),
std::back_inserter(j["branches"]),
[] (auto i) -> json {
return {
{ "address", i.first },
{ "targets", i.second }
};
});
return j;
}
json
construct_json()
{
/*
if (!racy.get_value()) {
std::lock_guard<std::mutex> g(mtx);
return construct_json_impl();
} else
*/
return construct_json_impl();
}
bool
branch_present(uintptr_t src, uintptr_t trg)
{
if (!racy.get_value()) {
std::lock_guard<std::mutex> g(mtx);
return cbr[src].find(trg) != cbr[src].end();
} else
return cbr[src].find(trg) != cbr[src].end();
}