From: Paul Cercueil Date: Sat, 11 Feb 2023 14:17:13 +0000 (+0000) Subject: Support compiling without mmap functions X-Git-Tag: r24l~290^2~3 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71012b7bb948465c33ae3d22123388ad0eed6deb;p=pcsx_rearmed.git 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 4edc0076..779f67a4 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ else CFLAGS += -O2 -DNDEBUG endif endif +CFLAGS += -DHAVE_MMAP=$(if $(NO_MMAP),0,1) CXXFLAGS += $(CFLAGS) #DRC_DBG = 1 #PCNT = 1 @@ -94,7 +95,6 @@ LIGHTREC_CUSTOM_MAP ?= 0 LIGHTREC_THREADED_COMPILER ?= 0 CFLAGS += -DLIGHTREC_CUSTOM_MAP=$(LIGHTREC_CUSTOM_MAP) \ -DLIGHTREC_ENABLE_THREADED_COMPILER=$(LIGHTREC_THREADED_COMPILER) -deps/lightning/lib/%.o: CFLAGS += -DHAVE_MMAP ifeq ($(LIGHTREC_CUSTOM_MAP),1) LDLIBS += -lrt OBJS += libpcsxcore/lightrec/mem.o 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,