X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Flightrec%2Fmem.c;h=c0186da16ce96206e6da7f48524941816440199a;hb=3569821141fcc25a47b5d6942d219b659aba5547;hp=76608ea44c9895b727b55b992e7db7924bc12f9d;hpb=a093e81fbfc1c588b091656844b26684ec3dc01d;p=pcsx_rearmed.git diff --git a/libpcsxcore/lightrec/mem.c b/libpcsxcore/lightrec/mem.c index 76608ea4..c0186da1 100644 --- a/libpcsxcore/lightrec/mem.c +++ b/libpcsxcore/lightrec/mem.c @@ -3,6 +3,7 @@ * Copyright (C) 2022 Paul Cercueil */ +#define _GNU_SOURCE #include #include #include @@ -11,6 +12,7 @@ #include #include #include +#include #include #include "../psxhw.h" @@ -25,6 +27,12 @@ #define MAP_FIXED_NOREPLACE 0x100000 #endif +#ifndef MFD_HUGETLB +#define MFD_HUGETLB 0x0004 +#endif + +void *code_buffer; + static const uintptr_t supported_io_bases[] = { 0x0, 0x10000000, @@ -64,7 +72,8 @@ static int lightrec_mmap_ram(bool hugetlb) if (hugetlb) flags |= MFD_HUGETLB; - memfd = memfd_create("/lightrec_memfd", flags); + memfd = syscall(SYS_memfd_create, "/lightrec_memfd", + flags); if (memfd < 0) { err = -errno; fprintf(stderr, "Failed to create memfd: %d\n", err); @@ -120,9 +129,7 @@ int lightrec_init_mmap(void) unsigned int i; uintptr_t base; void *map; - int err; - - err = lightrec_mmap_ram(true); + int err = lightrec_mmap_ram(true); if (err) { err = lightrec_mmap_ram(false); if (err) { @@ -166,10 +173,24 @@ int lightrec_init_mmap(void) psxH = (s8 *)map; + map = mmap_huge((void *)(base + 0x800000), CODE_BUFFER_SIZE, + PROT_EXEC | PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_FIXED_NOREPLACE | MAP_ANONYMOUS, + 0, 0); + if (map == MAP_FAILED) { + err = -EINVAL; + fprintf(stderr, "Unable to mmap code buffer\n"); + goto err_unmap_scratch; + } + + code_buffer = map; + return 0; +err_unmap_scratch: + munmap(psxH, 0x10000); err_unmap_bios: - munmap(psxR, 0x80000); + munmap(psxR, 0x200000); err_unmap_parallel: munmap(psxP, 0x10000); err_unmap: @@ -182,8 +203,9 @@ void lightrec_free_mmap(void) { unsigned int i; + munmap(code_buffer, CODE_BUFFER_SIZE); munmap(psxH, 0x10000); - munmap(psxR, 0x80000); + munmap(psxR, 0x200000); munmap(psxP, 0x10000); for (i = 0; i < 4; i++) munmap((void *)((uintptr_t)psxM + i * 0x200000), 0x200000);