From: Frode Solheim Date: Fri, 4 Sep 2015 23:27:05 +0000 (+0200) Subject: memory/mman: compatibility updates for FS-UAE X-Git-Tag: 3200~89^2~1 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=024508e7ae5d384fda1d0dce10f115c4d8a0367c;p=francis%2Fwinuae.git memory/mman: compatibility updates for FS-UAE --- diff --git a/include/uae/mman.h b/include/uae/mman.h new file mode 100644 index 00000000..393fa571 --- /dev/null +++ b/include/uae/mman.h @@ -0,0 +1,34 @@ +#ifndef UAE_MMAN_H +#define UAE_MMAN_H + +#include "uae/types.h" + +#define MAX_SHMID 256 + +typedef int uae_key_t; + +/* One shmid data structure for each shared memory segment in the system. */ +struct uae_shmid_ds { + uae_key_t key; + uae_u32 size; + uae_u32 rosize; + void *addr; + TCHAR name[MAX_PATH]; + void *attached; + int mode; + void *natmembase; + bool fake; + int maprom; +}; + +void *uae_shmat(addrbank *ab, int shmid, void *shmaddr, int shmflg); +int uae_shmdt(const void *shmaddr); +int uae_shmget(uae_key_t key, size_t size, int shmflg, const TCHAR *name); +int uae_shmctl(int shmid, int cmd, struct uae_shmid_ds *buf); + +#define UAE_IPC_PRIVATE 0x01 +#define UAE_IPC_RMID 0x02 +#define UAE_IPC_CREAT 0x04 +#define UAE_IPC_STAT 0x08 + +#endif /* UAE_MMAN_H */ diff --git a/memory.cpp b/memory.cpp index ad8ad73d..61925290 100644 --- a/memory.cpp +++ b/memory.cpp @@ -552,7 +552,7 @@ static void REGPARAM2 chipmem_bput_ce2 (uaecptr addr, uae_u32 b) #endif -uae_u32 REGPARAM2 chipmem_lget (uaecptr addr) +static uae_u32 REGPARAM2 chipmem_lget (uaecptr addr) { uae_u32 *m; @@ -625,24 +625,28 @@ static uae_u32 chipmem_dummy (void) /* not really right but something random that has more ones than zeros.. */ return 0xffff & ~((1 << (uaerand () & 31)) | (1 << (uaerand () & 31))); } -void REGPARAM2 chipmem_dummy_bput (uaecptr addr, uae_u32 b) + +static void REGPARAM2 chipmem_dummy_bput (uaecptr addr, uae_u32 b) { #ifdef JIT special_mem |= S_WRITE; #endif } -void REGPARAM2 chipmem_dummy_wput (uaecptr addr, uae_u32 b) + +static void REGPARAM2 chipmem_dummy_wput (uaecptr addr, uae_u32 b) { #ifdef JIT special_mem |= S_WRITE; #endif } -void REGPARAM2 chipmem_dummy_lput (uaecptr addr, uae_u32 b) + +static void REGPARAM2 chipmem_dummy_lput (uaecptr addr, uae_u32 b) { #ifdef JIT special_mem |= S_WRITE; #endif } + static uae_u32 REGPARAM2 chipmem_dummy_bget (uaecptr addr) { #ifdef JIT @@ -1308,7 +1312,6 @@ static int read_kickstart (struct zfile *f, uae_u8 *mem, int size, int dochecksu #endif if (i < size - 20) kickstart_fix_checksum (mem, size); - j = 1; while (j < i) j <<= 1; @@ -1485,7 +1488,6 @@ extern int seriallog; static bool load_kickstart_replacement (void) { struct zfile *f; - f = zfile_fopen_data (_T("aros.gz"), arosrom_len, arosrom); if (!f) return false; @@ -1500,6 +1502,7 @@ static bool load_kickstart_replacement (void) mapped_malloc (&extendedkickmem_bank); read_kickstart (f, extendedkickmem_bank.baseaddr, ROM_SIZE_512, 0, 1); + kickmem_bank.allocated = ROM_SIZE_512; kickmem_bank.mask = ROM_SIZE_512 - 1; read_kickstart (f, kickmem_bank.baseaddr, ROM_SIZE_512, 1, 0); @@ -1645,10 +1648,7 @@ void mapped_free (addrbank *ab) #else -#include -#include -#include -#include +#include shmpiece *shm_start; @@ -1701,7 +1701,7 @@ static void delete_shmmaps (uae_u32 start, uae_u32 size) size = x->size; } - shmdt (x->native_address); + uae_shmdt (x->native_address); size -= x->size; start += x->size; if (x->next) @@ -1737,7 +1737,7 @@ static void add_shmmaps (uae_u32 start, addrbank *what) y = xmalloc (shmpiece, 1); *y = *x; base = ((uae_u8 *) NATMEM_OFFSET) + start; - y->native_address = (uae_u8*)shmat (what, y->id, base, 0); + y->native_address = (uae_u8*)uae_shmat (what, y->id, base, 0); if (y->native_address == (void *) -1) { write_log (_T("NATMEM: Failure to map existing at %08x (%p)\n"), start, base); dumplist (); @@ -1778,7 +1778,7 @@ bool mapped_malloc (addrbank *ab) return ab->baseaddr != NULL; } - id = shmget (IPC_PRIVATE, ab->allocated, 0x1ff, ab->label); + id = uae_shmget (UAE_IPC_PRIVATE, ab->allocated, 0x1ff, ab->label); if (id == -1) { nocanbang (); if (recurse) @@ -1789,8 +1789,8 @@ bool mapped_malloc (addrbank *ab) return ab->baseaddr != NULL; } if (!(ab->flags & ABFLAG_NOALLOC)) { - answer = shmat (ab, id, 0, 0); - shmctl (id, IPC_RMID, NULL); + answer = uae_shmat (ab, id, 0, 0); + uae_shmctl (id, UAE_IPC_RMID, NULL); } else { answer = ab->baseaddr; } @@ -2230,7 +2230,7 @@ uae_u32 getz2endaddr (void) return start + 2 * 1024 * 1024; } -void map_banks_set(addrbank *bank, int start, int size, int realsize) +static void map_banks_set(addrbank *bank, int start, int size, int realsize) { bank->startmask = start << 16; map_banks(bank, start, size, realsize); @@ -2509,8 +2509,9 @@ void memory_reset (void) map_banks_set(&rtarea_bank, rtarea_base >> 16, 1, 0); #endif - if ((cloanto_rom || currprefs.cs_ksmirror_e0) && (currprefs.maprom != 0xe00000) && !extendedkickmem_type) + if ((cloanto_rom || currprefs.cs_ksmirror_e0) && (currprefs.maprom != 0xe00000) && !extendedkickmem_type) { map_banks(&kickmem_bank, 0xE0, 8, 0); + } if (currprefs.cs_ksmirror_a8) { if (extendedkickmem2_bank.allocated) { map_banks_set(&extendedkickmem2_bank, 0xa8, 16, 0); @@ -2992,7 +2993,7 @@ uae_u8 *save_bram (int *len) return bogomem_bank.baseaddr; } -uae_u8 *save_mem25bitram (int *len) +static uae_u8 *save_mem25bitram (int *len) { *len = mem25bit_bank.allocated; return mem25bit_bank.baseaddr; diff --git a/od-win32/mman.cpp b/od-win32/mman.cpp index cc1b4057..da4890c8 100644 --- a/od-win32/mman.cpp +++ b/od-win32/mman.cpp @@ -7,13 +7,16 @@ #include "sysconfig.h" #include "sysdeps.h" #include "memory.h" -#include "sys/mman.h" +#include "uae/mman.h" #include "options.h" #include "autoconf.h" #include "gfxboard.h" #include "cpuboard.h" #include "rommgr.h" +#include "newcpu.h" +#ifdef WINUAE #include "win32.h" +#endif #if defined(NATMEM_OFFSET) @@ -25,7 +28,7 @@ uae_u32 max_z3fastmem; #define MAXZ3MEM32 0x7F000000 #define MAXZ3MEM64 0xF0000000 -static struct shmid_ds shmids[MAX_SHMID]; +static struct uae_shmid_ds shmids[MAX_SHMID]; uae_u8 *natmem_offset_allocated, *natmem_offset, *natmem_offset_end; static uae_u8 *p96mem_offset; static int p96mem_size; @@ -45,6 +48,9 @@ static void virtualfreewithlock (LPVOID addr, SIZE_T size, DWORD freetype) VirtualFree(addr, size, freetype); } +#ifdef JIT +#ifdef _WIN32 + void cache_free (uae_u8 *cache) { virtualfreewithlock (cache, 0, MEM_RELEASE); @@ -55,6 +61,9 @@ uae_u8 *cache_alloc (int size) return virtualallocwithlock (NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); } +#endif /*_WIN32 */ +#endif /* JIT */ + static uae_u32 lowmem (void) { uae_u32 change = 0; @@ -97,13 +106,15 @@ void mman_ResetWatch (PVOID lpBaseAddress, SIZE_T dwRegionSize) } static uae_u64 size64; +#ifdef _WIN32 typedef BOOL (CALLBACK* GLOBALMEMORYSTATUSEX)(LPMEMORYSTATUSEX); +#endif static void clear_shm (void) { shm_start = NULL; for (int i = 0; i < MAX_SHMID; i++) { - memset (&shmids[i], 0, sizeof (struct shmid_ds)); + memset (&shmids[i], 0, sizeof(struct uae_shmid_ds)); shmids[i].key = -1; } } @@ -112,17 +123,26 @@ bool preinit_shm (void) { uae_u64 total64; uae_u64 totalphys64; +#ifdef _WIN32 MEMORYSTATUS memstats; GLOBALMEMORYSTATUSEX pGlobalMemoryStatusEx; MEMORYSTATUSEX memstatsex; +#endif uae_u32 max_allowed_mman; if (natmem_offset_allocated) +#ifdef _WIN32 VirtualFree (natmem_offset_allocated, 0, MEM_RELEASE); +#else +#endif natmem_offset_allocated = NULL; natmem_offset = NULL; - if (p96mem_offset) + if (p96mem_offset) { +#ifdef _WIN32 VirtualFree (p96mem_offset, 0, MEM_RELEASE); +#else +#endif + } p96mem_offset = NULL; GetSystemInfo (&si); @@ -139,6 +159,7 @@ bool preinit_shm (void) if (maxmem > max_allowed_mman) max_allowed_mman = maxmem; +#ifdef _WIN32 memstats.dwLength = sizeof(memstats); GlobalMemoryStatus(&memstats); totalphys64 = memstats.dwTotalPhys; @@ -151,6 +172,8 @@ bool preinit_shm (void) total64 = memstatsex.ullAvailPageFile + memstatsex.ullTotalPhys; } } +#else +#endif size64 = total64; if (os_64bit) { if (size64 > MAXZ3MEM64) @@ -186,7 +209,7 @@ bool preinit_shm (void) if (natmem_size <= 768 * 1024 * 1024) { uae_u32 p = 0x78000000 - natmem_size; for (;;) { - natmem_offset_allocated = (uae_u8*)VirtualAlloc ((void*)p, natmem_size, MEM_RESERVE | MEM_WRITE_WATCH, PAGE_READWRITE); + natmem_offset_allocated = (uae_u8*) VirtualAlloc((void*)(intptr_t)p, natmem_size, MEM_RESERVE | MEM_WRITE_WATCH, PAGE_READWRITE); if (natmem_offset_allocated) break; p -= 128 * 1024 * 1024; @@ -196,8 +219,10 @@ bool preinit_shm (void) } if (!natmem_offset_allocated) { DWORD vaflags = MEM_RESERVE | MEM_WRITE_WATCH; +#ifdef _WIN32 if (!os_vista) vaflags |= MEM_TOP_DOWN; +#endif for (;;) { natmem_offset_allocated = (uae_u8*)VirtualAlloc (NULL, natmem_size, vaflags, PAGE_READWRITE); if (natmem_offset_allocated) @@ -239,7 +264,7 @@ static void resetmem (bool decommit) if (!shm_start) return; for (i = 0; i < MAX_SHMID; i++) { - struct shmid_ds *s = &shmids[i]; + struct uae_shmid_ds *s = &shmids[i]; int size = s->size; uae_u8 *shmaddr; uae_u8 *result; @@ -298,13 +323,12 @@ static int doinit_shm (void) uae_u32 size, totalsize, z3size, natmemsize, othersize; uae_u32 startbarrier, z3offset, align; int rounds = 0; - ULONG z3rtgmem_size; + uae_u32 z3rtgmem_size; canbang = 1; natmem_offset = natmem_offset_allocated; for (;;) { int lowround = 0; - uae_u8 *blah = NULL; if (rounds > 0) write_log (_T("NATMEM: retrying %d..\n"), rounds); rounds++; @@ -327,7 +351,7 @@ static int doinit_shm (void) int change = lowmem (); if (!change) return 0; - write_log (_T("NATMEM: %d, %dM > %dM = %dM\n"), ++lowround, totalsize >> 20, size64 >> 20, (totalsize - change) >> 20); + write_log (_T("NATMEM: %d, %dM > %lldM = %dM\n"), ++lowround, totalsize >> 20, size64 >> 20, (totalsize - change) >> 20); totalsize -= change; } if ((rounds > 1 && totalsize < 0x10000000) || rounds > 20) { @@ -514,15 +538,15 @@ void mapped_free (addrbank *ab) while(x) { if(ab->baseaddr == x->native_address) - shmdt (x->native_address); + uae_shmdt (x->native_address); x = x->next; } x = shm_start; while(x) { - struct shmid_ds blah; + struct uae_shmid_ds blah; if (ab->baseaddr == x->native_address) { - if (shmctl (x->id, IPC_STAT, &blah) == 0) - shmctl (x->id, IPC_RMID, &blah); + if (uae_shmctl (x->id, UAE_IPC_STAT, &blah) == 0) + uae_shmctl (x->id, UAE_IPC_RMID, &blah); } x = x->next; } @@ -530,9 +554,9 @@ void mapped_free (addrbank *ab) write_log(_T("mapped_free direct %s\n"), ab->name); } -static key_t get_next_shmkey (void) +static uae_key_t get_next_shmkey (void) { - key_t result = -1; + uae_key_t result = -1; int i; for (i = 0; i < MAX_SHMID; i++) { if (shmids[i].key == -1) { @@ -544,7 +568,7 @@ static key_t get_next_shmkey (void) return result; } -STATIC_INLINE key_t find_shmkey (key_t key) +STATIC_INLINE uae_key_t find_shmkey (uae_key_t key) { int result = -1; if(shmids[key].key == key) { @@ -553,16 +577,10 @@ STATIC_INLINE key_t find_shmkey (key_t key) return result; } -int mprotect (void *addr, size_t len, int prot) -{ - int result = 0; - return result; -} - -void *shmat (addrbank *ab, int shmid, void *shmaddr, int shmflg) +void *uae_shmat (addrbank *ab, int shmid, void *shmaddr, int shmflg) { void *result = (void *)-1; - BOOL got = FALSE, readonly = FALSE, maprom = FALSE; + bool got = false, readonly = false, maprom = false; int p96special = FALSE; #ifdef NATMEM_OFFSET @@ -582,47 +600,47 @@ void *shmat (addrbank *ab, int shmid, void *shmaddr, int shmflg) if ((uae_u8*)shmaddr < natmem_offset) { if(!_tcscmp (shmids[shmid].name, _T("chip"))) { shmaddr=natmem_offset; - got = TRUE; + got = true; if (getz2endaddr () <= 2 * 1024 * 1024 || currprefs.chipmem_size < 2 * 1024 * 1024) size += BARRIER; } else if(!_tcscmp (shmids[shmid].name, _T("kick"))) { shmaddr=natmem_offset + 0xf80000; - got = TRUE; + got = true; size += BARRIER; - readonly = TRUE; - maprom = TRUE; + readonly = true; + maprom = true; } else if(!_tcscmp (shmids[shmid].name, _T("rom_a8"))) { shmaddr=natmem_offset + 0xa80000; - got = TRUE; - readonly = TRUE; - maprom = TRUE; + got = true; + readonly = true; + maprom = true; } else if(!_tcscmp (shmids[shmid].name, _T("rom_e0"))) { shmaddr=natmem_offset + 0xe00000; - got = TRUE; - readonly = TRUE; - maprom = TRUE; + got = true; + readonly = true; + maprom = true; } else if(!_tcscmp (shmids[shmid].name, _T("rom_f0"))) { shmaddr=natmem_offset + 0xf00000; - got = TRUE; - readonly = TRUE; + got = true; + readonly = true; } else if(!_tcscmp (shmids[shmid].name, _T("rom_f0_ppc"))) { // this is flash and also contains IO shmaddr=natmem_offset + 0xf00000; - got = TRUE; - readonly = FALSE; + got = true; + readonly = true; } else if (!_tcscmp(shmids[shmid].name, _T("rtarea"))) { shmaddr = natmem_offset + rtarea_base; - got = TRUE; - readonly = TRUE; + got = true; + readonly = true; readonlysize = RTAREA_TRAPS; } else if (!_tcscmp(shmids[shmid].name, _T("fmv_rom"))) { - got = TRUE; + got = true; shmaddr = natmem_offset + 0x200000; } else if (!_tcscmp(shmids[shmid].name, _T("fmv_ram"))) { - got = TRUE; + got = true; shmaddr = natmem_offset + 0x280000; } else if(!_tcscmp (shmids[shmid].name, _T("fast"))) { - got = TRUE; + got = true; if (size < 524288) { shmaddr=natmem_offset + 0xec0000; } else { @@ -631,7 +649,7 @@ void *shmat (addrbank *ab, int shmid, void *shmaddr, int shmflg) size += BARRIER; } } else if(!_tcscmp (shmids[shmid].name, _T("fast2"))) { - got = TRUE; + got = true; if (size < 524288) { shmaddr=natmem_offset + 0xec0000; } else { @@ -643,13 +661,13 @@ void *shmat (addrbank *ab, int shmid, void *shmaddr, int shmflg) } } else if(!_tcscmp (shmids[shmid].name, _T("fast2"))) { shmaddr=natmem_offset + 0x200000; - got = TRUE; + got = true; if (!(currprefs.rtgmem_size && gfxboard_get_configtype(currprefs.rtgmem_type) == 3)) size += BARRIER; } else if(!_tcscmp (shmids[shmid].name, _T("z2_gfx"))) { ULONG start = getz2rtgaddr (size); - got = TRUE; - p96special = TRUE; + got = true; + p96special = true; shmaddr = natmem_offset + start; gfxmem_bank.start = start; if (start + currprefs.rtgmem_size < 10 * 1024 * 1024) @@ -658,62 +676,62 @@ void *shmat (addrbank *ab, int shmid, void *shmaddr, int shmflg) shmaddr=natmem_offset + a3000lmem_bank.start; if (!a3000hmem_bank.start) size += BARRIER; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("csmk1_maprom"))) { shmaddr = natmem_offset + 0x07f80000; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("25bitram"))) { shmaddr = natmem_offset + 0x01000000; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("ramsey_high"))) { shmaddr = natmem_offset + 0x08000000; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("dkb"))) { shmaddr = natmem_offset + 0x10000000; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("fusionforty"))) { shmaddr = natmem_offset + 0x11000000; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("blizzard_40"))) { shmaddr = natmem_offset + 0x40000000; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("blizzard_48"))) { shmaddr = natmem_offset + 0x48000000; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("blizzard_68"))) { shmaddr = natmem_offset + 0x68000000; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("blizzard_70"))) { shmaddr = natmem_offset + 0x70000000; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("cyberstorm"))) { shmaddr = natmem_offset + 0x0c000000; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("cyberstormmaprom"))) { shmaddr = natmem_offset + 0xfff00000; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("z3"))) { shmaddr=natmem_offset + z3fastmem_bank.start; if (!currprefs.z3fastmem2_size) size += BARRIER; - got = TRUE; + got = true; } else if(!_tcscmp (shmids[shmid].name, _T("z3_2"))) { shmaddr=natmem_offset + z3fastmem_bank.start + currprefs.z3fastmem_size; size += BARRIER; - got = TRUE; + got = true; } else if(!_tcscmp (shmids[shmid].name, _T("z3_chip"))) { shmaddr=natmem_offset + z3chipmem_bank.start; size += BARRIER; - got = TRUE; + got = true; } else if(!_tcscmp (shmids[shmid].name, _T("z3_gfx"))) { - got = TRUE; - p96special = TRUE; + got = true; + p96special = true; gfxmem_bank.start = p96mem_offset - natmem_offset; shmaddr = natmem_offset + gfxmem_bank.start; size += BARRIER; } else if(!_tcscmp (shmids[shmid].name, _T("bogo"))) { shmaddr=natmem_offset+0x00C00000; - got = TRUE; + got = true; if (currprefs.bogomem_size <= 0x100000) size += BARRIER; #if 0 @@ -728,53 +746,53 @@ void *shmat (addrbank *ab, int shmid, void *shmaddr, int shmflg) #endif } else if(!_tcscmp (shmids[shmid].name, _T("custmem1"))) { shmaddr=natmem_offset + currprefs.custom_memory_addrs[0]; - got = TRUE; + got = true; } else if(!_tcscmp (shmids[shmid].name, _T("custmem2"))) { shmaddr=natmem_offset + currprefs.custom_memory_addrs[1]; - got = TRUE; + got = true; } else if(!_tcscmp (shmids[shmid].name, _T("hrtmem"))) { shmaddr=natmem_offset + 0x00a10000; - got = TRUE; + got = true; } else if(!_tcscmp (shmids[shmid].name, _T("arhrtmon"))) { shmaddr=natmem_offset + 0x00800000; size += BARRIER; - got = TRUE; + got = true; } else if(!_tcscmp (shmids[shmid].name, _T("xpower_e2"))) { shmaddr=natmem_offset + 0x00e20000; size += BARRIER; - got = TRUE; + got = true; } else if(!_tcscmp (shmids[shmid].name, _T("xpower_f2"))) { shmaddr=natmem_offset + 0x00f20000; size += BARRIER; - got = TRUE; + got = true; } else if(!_tcscmp (shmids[shmid].name, _T("nordic_f0"))) { shmaddr=natmem_offset + 0x00f00000; size += BARRIER; - got = TRUE; + got = true; } else if(!_tcscmp (shmids[shmid].name, _T("nordic_f4"))) { shmaddr=natmem_offset + 0x00f40000; size += BARRIER; - got = TRUE; + got = true; } else if(!_tcscmp (shmids[shmid].name, _T("nordic_f6"))) { shmaddr=natmem_offset + 0x00f60000; size += BARRIER; - got = TRUE; + got = true; } else if(!_tcscmp(shmids[shmid].name, _T("superiv_b0"))) { shmaddr=natmem_offset + 0x00b00000; size += BARRIER; - got = TRUE; + got = true; } else if(!_tcscmp (shmids[shmid].name, _T("superiv_d0"))) { shmaddr=natmem_offset + 0x00d00000; size += BARRIER; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("superiv_e0"))) { shmaddr = natmem_offset + 0x00e00000; size += BARRIER; - got = TRUE; + got = true; } else if (!_tcscmp(shmids[shmid].name, _T("ram_a8"))) { shmaddr = natmem_offset + 0x00a80000; size += BARRIER; - got = TRUE; + got = true; } } #endif @@ -794,7 +812,7 @@ void *shmat (addrbank *ab, int shmid, void *shmaddr, int shmflg) if (result == NULL) { result = (void*)-1; error_log (_T("Memory %s failed to allocate %p: VA %08X - %08X %x (%dk). Error %d."), - shmids[shmid].name, shmaddr, + shmids[shmid].name, shmaddr, (uae_u8*)shmaddr - natmem_offset, (uae_u8*)shmaddr - natmem_offset + size, size, size >> 10, GetLastError ()); } else { @@ -811,8 +829,7 @@ void unprotect_maprom (void) { bool protect = false; for (int i = 0; i < MAX_SHMID; i++) { - DWORD old; - struct shmid_ds *shm = &shmids[i]; + struct uae_shmid_ds *shm = &shmids[i]; if (shm->mode != PAGE_READONLY) continue; if (!shm->attached || !shm->rosize) @@ -820,6 +837,7 @@ void unprotect_maprom (void) if (shm->maprom <= 0) continue; shm->maprom = -1; + DWORD old; if (!VirtualProtect (shm->attached, shm->rosize, protect ? PAGE_READONLY : PAGE_READWRITE, &old)) { write_log (_T("unprotect_maprom VP %08X - %08X %x (%dk) failed %d\n"), (uae_u8*)shm->attached - natmem_offset, (uae_u8*)shm->attached - natmem_offset + shm->size, @@ -836,14 +854,14 @@ void protect_roms (bool protect) return; } for (int i = 0; i < MAX_SHMID; i++) { - DWORD old; - struct shmid_ds *shm = &shmids[i]; + struct uae_shmid_ds *shm = &shmids[i]; if (shm->mode != PAGE_READONLY) continue; if (!shm->attached || !shm->rosize) continue; if (shm->maprom < 0 && protect) continue; + DWORD old; if (!VirtualProtect (shm->attached, shm->rosize, protect ? PAGE_READONLY : PAGE_READWRITE, &old)) { write_log (_T("protect_roms VP %08X - %08X %x (%dk) failed %d\n"), (uae_u8*)shm->attached - natmem_offset, (uae_u8*)shm->attached - natmem_offset + shm->size, @@ -852,17 +870,17 @@ void protect_roms (bool protect) } } -int shmdt (const void *shmaddr) +int uae_shmdt (const void *shmaddr) { return 0; } -int shmget (key_t key, size_t size, int shmflg, const TCHAR *name) +int uae_shmget (uae_key_t key, size_t size, int shmflg, const TCHAR *name) { int result = -1; - if((key == IPC_PRIVATE) || ((shmflg & IPC_CREAT) && (find_shmkey (key) == -1))) { - write_log (_T("shmget of size %d (%dk) for %s\n"), size, size >> 10, name); + if ((key == UAE_IPC_PRIVATE) || ((shmflg & UAE_IPC_CREAT) && (find_shmkey (key) == -1))) { + write_log (_T("shmget of size %zd (%zdk) for %s\n"), size, size >> 10, name); if ((result = get_next_shmkey ()) != -1) { shmids[result].size = size; _tcscpy (shmids[result].name, name); @@ -873,18 +891,18 @@ int shmget (key_t key, size_t size, int shmflg, const TCHAR *name) return result; } -int shmctl (int shmid, int cmd, struct shmid_ds *buf) +int uae_shmctl (int shmid, int cmd, struct uae_shmid_ds *buf) { int result = -1; if ((find_shmkey (shmid) != -1) && buf) { switch (cmd) { - case IPC_STAT: + case UAE_IPC_STAT: *buf = shmids[shmid]; result = 0; break; - case IPC_RMID: + case UAE_IPC_RMID: VirtualFree (shmids[shmid].attached, shmids[shmid].size, MEM_DECOMMIT); shmids[shmid].key = -1; shmids[shmid].name[0] = '\0'; diff --git a/od-win32/shm.cpp b/od-win32/shm.cpp deleted file mode 100644 index 65552280..00000000 --- a/od-win32/shm.cpp +++ /dev/null @@ -1,172 +0,0 @@ -#include - -#include "sysconfig.h" -#include "sysdeps.h" -#include "sys/mman.h" -#include "include/memory.h" -#include "options.h" -#include "autoconf.h" - -static void win32_error (const char *format,...) -{ - LPVOID lpMsgBuf; - va_list arglist; - char buf[1000]; - - va_start (arglist, format ); - vsprintf (buf, format, arglist); - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, - NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &lpMsgBuf,0,NULL); - write_log ("%s: %s",buf , (char*)lpMsgBuf); - va_end( arglist ); -} - -static struct shmid_ds shmids[ MAX_SHMID ]; - -uae_u32 natmem_offset; - -void init_shm( void ) -{ - int i; - -#ifdef NATMEM_OFFSET - uae_u32 addr; - - canbang = 1; - for( i = 0; i < MAX_SHMID; i++ ) { - shmids[i].attached = 0; - shmids[i].key = -1; - shmids[i].size = 0; - shmids[i].addr = (void*)0xffffffff; - shmids[i].name[0] = 0; - shmids[i].filemapping = INVALID_HANDLE_VALUE; - } - addr = 0x10000000; - while( addr < 0xa0000000 ) { - if (VirtualAlloc( (LPVOID)addr, 0x18800000, MEM_RESERVE, PAGE_EXECUTE_READWRITE )) { - VirtualFree ( (LPVOID)addr, 0, MEM_RELEASE); - addr += 0x01000000; - natmem_offset = addr; - break; - } - addr += 0x01000000; - } - if (natmem_offset) { - write_log ( "NATMEM: Our special area is 0x%x\n", natmem_offset); - } else { - canbang = 0; - } -#endif -} - -static key_t get_next_shmkey( void ) -{ - key_t result = -1; - int i; - for( i = 0; i < MAX_SHMID; i++ ) - { - if( shmids[i].key == -1 ) - { - shmids[i].key = i; - result = i; - break; - } - } - return result; -} - -STATIC_INLINE key_t find_shmkey( key_t key ) -{ - int result = -1; - if( shmids[key].key == key ) - { - result = key; - } - return result; -} - -int mprotect(void *addr, size_t len, int prot) -{ - int result = 0; - - return result; -} - -int shmget(key_t key, size_t size, int shmflg, char *name) -{ - int result = -1; - - if( ( key == IPC_PRIVATE ) || ( ( shmflg & IPC_CREAT ) && ( find_shmkey( key ) == -1) ) ) { - write_log ( "shmget of size %d for %s\n", size, name ); - if( ( result = get_next_shmkey() ) != -1 ) { - HANDLE h = CreateFileMapping (NULL, 0, PAGE_READWRITE, 0, size, NULL); - if (h == NULL) - win32_error ("CreateFileMapping %d\n", size); - shmids[result].filemapping = h; - shmids[result].size = size; - strcpy( shmids[result].name, name ); - } else { - result = -1; - } - } - return result; -} - -int shmctl(int shmid, int cmd, struct shmid_ds *buf) -{ - int result = -1; - - return result; - if( ( find_shmkey( shmid ) != -1 ) && buf ) { - switch( cmd ) - { - case IPC_STAT: - *buf = shmids[shmid]; - result = 0; - break; - case IPC_RMID: - shmids[shmid].key = -1; - shmids[shmid].name[0] = '\0'; - shmids[shmid].size = 0; - CloseHandle(shmids[shmid].filemapping); - shmids[shmid].filemapping = INVALID_HANDLE_VALUE; - result = 0; - break; - } - } - return result; -} - -void *shmat(int shmid, LPVOID shmaddr, int shmflg) -{ - struct shmid_ds *shm = &shmids[shmid]; - - if(shm->addr == shmaddr ) - return shm->addr; - shm->addr = MapViewOfFileEx (shm->filemapping, FILE_MAP_WRITE, 0, 0, shm->size, shmaddr); - if (addr == NULL) - win32_error("MapViewOfFileEx %08X", shmaddr); - write_log ("shmat %08X -> %08X\n", shmaddr, shm->addr); - shm->attached = 1; - return shm->addr; -} - -int shmdt(const void *shmaddr) -{ - int i; - if (shmaddr == (void*)0xffffffff) - return 0; - write_log ("shmdt: %08X\n", shmaddr); - if (UnmapViewOfFile ((LPCVOID)shmaddr) == FALSE) { - win32_error("UnmapViewOfFile %08X", shmaddr); - return 0; - } - for( i = 0; i < MAX_SHMID; i++ ) { - struct shmid_ds *shm = &shmids[i]; - if (shm->addr == shmaddr) { - shm->addr = (void*)0xffffffff; - } - } - return -1; -} \ No newline at end of file