summaryrefslogtreecommitdiff
path: root/patches/bad-abi-fix
blob: dc89ec5db04326c1d3daad317ffc6fbf3df4134c (plain)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
Index: libffi/ChangeLog
===================================================================
--- libffi.orig/ChangeLog
+++ libffi/ChangeLog
@@ -33,6 +33,23 @@
 
 	* configure: Regenerate.
 
+2011-02-13  Anthony Green  <green@moxielogic.com>
+
+	* include/ffi_common.h (UNLIKELY, LIKELY): Define.
+	* src/x86/ffi64.c (UNLIKELY, LIKELY): Remove definition.
+	* src/prep_cif.c (UNLIKELY, LIKELY): Remove definition.
+
+	* src/prep_cif.c (initialize_aggregate): Convert assertion into
+	FFI_BAD_TYPEDEF return.  Initialize arg size and alignment to 0.
+
+	* src/pa/ffi.c (ffi_prep_closure_loc): Don't ASSERT ABI test,
+	just return FFI_BAD_ABI when things are wrong.
+	* src/arm/ffi.c (ffi_prep_closure_loc): Ditto.
+	* src/powerpc/ffi.c (ffi_prep_closure_loc): Ditto.
+	* src/mips/ffi.c (ffi_prep_closure_loc): Ditto.
+	* src/ia64/ffi.c (ffi_prep_closure_loc): Ditto.
+	* src/avr32/ffi.c (ffi_prep_closure_loc): Ditto.
+
 2011-02-11  Anthony Green  <green@moxielogic.com>
 
 	* src/sparc/ffi.c (ffi_prep_closure_loc): Don't ASSERT ABI test,
Index: libffi/include/ffi_common.h
===================================================================
--- libffi.orig/include/ffi_common.h
+++ libffi/include/ffi_common.h
@@ -1,7 +1,8 @@
 /* -----------------------------------------------------------------------
-   ffi_common.h - Copyright (c) 1996  Red Hat, Inc.
-   Copyright (C) 2007 Free Software Foundation, Inc
-
+   ffi_common.h - Copyright (C) 2011  Anthony Green
+                  Copyright (C) 2007  Free Software Foundation, Inc
+                  Copyright (c) 1996  Red Hat, Inc.
+                  
    Common internal definitions and macros. Only necessary for building
    libffi.
    ----------------------------------------------------------------------- */
@@ -112,11 +113,14 @@ typedef signed int   SINT64 __attribute_
 
 typedef float FLOAT32;
 
+#ifndef __GNUC__
+#define __builtin_expect(x, expected_value) (x)
+#endif
+#define LIKELY(x)    __builtin_expect((x),1)
+#define UNLIKELY(x)  __builtin_expect((x),1)
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif
-
-
Index: libffi/src/arm/ffi.c
===================================================================
--- libffi.orig/src/arm/ffi.c
+++ libffi/src/arm/ffi.c
@@ -1,7 +1,9 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1998, 2008, 2011  Red Hat, Inc.
-	   Copyright (c) 2011 Plausible Labs Cooperative, Inc.
-   
+   ffi.c - Copyright (c) 2011 Plausible Labs Cooperative, Inc.
+           Copyright (c) 2011 Anthony Green
+	   Copyright (c) 2011 Free Software Foundation
+           Copyright (c) 1998, 2008, 2011  Red Hat, Inc.
+	   
    ARM Foreign Function Interface 
 
    Permission is hereby granted, free of charge, to any person obtaining
