pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/devel/libffi Implement a W^X-aware closure allocator. ...
details: https://anonhg.NetBSD.org/pkgsrc/rev/a73ee45d0d07
branches: trunk
changeset: 362828:a73ee45d0d07
user: joerg <joerg%pkgsrc.org@localhost>
date: Fri May 26 18:55:41 2017 +0000
description:
Implement a W^X-aware closure allocator. Overhead is one page per
closure, but the number should normally be moderately small. A smarter
scheme can be implemented if necessary. Requires NetBSD 7.99.72+.
Bump revision.
diffstat:
devel/libffi/Makefile | 4 +-
devel/libffi/distinfo | 3 +-
devel/libffi/patches/patch-src_closures.c | 94 +++++++++++++++++++++++++++++++
3 files changed, 98 insertions(+), 3 deletions(-)
diffs (127 lines):
diff -r 5637a8beb435 -r a73ee45d0d07 devel/libffi/Makefile
--- a/devel/libffi/Makefile Fri May 26 18:01:07 2017 +0000
+++ b/devel/libffi/Makefile Fri May 26 18:55:41 2017 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.31 2017/01/28 15:39:56 wiz Exp $
+# $NetBSD: Makefile,v 1.32 2017/05/26 18:55:41 joerg Exp $
DISTNAME= libffi-3.2.1
-PKGREVISION= 2
+PKGREVISION= 3
CATEGORIES= devel
MASTER_SITES= ftp://sourceware.org/pub/libffi/
diff -r 5637a8beb435 -r a73ee45d0d07 devel/libffi/distinfo
--- a/devel/libffi/distinfo Fri May 26 18:01:07 2017 +0000
+++ b/devel/libffi/distinfo Fri May 26 18:55:41 2017 +0000
@@ -1,4 +1,4 @@
-$NetBSD: distinfo,v 1.43 2016/11/03 11:40:28 maya Exp $
+$NetBSD: distinfo,v 1.44 2017/05/26 18:55:41 joerg Exp $
SHA1 (libffi-3.2.1.tar.gz) = 280c265b789e041c02e5c97815793dfc283fb1e6
RMD160 (libffi-3.2.1.tar.gz) = 9b546a3d002380bec3f00d86fc47d730abf51dfd
@@ -13,5 +13,6 @@
SHA1 (patch-aj) = 5179cfd150bc7de15eb1c5ee0a327016c2c32b3e
SHA1 (patch-src_alpha_osf.S) = 50d564a1d88284f04f6896719fa3613e9b0be70b
SHA1 (patch-src_arm_sysv.S) = 2c97e0d069a4df2e1f5b6604e54b2d02c92691e2
+SHA1 (patch-src_closures.c) = 04f27d89e0604b6358f809fea8692e8d8e476511
SHA1 (patch-src_m88k_elfbsd.S) = 6572c7fa39c00096cb4a80bb88993ff1b4aaa8cc
SHA1 (patch-src_x86_win32.S) = 8a41cbc7237d6a171605a66e91d8d92a57181569
diff -r 5637a8beb435 -r a73ee45d0d07 devel/libffi/patches/patch-src_closures.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/libffi/patches/patch-src_closures.c Fri May 26 18:55:41 2017 +0000
@@ -0,0 +1,94 @@
+$NetBSD: patch-src_closures.c,v 1.1 2017/05/26 18:55:41 joerg Exp $
+
+--- src/closures.c.orig 2017-05-22 23:16:12.516083134 +0000
++++ src/closures.c
+@@ -33,6 +33,83 @@
+ #include <ffi.h>
+ #include <ffi_common.h>
+
++#ifdef __NetBSD__
++#include <sys/param.h>
++#endif
++
++#if __NetBSD_Version__ - 0 >= 799007200
++/* NetBSD with PROT_MPROTECT */
++#include <sys/mman.h>
++
++#include <stddef.h>
++#include <unistd.h>
++
++static const size_t overhead =
++ (sizeof(max_align_t) > sizeof(void *) + sizeof(size_t)) ?
++ sizeof(max_align_t)
++ : sizeof(void *) + sizeof(size_t);
++
++#define ADD_TO_POINTER(p, d) ((void *)((uintptr_t)(p) + (d)))
++
++void *
++ffi_closure_alloc (size_t size, void **code)
++{
++ static size_t page_size;
++ size_t rounded_size;
++ void *codeseg, *dataseg;
++ int prot;
++
++
++ /* Expect that PAX mprotect is active and a separate code mapping is necessary. */
++ if (!code)
++ return NULL;
++
++ /* Obtain system page size. */
++ if (!page_size)
++ page_size = sysconf(_SC_PAGESIZE);
++
++ /* Round allocation size up to the next page, keeping in mind the size field and pointer to code map. */
++ rounded_size = (size + overhead + page_size - 1) & ~(page_size - 1);
++
++ /* Primary mapping is RW, but request permission to switch to PROT_EXEC later. */
++ prot = PROT_READ | PROT_WRITE | PROT_MPROTECT(PROT_EXEC);
++ dataseg = mmap(NULL, rounded_size, prot, MAP_ANON | MAP_PRIVATE, -1, 0);
++ if (dataseg == MAP_FAILED)
++ return NULL;
++
++ /* Create secondary mapping and switch it to RX. */
++ codeseg = mremap(dataseg, rounded_size, NULL, rounded_size, MAP_REMAPDUP);
++ if (codeseg == MAP_FAILED) {
++ munmap(dataseg, rounded_size);
++ return NULL;
++ }
++ if (mprotect(codeseg, rounded_size, PROT_READ | PROT_EXEC) == -1) {
++ munmap(codeseg, rounded_size);
++ munmap(dataseg, rounded_size);
++ return NULL;
++ }
++
++ /* Remember allocation size and location of the secondary mapping for ffi_closure_free. */
++ memcpy(dataseg, &rounded_size, sizeof(rounded_size));
++ memcpy(ADD_TO_POINTER(dataseg, sizeof(size_t)), &codeseg, sizeof(void *));
++ *code = ADD_TO_POINTER(codeseg, overhead);
++ return ADD_TO_POINTER(dataseg, overhead);
++}
++
++void
++ffi_closure_free (void *ptr)
++{
++ void *codeseg, *dataseg;
++ size_t rounded_size;
++
++ dataseg = ADD_TO_POINTER(ptr, overhead);
++ memcpy(&rounded_size, dataseg, sizeof(rounded_size));
++ memcpy(&codeseg, ADD_TO_POINTER(dataseg, sizeof(size_t)), sizeof(void *));
++ munmap(dataseg, rounded_size);
++ munmap(codeseg, rounded_size);
++}
++#else /* !NetBSD with PROT_MPROTECT */
++
+ #if !FFI_MMAP_EXEC_WRIT && !FFI_EXEC_TRAMPOLINE_TABLE
+ # if __gnu_linux__ && !defined(__ANDROID__)
+ /* This macro indicates it may be forbidden to map anonymous memory
+@@ -686,3 +763,5 @@ ffi_closure_free (void *ptr)
+
+ # endif /* ! FFI_MMAP_EXEC_WRIT */
+ #endif /* FFI_CLOSURES */
++
++#endif /* NetBSD with PROT_MPROTECT */
Home |
Main Index |
Thread Index |
Old Index