ffi 1.0.9-x86-mingw32 → 1.0.12.pre-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

Files changed (218) hide show
  1. data/Rakefile +16 -16
  2. data/ext/ffi_c/AbstractMemory.c +376 -14
  3. data/ext/ffi_c/AbstractMemory.h +8 -0
  4. data/ext/ffi_c/ArrayType.c +28 -0
  5. data/ext/ffi_c/Buffer.c +109 -25
  6. data/ext/ffi_c/Call.c +16 -5
  7. data/ext/ffi_c/ClosurePool.c +21 -8
  8. data/ext/ffi_c/DataConverter.c +29 -0
  9. data/ext/ffi_c/DynamicLibrary.c +71 -2
  10. data/ext/ffi_c/Function.c +122 -11
  11. data/ext/ffi_c/Function.h +6 -0
  12. data/ext/ffi_c/FunctionInfo.c +21 -1
  13. data/ext/ffi_c/LastError.c +24 -0
  14. data/ext/ffi_c/MappedType.c +22 -0
  15. data/ext/ffi_c/MemoryPointer.c +19 -1
  16. data/ext/ffi_c/MemoryPointer.h +6 -0
  17. data/ext/ffi_c/MethodHandle.c +26 -11
  18. data/ext/ffi_c/Platform.c +17 -3
  19. data/ext/ffi_c/Pointer.c +106 -0
  20. data/ext/ffi_c/Pointer.h +6 -0
  21. data/ext/ffi_c/Struct.c +10 -4
  22. data/ext/ffi_c/Struct.h +2 -1
  23. data/ext/ffi_c/StructByReference.c +8 -0
  24. data/ext/ffi_c/StructByValue.c +8 -0
  25. data/ext/ffi_c/StructLayout.c +8 -2
  26. data/ext/ffi_c/Thread.c +131 -1
  27. data/ext/ffi_c/Thread.h +6 -0
  28. data/ext/ffi_c/Type.c +111 -17
  29. data/ext/ffi_c/Types.c +9 -2
  30. data/ext/ffi_c/Types.h +4 -0
  31. data/ext/ffi_c/Variadic.c +13 -4
  32. data/ext/ffi_c/compat.h +8 -0
  33. data/ext/ffi_c/endian.h +10 -1
  34. data/ext/ffi_c/extconf.rb +51 -35
  35. data/ext/ffi_c/ffi.c +5 -0
  36. data/ext/ffi_c/libffi.darwin.mk +15 -15
  37. data/ext/ffi_c/libffi.gnu.mk +3 -3
  38. data/ext/ffi_c/libffi.mk +4 -4
  39. data/ext/ffi_c/libffi.vc.mk +26 -0
  40. data/ext/ffi_c/libffi.vc64.mk +26 -0
  41. data/ext/ffi_c/libffi/ChangeLog +541 -0
  42. data/ext/ffi_c/libffi/ChangeLog.libffi +13 -87
  43. data/ext/ffi_c/libffi/LICENSE +3 -3
  44. data/ext/ffi_c/libffi/Makefile.am +41 -32
  45. data/ext/ffi_c/libffi/Makefile.in +95 -66
  46. data/ext/ffi_c/libffi/Makefile.vc +141 -0
  47. data/ext/ffi_c/libffi/Makefile.vc64 +141 -0
  48. data/ext/ffi_c/libffi/README +40 -4
  49. data/ext/ffi_c/libffi/aclocal.m4 +729 -7854
  50. data/ext/ffi_c/libffi/build-ios.sh +67 -0
  51. data/ext/ffi_c/libffi/compile +11 -10
  52. data/ext/ffi_c/libffi/config.guess +4 -1
  53. data/ext/ffi_c/libffi/config.sub +6 -3
  54. data/ext/ffi_c/libffi/configure +6264 -6354
  55. data/ext/ffi_c/libffi/configure.ac +155 -63
  56. data/ext/ffi_c/libffi/depcomp +81 -35
  57. data/ext/ffi_c/libffi/doc/libffi.info +78 -18
  58. data/ext/ffi_c/libffi/doc/libffi.texi +64 -5
  59. data/ext/ffi_c/libffi/doc/stamp-vti +4 -4
  60. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  61. data/ext/ffi_c/libffi/fficonfig.h.in +18 -0
  62. data/ext/ffi_c/libffi/fficonfig.hw +57 -0
  63. data/ext/ffi_c/libffi/include/Makefile.in +21 -3
  64. data/ext/ffi_c/libffi/include/ffi.h.in +42 -14
  65. data/ext/ffi_c/libffi/include/ffi.h.vc +427 -0
  66. data/ext/ffi_c/libffi/include/ffi.h.vc64 +427 -0
  67. data/ext/ffi_c/libffi/include/ffi_common.h +9 -5
  68. data/ext/ffi_c/libffi/install-sh +364 -167
  69. data/ext/ffi_c/libffi/ltmain.sh +2599 -1369
  70. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +176 -0
  71. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +195 -0
  72. data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +76 -0
  73. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +63 -0
  74. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
  75. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +300 -0
  76. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +215 -0
  77. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +79 -0
  78. data/ext/ffi_c/libffi/m4/libtool.m4 +1239 -768
  79. data/ext/ffi_c/libffi/m4/ltoptions.m4 +7 -6
  80. data/ext/ffi_c/libffi/m4/ltversion.m4 +6 -6
  81. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +9 -3
  82. data/ext/ffi_c/libffi/man/Makefile.in +21 -3
  83. data/ext/ffi_c/libffi/mdate-sh +0 -0
  84. data/ext/ffi_c/libffi/missing +60 -44
  85. data/ext/ffi_c/libffi/msvcc.sh +197 -0
  86. data/ext/ffi_c/libffi/src/alpha/osf.S +39 -18
  87. data/ext/ffi_c/libffi/src/arm/ffi.c +443 -24
  88. data/ext/ffi_c/libffi/src/arm/ffitarget.h +17 -1
  89. data/ext/ffi_c/libffi/src/arm/gentramp.sh +118 -0
  90. data/ext/ffi_c/libffi/src/arm/sysv.S +206 -15
  91. data/ext/ffi_c/libffi/src/arm/trampoline.S +4450 -0
  92. data/ext/ffi_c/libffi/src/avr32/ffi.c +4 -2
  93. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +2 -2
  94. data/ext/ffi_c/libffi/src/closures.c +17 -35
  95. data/ext/ffi_c/libffi/src/cris/ffi.c +1 -1
  96. data/ext/ffi_c/libffi/src/cris/ffitarget.h +2 -2
  97. data/ext/ffi_c/libffi/src/dlmalloc.c +66 -4
  98. data/ext/ffi_c/libffi/src/frv/ffitarget.h +2 -6
  99. data/ext/ffi_c/libffi/src/ia64/ffi.c +7 -5
  100. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +2 -2
  101. data/ext/ffi_c/libffi/src/java_raw_api.c +1 -1
  102. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +2 -2
  103. data/ext/ffi_c/libffi/src/m68k/ffi.c +10 -0
  104. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +2 -2
  105. data/ext/ffi_c/libffi/src/m68k/sysv.S +36 -0
  106. data/ext/ffi_c/libffi/src/mips/ffi.c +12 -5
  107. data/ext/ffi_c/libffi/src/mips/ffitarget.h +18 -11
  108. data/ext/ffi_c/libffi/src/mips/n32.S +4 -4
  109. data/ext/ffi_c/libffi/src/moxie/eabi.S +128 -0
  110. data/ext/ffi_c/libffi/src/moxie/ffi.c +276 -0
  111. data/ext/ffi_c/libffi/src/pa/ffi.c +7 -4
  112. data/ext/ffi_c/libffi/src/pa/ffitarget.h +6 -5
  113. data/ext/ffi_c/libffi/src/powerpc/aix.S +5 -1
  114. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +2 -0
  115. data/ext/ffi_c/libffi/src/powerpc/asm.h +1 -1
  116. data/ext/ffi_c/libffi/src/powerpc/darwin.S +215 -77
  117. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +358 -100
  118. data/ext/ffi_c/libffi/src/powerpc/ffi.c +11 -5
  119. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +603 -172
  120. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +17 -4
  121. data/ext/ffi_c/libffi/src/prep_cif.c +16 -13
  122. data/ext/ffi_c/libffi/src/s390/ffitarget.h +4 -2
  123. data/ext/ffi_c/libffi/src/sh/ffitarget.h +2 -2
  124. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +2 -2
  125. data/ext/ffi_c/libffi/src/sparc/ffi.c +55 -11
  126. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +5 -3
  127. data/ext/ffi_c/libffi/src/x86/ffi.c +54 -92
  128. data/ext/ffi_c/libffi/src/x86/ffi64.c +17 -8
  129. data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -14
  130. data/ext/ffi_c/libffi/src/x86/sysv.S +40 -26
  131. data/ext/ffi_c/libffi/src/x86/unix64.S +4 -0
  132. data/ext/ffi_c/libffi/src/x86/win32.S +379 -191
  133. data/ext/ffi_c/libffi/src/x86/win64.S +15 -7
  134. data/ext/ffi_c/libffi/testsuite/Makefile.am +1 -1
  135. data/ext/ffi_c/libffi/testsuite/Makefile.in +22 -4
  136. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +350 -0
  137. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +1 -5
  138. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +1 -1
  139. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +1 -1
  140. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +1 -0
  141. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +1 -0
  142. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +3 -0
  143. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +2 -2
  144. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +3 -0
  145. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +1 -1
  146. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +1 -1
  147. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +1 -0
  148. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +2 -3
  149. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +2 -1
  150. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +36 -0
  151. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +17 -17
  152. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +1 -0
  153. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +1 -0
  154. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +1 -1
  155. data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +1 -3
  156. data/ext/ffi_c/win32/stdint.h +199 -0
  157. data/gen/Rakefile +18 -2
  158. data/lib/1.8/ffi_c.so +0 -0
  159. data/lib/ffi.rb +13 -9
  160. data/lib/ffi/autopointer.rb +88 -26
  161. data/lib/ffi/enum.rb +42 -0
  162. data/lib/ffi/errno.rb +6 -1
  163. data/lib/ffi/ffi.rb +1 -0
  164. data/lib/ffi/io.rb +13 -2
  165. data/lib/ffi/library.rb +219 -24
  166. data/lib/ffi/memorypointer.rb +1 -33
  167. data/lib/ffi/platform.rb +21 -7
  168. data/lib/ffi/platform/arm-linux/types.conf +102 -0
  169. data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  170. data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  171. data/lib/ffi/platform/i486-gnu/types.conf +107 -0
  172. data/lib/ffi/platform/ia64-linux/types.conf +102 -0
  173. data/lib/ffi/platform/mips-linux/types.conf +102 -0
  174. data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  175. data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
  176. data/lib/ffi/platform/s390-linux/types.conf +102 -0
  177. data/lib/ffi/platform/s390x-linux/types.conf +102 -0
  178. data/lib/ffi/platform/sparc-linux/types.conf +102 -0
  179. data/lib/ffi/platform/x86_64-freebsd/types.conf +126 -0
  180. data/lib/ffi/platform/x86_64-netbsd/types.conf +126 -0
  181. data/lib/ffi/pointer.rb +44 -0
  182. data/lib/ffi/struct.rb +2 -6
  183. data/lib/ffi/struct_layout_builder.rb +2 -1
  184. data/lib/ffi/tools/const_generator.rb +78 -26
  185. data/lib/ffi/tools/types_generator.rb +8 -1
  186. data/lib/ffi/types.rb +21 -1
  187. data/spec/ffi/async_callback_spec.rb +2 -2
  188. data/spec/ffi/bool_spec.rb +6 -6
  189. data/spec/ffi/buffer_spec.rb +23 -23
  190. data/spec/ffi/callback_spec.rb +101 -102
  191. data/spec/ffi/custom_type_spec.rb +20 -24
  192. data/spec/ffi/dup_spec.rb +7 -7
  193. data/spec/ffi/enum_spec.rb +127 -127
  194. data/spec/ffi/errno_spec.rb +2 -2
  195. data/spec/ffi/ffi_spec.rb +3 -3
  196. data/spec/ffi/function_spec.rb +10 -10
  197. data/spec/ffi/library_spec.rb +30 -12
  198. data/spec/ffi/managed_struct_spec.rb +4 -4
  199. data/spec/ffi/number_spec.rb +40 -40
  200. data/spec/ffi/pointer_spec.rb +21 -24
  201. data/spec/ffi/rbx/memory_pointer_spec.rb +17 -15
  202. data/spec/ffi/rbx/struct_spec.rb +2 -2
  203. data/spec/ffi/spec_helper.rb +1 -1
  204. data/spec/ffi/string_spec.rb +9 -9
  205. data/spec/ffi/strptr_spec.rb +3 -3
  206. data/spec/ffi/struct_callback_spec.rb +7 -7
  207. data/spec/ffi/struct_initialize_spec.rb +2 -2
  208. data/spec/ffi/struct_packed_spec.rb +6 -6
  209. data/spec/ffi/struct_spec.rb +94 -84
  210. data/spec/ffi/typedef_spec.rb +15 -4
  211. data/spec/ffi/union_spec.rb +3 -3
  212. data/spec/ffi/variadic_spec.rb +17 -14
  213. data/tasks/extension.rake +0 -1
  214. data/tasks/gem.rake +0 -1
  215. data/tasks/rdoc.rake +1 -1
  216. data/tasks/yard.rake +11 -0
  217. metadata +50 -11
  218. data/lib/1.9/ffi_c.so +0 -0
