Skip to content

Commit 9d2197b

Browse files
authored
Better typed syx snapshot check result (#74)
* better typed snapshot check * edit compile_commands.json to use the real compiler
1 parent 9f3e239 commit 9d2197b

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

include/libafl/syx-snapshot/syx-snapshot.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ typedef struct SyxSnapshotState {
5959
// Root
6060
} SyxSnapshotState;
6161

62+
typedef struct SyxSnapshotCheckResult {
63+
uint64_t nb_inconsistencies;
64+
} SyxSnapshotCheckResult;
65+
6266
void syx_snapshot_init(bool cached_bdrvs);
6367

6468
//
@@ -71,7 +75,7 @@ void syx_snapshot_free(SyxSnapshot *snapshot);
7175

7276
void syx_snapshot_root_restore(SyxSnapshot *snapshot);
7377

74-
uint64_t syx_snapshot_check_memory_consistency(SyxSnapshot *snapshot);
78+
SyxSnapshotCheckResult syx_snapshot_check(SyxSnapshot* ref_snapshot);
7579

7680
// Push the current RAM state and saves it
7781
void syx_snapshot_increment_push(SyxSnapshot *snapshot, DeviceSnapshotKind kind, char **devices);

libafl/syx-snapshot/syx-snapshot.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ static void root_restore_check_memory_rb(gpointer rb_idstr_hash, gpointer rb_dir
577577
SyxSnapshot *snapshot = args->snapshot;
578578
RAMBlock *rb = ramblock_lookup(rb_idstr_hash);
579579

580-
args->nb_inconsistent_pages = 0;
581580
if (rb) {
582581
SYX_PRINTF("Checking memory consistency of %s... ", rb->idstr);
583582
SyxSnapshotRAMBlock *rb_snapshot = g_hash_table_lookup(snapshot->root_snapshot->rbs_snapshot, rb_idstr_hash);
@@ -610,12 +609,19 @@ static void root_restore_check_memory_rb(gpointer rb_idstr_hash, gpointer rb_dir
610609
}
611610
}
612611

613-
uint64_t syx_snapshot_check_memory_consistency(SyxSnapshot *snapshot) {
612+
SyxSnapshotCheckResult syx_snapshot_check(SyxSnapshot* ref_snapshot) {
614613
struct rb_check_memory_args args = {
615-
.snapshot = snapshot
614+
.snapshot = ref_snapshot,
615+
.nb_inconsistent_pages = 0,
616616
};
617-
g_hash_table_foreach(snapshot->rbs_dirty_list, root_restore_check_memory_rb, &args);
618-
return args.nb_inconsistent_pages;
617+
618+
g_hash_table_foreach(ref_snapshot->rbs_dirty_list, root_restore_check_memory_rb, &args);
619+
620+
struct SyxSnapshotCheckResult res = {
621+
.nb_inconsistencies = args.nb_inconsistent_pages
622+
};
623+
624+
return res;
619625
}
620626

621627
void syx_snapshot_root_restore(SyxSnapshot *snapshot) {

linker_interceptor.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@
2727
rpath_pattern = r"^'.*,-rpath,(.*)'$"
2828
rpath_link_pattern = r"^.*,-rpath-link,(.*)$"
2929

30+
linker_interceptor_pattern = r"(\": \")(.*linker_interceptor.py)( )"
31+
linker_interceptorpp_pattern = r"(\": \")(.*linker_interceptor\+\+.py)( )"
32+
33+
def fix_compile_commands():
34+
with open("compile_commands.json", 'r') as f:
35+
compile_commands = f.read()
36+
37+
res = re.sub(linker_interceptor_pattern, rf"\g<1>{CC}\g<3>", compile_commands)
38+
res = re.sub(linker_interceptorpp_pattern, rf"\g<1>{CXX}\g<3>", res)
39+
40+
with open("compile_commands.json", 'w') as f:
41+
f.write(res)
42+
3043
def process_args(args):
3144
global out_args, shareds, search, is_linking_qemu
3245
prev_o = False
@@ -75,6 +88,8 @@ def process_args(args):
7588
for entry in compile_commands:
7689
sources.append(entry["file"])
7790

91+
fix_compile_commands()
92+
7893
with open(OUT, 'w') as f:
7994
json.dump({
8095
'cmd': out_args,

0 commit comments

Comments
 (0)