| 1 |
#include "src/precommondefs.h" |
| 2 |
#include <assert.h> |
| 3 |
|
| 4 |
#ifndef HAS_SKIPLIST |
| 5 |
# error "skiplist.c needs to be included before" |
| 6 |
#endif |
| 7 |
|
| 8 |
#ifdef RPYTHON_VMPROF |
| 9 |
RPY_EXTERN void vmprof_ignore_signals(int ignored); |
| 10 |
static void pypy_codemap_invalid_set(int ignored) { |
| 11 |
vmprof_ignore_signals(ignored); |
| 12 |
} |
| 13 |
#else |
| 14 |
static void pypy_codemap_invalid_set(int ignored) { |
| 15 |
|
| 16 |
} |
| 17 |
#endif |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
typedef struct { |
| 25 |
unsigned int machine_code_size; |
| 26 |
unsigned int bytecode_info_size; |
| 27 |
long *bytecode_info; |
| 28 |
} codemap_data_t; |
| 29 |
|
| 30 |
static skipnode_t jit_codemap_head; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
RPY_EXTERN |
| 35 |
long pypy_jit_codemap_add(unsigned long addr, unsigned int machine_code_size, |
| 36 |
long *bytecode_info, unsigned int bytecode_info_size) |
| 37 |
{ |
| 38 |
skipnode_t *new = skiplist_malloc(sizeof(codemap_data_t)); |
| 39 |
codemap_data_t *data; |
| 40 |
if (new == NULL) |
| 41 |
return -1; |
| 42 |
|
| 43 |
new->key = addr; |
| 44 |
data = (codemap_data_t *)new->data; |
| 45 |
data->machine_code_size = machine_code_size; |
| 46 |
data->bytecode_info = bytecode_info; |
| 47 |
data->bytecode_info_size = bytecode_info_size; |
| 48 |
|
| 49 |
pypy_codemap_invalid_set(1); |
| 50 |
skiplist_insert(&jit_codemap_head, new); |
| 51 |
pypy_codemap_invalid_set(0); |
| 52 |
return 0; |
| 53 |
} |
| 54 |
|
| 55 |
RPY_EXTERN |
| 56 |
long *pypy_jit_codemap_del(unsigned long addr, unsigned int size) |
| 57 |
{ |
| 58 |
unsigned long search_key = addr + size - 1; |
| 59 |
long *result; |
| 60 |
skipnode_t *node; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
node = skiplist_search(&jit_codemap_head, search_key); |
| 66 |
if (node->key < addr) |
| 67 |
return NULL; |
| 68 |
|
| 69 |
pypy_codemap_invalid_set(1); |
| 70 |
skiplist_remove(&jit_codemap_head, node->key); |
| 71 |
pypy_codemap_invalid_set(0); |
| 72 |
|
| 73 |
|
| 74 |
assert(skiplist_search(&jit_codemap_head, search_key)->key < addr); |
| 75 |
|
| 76 |
result = ((codemap_data_t *)node->data)->bytecode_info; |
| 77 |
free(node); |
| 78 |
return result; |
| 79 |
} |
| 80 |
|
| 81 |
RPY_EXTERN |
| 82 |
unsigned long pypy_jit_codemap_firstkey(void) |
| 83 |
{ |
| 84 |
return skiplist_firstkey(&jit_codemap_head); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
RPY_EXTERN |
| 90 |
void *pypy_find_codemap_at_addr(long addr, long* start_addr) |
| 91 |
{ |
| 92 |
skipnode_t *codemap = skiplist_search(&jit_codemap_head, addr); |
| 93 |
codemap_data_t *data; |
| 94 |
unsigned long rel_addr; |
| 95 |
|
| 96 |
if (codemap == &jit_codemap_head) { |
| 97 |
if (start_addr) |
| 98 |
*start_addr = 0; |
| 99 |
return NULL; |
| 100 |
} |
| 101 |
|
| 102 |
rel_addr = (unsigned long)addr - codemap->key; |
| 103 |
data = (codemap_data_t *)codemap->data; |
| 104 |
if (rel_addr >= data->machine_code_size) { |
| 105 |
if (start_addr) |
| 106 |
*start_addr = 0; |
| 107 |
return NULL; |
| 108 |
} |
| 109 |
|
| 110 |
if (start_addr) |
| 111 |
*start_addr = (long)codemap->key; |
| 112 |
return (void *)codemap; |
| 113 |
} |
| 114 |
|
| 115 |
RPY_EXTERN |
| 116 |
long pypy_yield_codemap_at_addr(void *codemap_raw, long addr, |
| 117 |
long *current_pos_addr) |
| 118 |
{ |
| 119 |
|
| 120 |
|
| 121 |
skipnode_t *codemap = (skipnode_t *)codemap_raw; |
| 122 |
long current_pos = *current_pos_addr; |
| 123 |
long rel_addr = addr - codemap->key; |
| 124 |
long next_start, next_stop; |
| 125 |
codemap_data_t *data = (codemap_data_t *)codemap->data; |
| 126 |
|
| 127 |
while (1) { |
| 128 |
if (current_pos >= data->bytecode_info_size) |
| 129 |
return -1; |
| 130 |
next_start = data->bytecode_info[current_pos + 1]; |
| 131 |
if (next_start > rel_addr) |
| 132 |
return -1; |
| 133 |
next_stop = data->bytecode_info[current_pos + 2]; |
| 134 |
if (next_stop > rel_addr) { |
| 135 |
*current_pos_addr = current_pos + 4; |
| 136 |
return data->bytecode_info[current_pos]; |
| 137 |
} |
| 138 |
|
| 139 |
current_pos = data->bytecode_info[current_pos + 3]; |
| 140 |
} |
| 141 |
} |