summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAchim Kriso <achim.kriso@student.kit.edu>2020-03-05 14:31:36 +0100
committerAndreas Fried <andreas.fried@kit.edu>2020-03-26 14:08:14 +0100
commit066cd08b0a7214c432157704e3b5d249d9fbffd7 (patch)
treec17e587746a4eb333f5c45df711944165c222c99
parent23350afa918f2362f38117116a1e4f539ec87c73 (diff)
added RETURN ESCAPE
-rw-r--r--Makefile2
-rw-r--r--ir/opt/lfasan.c18
-rw-r--r--runtime/lfmalloc/src/lfinternal.c9
-rwxr-xr-xscripts/gen_lf_sizes.py1
4 files changed, 24 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index a1ad54b..72d442c 100644
--- a/Makefile
+++ b/Makefile
@@ -214,7 +214,7 @@ REVISION ?= $(shell git --git-dir $(top_srcdir)/.git describe --abbrev=40 --alwa
REVISIONH = $(gendir)/firm_revision.h
libfirm_INCLUDEDIRS += $(gendir)
UNUSED2 := $(shell \
- REV="\#define libfirm_VERSION_REVISION \"$(REVISION)\""; \
+ REV="#define libfirm_VERSION_REVISION \"$(REVISION)\""; \
echo "$$REV" | cmp -s - "$(REVISIONH)" 2> /dev/null || echo "$$REV" > "$(REVISIONH)" \
)
diff --git a/ir/opt/lfasan.c b/ir/opt/lfasan.c
index 3994c51..ec732a3 100644
--- a/ir/opt/lfasan.c
+++ b/ir/opt/lfasan.c
@@ -146,6 +146,15 @@ static void collect_bounds_check_node_pairs(ir_node *irn, void *env) {
add_pair(collected_pairs, irn, param, FUNCTION_ESCAPE);
}
}
+ } else if (is_Return(irn)) {
+ int return_res = get_Return_n_ress(irn);
+ for (int i = 0; i < return_res; i++) {
+ ir_node *res = get_Return_res(irn, i);
+ if (get_irn_mode(res) == get_modeP()) {
+ DB((dbg, LEVEL_5, "Collected ptr %+F for %+F (RETURN_ESCAPE)\n", res, irn));
+ add_pair(collected_pairs, irn, res, RETURN_ESCAPE);
+ }
+ }
}
}
@@ -209,6 +218,7 @@ static lfptr_meta *is_alloc_res(ir_node *irn) {
return NULL;
}
+// Inserts metadata reconstruction logic of a pointer node into the firm graph.
static lfptr_meta *calc_metadata(ir_node *irn, ir_node *sizes_lookup) {
dbg_info *dbgi = get_irn_dbg_info_(irn);
@@ -221,9 +231,9 @@ static lfptr_meta *calc_metadata(ir_node *irn, ir_node *sizes_lookup) {
ir_node *const_region_bits = new_r_Const_long(irg, get_modeLu(), REGION_BITS);
ir_node *conv_p_lu = new_rd_Conv(dbgi, block, irn, get_modeLu());
- ir_node *index = new_rd_Shr(dbgi, block, conv_p_lu, const_region_bits);
+ ir_node *index = new_rd_Shr(dbgi, block, conv_p_lu, const_region_bits); //shift by bits of size of region
ir_node *byte_offset = new_rd_Mul(dbgi, block, index,
- new_rd_Const_long(dbgi, irg, get_modeLu(), 8));
+ new_rd_Const_long(dbgi, irg, get_modeLu(), 8)); //size of element in lookup table
ir_node *conv_lu_ls = new_rd_Conv(dbgi, block, byte_offset, get_modeLs());
ir_node *size_address = new_rd_Add(dbgi, block, sizes_lookup, conv_lu_ls);
mark_irn_visited(size_address);
@@ -239,7 +249,7 @@ static lfptr_meta *calc_metadata(ir_node *irn, ir_node *sizes_lookup) {
ir_node *mod_res = new_rd_Proj(dbgi, mod, get_modeLu(), pn_Mod_res);
ir_node *conv_mod_res = new_rd_Conv(dbgi, block, mod_res, get_modeLs());
ir_node *sub = new_rd_Sub(dbgi, block, irn, conv_mod_res);
- ir_node *base = new_rd_Conv(dbgi, block, sub, get_modeP());
+ ir_node *base = sub; //new_rd_Conv(dbgi, block, sub, get_modeP());
mark_irn_visited(base);
lfptr_meta *res = new_lfptr_meta(base, size);
@@ -582,7 +592,7 @@ static lfptr_meta *get_node_meta(insert_instrumentation_env *env, ir_node *irn)
static void insert_bound_check_between(ir_node *irn, ir_node *ptr,
insert_instrumentation_env *env,
unsigned int reason) {
- DB((dbg, LEVEL_5, "inserting check between %+F and %+F (reason: %i)\n", irn, ptr, reason));
+ DB((dbg, LEVEL_5, "try inserting check between %+F and %+F (reason: %i)\n", irn, ptr, reason));
dbg_info *dbgi = get_irn_dbg_info(irn);
diff --git a/runtime/lfmalloc/src/lfinternal.c b/runtime/lfmalloc/src/lfinternal.c
index cf7a55c..972e00f 100644
--- a/runtime/lfmalloc/src/lfinternal.c
+++ b/runtime/lfmalloc/src/lfinternal.c
@@ -241,6 +241,9 @@ void __lf_free(void* ptr) {
if (!__lf_alloc_enabled()) {
return __libc_free(ptr);
}
+
+ __init();
+
if (ptr == NULL) {
PRINTF_DBG("freeing NULL\n");
return;
@@ -338,6 +341,7 @@ void *__lf_memalign(size_t alignment, size_t size) {
}
size_t __lf_usable_size(void* ptr) {
+ __init();
size_t region_idx = __lf_index(ptr);
if (region_idx == 0 || region_idx > REGION_COUNT) {
@@ -360,11 +364,14 @@ void __lf_error(void *ptr, void* base, unsigned long size, unsigned int reason,
s_reason = "MEMORY READ";
break;
case MEMORY_ESCAPE:
- s_reason = "MEMORY ESCAPE"; /*TODO: implement*/
+ s_reason = "MEMORY ESCAPE";
break;
case FUNCTION_ESCAPE:
s_reason = "FUNCTION ESCAPE";
break;
+ case RETURN_ESCAPE:
+ s_reason = "RETURN ESCAPE";
+ break;
default:
s_reason = "UNKNOWN";
}
diff --git a/scripts/gen_lf_sizes.py b/scripts/gen_lf_sizes.py
index 004e6ec..b1f699e 100755
--- a/scripts/gen_lf_sizes.py
+++ b/scripts/gen_lf_sizes.py
@@ -48,4 +48,5 @@ print('#define MEMORY_WRITE 0')
print('#define MEMORY_READ 1')
print('#define FUNCTION_ESCAPE 2')
print('#define MEMORY_ESCAPE 3')
+print('#define RETURN_ESCAPE 4')
print('#endif')