From: notaz Date: Wed, 27 Jan 2010 15:16:25 +0000 (+0000) Subject: bugfixes related to mmap usage for ROM X-Git-Tag: v1.85~187 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a736af3ecf708652f90e9cb05445d984960a0eec;p=picodrive.git bugfixes related to mmap usage for ROM git-svn-id: file:///home/notaz/opt/svn/PicoDrive@867 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/cpu/drc/cmn.c b/cpu/drc/cmn.c index 0e794897..d796bfbf 100644 --- a/cpu/drc/cmn.c +++ b/cpu/drc/cmn.c @@ -13,7 +13,7 @@ void drc_cmn_init(void) #ifdef __linux__ void *tmp; - tmp = mmap(tcache, DRC_TCACHE_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0); + tmp = mmap(tcache, DRC_TCACHE_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); printf("mmap tcache: %p, asked %p\n", tmp, tcache); #endif } diff --git a/pico/cart.c b/pico/cart.c index 42d08172..fa283c8d 100644 --- a/pico/cart.c +++ b/pico/cart.c @@ -592,6 +592,17 @@ int PicoCartInsert(unsigned char *rom, unsigned int romsize, const char *carthw_ return 0; } +int PicoCartResize(int newsize) +{ + void *tmp = plat_mremap(Pico.rom, rom_alloc_size, newsize); + if (tmp == NULL) + return -1; + + Pico.rom = tmp; + rom_alloc_size = newsize; + return 0; +} + void PicoCartUnload(void) { if (PicoCartUnloadHook != NULL) { diff --git a/pico/carthw/carthw.c b/pico/carthw/carthw.c index 9d81f8e0..e35ae75d 100644 --- a/pico/carthw/carthw.c +++ b/pico/carthw/carthw.c @@ -203,20 +203,17 @@ static void carthw_realtec_reset(void) void carthw_realtec_startup(void) { - void *tmp; int i; elprintf(EL_STATUS, "Realtec mapper startup"); // allocate additional bank for boot code // (we know those ROMs have aligned size) - tmp = realloc(Pico.rom, Pico.romsize + M68K_BANK_SIZE); - if (tmp == NULL) - { + i = PicoCartResize(Pico.romsize + M68K_BANK_SIZE); + if (i != 0) { elprintf(EL_STATUS, "OOM"); return; } - Pico.rom = tmp; // create bank for boot code for (i = 0; i < M68K_BANK_SIZE; i += 0x2000) @@ -487,18 +484,16 @@ static void carthw_prot_lk3_mem_setup(void) void carthw_prot_lk3_startup(void) { - void *tmp; + int ret; elprintf(EL_STATUS, "lk3 prot emu startup"); // allocate space for bank0 backup - tmp = realloc(Pico.rom, Pico.romsize + 0x8000); - if (tmp == NULL) - { + ret = PicoCartResize(Pico.romsize + 0x8000); + if (ret != 0) { elprintf(EL_STATUS, "OOM"); return; } - Pico.rom = tmp; memcpy(Pico.rom + Pico.romsize, Pico.rom, 0x8000); PicoCartMemSetup = carthw_prot_lk3_mem_setup; diff --git a/pico/carthw/svp/svp.c b/pico/carthw/svp/svp.c index 76904ae1..a3ed89eb 100644 --- a/pico/carthw/svp/svp.c +++ b/pico/carthw/svp/svp.c @@ -115,20 +115,17 @@ static void PicoSVPExit(void) void PicoSVPStartup(void) { - void *tmp; + int ret; elprintf(EL_STATUS, "SVP startup"); - tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp)); - if (tmp == NULL) - { + ret = PicoCartResize(Pico.romsize + sizeof(*svp)); + if (ret != 0) { elprintf(EL_STATUS|EL_SVP, "OOM for SVP data"); return; } - //PicoOpt &= ~0x20000; - Pico.rom = tmp; - svp = (void *) ((char *)tmp + 0x200000); + svp = (void *) ((char *)Pico.rom + Pico.romsize); memset(svp, 0, sizeof(*svp)); // init SVP compiler @@ -156,4 +153,3 @@ void PicoSVPStartup(void) PicoAHW |= PAHW_SVP; } - diff --git a/pico/cd/sek.c b/pico/cd/sek.c index 789bb18b..65c8c233 100644 --- a/pico/cd/sek.c +++ b/pico/cd/sek.c @@ -52,10 +52,7 @@ static void SekResetAckS68k(void) static int SekUnrecognizedOpcodeS68k(void) { - unsigned int pc, op; - pc = SekPcS68k; - op = PicoCpuCS68k.read16(pc); - elprintf(EL_ANOMALY, "Unrecognized Opcode %04x @ %06x", op, pc); + elprintf(EL_ANOMALY, "Unrecognized Opcode @ %06x", SekPcS68k); //exit(1); return 0; } diff --git a/platform/linux/plat.c b/platform/linux/plat.c index 492007cd..f5742b92 100644 --- a/platform/linux/plat.c +++ b/platform/linux/plat.c @@ -1,3 +1,4 @@ +#define _GNU_SOURCE #include #include #include @@ -112,8 +113,9 @@ int plat_wait_event(int *fds_hnds, int count, int timeout_ms) void *plat_mmap(unsigned long addr, size_t size) { void *req, *ret; + req = (void *)addr; - ret = mmap(req, size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0); + ret = mmap(req, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if (ret == MAP_FAILED) return NULL; if (ret != req) @@ -122,6 +124,19 @@ void *plat_mmap(unsigned long addr, size_t size) return ret; } +void *plat_mremap(void *ptr, size_t oldsize, size_t newsize) +{ + void *ret; + + ret = mremap(ptr, oldsize, newsize, MREMAP_MAYMOVE); + if (ret == MAP_FAILED) + return NULL; + if (ret != ptr) + printf("warning: mremap moved: %p -> %p\n", ptr, ret); + + return ret; +} + void plat_munmap(void *ptr, size_t size) { munmap(ptr, size);