Skip to content

Commit

Permalink
Package: add mmap patch for libevent
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorxda committed Jan 17, 2024
1 parent 0c55434 commit a5f2697
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
41 changes: 41 additions & 0 deletions general/package/libevent-openipc/0002-use-mmap-syscall.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--- a/buffer.c
+++ b/buffer.c
@@ -63,6 +63,9 @@
#include <sys/stat.h>
#endif

+#if defined(BROKEN_MMAP)
+#include <sys/syscall.h>
+#endif

#include <errno.h>
#include <stdio.h>
@@ -2977,6 +2980,12 @@
return result;
}

+#if defined(BROKEN_MMAP)
+static void *mmap_ev(void *start, size_t len, int prot, int flags, int fd, off_t off) {
+ return (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off >> 12);
+}
+#endif
+
/* TODO(niels): we may want to add to automagically convert to mmap, in
* case evbuffer_remove() or evbuffer_pullup() are being used.
*/
@@ -3080,11 +3089,15 @@
offset_leftover = offset % page_size;
offset_rounded = offset - offset_leftover;
}
+#if defined(BROKEN_MMAP)
+ mapped = mmap_ev(NULL, length + offset_leftover,
+#else
#if defined(EVENT__HAVE_MMAP64)
mapped = mmap64(NULL, length + offset_leftover,
#else
mapped = mmap(NULL, length + offset_leftover,
#endif
+#endif
PROT_READ,
#ifdef MAP_NOCACHE
MAP_NOCACHE | /* ??? */
4 changes: 4 additions & 0 deletions general/package/libevent-openipc/libevent-openipc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ else
LIBEVENT_OPENIPC_CONF_OPTS += -DEVENT__DISABLE_MBEDTLS=ON
endif

ifeq ($(BR2_TOOLCHAIN_USES_MUSL),y)
LIBEVENT_OPENIPC_CONF_OPTS += -DCMAKE_C_FLAGS="$(TARGET_CFLAGS) -DBROKEN_MMAP=1"
endif

LIBEVENT_OPENIPC_POST_INSTALL_TARGET_HOOKS += LIBEVENT_OPENIPC_DELETE_UNUSED

$(eval $(cmake-package))

0 comments on commit a5f2697

Please sign in to comment.