Skip to content

Commit

Permalink
Remove the size limit for memory read and write
Browse files Browse the repository at this point in the history
Eliminate the maximum size restriction for uc_mem_read and uc_mem_write. This
change is required to support applications, such as LLVM CFI, that map or unmap
memory blocks with sizes equal to or greater than INT_MAX.
  • Loading branch information
secretnonempty committed Mar 10, 2023
1 parent 7b8c63d commit f11b153
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions uc.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ static bool check_mem_area(uc_engine *uc, uint64_t address, size_t size)
return (count == size);
}

#define MAX_RW_LENGTH ((INT_MAX >> (8*sizeof(int)/2)) << (8*sizeof(int)/2))

UNICORN_EXPORT
uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *_bytes, size_t size)
{
Expand All @@ -573,10 +575,6 @@ uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *_bytes, size_t size)

UC_INIT(uc);

// qemu cpu_physical_memory_rw() size is an int
if (size > INT_MAX)
return UC_ERR_ARG;

if (uc->mem_redirect) {
address = uc->mem_redirect(address);
}
Expand All @@ -590,6 +588,7 @@ uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *_bytes, size_t size)
MemoryRegion *mr = memory_mapping(uc, address);
if (mr) {
len = (size_t)MIN(size - count, mr->end - address);
len = (size_t)MIN(len, MAX_RW_LENGTH);
if (uc->read_mem(&uc->address_space_memory, address, bytes, len) ==
false) {
break;
Expand Down Expand Up @@ -618,10 +617,6 @@ uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *_bytes,

UC_INIT(uc);

// qemu cpu_physical_memory_rw() size is an int
if (size > INT_MAX)
return UC_ERR_ARG;

if (uc->mem_redirect) {
address = uc->mem_redirect(address);
}
Expand All @@ -642,6 +637,7 @@ uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *_bytes,
}

len = (size_t)MIN(size - count, mr->end - address);
len = (size_t)MIN(len, MAX_RW_LENGTH);
if (uc->write_mem(&uc->address_space_memory, address, bytes, len) ==
false) {
break;
Expand Down

0 comments on commit f11b153

Please sign in to comment.