mirror of
https://github.com/pound-emu/pound.git
synced 2025-12-18 10:36:57 +00:00
arm64/mem: Refactor guest memory access and made it endian aware
Refactors the core guest memory access subsystem (guest.h) to be safer and portable accross host systems with different endianness. The previous implementation used direct pointer casting, which is not endian safe. 1. All read and write functions have been converted from unsafe pointer casts to memcpy(). This resolves alignment warning -Wcast-align. 2. The access functions no longer rely on asserts for error checking. They now perform explicit boundary and alignment checking and returns a guest_mem_access_result_t status code. 3. A new header (endian.h) provides cross platform byte swapping macros. The memory access functions use these macros to ensure that the guest always sees memory in the correct endian format, regardless of the host's native byte order. The host endianness is now automatically detected via CMake. 3. Asserts are now explicitly enabled in release builds to catch critical errors. Signed-off-by: Ronald Caesar <github43132@proton.me>
This commit is contained in:
parent
768355712d
commit
8b483849f4
9 changed files with 467 additions and 218 deletions
27
src/kvm/endian.h
Normal file
27
src/kvm/endian.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef POUND_KVM_ENDIAN_H
|
||||
#define POUND_KVM_ENDIAN_H
|
||||
|
||||
#define GUEST_IS_LITTLE_ENDIAN 1
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <stdlib.h>
|
||||
#define bswap_16(x) _byteswap_ushort(x)
|
||||
#define bswap_32(x) _byteswap_ulong(x)
|
||||
#define bswap_64(x) _byteswap_uint64(x)
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
#include <libkern/OSByteOrder.h>
|
||||
#define bswap_16(x) OSSwaoInt16(x)
|
||||
#define bswap_32(x) OSSwapInt32(x)
|
||||
#define bswap_64(x) OSSwapInt64(x)
|
||||
|
||||
#else
|
||||
|
||||
#include <byteswap.h>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // POUND_KVM_ENDIAN_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue