forked from ish-app/ish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jit.h
68 lines (53 loc) · 1.62 KB
/
jit.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
66
67
68
#ifndef JIT_H
#define JIT_H
#include "misc.h"
#include "emu/memory.h"
#include "util/list.h"
#include "util/sync.h"
#if ENGINE_JIT
#define JIT_INITIAL_HASH_SIZE (1 << 10)
#define JIT_CACHE_SIZE (1 << 10)
struct jit {
// there is one jit per address space
struct mem *mem;
size_t mem_used;
size_t num_blocks;
struct list *hash;
size_t hash_size;
// list of jit_blocks that should be freed soon (at the next RCU grace
// period, if we had such a thing)
struct list jetsam;
lock_t lock;
};
// this is roughly the average number of instructions in a basic block according to anonymous sources
// times 4, roughly the average number of gadgets/parameters in an instruction, according to anonymous sources
#define JIT_BLOCK_INITIAL_CAPACITY 16
struct jit_block {
addr_t addr;
addr_t end_addr;
size_t used;
// pointers to the ip values in the last gadget
unsigned long *jump_ip[2];
// original values of *jump_ip[]
unsigned long old_jump_ip[2];
// blocks that jump to this block
struct list jumps_from[2];
// hashtable bucket links
struct list chain;
// list of blocks in a page
struct list page[2];
// links for jumps_from
struct list jumps_from_links[2];
// links for free list
struct list jetsam;
bool is_jetsam;
unsigned long code[];
};
// Create a new jit
struct jit *jit_new(struct mem *mem);
void jit_free(struct jit *jit);
// Invalidate all jit blocks in the given page. Locks the jit. Should only be
// called by memory.c in conjunction with mem_changed.
void jit_invalidate_page(struct jit *jit, page_t page);
#endif
#endif