Commit 7a4146b9 authored by Ramon Nou's avatar Ramon Nou
Browse files

fix recursion

parent 656ab020
Loading
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -2522,19 +2522,20 @@ mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) {
// Python's built-in mmap module and NumPy memmap call this variant directly,
// bypassing plain mmap(). Without this interceptor, GekkoFS fds fall through
// to the kernel and return ENXIO.
//
// IMPORTANT: We intentionally fall back to dlsym_mmap (not dlsym_mmap64) for
// non-GekkoFS fds. On 64-bit Linux, mmap64 is implemented as an alias of mmap
// in glibc — dlsym(RTLD_NEXT, "mmap64") can therefore resolve back to our own
// mmap64 interposer, causing infinite recursion → stack overflow → SIGSEGV.
#if defined(__USE_LARGEFILE64) || defined(_LARGEFILE64_SOURCE) ||              \
        defined(__linux__)
DLSYM_WRAPPER(void*, mmap64,
              (void* addr, size_t length, int prot, int flags, int fd,
               off_t offset),
              (addr, length, prot, flags, fd, offset), "mmap64")

void*
mmap64(void* addr, size_t length, int prot, int flags, int fd, off_t offset) {
    gkfs_init_routine_placeholder();
    // Delegate to gkfs_mmap when fd belongs to GekkoFS, otherwise fallback.
    GKFS_OPERATION(mmap, addr, length, prot, flags, fd, offset);
    GKFS_FALLBACK(mmap64, addr, length, prot, flags, fd, offset);
    // Fall back via the plain mmap dlsym wrapper — avoids infinite recursion.
    GKFS_FALLBACK(mmap, addr, length, prot, flags, fd, offset);
}
#endif