Support uc_mem_protect on mmio regions

Also make mmio ranges return the correct errors on wrong protection
This commit is contained in:
2022-05-28 23:33:43 +02:00
parent 6a2e2a1291
commit 2a6529348c
4 changed files with 90 additions and 15 deletions

View File

@@ -1657,6 +1657,13 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi,
res = load_memop(haddr, op);
_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
if (!code_read) {
if (!uc->size_recur_mem) { // disabling read callback if in recursive call

View File

@@ -88,6 +88,7 @@ static uint64_t mmio_read_wrapper(struct uc_struct *uc, void *opaque, hwaddr add
if (cbs->read) {
return cbs->read(uc, addr, size, cbs->user_data_read);
} else {
uc->invalid_error = UC_ERR_READ_PROT;
return 0;
}
}
@@ -100,6 +101,8 @@ static void mmio_write_wrapper(struct uc_struct *uc, void *opaque, hwaddr addr,
addr = addr & ( (target_ulong)(-1) );
if (cbs->write) {
cbs->write(uc, addr, size, data, cbs->user_data_write);
} else {
uc->invalid_error = UC_ERR_WRITE_PROT;
}
}
@@ -123,7 +126,9 @@ MemoryRegion *memory_map_io(struct uc_struct *uc, ram_addr_t begin, size_t size,
memset(ops, 0, sizeof(*ops));
ops->read = mmio_read_wrapper;
ops->read_with_attrs = NULL;
ops->write = mmio_write_wrapper;
ops->write_with_attrs = NULL;
ops->endianness = DEVICE_NATIVE_ENDIAN;
memory_region_init_io(uc, mmio, ops, opaques, size);