Cleaner implementation for uc_mem_prot on mmio regions
This commit is contained in:
parent
2a6529348c
commit
289034538d
|
@ -1657,13 +1657,6 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi,
|
||||||
res = load_memop(haddr, op);
|
res = load_memop(haddr, op);
|
||||||
|
|
||||||
_out:
|
_out:
|
||||||
// mmio error check
|
|
||||||
if (uc->invalid_error != UC_ERR_OK) {
|
|
||||||
uc->invalid_addr = addr;
|
|
||||||
cpu_exit(uc->cpu);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unicorn: callback on successful data read
|
// Unicorn: callback on successful data read
|
||||||
if (!code_read) {
|
if (!code_read) {
|
||||||
if (!uc->size_recur_mem) { // disabling read callback if in recursive call
|
if (!uc->size_recur_mem) { // disabling read callback if in recursive call
|
||||||
|
|
|
@ -82,13 +82,12 @@ MemoryRegion *memory_map_ptr(struct uc_struct *uc, hwaddr begin, size_t size, ui
|
||||||
static uint64_t mmio_read_wrapper(struct uc_struct *uc, void *opaque, hwaddr addr, unsigned size)
|
static uint64_t mmio_read_wrapper(struct uc_struct *uc, void *opaque, hwaddr addr, unsigned size)
|
||||||
{
|
{
|
||||||
mmio_cbs* cbs = (mmio_cbs*)opaque;
|
mmio_cbs* cbs = (mmio_cbs*)opaque;
|
||||||
|
|
||||||
// We have to care about 32bit target.
|
// We have to care about 32bit target.
|
||||||
addr = addr & ( (target_ulong)(-1) );
|
addr = addr & ( (target_ulong)(-1) );
|
||||||
if (cbs->read) {
|
if (cbs->read) {
|
||||||
return cbs->read(uc, addr, size, cbs->user_data_read);
|
return cbs->read(uc, addr, size, cbs->user_data_read);
|
||||||
} else {
|
} else {
|
||||||
uc->invalid_error = UC_ERR_READ_PROT;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,8 +100,6 @@ static void mmio_write_wrapper(struct uc_struct *uc, void *opaque, hwaddr addr,
|
||||||
addr = addr & ( (target_ulong)(-1) );
|
addr = addr & ( (target_ulong)(-1) );
|
||||||
if (cbs->write) {
|
if (cbs->write) {
|
||||||
cbs->write(uc, addr, size, data, cbs->user_data_write);
|
cbs->write(uc, addr, size, data, cbs->user_data_write);
|
||||||
} else {
|
|
||||||
uc->invalid_error = UC_ERR_WRITE_PROT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
uc.c
14
uc.c
|
@ -1366,7 +1366,7 @@ uc_err uc_mem_protect(struct uc_struct *uc, uint64_t address, size_t size,
|
||||||
uint64_t addr = address;
|
uint64_t addr = address;
|
||||||
uint64_t pc;
|
uint64_t pc;
|
||||||
size_t count, len;
|
size_t count, len;
|
||||||
mmio_cbs* new_cb;
|
mmio_cbs *mmio;
|
||||||
bool remove_exec = false;
|
bool remove_exec = false;
|
||||||
|
|
||||||
UC_INIT(uc);
|
UC_INIT(uc);
|
||||||
|
@ -1422,20 +1422,12 @@ uc_err uc_mem_protect(struct uc_struct *uc, uint64_t address, size_t size,
|
||||||
uc->readonly_mem(mr, (perms & UC_PROT_WRITE) == 0);
|
uc->readonly_mem(mr, (perms & UC_PROT_WRITE) == 0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(!split_mmio_region(uc, mr, addr, len, false)) {
|
if (!split_mmio_region(uc, mr, addr, len, false)) {
|
||||||
return UC_ERR_NOMEM;
|
return UC_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
mr = memory_mapping(uc, addr);
|
mr = memory_mapping(uc, addr);
|
||||||
new_cb = (mmio_cbs*)mr->opaque;
|
mr->perms = perms;
|
||||||
|
|
||||||
if (!(perms & UC_PROT_READ)) {
|
|
||||||
new_cb->read = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(perms & UC_PROT_WRITE)) {
|
|
||||||
new_cb->write = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
count += len;
|
count += len;
|
||||||
|
|
Loading…
Reference in New Issue