Add static trampoline support for Cygwin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
diff --git a/configure.ac b/configure.ac
index 8edb7b6..75cc455 100644
--- a/configure.ac
+++ b/configure.ac
@@ -392,6 +392,12 @@ AC_ARG_ENABLE(exec-static-tramp,
if test "$enable_exec_static_tramp" != no; then
case "$target" in
*-cygwin*)
+ # Only define static trampolines if we are using the cygwin runtime.
+ # Will this need to be changed for mingw?
+ if test "x$GCC" = "xyes"; then
+ AC_DEFINE(FFI_EXEC_STATIC_TRAMP, 1,
+ [Define this if you want statically defined trampolines])
+ fi
;;
*arm*-*-linux-* | aarch64*-*-linux-* | i*86-*-linux-* | x86_64-*-linux-* | loongarch*-*-linux-*)
AC_DEFINE(FFI_EXEC_STATIC_TRAMP, 1,
diff --git a/src/closures.c b/src/closures.c
index 6cbe2f0..e2bc651 100644
--- a/src/closures.c
+++ b/src/closures.c
@@ -1,5 +1,5 @@
/* -----------------------------------------------------------------------
- closures.c - Copyright (c) 2019 Anthony Green
+ closures.c - Copyright (c) 2019, 2022 Anthony Green
Copyright (c) 2007, 2009, 2010 Red Hat, Inc.
Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc
Copyright (c) 2011 Plausible Labs Cooperative, Inc.
@@ -133,7 +133,7 @@ ffi_tramp_is_present (__attribute__((unused)) void *ptr)
# define FFI_MMAP_EXEC_WRIT 1
# define HAVE_MNTENT 1
# endif
-# if defined(_WIN32) || defined(__OS2__)
+# if defined(__CYGWIN__) || defined(_WIN32) || defined(__OS2__)
/* Windows systems may have Data Execution Protection (DEP) enabled,
which requires the use of VirtualMalloc/VirtualFree to alloc/free
executable memory. */
diff --git a/src/tramp.c b/src/tramp.c
index 265aeaa..19707fb 100644
--- a/src/tramp.c
+++ b/src/tramp.c
@@ -1,5 +1,6 @@
/* -----------------------------------------------------------------------
tramp.c - Copyright (c) 2020 Madhavan T. Venkataraman
+ Copyright (c) 2022 Anthony Green
API and support functions for managing statically defined closure
trampolines.
@@ -34,7 +35,7 @@
* Add support for other OSes later. For now, it is just Linux.
*/
-#if defined __linux__
+#if defined (__linux__) || defined (__CYGWIN__)
#ifdef __linux__
#define _GNU_SOURCE 1
#endif
@@ -50,7 +51,10 @@
#include <linux/limits.h>
#include <linux/types.h>
#endif
-#endif /* __linux__ */
+#ifdef __CYGWIN__
+#include <linux/limits.h>
+#endif
+#endif
/*
* Each architecture defines static code for a trampoline code table. The
@@ -191,7 +195,7 @@ static struct tramp_globals tramp_globals;
*/
static int tramp_table_alloc (void);
-#if defined __linux__
+#if defined (__linux__) || defined (__CYGWIN__)
static int
ffi_tramp_get_libffi (void)
@@ -245,9 +249,9 @@ ffi_tramp_get_libffi (void)
return 1;
}
-#endif /* __linux__ */
+#endif /* defined (__linux__) || defined (__CYGWIN__) */
-#if defined __linux__
+#if defined (__linux__) || defined (__CYGWIN__)
#if defined HAVE_MKSTEMP
@@ -294,11 +298,11 @@ ffi_tramp_get_temp_file (void)
#endif /* defined HAVE_MKSTEMP */
-#endif /* __linux__ */
+#endif /* defined (__linux__) || defined (__CYGWIN__) */
/* ------------------------ OS-specific Initialization ----------------------*/
-#if defined __linux__
+#if defined (__linux__) || defined (__CYGWIN__)
static int
ffi_tramp_init_os (void)
@@ -308,11 +312,11 @@ ffi_tramp_init_os (void)
return ffi_tramp_get_temp_file ();
}
-#endif /* __linux__ */
+#endif /* defined (__linux__) || defined (__CYGWIN__) */
/* --------------------------- OS-specific Locking -------------------------*/
-#if defined __linux__
+#if defined (__linux__) || defined (__CYGWIN__)
static pthread_mutex_t tramp_globals_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -328,7 +332,7 @@ ffi_tramp_unlock()
pthread_mutex_unlock (&tramp_globals_mutex);
}
-#endif /* __linux__ */
+#endif /* defined (__linux__) || defined (__CYGWIN__) */
/* ------------------------ OS-specific Memory Mapping ----------------------*/
@@ -347,7 +351,7 @@ ffi_tramp_unlock()
* sizeof (struct tramp_parm) cannot exceed the size of a parameter block.
*/
-#if defined __linux__
+#if defined (__linux__) || defined (__CYGWIN__)
static int
tramp_table_map (struct tramp_table *table)
@@ -384,7 +388,7 @@ tramp_table_unmap (struct tramp_table *table)
(void) munmap (table->parm_table, tramp_globals.map_size);
}
-#endif /* __linux__ */
+#endif /* defined (__linux__) || defined (__CYGWIN__) */
/* ------------------------ Trampoline Initialization ----------------------*/