system/memory: use ldn_he_p/stn_he_p
Using direct pointer dereferencing can allow for unaligned accesses, which was seen during execution with sanitizers enabled. Cc: qemu-stable@nongnu.org Reviewed-by: Chris Rauer <crauer@google.com> Reviewed-by: Peter Foley <pefoley@google.com> Signed-off-by: Patrick Venture <venture@google.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: David Hildenbrand <david@redhat.com> Message-ID: <20231116163633.276671-1-venture@google.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
parent
17dacf7ac9
commit
2b8fe81b3c
@ -1339,22 +1339,7 @@ static uint64_t memory_region_ram_device_read(void *opaque,
|
|||||||
hwaddr addr, unsigned size)
|
hwaddr addr, unsigned size)
|
||||||
{
|
{
|
||||||
MemoryRegion *mr = opaque;
|
MemoryRegion *mr = opaque;
|
||||||
uint64_t data = (uint64_t)~0;
|
uint64_t data = ldn_he_p(mr->ram_block->host + addr, size);
|
||||||
|
|
||||||
switch (size) {
|
|
||||||
case 1:
|
|
||||||
data = *(uint8_t *)(mr->ram_block->host + addr);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
data = *(uint16_t *)(mr->ram_block->host + addr);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
data = *(uint32_t *)(mr->ram_block->host + addr);
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
data = *(uint64_t *)(mr->ram_block->host + addr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
trace_memory_region_ram_device_read(get_cpu_index(), mr, addr, data, size);
|
trace_memory_region_ram_device_read(get_cpu_index(), mr, addr, data, size);
|
||||||
|
|
||||||
@ -1368,20 +1353,7 @@ static void memory_region_ram_device_write(void *opaque, hwaddr addr,
|
|||||||
|
|
||||||
trace_memory_region_ram_device_write(get_cpu_index(), mr, addr, data, size);
|
trace_memory_region_ram_device_write(get_cpu_index(), mr, addr, data, size);
|
||||||
|
|
||||||
switch (size) {
|
stn_he_p(mr->ram_block->host + addr, size, data);
|
||||||
case 1:
|
|
||||||
*(uint8_t *)(mr->ram_block->host + addr) = (uint8_t)data;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
*(uint16_t *)(mr->ram_block->host + addr) = (uint16_t)data;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
*(uint32_t *)(mr->ram_block->host + addr) = (uint32_t)data;
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
*(uint64_t *)(mr->ram_block->host + addr) = data;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const MemoryRegionOps ram_device_mem_ops = {
|
static const MemoryRegionOps ram_device_mem_ops = {
|
||||||
|
Loading…
Reference in New Issue
Block a user