memory: don't sign-extend 32-bit writes

ldl_p has a signed return type so assigning it to uint64_t implicitly
sign-extends the value. This results in devices with min_access_size = 8
seeing unexpected values passed to their write handlers.

Example: guest performs a 32-bit write of 0x80000000 to an mmio region
and the handler receives 0xFFFFFFFF80000000 in its value argument.

Backports commit 6da67de6803e93cbb7e93ac3497865832f8c00ea from qemu
This commit is contained in:
Ladi Prosek 2018-03-02 00:00:13 -05:00 committed by Lioncash
parent 48825c1be2
commit babf848b82
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -2026,7 +2026,7 @@ static MemTxResult address_space_write_continue(AddressSpace *as, hwaddr addr,
break;
case 4:
/* 32 bit write access */
val = ldl_p(buf);
val = (uint32_t)ldl_p(buf);
result |= memory_region_dispatch_write(mr, addr1, val, 4,
attrs);
break;