From: notaz Date: Tue, 1 Oct 2024 16:43:13 +0000 (+0300) Subject: add dedicated mmap functions for libnx X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d4dbe7a2b2b6ad967401437dce3a355546e682a;p=pcsx_rearmed.git add dedicated mmap functions for libnx the previous code would call svcUnmapPhysicalMemory() on mem possibly allocated by aligned_alloc() which didn't look right --- diff --git a/Makefile.libretro b/Makefile.libretro index 67754703..4b466e52 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -249,6 +249,7 @@ else ifeq ($(platform), libnx) CFLAGS += -Ifrontend/switch -ftree-vectorize NO_POSIX_MEMALIGN := 1 NO_PTHREAD=1 + NO_MMAP := 1 # for psxmem LIBPTHREAD := STATIC_LINKING=1 BUILTIN_GPU = neon diff --git a/frontend/libretro.c b/frontend/libretro.c index bcd3c615..52c2c1c9 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -498,6 +498,31 @@ static void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag) } #endif +#ifdef HAVE_LIBNX +static void *pl_switch_mmap(unsigned long addr, size_t size, + enum psxMapTag tag, int *can_retry_addr) +{ + void *ret = MAP_FAILED; + *can_retry_addr = 0; + (void)addr; + + // there's svcMapPhysicalMemory() but user logs show it doesn't hand out + // any desired addresses, so don't even bother + ret = aligned_alloc(0x1000, size); + if (!ret) + return MAP_FAILED; + memset(ret, 0, size); + return ret; +} + +static void pl_switch_munmap(void *ptr, size_t size, enum psxMapTag tag) +{ + (void)size; + (void)tag; + free(ptr); +} +#endif + #ifdef VITA typedef struct { @@ -3792,11 +3817,13 @@ void retro_init(void) syscall(SYS_ptrace, 0 /*PTRACE_TRACEME*/, 0, 0, 0); #endif -#ifdef _3DS +#if defined(_3DS) psxMapHook = pl_3ds_mmap; psxUnmapHook = pl_3ds_munmap; -#endif -#ifdef VITA +#elif defined(HAVE_LIBNX) + psxMapHook = pl_switch_mmap; + psxUnmapHook = pl_switch_munmap; +#elif defined(VITA) if (init_vita_mmap() < 0) abort(); psxMapHook = pl_vita_mmap; diff --git a/frontend/switch/sys/mman.h b/frontend/switch/sys/mman.h index 2e084a64..1d31e252 100644 --- a/frontend/switch/sys/mman.h +++ b/frontend/switch/sys/mman.h @@ -20,6 +20,7 @@ extern "C" { #define ALIGNMENT 0x1000 +#if 0 // not used static inline void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { (void)fd; @@ -51,6 +52,7 @@ static inline int munmap(void *addr, size_t len) } return 0; } +#endif #ifdef __cplusplus };