@@ -1,5 +1,6 @@
1
1
  /* -----------------------------------------------------------------------
2
- ffi.c - Copyright (c) 2009 Bradley Smith <brad@brad-smith.co.uk>
2
+ ffi.c - Copyright (c) 2011 Anthony Green
3
+ Copyright (c) 2009 Bradley Smith <brad@brad-smith.co.uk>
3
4
 
4
5
  AVR32 Foreign Function Interface
5
6
 
@@ -394,7 +395,8 @@ ffi_status ffi_prep_closure_loc(ffi_closure* closure, ffi_cif* cif,
394
395
  void (*fun)(ffi_cif*, void*, void**, void*), void *user_data,
395
396
  void *codeloc)
396
397
  {
397
- FFI_ASSERT(cif->abi == FFI_SYSV);
398
+ if (cif->abi != FFI_SYSV)
399
+ return FFI_BAD_ABI;
398
400
 
399
401
  unsigned char *__tramp = (unsigned char*)(&closure->tramp[0]);
400
402
  unsigned int __fun = (unsigned int)(&ffi_closure_SYSV);
@@ -34,8 +34,8 @@ typedef signed long ffi_sarg;
34
34
  typedef enum ffi_abi {
35
35
  FFI_FIRST_ABI = 0,
36
36
  FFI_SYSV,
37
- FFI_DEFAULT_ABI = FFI_SYSV,
38
- FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
37
+ FFI_LAST_ABI,
38
+ FFI_DEFAULT_ABI = FFI_SYSV
39
39
  } ffi_abi;
40
40
  #endif
41
41
 
@@ -1,6 +1,7 @@
1
1
  /* -----------------------------------------------------------------------
2
- closures.c - Copyright (c) 2007, 2009 Red Hat, Inc.
3
- Copyright (C) 2007, 2009 Free Software Foundation, Inc
2
+ closures.c - Copyright (c) 2007, 2009, 2010 Red Hat, Inc.
3
+ Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc
4
+ Copyright (c) 2011 Plausible Labs Cooperative, Inc.
4
5
 
5
6
  Code to allocate and deallocate memory for closures.
6
7
 
@@ -32,7 +33,7 @@
32
33
  #include <ffi.h>
33
34
  #include <ffi_common.h>
34
35
 
35
- #ifndef FFI_MMAP_EXEC_WRIT
36
+ #if !FFI_MMAP_EXEC_WRIT && !FFI_EXEC_TRAMPOLINE_TABLE
36
37
  # if __gnu_linux__
37
38
  /* This macro indicates it may be forbidden to map anonymous memory
38
39
  with both write and execute permission. Code compiled when this
@@ -44,7 +45,7 @@
44
45
  # define FFI_MMAP_EXEC_WRIT 1
45
46
  # define HAVE_MNTENT 1
46
47
  # endif
47
- # if defined(X86_WIN32) || defined(X86_WIN64)
48
+ # if defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)
48
49
  /* Windows systems may have Data Execution Protection (DEP) enabled,
49
50
  which requires the use of VirtualMalloc/VirtualFree to alloc/free
50
51
  executable memory. */
