Fix pointer serialization in the memory system

This makes savestates potentially unstable under certain conditions (and
definitely not portable)
This commit is contained in:
David Guillen Fandos 2021-07-27 21:18:15 +02:00
parent 19d67af0bd
commit ba51aa6a1c
2 changed files with 12 additions and 3 deletions

View file

@ -3204,7 +3204,7 @@ void memory_##type##_savestate(void) \
state_mem_##type##_variable(sram_size); \
state_mem_##type##_variable(flash_mode); \
state_mem_##type##_variable(flash_command_position); \
state_mem_##type##_variable(flash_bank_ptr); \
state_mem_##type##_pointer(flash_bank_ptr, gamepak_backup); \
state_mem_##type##_variable(flash_device_id); \
state_mem_##type##_variable(flash_manufacturer_id); \
state_mem_##type##_variable(flash_size); \
@ -3231,9 +3231,9 @@ void memory_##type##_savestate(void) \
state_mem_##type(palette_ram, 0x400); \
state_mem_##type(io_registers, 0x8000); \
\
/* This is a hack, for now. */ \
/* This should not happen anymore :P */ \
if((flash_bank_ptr < gamepak_backup) || \
(flash_bank_ptr > (gamepak_backup + (1024 * 64)))) \
(flash_bank_ptr > (&gamepak_backup[sizeof(gamepak_backup)])))\
flash_bank_ptr = gamepak_backup; \
}

View file

@ -313,6 +313,10 @@ static inline void clear_gamepak_stickybits(void)
#define state_mem_write_array(array) state_mem_write(array, sizeof(array))
#define state_mem_write_variable(variable) state_mem_write(&variable, sizeof(variable))
#define state_mem_write_pointer(ptr, base) { \
u32 offset = ((u8*)ptr) - ((u8*)base); \
state_mem_write(&offset, sizeof(offset)); \
}
static inline void state_mem_read(void* dst, size_t size)
{
@ -322,6 +326,11 @@ static inline void state_mem_read(void* dst, size_t size)
#define state_mem_read_array(array) state_mem_read(array, sizeof(array))
#define state_mem_read_variable(variable) state_mem_read(&variable, sizeof(variable))
#define state_mem_read_pointer(ptr, base) { \
u32 offset; \
state_mem_read(&offset, sizeof(offset)); \
ptr = (typeof(ptr))(((u8*)base) + offset); \
}
void memory_write_savestate(void);
void memory_read_savestate(void);