@@ -586,7 +588,7 @@ ffi_prep_closure_loc (ffi_closure* closu
   else if (cif->abi == FFI_VFP)
     closure_func = &ffi_closure_VFP;
   else
-    FFI_ASSERT (0);
+    return FFI_BAD_ABI;
     
 #if FFI_EXEC_TRAMPOLINE_TABLE
   void **config = FFI_TRAMPOLINE_CODELOC_CONFIG(codeloc);
Index: libffi/src/avr32/ffi.c
===================================================================
--- libffi.orig/src/avr32/ffi.c
+++ libffi/src/avr32/ffi.c
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 2009  Bradley Smith <brad@brad-smith.co.uk>
+   ffi.c - Copyright (c) 2011  Anthony Green
+           Copyright (c) 2009  Bradley Smith <brad@brad-smith.co.uk>
 
    AVR32 Foreign Function Interface
 
@@ -394,7 +395,8 @@ ffi_status ffi_prep_closure_loc(ffi_clos
     void (*fun)(ffi_cif*, void*, void**, void*), void *user_data,
     void *codeloc)
 {
-    FFI_ASSERT(cif->abi == FFI_SYSV);
+    if (cif->abi != FFI_SYSV)
+      return FFI_BAD_ABI;
 
     unsigned char *__tramp = (unsigned char*)(&closure->tramp[0]);
     unsigned int  __fun = (unsigned int)(&ffi_closure_SYSV);
Index: libffi/src/ia64/ffi.c
===================================================================
--- libffi.orig/src/ia64/ffi.c
+++ libffi/src/ia64/ffi.c
@@ -1,7 +1,8 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1998, 2007, 2008 Red Hat, Inc.
-	   Copyright (c) 2000 Hewlett Packard Company
-   
+   ffi.c - Copyright (c) 2011 Anthony Green
+           Copyright (c) 2000 Hewlett Packard Company
+           Copyright (c) 1998, 2007, 2008 Red Hat, Inc.
+	   
    IA64 Foreign Function Interface 
 
    Permission is hereby granted, free of charge, to any person obtaining
@@ -425,7 +426,8 @@ ffi_prep_closure_loc (ffi_closure* closu
   struct ffi_ia64_trampoline_struct *tramp;
   struct ia64_fd *fd;
 
-  FFI_ASSERT (cif->abi == FFI_UNIX);
+  if (cif->abi != FFI_UNIX)
+    return FFI_BAD_ABI;
 
   tramp = (struct ffi_ia64_trampoline_struct *)closure->tramp;
   fd = (struct ia64_fd *)(void *)ffi_closure_unix;
Index: libffi/src/mips/ffi.c
===================================================================
--- libffi.orig/src/mips/ffi.c
+++ libffi/src/mips/ffi.c
@@ -1,6 +1,7 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1996, 2007, 2008  Red Hat, Inc.
-           Copyright (c) 2008       David Daney
+   ffi.c - Copyright (c) 2011  Anthony Green
+           Copyright (c) 2008  David Daney
+           Copyright (c) 1996, 2007, 2008, 2011  Red Hat, Inc.
    
    MIPS Foreign Function Interface 
 
@@ -662,10 +663,12 @@ ffi_prep_closure_loc (ffi_closure *closu
   char *clear_location = (char *) codeloc;
 
 #if defined(FFI_MIPS_O32)
-  FFI_ASSERT(cif->abi == FFI_O32 || cif->abi == FFI_O32_SOFT_FLOAT);
+  if (cif->abi != FFI_O32 && cif->abi != FFI_O32_SOFT_FLOAT)
+    return FFI_BAD_ABI;
   fn = ffi_closure_O32;
 #else /* FFI_MIPS_N32 */
-  FFI_ASSERT(cif->abi == FFI_N32 || cif->abi == FFI_N64);
+  if (cif->abi != FFI_N32 && cif->abi != FFI_N64)
+    return FFI_BAD_ABI;
   fn = ffi_closure_N32;
 #endif /* FFI_MIPS_O32 */
 
Index: libffi/src/pa/ffi.c
===================================================================
--- libffi.orig/src/pa/ffi.c
+++ libffi/src/pa/ffi.c
@@ -1,9 +1,11 @@
 /* -----------------------------------------------------------------------
-   ffi.c - (c) 2003-2004 Randolph Chung <tausq@debian.org>
+   ffi.c - (c) 2011 Anthony Green
            (c) 2008 Red Hat, Inc.
-
+	   (c) 2006 Free Software Foundation, Inc.
+           (c) 2003-2004 Randolph Chung <tausq@debian.org>
+           
    HPPA Foreign Function Interface
-   HP-UX PA ABI support (c) 2006 Free Software Foundation, Inc.
+   HP-UX PA ABI support 
 
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
@@ -633,7 +635,8 @@ ffi_prep_closure_loc (ffi_closure* closu
   UINT32 *tmp;
 #endif
 
-  FFI_ASSERT (cif->abi == FFI_PA32);
+  if (cif->abi != FFI_PA32)
+    return FFI_BAD_ABI;
 
   /* Make a small trampoline that will branch to our
      handler function. Use PC-relative addressing.  */
Index: libffi/src/powerpc/ffi.c
===================================================================
--- libffi.orig/src/powerpc/ffi.c
+++ libffi/src/powerpc/ffi.c
@@ -1,7 +1,8 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1998 Geoffrey Keating
-   Copyright (C) 2007, 2008 Free Software Foundation, Inc
-   Copyright (C) 2008 Red Hat, Inc
+   ffi.c - Copyright (C) 2011 Anthony Green
+           Copyright (C) 2008 Red Hat, Inc
+           Copyright (C) 2007, 2008 Free Software Foundation, Inc
+	   Copyright (c) 1998 Geoffrey Keating
 
    PowerPC Foreign Function Interface
 
@@ -949,14 +950,16 @@ ffi_prep_closure_loc (ffi_closure *closu
 #ifdef POWERPC64
   void **tramp = (void **) &closure->tramp[0];
 
-  FFI_ASSERT (cif->abi == FFI_LINUX64);
+  if (cif->abi != FFI_LINUX64)
+    return FFI_BAD_ABI;
   /* Copy function address and TOC from ffi_closure_LINUX64.  */
   memcpy (tramp, (char *) ffi_closure_LINUX64, 16);
   tramp[2] = codeloc;
 #else
   unsigned int *tramp;
 
-  FFI_ASSERT (cif->abi == FFI_GCC_SYSV || cif->abi == FFI_SYSV);
+  if (! (cif->abi == FFI_GCC_SYSV || cif->abi == FFI_SYSV))
+    return FFI_BAD_ABI;
 
   tramp = (unsigned int *) &closure->tramp[0];
   tramp[0] = 0x7c0802a6;  /*   mflr    r0 */
Index: libffi/src/prep_cif.c
===================================================================
--- libffi.orig/src/prep_cif.c
+++ libffi/src/prep_cif.c
@@ -27,12 +27,6 @@
 #include <ffi_common.h>
 #include <stdlib.h>
 
-#ifndef __GNUC__
-#define __builtin_expect(x, expected_value) (x)
-#endif
-#define LIKELY(x)    __builtin_expect((x),1)
-#define UNLIKELY(x)  __builtin_expect((x),1)
-
 /* Round up to FFI_SIZEOF_ARG. */
 
 #define STACK_ARG_SIZE(x) ALIGN(x, FFI_SIZEOF_ARG)
@@ -44,11 +38,11 @@ static ffi_status initialize_aggregate(f
 {
   ffi_type **ptr;
 
-  FFI_ASSERT(arg != NULL);
+  if (UNLIKELY(arg == NULL || arg->elements == NULL))
+    return FFI_BAD_TYPEDEF;
 
-  FFI_ASSERT(arg->elements != NULL);
-  FFI_ASSERT(arg->size == 0);
-  FFI_ASSERT(arg->alignment == 0);
+  arg->size = 0;
+  arg->alignment = 0;
 
   ptr = &(arg->elements[0]);
 
Index: libffi/src/x86/ffi64.c
===================================================================
--- libffi.orig/src/x86/ffi64.c
+++ libffi/src/x86/ffi64.c
@@ -1,7 +1,8 @@
 /* -----------------------------------------------------------------------
-   ffi64.c - Copyright (c) 2002, 2007  Bo Thorsen <bo@suse.de>
+   ffi64.c - Copyright (c) 20011  Anthony Green
              Copyright (c) 2008, 2010  Red Hat, Inc.
-   
+             Copyright (c) 2002, 2007  Bo Thorsen <bo@suse.de>
+             
    x86-64 Foreign Function Interface 
 
    Permission is hereby granted, free of charge, to any person obtaining
@@ -28,12 +29,6 @@
 #include <ffi.h>
 #include <ffi_common.h>
 
-#ifndef __GNUC__
-#define __builtin_expect(x, expected_value) (x)
-#endif
-#define LIKELY(x)    __builtin_expect((x),1)
-#define UNLIKELY(x)  __builtin_expect((x),1)
-
 #include <stdlib.h>
 #include <stdarg.h>