-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_hashmap.cpp
More file actions
56 lines (48 loc) · 1.3 KB
/
source_hashmap.cpp
File metadata and controls
56 lines (48 loc) · 1.3 KB
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
#include <string>
#include <map>
#include <cstdint>
#include <cstring>
#include "source_hashmap.h"
namespace hashmap {
std::string make_key(const char *binary_, uint64_t paddr_)
{
return (std::string(binary_) + "+" + std::to_string(paddr_));
}
typedef std::map<std::string, std::tuple<std::string, uint64_t>> hashmap;
}
extern "C" {
void *
source_hash_init()
{
hashmap::hashmap *map;
map = new(hashmap::hashmap);
return (void *) map;
}
void
source_hash_fini(void *p)
{
hashmap::hashmap *map = (hashmap::hashmap *) p;
delete(map);
}
bool
source_hash_find(void *p, const char *binary, uint64_t paddr, char *buf, size_t buflen, uint64_t *vaddr)
{
hashmap::hashmap *map = (hashmap::hashmap *) p;
std::string key(hashmap::make_key(binary, paddr));
if (map->find(key) != map->end()) {
std::tuple<std::string, uint64_t> v = (*map)[key];
std::string src = std::get<0>(v);
strncpy(buf, src.c_str(), buflen);
*vaddr = std::get<1>(v);
return true;
} else
return false;
}
void
source_hash_insert(void *p, const char *binary, uint64_t paddr, const char *value, uint64_t vaddr)
{
hashmap::hashmap *map = (hashmap::hashmap *) p;
std::string key(hashmap::make_key(binary, paddr));
(*map)[key] = make_tuple(std::string(value), vaddr);
}
};