Use helper fn for dereference

This commit is contained in:
Lucas Schumacher 2024-07-11 13:13:32 -04:00
parent b078ba9ac1
commit 324231b00f

10
mem.c
View File

@ -16,7 +16,7 @@ void segfault_handler(int signal_num) {
exit(signal_num); exit(signal_num);
} }
} }
int tryDereference(uintptr_t* pointer, uintptr_t* output) { int tryDereference(uint8_t* pointer, uint8_t* output) {
uintptr_t val; uintptr_t val;
if (setjmp(env_buffer) == 0) { if (setjmp(env_buffer) == 0) {
enable_handler = 1; enable_handler = 1;
@ -30,13 +30,11 @@ int tryDereference(uintptr_t* pointer, uintptr_t* output) {
} }
} }
void printMem(uint8_t* location) { void printMem(uint8_t* location) {
if (setjmp(env_buffer) == 0) { uint8_t value;
enable_handler = 1; if(tryDereference(location, &value)) {
printf("%p: 0x%02x\n", location, *location); printf("%p: 0x%02x\n", location, value);
enable_handler = 0;
} }
else { else {
enable_handler = 0;
printf("%p: SEGFAULT\n", location); printf("%p: SEGFAULT\n", location);
} }
} }