mirror of https://github.com/mgba-emu/mgba.git
Make writing to RO mapped memory perform COW
This commit is contained in:
parent
5825c2ee5f
commit
16cf389986
|
@ -85,7 +85,7 @@ void GBASavedataInitFlash(struct GBASavedata* savedata) {
|
||||||
if (end < SIZE_CART_FLASH512) {
|
if (end < SIZE_CART_FLASH512) {
|
||||||
savedata->vf->truncate(savedata->vf, SIZE_CART_FLASH1M);
|
savedata->vf->truncate(savedata->vf, SIZE_CART_FLASH1M);
|
||||||
}
|
}
|
||||||
savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_FLASH1M, MEMORY_WRITE);
|
savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_FLASH1M, MAP_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
savedata->currentBank = savedata->data;
|
savedata->currentBank = savedata->data;
|
||||||
|
@ -110,7 +110,7 @@ void GBASavedataInitEEPROM(struct GBASavedata* savedata) {
|
||||||
if (end < SIZE_CART_EEPROM) {
|
if (end < SIZE_CART_EEPROM) {
|
||||||
savedata->vf->truncate(savedata->vf, SIZE_CART_EEPROM);
|
savedata->vf->truncate(savedata->vf, SIZE_CART_EEPROM);
|
||||||
}
|
}
|
||||||
savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_EEPROM, MEMORY_WRITE);
|
savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_EEPROM, MAP_WRITE);
|
||||||
}
|
}
|
||||||
if (end < SIZE_CART_EEPROM) {
|
if (end < SIZE_CART_EEPROM) {
|
||||||
memset(&savedata->data[end], 0xFF, SIZE_CART_EEPROM - end);
|
memset(&savedata->data[end], 0xFF, SIZE_CART_EEPROM - end);
|
||||||
|
@ -133,7 +133,7 @@ void GBASavedataInitSRAM(struct GBASavedata* savedata) {
|
||||||
if (end < SIZE_CART_SRAM) {
|
if (end < SIZE_CART_SRAM) {
|
||||||
savedata->vf->truncate(savedata->vf, SIZE_CART_SRAM);
|
savedata->vf->truncate(savedata->vf, SIZE_CART_SRAM);
|
||||||
}
|
}
|
||||||
savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_SRAM, MEMORY_WRITE);
|
savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_SRAM, MAP_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end < SIZE_CART_SRAM) {
|
if (end < SIZE_CART_SRAM) {
|
||||||
|
|
|
@ -99,7 +99,7 @@ bool GBALoadState(struct GBA* gba, int slot) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GBASerializedState* GBAMapState(struct VFile* vf) {
|
struct GBASerializedState* GBAMapState(struct VFile* vf) {
|
||||||
return vf->map(vf, sizeof(struct GBASerializedState), MEMORY_WRITE);
|
return vf->map(vf, sizeof(struct GBASerializedState), MAP_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAUnmapState(struct VFile* vf, struct GBASerializedState* state) {
|
void GBAUnmapState(struct VFile* vf, struct GBASerializedState* state) {
|
||||||
|
|
|
@ -386,7 +386,7 @@ void GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char
|
||||||
gba->romVf = vf;
|
gba->romVf = vf;
|
||||||
gba->pristineRomSize = vf->seek(vf, 0, SEEK_END);
|
gba->pristineRomSize = vf->seek(vf, 0, SEEK_END);
|
||||||
vf->seek(vf, 0, SEEK_SET);
|
vf->seek(vf, 0, SEEK_SET);
|
||||||
gba->pristineRom = vf->map(vf, SIZE_CART0, MEMORY_READ);
|
gba->pristineRom = vf->map(vf, SIZE_CART0, MAP_READ);
|
||||||
gba->memory.rom = gba->pristineRom;
|
gba->memory.rom = gba->pristineRom;
|
||||||
gba->activeFile = fname;
|
gba->activeFile = fname;
|
||||||
gba->memory.romSize = gba->pristineRomSize;
|
gba->memory.romSize = gba->pristineRomSize;
|
||||||
|
@ -398,7 +398,7 @@ void GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char
|
||||||
|
|
||||||
void GBALoadBIOS(struct GBA* gba, struct VFile* vf) {
|
void GBALoadBIOS(struct GBA* gba, struct VFile* vf) {
|
||||||
gba->biosVf = vf;
|
gba->biosVf = vf;
|
||||||
gba->memory.bios = vf->map(vf, SIZE_BIOS, MEMORY_READ);
|
gba->memory.bios = vf->map(vf, SIZE_BIOS, MAP_READ);
|
||||||
gba->memory.fullBios = 1;
|
gba->memory.fullBios = 1;
|
||||||
uint32_t checksum = GBAChecksum(gba->memory.bios, SIZE_BIOS);
|
uint32_t checksum = GBAChecksum(gba->memory.bios, SIZE_BIOS);
|
||||||
GBALog(gba, GBA_LOG_DEBUG, "BIOS Checksum: 0x%X", checksum);
|
GBALog(gba, GBA_LOG_DEBUG, "BIOS Checksum: 0x%X", checksum);
|
||||||
|
|
|
@ -3,9 +3,6 @@
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#define MEMORY_READ 1
|
|
||||||
#define MEMORY_WRITE 2
|
|
||||||
|
|
||||||
void* anonymousMemoryMap(size_t size);
|
void* anonymousMemoryMap(size_t size);
|
||||||
void mappedMemoryFree(void* memory, size_t size);
|
void mappedMemoryFree(void* memory, size_t size);
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ ssize_t _vfdWrite(struct VFile* vf, void* buffer, size_t size) {
|
||||||
static void* _vfdMap(struct VFile* vf, size_t size, int flags) {
|
static void* _vfdMap(struct VFile* vf, size_t size, int flags) {
|
||||||
struct VFileFD* vfd = (struct VFileFD*) vf;
|
struct VFileFD* vfd = (struct VFileFD*) vf;
|
||||||
int mmapFlags = MAP_PRIVATE;
|
int mmapFlags = MAP_PRIVATE;
|
||||||
if (flags & MEMORY_WRITE) {
|
if (flags & MAP_WRITE) {
|
||||||
mmapFlags = MAP_SHARED;
|
mmapFlags = MAP_SHARED;
|
||||||
}
|
}
|
||||||
return mmap(0, size, PROT_READ | PROT_WRITE, mmapFlags, vfd->fd, 0);
|
return mmap(0, size, PROT_READ | PROT_WRITE, mmapFlags, vfd->fd, 0);
|
||||||
|
@ -118,9 +118,9 @@ static void _vfdUnmap(struct VFile* vf, void* memory, size_t size) {
|
||||||
#else
|
#else
|
||||||
static void* _vfdMap(struct VFile* vf, size_t size, int flags) {
|
static void* _vfdMap(struct VFile* vf, size_t size, int flags) {
|
||||||
struct VFileFD* vfd = (struct VFileFD*) vf;
|
struct VFileFD* vfd = (struct VFileFD*) vf;
|
||||||
int createFlags = PAGE_READONLY;
|
int createFlags = PAGE_WRITECOPY;
|
||||||
int mapFiles = FILE_MAP_READ;
|
int mapFiles = FILE_MAP_COPY;
|
||||||
if (flags & MEMORY_WRITE) {
|
if (flags & MAP_WRITE) {
|
||||||
createFlags = PAGE_READWRITE;
|
createFlags = PAGE_READWRITE;
|
||||||
mapFiles = FILE_MAP_WRITE;
|
mapFiles = FILE_MAP_WRITE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#include "memory.h"
|
enum {
|
||||||
|
MAP_READ = 1,
|
||||||
|
MAP_WRITE = 2
|
||||||
|
};
|
||||||
|
|
||||||
struct VFile {
|
struct VFile {
|
||||||
bool (*close)(struct VFile* vf);
|
bool (*close)(struct VFile* vf);
|
||||||
|
|
Loading…
Reference in New Issue