@@ -63,7 +64,11 @@
63
64
 
64
65
  #if FFI_CLOSURES
65
66
 
66
- # if FFI_MMAP_EXEC_WRIT
67
+ # if FFI_EXEC_TRAMPOLINE_TABLE
68
+
69
+ // Per-target implementation; It's unclear what can reasonable be shared between two OS/architecture implementations.
70
+
71
+ # elif FFI_MMAP_EXEC_WRIT /* !FFI_EXEC_TRAMPOLINE_TABLE */
67
72
 
68
73
  #define USE_LOCKS 1
69
74
  #define USE_DL_PREFIX 1
@@ -146,7 +151,7 @@ selinux_enabled_check (void)
146
151
  p = strchr (p + 1, ' ');
147
152
  if (p == NULL)
148
153
  break;
149
- if (strncmp (p + 1, "selinuxfs ", 10) != 0)
154
+ if (strncmp (p + 1, "selinuxfs ", 10) == 0)
150
155
  {
151
156
  free (buf);
152
157
  fclose (f);
@@ -167,7 +172,7 @@ selinux_enabled_check (void)
167
172
 
168
173
  #endif /* !FFI_MMAP_EXEC_SELINUX */
169
174
 
170
- #elif defined (__CYGWIN__)
175
+ #elif defined (__CYGWIN__) || defined(__INTERIX)
171
176
 
172
177
  #include <sys/mman.h>
173
178
 
@@ -193,11 +198,11 @@ static int dlmalloc_trim(size_t) MAYBE_UNUSED;
193
198
  static size_t dlmalloc_usable_size(void*) MAYBE_UNUSED;
194
199
  static void dlmalloc_stats(void) MAYBE_UNUSED;
195
200
 
196
- #if !(defined(X86_WIN32) || defined(X86_WIN64)) || defined (__CYGWIN__)
201
+ #if !(defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX)
197
202
  /* Use these for mmap and munmap within dlmalloc.c. */
198
203
  static void *dlmmap(void *, size_t, int, int, int, off_t);
199
204
  static int dlmunmap(void *, size_t);
200
- #endif /* !(defined(X86_WIN32) || defined(X86_WIN64)) || defined (__CYGWIN__) */
205
+ #endif /* !(defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */
201
206
 
202
207
  #define mmap dlmmap
203
208
  #define munmap dlmunmap
@@ -207,9 +212,7 @@ static int dlmunmap(void *, size_t);
207
212
  #undef mmap
208
213
  #undef munmap
209
214
 
210
- #if !(defined(X86_WIN32) || defined(X86_WIN64)) || defined (__CYGWIN__)
211
-
212
- #if FFI_MMAP_EXEC_SELINUX
215
+ #if !(defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX)
213
216
 
214
217
  /* A mutex used to synchronize access to *exec* variables in this file. */
215
218
  static pthread_mutex_t open_temp_exec_file_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -296,7 +299,7 @@ open_temp_exec_file_mnt (const char *mounts)
296
299
  struct mntent mnt;
297
300
  char buf[MAXPATHLEN * 3];
298
301
 
299
- if (getmntent_r (last_mntent, &mnt, buf, sizeof (buf)))
302
+ if (getmntent_r (last_mntent, &mnt, buf, sizeof (buf)) == NULL)
300
303
  return -1;
301
304
 
302
305
  if (hasmntopt (&mnt, "ro")
@@ -480,27 +483,6 @@ dlmmap (void *start, size_t length, int prot,
480
483
  return dlmmap_locked (start, length, prot, flags, offset);
481
484
  }
482
485
 
483
- #else
484
-
485
- static void *
486
- dlmmap (void *start, size_t length, int prot,
487
- int flags, int fd, off_t offset)
488
- {
489
-
490
- assert (start == NULL && length % malloc_getpagesize == 0
491
- && prot == (PROT_READ | PROT_WRITE)
492
- && flags == (MAP_PRIVATE | MAP_ANONYMOUS)
493
- && fd == -1 && offset == 0);
494
-
495
- #if FFI_CLOSURE_TEST
496
- printf ("mapping in %zi\n", length);
497
- #endif
498
-
499
- return mmap (start, length, prot | PROT_EXEC, flags, fd, offset);
500
- }
501
-
502
- #endif
503
-
504
486
  /* Release memory at the given address, as well as the corresponding
505
487
  executable page if it's separate. */
506
488
  static int
@@ -545,7 +527,7 @@ segment_holding_code (mstate m, char* addr)
545
527
  }
546
528
  #endif
547
529
 
548
- #endif /* !(defined(X86_WIN32) || defined(X86_WIN64)) || defined (__CYGWIN__) */
530
+ #endif /* !(defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */
549
531
 
550
532
  /* Allocate a chunk of memory with the given size. Returns a pointer
551
533
  to the writable address, and sets *CODE to the executable
@@ -163,7 +163,7 @@ ffi_prep_cif (ffi_cif * cif,
163
163
  ffi_type **ptr;
164
164
 
165
165
  FFI_ASSERT (cif != NULL);
166
- FFI_ASSERT ((abi > FFI_FIRST_ABI) && (abi <= FFI_DEFAULT_ABI));
166
+ FFI_ASSERT (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI);
167
167
 
168
168
  cif->abi = abi;
169
169
  cif->arg_types = atypes;
@@ -34,8 +34,8 @@ typedef signed long ffi_sarg;
34
34
  typedef enum ffi_abi {
35
35
  FFI_FIRST_ABI = 0,
36
36
  FFI_SYSV,
37
- FFI_DEFAULT_ABI = FFI_SYSV,
38
- FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
37
+ FFI_LAST_ABI,
38
+ FFI_DEFAULT_ABI = FFI_SYSV
39
39
  } ffi_abi;
40
40
  #endif
41
41
 
@@ -459,6 +459,14 @@ DEFAULT_MMAP_THRESHOLD default: 256K
459
459
  #define MMAP_CLEARS 0 /* WINCE and some others apparently don't clear */
460
460
  #endif /* WIN32 */
461
461
 
462
+ #ifdef __OS2__
463
+ #define INCL_DOS
464
+ #include <os2.h>
465
+ #define HAVE_MMAP 1
466
+ #define HAVE_MORECORE 0
467
+ #define LACKS_SYS_MMAN_H
468
+ #endif /* __OS2__ */
469
+
462
470
  #if defined(DARWIN) || defined(_DARWIN)
463
471
  /* Mac OSX docs advise not to use sbrk; it seems better to use mmap */
464
472
  #ifndef HAVE_MORECORE
@@ -614,6 +622,9 @@ DEFAULT_MMAP_THRESHOLD default: 256K
614
622
  #include "/usr/include/malloc.h"
615
623
  #else /* HAVE_USR_INCLUDE_MALLOC_H */
616
624
 
625
+ /* HP-UX's stdlib.h redefines mallinfo unless _STRUCT_MALLINFO is defined */
626
+ #define _STRUCT_MALLINFO
627
+
617
628
  struct mallinfo {
618
629
  MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */
619
630
  MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */
@@ -1288,7 +1299,7 @@ extern void* sbrk(ptrdiff_t);
1288
1299
  #define IS_MMAPPED_BIT (SIZE_T_ONE)
1289
1300
  #define USE_MMAP_BIT (SIZE_T_ONE)
1290
1301
 
1291
- #ifndef WIN32
1302
+ #if !defined(WIN32) && !defined (__OS2__)
1292
1303
  #define CALL_MUNMAP(a, s) munmap((a), (s))
1293
1304
  #define MMAP_PROT (PROT_READ|PROT_WRITE)
1294
1305
  #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
@@ -1311,6 +1322,42 @@ static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */
1311
1322
  #endif /* MAP_ANONYMOUS */
1312
1323
 
1313
1324
  #define DIRECT_MMAP(s) CALL_MMAP(s)
1325
+
1326
+ #elif defined(__OS2__)
1327
+
1328
+ /* OS/2 MMAP via DosAllocMem */
1329
+ static void* os2mmap(size_t size) {
1330
+ void* ptr;
1331
+ if (DosAllocMem(&ptr, size, OBJ_ANY|PAG_COMMIT|PAG_READ|PAG_WRITE) &&
1332
+ DosAllocMem(&ptr, size, PAG_COMMIT|PAG_READ|PAG_WRITE))
1333
+ return MFAIL;
1334
+ return ptr;
1335
+ }
1336
+
1337
+ #define os2direct_mmap(n) os2mmap(n)
1338
+
1339
+ /* This function supports releasing coalesed segments */
1340
+ static int os2munmap(void* ptr, size_t size) {
1341
+ while (size) {
1342
+ ULONG ulSize = size;
1343
+ ULONG ulFlags = 0;
1344
+ if (DosQueryMem(ptr, &ulSize, &ulFlags) != 0)
1345
+ return -1;
1346
+ if ((ulFlags & PAG_BASE) == 0 ||(ulFlags & PAG_COMMIT) == 0 ||
1347
+ ulSize > size)
1348
+ return -1;
1349
+ if (DosFreeMem(ptr) != 0)
1350
+ return -1;
1351
+ ptr = ( void * ) ( ( char * ) ptr + ulSize );
1352
+ size -= ulSize;
1353
+ }
1354
+ return 0;
1355
+ }
1356
+
1357
+ #define CALL_MMAP(s) os2mmap(s)
1358
+ #define CALL_MUNMAP(a, s) os2munmap((a), (s))
1359
+ #define DIRECT_MMAP(s) os2direct_mmap(s)
1360
+
1314
1361
  #else /* WIN32 */
1315
1362
 
1316
1363
  /* Win32 MMAP via VirtualAlloc */
@@ -1387,7 +1434,7 @@ static int win32munmap(void* ptr, size_t size) {
1387
1434
  unique mparams values are initialized only once.
1388
1435
  */
1389
1436
 
1390
- #ifndef WIN32
1437
+ #if !defined(WIN32) && !defined(__OS2__)
1391
1438
  /* By default use posix locks */
1392
1439
  #include <pthread.h>
1393
1440
  #define MLOCK_T pthread_mutex_t
@@ -1401,6 +1448,16 @@ static MLOCK_T morecore_mutex = PTHREAD_MUTEX_INITIALIZER;
1401
1448
 
1402
1449
  static MLOCK_T magic_init_mutex = PTHREAD_MUTEX_INITIALIZER;
1403
1450
 
1451
+ #elif defined(__OS2__)
1452
+ #define MLOCK_T HMTX
1453
+ #define INITIAL_LOCK(l) DosCreateMutexSem(0, l, 0, FALSE)
1454
+ #define ACQUIRE_LOCK(l) DosRequestMutexSem(*l, SEM_INDEFINITE_WAIT)
1455
+ #define RELEASE_LOCK(l) DosReleaseMutexSem(*l)
1456
+ #if HAVE_MORECORE
1457
+ static MLOCK_T morecore_mutex;
1458
+ #endif /* HAVE_MORECORE */
1459
+ static MLOCK_T magic_init_mutex;
1460
+
1404
1461
  #else /* WIN32 */
1405
1462
  /*
1406
1463
  Because lock-protected regions have bounded times, and there
@@ -2492,10 +2549,15 @@ static int init_mparams(void) {
2492
2549
  }
2493
2550
  RELEASE_MAGIC_INIT_LOCK();
2494
2551
 
2495
- #ifndef WIN32
2552
+ #if !defined(WIN32) && !defined(__OS2__)
2496
2553
  mparams.page_size = malloc_getpagesize;
2497
2554
  mparams.granularity = ((DEFAULT_GRANULARITY != 0)?
2498
2555
  DEFAULT_GRANULARITY : mparams.page_size);
2556
+ #elif defined (__OS2__)
2557
+ /* if low-memory is used, os2munmap() would break
2558
+ if it were anything other than 64k */
2559
+ mparams.page_size = 4096u;
2560
+ mparams.granularity = 65536u;
2499
2561
  #else /* WIN32 */
2500
2562
  {
2501
2563
  SYSTEM_INFO system_info;
@@ -4192,7 +4254,7 @@ void* dlmalloc(size_t bytes) {
4192
4254
 
4193
4255
  void dlfree(void* mem) {
4194
4256
  /*
4195
- Consolidate freed chunks with preceeding or succeeding bordering
4257
+ Consolidate freed chunks with preceding or succeeding bordering
4196
4258
  free chunks, if they exist, and then place in a bin. Intermixed
4197
4259
  with special cases for top, dv, mmapped chunks, and usage errors.
4198
4260
  */
@@ -35,13 +35,9 @@ typedef signed long ffi_sarg;
35
35
 
36
36
  typedef enum ffi_abi {
37
37
  FFI_FIRST_ABI = 0,
38
-
39
- #ifdef FRV
40
38
  FFI_EABI,
41
- FFI_DEFAULT_ABI = FFI_EABI,
42
- #endif
43
-
44
- FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
39
+ FFI_LAST_ABI,
40
+ FFI_DEFAULT_ABI = FFI_EABI
45
41
  } ffi_abi;
46
42
  #endif
47
43
 
@@ -1,7 +1,8 @@
1
1
  /* -----------------------------------------------------------------------
2
- ffi.c - Copyright (c) 1998, 2007, 2008 Red Hat, Inc.
3
- Copyright (c) 2000 Hewlett Packard Company
4
-
2
+ ffi.c - Copyright (c) 2011 Anthony Green
3
+ Copyright (c) 2000 Hewlett Packard Company
4
+ Copyright (c) 1998, 2007, 2008 Red Hat, Inc.
5
+
5
6
  IA64 Foreign Function Interface
6
7
 
7
8
  Permission is hereby granted, free of charge, to any person obtaining
@@ -225,7 +226,7 @@ ffi_prep_cif_machdep(ffi_cif *cif)
225
226
  int flags;
226
227
 
227
228
  /* Adjust cif->bytes to include space for the bits of the ia64_args frame
228
- that preceeds the integer register portion. The estimate that the
229
+ that precedes the integer register portion. The estimate that the
229
230
  generic bits did for the argument space required is good enough for the
230
231
  integer component. */
231
232
  cif->bytes += offsetof(struct ia64_args, gp_regs[0]);
@@ -425,7 +426,8 @@ ffi_prep_closure_loc (ffi_closure* closure,
425
426
  struct ffi_ia64_trampoline_struct *tramp;
426
427
  struct ia64_fd *fd;
427
428
 
428
- FFI_ASSERT (cif->abi == FFI_UNIX);
429
+ if (cif->abi != FFI_UNIX)
430
+ return FFI_BAD_ABI;
429
431
 
430
432
  tramp = (struct ffi_ia64_trampoline_struct *)closure->tramp;
431
433
  fd = (struct ia64_fd *)(void *)ffi_closure_unix;
@@ -34,8 +34,8 @@ typedef signed long long ffi_sarg;
34
34
  typedef enum ffi_abi {
35
35
  FFI_FIRST_ABI = 0,
36
36
  FFI_UNIX, /* Linux and all Unix variants use the same conventions */
37
- FFI_DEFAULT_ABI = FFI_UNIX,
38
- FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
37
+ FFI_LAST_ABI,
38
+ FFI_DEFAULT_ABI = FFI_UNIX
39
39
  } ffi_abi;
40
40
  #endif
41
41
 
@@ -311,7 +311,7 @@ ffi_java_translate_args (ffi_cif *cif, void *rvalue,
311
311
  ffi_raw_closure *cl = (ffi_raw_closure*)user_data;
312
312
 
313
313
  ffi_java_ptrarray_to_raw (cif, avalue, raw);
314
- (*cl->fun) (cif, rvalue, raw, cl->user_data);
314
+ (*cl->fun) (cif, rvalue, (ffi_raw*)raw, cl->user_data);
315
315
  ffi_java_raw_to_rvalue (cif, rvalue);
316
316
  }
317
317
 
@@ -36,8 +36,8 @@ typedef enum ffi_abi
36
36
  {
37
37
  FFI_FIRST_ABI = 0,
38
38
  FFI_SYSV,
39
- FFI_DEFAULT_ABI = FFI_SYSV,
40
- FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
39
+ FFI_LAST_ABI,
40
+ FFI_DEFAULT_ABI = FFI_SYSV
41
41
  } ffi_abi;
42
42
  #endif
43
43
 
@@ -9,8 +9,12 @@
9
9
 
10
10
  #include <stdlib.h>
11
11
  #include <unistd.h>
12
+ #ifdef __rtems__
13
+ void rtems_cache_flush_multiple_data_lines( const void *, size_t );
14
+ #else
12
15
  #include <sys/syscall.h>
13
16
  #include <asm/cachectl.h>
17
+ #endif
14
18
 
15
19
  void ffi_call_SYSV (extended_cif *,
16
20
  unsigned, unsigned,
@@ -144,9 +148,11 @@ ffi_prep_cif_machdep (ffi_cif *cif)
144
148
  cif->flags = CIF_FLAGS_DOUBLE;
145
149
  break;
146
150
 
151
+ #if (FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE)
147
152
  case FFI_TYPE_LONGDOUBLE:
148
153
  cif->flags = CIF_FLAGS_LDOUBLE;
149
154
  break;
155
+ #endif
150
156
 
151
157
  case FFI_TYPE_POINTER:
152
158
  cif->flags = CIF_FLAGS_POINTER;
@@ -266,8 +272,12 @@ ffi_prep_closure_loc (ffi_closure* closure,
266
272
  else
267
273
  *(void **)(closure->tramp + 8) = ffi_closure_SYSV;
268
274
 
275
+ #ifdef __rtems__
276
+ rtems_cache_flush_multiple_data_lines( codeloc, FFI_TRAMPOLINE_SIZE );
277
+ #else
269
278
  syscall(SYS_cacheflush, codeloc, FLUSH_SCOPE_LINE,
270
279
  FLUSH_CACHE_BOTH, FFI_TRAMPOLINE_SIZE);
280
+ #endif
271
281
 
272
282
  closure->cif = cif;
273
283
  closure->user_data = user_data;
@@ -34,8 +34,8 @@ typedef signed long ffi_sarg;
34
34
  typedef enum ffi_abi {
35
35
  FFI_FIRST_ABI = 0,
36
36
  FFI_SYSV,
37
- FFI_DEFAULT_ABI = FFI_SYSV,
38
- FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
37
+ FFI_LAST_ABI,
38
+ FFI_DEFAULT_ABI = FFI_SYSV
39
39
  } ffi_abi;
40
40
  #endif
41
41
 
@@ -1,4 +1,5 @@
1
1
  /* -----------------------------------------------------------------------
2
+
2
3
  sysv.S - Copyright (c) 1998 Andreas Schwab
3
4
  Copyright (c) 2008 Red Hat, Inc.
4
5
 
@@ -85,7 +86,12 @@ ffi_call_SYSV:
85
86
  move.l 16(%fp),%d2
86
87
 
87
88
  | If the return value pointer is NULL, assume no return value.
89
+ | NOTE: On the mc68000, tst on an address register is not supported.
90
+ #if defined(__mc68000__) && !defined(__mcoldfire__)
91
+ cmp.w #0, %a1
92
+ #else
88
93
  tst.l %a1
94
+ #endif
89
95
  jbeq noretval
90
96
 
91
97
  btst #0,%d2
@@ -103,19 +109,34 @@ retlongint:
103
109
  retfloat:
104
110
  btst #2,%d2
105
111
  jbeq retdouble
112
+ #if defined(__MC68881__)
106
113
  fmove.s %fp0,(%a1)
114
+ #else
115
+ move.l %d0,(%a1)
116
+ #endif
107
117
  jbra epilogue
108
118
 
109
119
  retdouble:
110
120
  btst #3,%d2
111
121
  jbeq retlongdouble
122
+ #if defined(__MC68881__)
112
123
  fmove.d %fp0,(%a1)
124
+ #else
125
+ move.l %d0,(%a1)+
126
+ move.l %d1,(%a1)
127
+ #endif
113
128
  jbra epilogue
114
129
 
115
130
  retlongdouble:
116
131
  btst #4,%d2
117
132
  jbeq retpointer
133
+ #if defined(__MC68881__)
118
134
  fmove.x %fp0,(%a1)
135
+ #else
136
+ move.l %d0,(%a1)+
137
+ move.l %d1,(%a1)+
138
+ move.l %d2,(%a1)
139
+ #endif
119
140
  jbra epilogue
120
141
 
121
142
  retpointer:
@@ -178,16 +199,31 @@ ffi_closure_SYSV:
178
199
  move.l (%a0),%d1
179
200
  jra .Lcls_epilogue
180
201
  .Lcls_ret_float:
202
+ #if defined(__MC68881__)
181
203
  fmove.s (%a0),%fp0
204
+ #else
205
+ move.l (%a0),%d0
206
+ #endif
182
207
  jra .Lcls_epilogue
183
208
  1:
184
209
  lsr.l #2,%d0
185
210
  jne 1f
186
211
  jcs .Lcls_ret_ldouble
212
+ #if defined(__MC68881__)
187
213
  fmove.d (%a0),%fp0
214
+ #else
215
+ move.l (%a0)+,%d0
216
+ move.l (%a0),%d1
217
+ #endif
188
218
  jra .Lcls_epilogue
189
219
  .Lcls_ret_ldouble:
220
+ #if defined(__MC68881__)
190
221
  fmove.x (%a0),%fp0
222
+ #else
223
+ move.l (%a0)+,%d0
224
+ move.l (%a0)+,%d1
225
+ move.l (%a0),%d2
226
+ #endif
191
227
  jra .Lcls_epilogue
192
228
  1:
193
229
  lsr.l #2,%d0