From: Paul Cercueil Date: Sat, 11 Feb 2023 14:17:13 +0000 (+0000) Subject: Support compiling without mmap functions X-Git-Tag: r24~237 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=commitdiff_plain;h=5e282df80d579f9a19c77a655c2c0dda6dc2c7b4 Support compiling without mmap functions Add NO_MMAP option in Makefile.libretro that can be turned ON on platforms that don't support mmap(), and for which memory mapping hooks must be provided. Signed-off-by: Paul Cercueil --- diff --git a/Makefile b/Makefile index ded26893..7b7ce5ce 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ CFLAGS += -Wall -ggdb -Iinclude -ffast-math ifndef DEBUG CFLAGS += -O2 -DNDEBUG endif +CFLAGS += -DHAVE_MMAP=$(if $(NO_MMAP),0,1) CXXFLAGS += $(CFLAGS) #DRC_DBG = 1 #PCNT = 1 diff --git a/libpcsxcore/memmap.h b/libpcsxcore/memmap.h index 262cd7c2..da1d0e11 100644 --- a/libpcsxcore/memmap.h +++ b/libpcsxcore/memmap.h @@ -34,6 +34,9 @@ #include <_mingw.h> #endif +#endif //_WIN32 + +#if defined(_WIN32) || !HAVE_MMAP #include #ifdef __cplusplus @@ -60,12 +63,14 @@ extern "C" { #define MS_SYNC 2 #define MS_INVALIDATE 4 +#ifdef _WIN32 void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off); int munmap(void *addr, size_t len); int mprotect(void *addr, size_t len, int prot); int msync(void *addr, size_t len, int flags); int mlock(const void *addr, size_t len); int munlock(const void *addr, size_t len); +#endif #ifdef __cplusplus }; diff --git a/libpcsxcore/psxmem.c b/libpcsxcore/psxmem.c index 54219ae0..14e7a9e9 100644 --- a/libpcsxcore/psxmem.c +++ b/libpcsxcore/psxmem.c @@ -44,15 +44,26 @@ static void * psxMapDefault(unsigned long addr, size_t size, int is_fixed, enum psxMapTag tag) { +#if !HAVE_MMAP + void *ptr; + + ptr = malloc(size); + return ptr ? ptr : MAP_FAILED; +#else int flags = MAP_PRIVATE | MAP_ANONYMOUS; return mmap((void *)(uintptr_t)addr, size, PROT_READ | PROT_WRITE, flags, -1, 0); +#endif } static void psxUnmapDefault(void *ptr, size_t size, enum psxMapTag tag) { +#if !HAVE_MMAP + free(ptr); +#else munmap(ptr, size); +#endif } void *(*psxMapHook)(unsigned long addr, size_t size, int is_fixed,