Add ability to mark memory are read only. Add new API uc_mem_map_ex to allow permissions to be passed. Change MemoryBlock to track created MemoryRegions. Add regress/ro_mem_test.c
This commit is contained in:
4
qemu/include/exec/memory.h
Normal file → Executable file
4
qemu/include/exec/memory.h
Normal file → Executable file
@ -315,12 +315,14 @@ void memory_region_init_io(struct uc_struct *uc, MemoryRegion *mr,
|
||||
* @owner: the object that tracks the region's reference count
|
||||
* @name: the name of the region.
|
||||
* @size: size of the region.
|
||||
* @perms: permissions on the region (UC_PROT_READ, UC_PROT_WRITE, UC_PROT_EXEC).
|
||||
* @errp: pointer to Error*, to store an error if it happens.
|
||||
*/
|
||||
void memory_region_init_ram(struct uc_struct *uc, MemoryRegion *mr,
|
||||
struct Object *owner,
|
||||
const char *name,
|
||||
uint64_t size,
|
||||
uint32_t perms,
|
||||
Error **errp);
|
||||
|
||||
/**
|
||||
@ -934,7 +936,7 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
|
||||
|
||||
void memory_register_types(struct uc_struct *uc);
|
||||
|
||||
int memory_map(struct uc_struct *uc, ram_addr_t begin, size_t size);
|
||||
MemoryRegion *memory_map(struct uc_struct *uc, ram_addr_t begin, size_t size, uint32_t perms);
|
||||
int memory_free(struct uc_struct *uc);
|
||||
|
||||
#endif
|
||||
|
10
qemu/memory.c
Normal file → Executable file
10
qemu/memory.c
Normal file → Executable file
@ -31,18 +31,18 @@
|
||||
|
||||
|
||||
// Unicorn engine
|
||||
int memory_map(struct uc_struct *uc, ram_addr_t begin, size_t size)
|
||||
MemoryRegion *memory_map(struct uc_struct *uc, ram_addr_t begin, size_t size, uint32_t perms)
|
||||
{
|
||||
uc->ram = g_new(MemoryRegion, 1);
|
||||
|
||||
memory_region_init_ram(uc, uc->ram, NULL, "pc.ram", size, &error_abort);
|
||||
memory_region_init_ram(uc, uc->ram, NULL, "pc.ram", size, perms, &error_abort);
|
||||
|
||||
memory_region_add_subregion(get_system_memory(uc), begin, uc->ram);
|
||||
|
||||
if (uc->current_cpu)
|
||||
tlb_flush(uc->current_cpu, 1);
|
||||
|
||||
return 0;
|
||||
return uc->ram;
|
||||
}
|
||||
|
||||
int memory_free(struct uc_struct *uc)
|
||||
@ -1151,10 +1151,14 @@ void memory_region_init_ram(struct uc_struct *uc, MemoryRegion *mr,
|
||||
Object *owner,
|
||||
const char *name,
|
||||
uint64_t size,
|
||||
uint32_t perms,
|
||||
Error **errp)
|
||||
{
|
||||
memory_region_init(uc, mr, owner, name, size);
|
||||
mr->ram = true;
|
||||
if (!(perms & UC_PROT_WRITE)) {
|
||||
mr->readonly = true;
|
||||
}
|
||||
mr->terminates = true;
|
||||
mr->destructor = memory_region_destructor_ram;
|
||||
mr->ram_addr = qemu_ram_alloc(size, mr, errp);
|
||||
|
1
qemu/unicorn_common.h
Normal file → Executable file
1
qemu/unicorn_common.h
Normal file → Executable file
@ -73,6 +73,7 @@ static inline void uc_common_init(struct uc_struct* uc)
|
||||
uc->pause_all_vcpus = pause_all_vcpus;
|
||||
uc->vm_start = vm_start;
|
||||
uc->memory_map = memory_map;
|
||||
uc->readonly_mem = memory_region_set_readonly;
|
||||
|
||||
if (!uc->release)
|
||||
uc->release = release_common;
|
||||
|
Reference in New Issue
Block a user