From: Dmitry Ilyin Date: Sun, 7 Aug 2022 10:51:48 +0000 (+0300) Subject: Add check of mmap64 function and use it when available rather that mmap X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99fd68abde4a59b90148db733fc51a7256cbd320;p=libevent Add check of mmap64 function and use it when available rather that mmap There can be issues on 32-bit architectures to mmap 2+GiB file, and to make this portable between different version of glibc, mmap64 was prefered over _FILE_OFFSET_BITS --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a4529032..5016840c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -545,6 +545,7 @@ else() unsetenv setrlimit gethostbyname_r + mmap64 ) if (APPLE) list(APPEND SYMBOLS_TO_CHECK mach_absolute_time) diff --git a/buffer.c b/buffer.c index fcbcba3c..825f6a29 100644 --- a/buffer.c +++ b/buffer.c @@ -3080,7 +3080,11 @@ evbuffer_file_segment_materialize(struct evbuffer_file_segment *seg) offset_leftover = offset % page_size; offset_rounded = offset - offset_leftover; } +#if defined(EVENT__HAVE_MMAP64) + mapped = mmap64(NULL, length + offset_leftover, +#else mapped = mmap(NULL, length + offset_leftover, +#endif PROT_READ, #ifdef MAP_NOCACHE MAP_NOCACHE | /* ??? */ diff --git a/configure.ac b/configure.ac index f90f2105..0d7e098c 100644 --- a/configure.ac +++ b/configure.ac @@ -272,7 +272,7 @@ dnl Checks for typedefs, structures, and compiler characteristics. AC_C_INLINE dnl Checks for library functions. -AC_CHECK_FUNCS([accept4 arc4random arc4random_buf arc4random_addrandom eventfd epoll_create1 fcntl getegid geteuid getifaddrs gettimeofday issetugid mach_absolute_time mmap nanosleep pipe pipe2 putenv sendfile setenv setrlimit sigaction signal strsignal strlcpy strsep strtok_r strtoll sysctl timerfd_create umask unsetenv usleep getrandom ]) +AC_CHECK_FUNCS([accept4 arc4random arc4random_buf arc4random_addrandom eventfd epoll_create1 fcntl getegid geteuid getifaddrs gettimeofday issetugid mach_absolute_time mmap nanosleep pipe pipe2 putenv sendfile setenv setrlimit sigaction signal strsignal strlcpy strsep strtok_r strtoll sysctl timerfd_create umask unsetenv usleep getrandom mmap64]) AS_IF([test "$bwin32" = "true"], AC_CHECK_FUNCS(_gmtime64_s, , [AC_CHECK_FUNCS(_gmtime64)]) diff --git a/event-config.h.cmake b/event-config.h.cmake index 4a626701..a52e7136 100644 --- a/event-config.h.cmake +++ b/event-config.h.cmake @@ -190,6 +190,9 @@ /* Define to 1 if you have the `mmap' function. */ #cmakedefine EVENT__HAVE_MMAP 1 +/* Define to 1 if you have the `mmap64' function. */ +#cmakedefine EVENT__HAVE_MMAP64 1 + /* Define to 1 if you have the `nanosleep' function. */ #cmakedefine EVENT__HAVE_NANOSLEEP 1