From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/ext/fiddle/win32/fficonfig.h | 29 +++++ jni/ruby/ext/fiddle/win32/libffi-3.2.1-mswin.patch | 132 +++++++++++++++++++++ jni/ruby/ext/fiddle/win32/libffi-config.rb | 47 ++++++++ jni/ruby/ext/fiddle/win32/libffi.mk.tmpl | 96 +++++++++++++++ 4 files changed, 304 insertions(+) create mode 100755 jni/ruby/ext/fiddle/win32/fficonfig.h create mode 100644 jni/ruby/ext/fiddle/win32/libffi-3.2.1-mswin.patch create mode 100755 jni/ruby/ext/fiddle/win32/libffi-config.rb create mode 100755 jni/ruby/ext/fiddle/win32/libffi.mk.tmpl (limited to 'jni/ruby/ext/fiddle/win32') diff --git a/jni/ruby/ext/fiddle/win32/fficonfig.h b/jni/ruby/ext/fiddle/win32/fficonfig.h new file mode 100755 index 0000000..7768081 --- /dev/null +++ b/jni/ruby/ext/fiddle/win32/fficonfig.h @@ -0,0 +1,29 @@ +#define HAVE_ALLOCA 1 +#define HAVE_MEMCPY 1 +#define HAVE_MEMORY_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STRING_H 1 +#define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_TYPES_H 1 +#if _MSC_VER >= 1600 +#define HAVE_INTTYPES_H 1 +#define HAVE_STDINT_H 1 +#endif + +#define SIZEOF_DOUBLE 8 +#if defined(X86_WIN64) +#define SIZEOF_SIZE_T 8 +#else +#define SIZEOF_SIZE_T 4 +#endif + +#define STACK_DIRECTION -1 + +#define STDC_HEADERS 1 + +#ifdef LIBFFI_ASM +#define FFI_HIDDEN(name) +#else +#define FFI_HIDDEN +#endif + diff --git a/jni/ruby/ext/fiddle/win32/libffi-3.2.1-mswin.patch b/jni/ruby/ext/fiddle/win32/libffi-3.2.1-mswin.patch new file mode 100644 index 0000000..782cf41 --- /dev/null +++ b/jni/ruby/ext/fiddle/win32/libffi-3.2.1-mswin.patch @@ -0,0 +1,132 @@ +diff -ru libffi-3.2.1/src/x86/ffi.c libffi-3.2.1/src/x86/ffi.c +--- libffi-3.2.1/src/x86/ffi.c 2014-11-08 21:47:24.000000000 +0900 ++++ libffi-3.2.1/src/x86/ffi.c 2014-12-22 16:00:42.000000000 +0900 +@@ -99,11 +99,13 @@ + i != 0; + i--, p_arg += dir, p_argv += dir) + { ++ size_t z; ++ + /* Align if necessary */ + if ((sizeof(void*) - 1) & (size_t) argp) + argp = (char *) ALIGN(argp, sizeof(void*)); + +- size_t z = (*p_arg)->size; ++ z = (*p_arg)->size; + + #ifdef X86_WIN64 + if (z > FFI_SIZEOF_ARG +@@ -599,11 +601,13 @@ + i != 0; + i--, p_arg += dir, p_argv += dir) + { ++ size_t z; ++ + /* Align if necessary */ + if ((sizeof(void*) - 1) & (size_t) argp) + argp = (char *) ALIGN(argp, sizeof(void*)); + +- size_t z = (*p_arg)->size; ++ z = (*p_arg)->size; + + #ifdef X86_WIN64 + if (z > FFI_SIZEOF_ARG +@@ -642,7 +646,7 @@ + #endif + } + +- return (size_t)argp - (size_t)stack; ++ return (int)((size_t)argp - (size_t)stack); + } + + #define FFI_INIT_TRAMPOLINE_WIN64(TRAMP,FUN,CTX,MASK) \ +diff -ru libffi-3.2.1/src/x86/ffitarget.h libffi-3.2.1/src/x86/ffitarget.h +--- libffi-3.2.1/src/x86/ffitarget.h 2014-11-08 21:47:24.000000000 +0900 ++++ libffi-3.2.1/src/x86/ffitarget.h 2014-12-22 15:45:54.000000000 +0900 +@@ -50,7 +50,9 @@ + #endif + + #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION ++#ifndef _MSC_VER + #define FFI_TARGET_HAS_COMPLEX_TYPE ++#endif + + /* ---- Generic type definitions ----------------------------------------- */ + +diff -ru libffi-3.2.1/src/x86/win64.S libffi-3.2.1/src/x86/win64.S +--- libffi-3.2.1/src/x86/win64.S 2014-11-08 21:47:24.000000000 +0900 ++++ libffi-3.2.1/src/x86/win64.S 2014-12-22 16:14:40.000000000 +0900 +@@ -127,7 +127,7 @@ + + mov rcx, QWORD PTR RVALUE[rbp] + mov DWORD PTR [rcx], eax +- jmp ret_void$ ++ jmp SHORT ret_void$ + + ret_struct2b$: + cmp DWORD PTR CIF_FLAGS[rbp], FFI_TYPE_SMALL_STRUCT_2B +@@ -135,7 +135,7 @@ + + mov rcx, QWORD PTR RVALUE[rbp] + mov WORD PTR [rcx], ax +- jmp ret_void$ ++ jmp SHORT ret_void$ + + ret_struct1b$: + cmp DWORD PTR CIF_FLAGS[rbp], FFI_TYPE_SMALL_STRUCT_1B +@@ -143,7 +143,7 @@ + + mov rcx, QWORD PTR RVALUE[rbp] + mov BYTE PTR [rcx], al +- jmp ret_void$ ++ jmp SHORT ret_void$ + + ret_uint8$: + cmp DWORD PTR CIF_FLAGS[rbp], FFI_TYPE_UINT8 +@@ -152,7 +152,7 @@ + mov rcx, QWORD PTR RVALUE[rbp] + movzx rax, al + mov QWORD PTR [rcx], rax +- jmp ret_void$ ++ jmp SHORT ret_void$ + + ret_sint8$: + cmp DWORD PTR CIF_FLAGS[rbp], FFI_TYPE_SINT8 +@@ -161,7 +161,7 @@ + mov rcx, QWORD PTR RVALUE[rbp] + movsx rax, al + mov QWORD PTR [rcx], rax +- jmp ret_void$ ++ jmp SHORT ret_void$ + + ret_uint16$: + cmp DWORD PTR CIF_FLAGS[rbp], FFI_TYPE_UINT16 +@@ -188,7 +188,13 @@ + mov rcx, QWORD PTR RVALUE[rbp] + mov eax, eax + mov QWORD PTR [rcx], rax +- jmp SHORT ret_void$ ++ ++ret_void$: ++ xor rax, rax ++ ++ lea rsp, QWORD PTR [rbp+16] ++ pop rbp ++ ret 0 + + ret_sint32$: + cmp DWORD PTR CIF_FLAGS[rbp], FFI_TYPE_SINT32 +@@ -247,13 +253,6 @@ + cdqe + mov QWORD PTR [rcx], rax + jmp SHORT ret_void$ +- +-ret_void$: +- xor rax, rax +- +- lea rsp, QWORD PTR [rbp+16] +- pop rbp +- ret 0 + ffi_call_win64 ENDP + _TEXT ENDS + END diff --git a/jni/ruby/ext/fiddle/win32/libffi-config.rb b/jni/ruby/ext/fiddle/win32/libffi-config.rb new file mode 100755 index 0000000..ecd3b08 --- /dev/null +++ b/jni/ruby/ext/fiddle/win32/libffi-config.rb @@ -0,0 +1,47 @@ +#!/usr/bin/ruby +require 'fileutils' + +basedir = File.dirname(__FILE__) +conf = {} +enable = {} +until ARGV.empty? + arg = ARGV.shift + case arg + when '-C' + # ignore + when /\A--srcdir=(.*)/ + conf['SRCDIR'] = srcdir = $1 + when /\A(CC|CFLAGS|CXX|CXXFLAGS|LD|LDFLAGS)=(.*)/ + conf[$1] = $2 + when /\A--host=(.*)/ + host = $1 + when /\A--enable-([^=]+)(?:=(.*))?/ + enable[$1] = $2 || true + when /\A--disable-([^=]+)/ + enable[$1] = false + end +end + +IO.foreach("#{srcdir}/configure.ac") do |line| + if /^AC_INIT\((.*)\)/ =~ line + version = $1.split(/,\s*/)[1] + version.gsub!(/\A\[|\]\z/, '') + conf['VERSION'] = version + break + end +end + +builddir = srcdir == "." ? enable['builddir'] : "." +conf['TARGET'] = /^x64/ =~ host ? "X86_WIN64" : "X86_WIN32" + +FileUtils.mkdir_p([builddir, "#{builddir}/include", "#{builddir}/src/x86"]) +FileUtils.cp("#{basedir}/fficonfig.h", ".", preserve: true) + +hdr = IO.binread("#{srcdir}/include/ffi.h.in") +hdr.gsub!(/@(\w+)@/) {conf[$1] || $&} +hdr.gsub!(/^(#if\s+)@\w+@/, '\10') +IO.binwrite("#{builddir}/include/ffi.h", hdr) + +mk = IO.binread("#{basedir}/libffi.mk.tmpl") +mk.gsub!(/@(\w+)@/) {conf[$1] || $&} +IO.binwrite("Makefile", mk) diff --git a/jni/ruby/ext/fiddle/win32/libffi.mk.tmpl b/jni/ruby/ext/fiddle/win32/libffi.mk.tmpl new file mode 100755 index 0000000..2a16e8e --- /dev/null +++ b/jni/ruby/ext/fiddle/win32/libffi.mk.tmpl @@ -0,0 +1,96 @@ +# -*- makefile -*- +# ==================================================================== +# +# libffi Windows Makefile +# +# +# ==================================================================== +# +NAME = ffi +TARGET = @TARGET@ +CC = cl +!if "$(TARGET)" == "X86_WIN64" +AS = ml64 +!else +AS = ml +!endif +AR = link +DLEXT = dll +OBJEXT = obj +LIBEXT = lib +TOPDIR = @SRCDIR@ +CPP = $(CC) -EP +CFLAGS = @CFLAGS@ +ARFLAGS = -lib +ASFLAGS = -coff -W3 -Cx +INCLUDES= -I. -I./include -I./src/x86 \ + -I$(TOPDIR)/include -I$(TOPDIR)/include/src/x86 + +SRCDIR = $(TOPDIR)/src +WORKDIR = ./.libs +BUILDDIR= ./src +LIBNAME = lib$(NAME) +STATICLIB= $(WORKDIR)/$(LIBNAME)_convenience.$(LIBEXT) + +HEADERS = \ + ./fficonfig.h +FFI_HEADERS = \ + ./include/ffi.h \ + ./include/ffitarget.h + +!if "$(TARGET)" == "X86_WIN32" +OSSRC = win32 +!else if "$(TARGET)" == "X86_WIN64" +OSSRC = win64 +!else +! error unknown target: $(TARGET) +!endif + +OBJECTS = \ + $(BUILDDIR)/closures.$(OBJEXT) \ + $(BUILDDIR)/debug.$(OBJEXT) \ + $(BUILDDIR)/java_raw_api.$(OBJEXT) \ + $(BUILDDIR)/prep_cif.$(OBJEXT) \ + $(BUILDDIR)/raw_api.$(OBJEXT) \ + $(BUILDDIR)/types.$(OBJEXT) \ + $(BUILDDIR)/x86/ffi.$(OBJEXT) \ + $(BUILDDIR)/x86/$(OSSRC).$(OBJEXT) +ASMSRCS = \ + $(BUILDDIR)/x86/$(OSSRC).asm + +.SUFFIXES : .S .asm + +all: $(WORKDIR) $(STATICLIB) + +{$(SRCDIR)}.c{$(BUILDDIR)}.$(OBJEXT): + $(CC) -c $(CFLAGS) $(INCLUDES) -Fo$(@:\=/) -Fd$(WORKDIR)/$(NAME)-src $(<:\=/) + +{$(SRCDIR)/x86}.c{$(BUILDDIR)/x86}.$(OBJEXT): + $(CC) -c $(CFLAGS) $(INCLUDES) -Fo$(@:\=/) -Fd$(WORKDIR)/$(NAME)-src $(<:\=/) + +{$(SRCDIR)/x86}.S{$(BUILDDIR)/x86}.asm: + $(CPP) $(CFLAGS) $(INCLUDES) $(<:\=/) >$(@:\=/) + +{$(BUILDDIR)/x86}.asm{$(BUILDDIR)/x86}.$(OBJEXT): + cd $(@D) && $(AS) -c $(ASFLAGS) -Fo $(@F) $(NUL + -@del /Q $(ASMSRCS:/=\) 2>NUL + -@del /Q /S $(WORKDIR:/=\) 2>NUL + +distclean: clean + -@del /Q $(HEADERS:/=\) $(FFI_HEADERS:/=\) 2>NUL + -@del /Q Makefile 2>NUL -- cgit v1.2.3-70-g09d2