Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/unicorn/unicorn.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ typedef enum uc_err {
UC_ERR_RESOURCE, // Insufficient resource: uc_emu_start()
UC_ERR_EXCEPTION, // Unhandled CPU exception
UC_ERR_OVERFLOW, // Provided buffer is not large enough: uc_reg_*2()
UC_ERR_MMU_FAULT, // The tlb_fill hook returned false (see tlb_fill hook)
} uc_err;

/*
Expand Down Expand Up @@ -605,6 +606,9 @@ typedef enum uc_control_type {
// controle if context_save/restore should work with snapshots
// Write: @args = (int)
UC_CTL_CONTEXT_MODE,
// read the invalid_addr after an error
// Read: @args = (uint64_t*)
UC_CTL_INVALID_ADDR,
} uc_control_type;

/*
Expand Down Expand Up @@ -688,6 +692,8 @@ See sample_ctl.c for a detailed example.
uc_ctl(uc, UC_CTL_WRITE(UC_CTL_TCG_BUFFER_SIZE, 1), (size))
#define uc_ctl_context_mode(uc, mode) \
uc_ctl(uc, UC_CTL_WRITE(UC_CTL_CONTEXT_MODE, 1), (mode))
#define uc_ctl_get_invalid_addr(uc, addr) \
uc_ctl(uc, UC_CTL_READ(UC_CTL_INVALID_ADDR, 1), (addr))

// Opaque storage for CPU context, used with uc_context_*()
struct uc_context;
Expand Down
2 changes: 1 addition & 1 deletion qemu/softmmu/unicorn_vtlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
static void raise_mmu_exception(CPUState *cs, target_ulong address,
int rw, uintptr_t retaddr)
{
cs->uc->invalid_error = UC_ERR_EXCEPTION;
cs->uc->invalid_error = UC_ERR_MMU_FAULT;
cs->uc->invalid_addr = address;
cpu_exit(cs->uc->cpu);
cpu_loop_exit_restore(cs, retaddr);
Expand Down
11 changes: 11 additions & 0 deletions uc.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ const char *uc_strerror(uc_err code)
return "Unhandled CPU exception (UC_ERR_EXCEPTION)";
case UC_ERR_OVERFLOW:
return "Provided buffer is too small (UC_ERR_OVERFLOW)";
case UC_ERR_MMU_FAULT:
return "The tlb_fill hook returned false (UC_ERR_MMU_FAULT)";
}
}

Expand Down Expand Up @@ -2977,6 +2979,15 @@ uc_err uc_ctl(uc_engine *uc, uc_control_type control, ...)
restore_jit_state(uc);
break;

case UC_CTL_INVALID_ADDR:
if (rw == UC_CTL_IO_READ) {
uint64_t *invalid_addr = va_arg(args, uint64_t *);
*invalid_addr = uc->invalid_addr;
} else {
err = UC_ERR_ARG;
}
break;

default:
err = UC_ERR_ARG;
break;
Expand Down
Loading