Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(106517)

Side by Side Diff: Modules/_ctypes/libffi_ios/include/ffi_x86_64.h

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #ifdef __x86_64__
2
3 /* -----------------------------------------------------------------*-C-*-
4 libffi 3.99999 - Copyright (c) 2011, 2014 Anthony Green
5 - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc.
6
7 Permission is hereby granted, free of charge, to any person
8 obtaining a copy of this software and associated documentation
9 files (the ``Software''), to deal in the Software without
10 restriction, including without limitation the rights to use, copy,
11 modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26
27 ----------------------------------------------------------------------- */
28
29 /* -------------------------------------------------------------------
30 The basic API is described in the README file.
31
32 The raw API is designed to bypass some of the argument packing
33 and unpacking on architectures for which it can be avoided.
34
35 The closure API allows interpreted functions to be packaged up
36 inside a C function pointer, so that they can be called as C functions,
37 with no understanding on the client side that they are interpreted.
38 It can also be used in other cases in which it is necessary to package
39 up a user specified parameter and a function pointer as a single
40 function pointer.
41
42 The closure API must be implemented in order to get its functionality,
43 e.g. for use by gij. Routines are provided to emulate the raw API
44 if the underlying platform doesn't allow faster implementation.
45
46 More details on the raw and cloure API can be found in:
47
48 http://gcc.gnu.org/ml/java/1999-q3/msg00138.html
49
50 and
51
52 http://gcc.gnu.org/ml/java/1999-q3/msg00174.html
53 -------------------------------------------------------------------- */
54
55 #ifndef LIBFFI_H
56 #define LIBFFI_H
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62 /* Specify which architecture libffi is configured for. */
63 #ifndef X86_64
64 #define X86_64
65 #endif
66
67 /* ---- System configuration information --------------------------------- */
68
69 #include <ffitarget.h>
70
71 #ifndef LIBFFI_ASM
72
73 #if defined(_MSC_VER) && !defined(__clang__)
74 #define __attribute__(X)
75 #endif
76
77 #include <stddef.h>
78 #include <limits.h>
79
80 /* LONG_LONG_MAX is not always defined (not if STRICT_ANSI, for example).
81 But we can find it either under the correct ANSI name, or under GNU
82 C's internal name. */
83
84 #define FFI_64_BIT_MAX 9223372036854775807
85
86 #ifdef LONG_LONG_MAX
87 # define FFI_LONG_LONG_MAX LONG_LONG_MAX
88 #else
89 # ifdef LLONG_MAX
90 # define FFI_LONG_LONG_MAX LLONG_MAX
91 # ifdef _AIX52 /* or newer has C99 LLONG_MAX */
92 # undef FFI_64_BIT_MAX
93 # define FFI_64_BIT_MAX 9223372036854775807LL
94 # endif /* _AIX52 or newer */
95 # else
96 # ifdef __GNUC__
97 # define FFI_LONG_LONG_MAX __LONG_LONG_MAX__
98 # endif
99 # ifdef _AIX /* AIX 5.1 and earlier have LONGLONG_MAX */
100 # ifndef __PPC64__
101 # if defined (__IBMC__) || defined (__IBMCPP__)
102 # define FFI_LONG_LONG_MAX LONGLONG_MAX
103 # endif
104 # endif /* __PPC64__ */
105 # undef FFI_64_BIT_MAX
106 # define FFI_64_BIT_MAX 9223372036854775807LL
107 # endif
108 # endif
109 #endif
110
111 /* The closure code assumes that this works on pointers, i.e. a size_t */
112 /* can hold a pointer. */
113
114 typedef struct _ffi_type
115 {
116 size_t size;
117 unsigned short alignment;
118 unsigned short type;
119 struct _ffi_type **elements;
120 } ffi_type;
121
122 #ifndef LIBFFI_HIDE_BASIC_TYPES
123 #if SCHAR_MAX == 127
124 # define ffi_type_uchar ffi_type_uint8
125 # define ffi_type_schar ffi_type_sint8
126 #else
127 #error "char size not supported"
128 #endif
129
130 #if SHRT_MAX == 32767
131 # define ffi_type_ushort ffi_type_uint16
132 # define ffi_type_sshort ffi_type_sint16
133 #elif SHRT_MAX == 2147483647
134 # define ffi_type_ushort ffi_type_uint32
135 # define ffi_type_sshort ffi_type_sint32
136 #else
137 #error "short size not supported"
138 #endif
139
140 #if INT_MAX == 32767
141 # define ffi_type_uint ffi_type_uint16
142 # define ffi_type_sint ffi_type_sint16
143 #elif INT_MAX == 2147483647
144 # define ffi_type_uint ffi_type_uint32
145 # define ffi_type_sint ffi_type_sint32
146 #elif INT_MAX == 9223372036854775807
147 # define ffi_type_uint ffi_type_uint64
148 # define ffi_type_sint ffi_type_sint64
149 #else
150 #error "int size not supported"
151 #endif
152
153 #if LONG_MAX == 2147483647
154 # if FFI_LONG_LONG_MAX != FFI_64_BIT_MAX
155 #error "no 64-bit data type supported"
156 # endif
157 #elif LONG_MAX != FFI_64_BIT_MAX
158 #error "long size not supported"
159 #endif
160
161 #if LONG_MAX == 2147483647
162 # define ffi_type_ulong ffi_type_uint32
163 # define ffi_type_slong ffi_type_sint32
164 #elif LONG_MAX == FFI_64_BIT_MAX
165 # define ffi_type_ulong ffi_type_uint64
166 # define ffi_type_slong ffi_type_sint64
167 #else
168 #error "long size not supported"
169 #endif
170
171 /* Need minimal decorations for DLLs to works on Windows. */
172 /* GCC has autoimport and autoexport. Rely on Libtool to */
173 /* help MSVC export from a DLL, but always declare data */
174 /* to be imported for MSVC clients. This costs an extra */
175 /* indirection for MSVC clients using the static version */
176 /* of the library, but don't worry about that. Besides, */
177 /* as a workaround, they can define FFI_BUILDING if they */
178 /* *know* they are going to link with the static library. */
179 #if defined _MSC_VER && !defined FFI_BUILDING
180 #define FFI_EXTERN extern __declspec(dllimport)
181 #else
182 #define FFI_EXTERN extern
183 #endif
184
185 /* These are defined in types.c */
186 FFI_EXTERN ffi_type ffi_type_void;
187 FFI_EXTERN ffi_type ffi_type_uint8;
188 FFI_EXTERN ffi_type ffi_type_sint8;
189 FFI_EXTERN ffi_type ffi_type_uint16;
190 FFI_EXTERN ffi_type ffi_type_sint16;
191 FFI_EXTERN ffi_type ffi_type_uint32;
192 FFI_EXTERN ffi_type ffi_type_sint32;
193 FFI_EXTERN ffi_type ffi_type_uint64;
194 FFI_EXTERN ffi_type ffi_type_sint64;
195 FFI_EXTERN ffi_type ffi_type_float;
196 FFI_EXTERN ffi_type ffi_type_double;
197 FFI_EXTERN ffi_type ffi_type_pointer;
198
199 #if 1
200 FFI_EXTERN ffi_type ffi_type_longdouble;
201 #else
202 #define ffi_type_longdouble ffi_type_double
203 #endif
204
205 #ifdef FFI_TARGET_HAS_COMPLEX_TYPE
206 FFI_EXTERN ffi_type ffi_type_complex_float;
207 FFI_EXTERN ffi_type ffi_type_complex_double;
208 #if 1
209 FFI_EXTERN ffi_type ffi_type_complex_longdouble;
210 #else
211 #define ffi_type_complex_longdouble ffi_type_complex_double
212 #endif
213 #endif
214 #endif /* LIBFFI_HIDE_BASIC_TYPES */
215
216 typedef enum {
217 FFI_OK = 0,
218 FFI_BAD_TYPEDEF,
219 FFI_BAD_ABI
220 } ffi_status;
221
222 typedef unsigned FFI_TYPE;
223
224 typedef struct {
225 ffi_abi abi;
226 unsigned nargs;
227 ffi_type **arg_types;
228 ffi_type *rtype;
229 unsigned bytes;
230 unsigned flags;
231 #ifdef FFI_EXTRA_CIF_FIELDS
232 FFI_EXTRA_CIF_FIELDS;
233 #endif
234 } ffi_cif;
235
236 #if 0
237 /* Used to adjust size/alignment of ffi types. */
238 void ffi_prep_types (ffi_abi abi);
239 #endif
240
241 /* Used internally, but overridden by some architectures */
242 ffi_status ffi_prep_cif_core(ffi_cif *cif,
243 ffi_abi abi,
244 unsigned int isvariadic,
245 unsigned int nfixedargs,
246 unsigned int ntotalargs,
247 ffi_type *rtype,
248 ffi_type **atypes);
249
250 /* ---- Definitions for the raw API -------------------------------------- */
251
252 #ifndef FFI_SIZEOF_ARG
253 # if LONG_MAX == 2147483647
254 # define FFI_SIZEOF_ARG 4
255 # elif LONG_MAX == FFI_64_BIT_MAX
256 # define FFI_SIZEOF_ARG 8
257 # endif
258 #endif
259
260 #ifndef FFI_SIZEOF_JAVA_RAW
261 # define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG
262 #endif
263
264 typedef union {
265 ffi_sarg sint;
266 ffi_arg uint;
267 float flt;
268 char data[FFI_SIZEOF_ARG];
269 void* ptr;
270 } ffi_raw;
271
272 #if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8
273 /* This is a special case for mips64/n32 ABI (and perhaps others) where
274 sizeof(void *) is 4 and FFI_SIZEOF_ARG is 8. */
275 typedef union {
276 signed int sint;
277 unsigned int uint;
278 float flt;
279 char data[FFI_SIZEOF_JAVA_RAW];
280 void* ptr;
281 } ffi_java_raw;
282 #else
283 typedef ffi_raw ffi_java_raw;
284 #endif
285
286
287 void ffi_raw_call (ffi_cif *cif,
288 void (*fn)(void),
289 void *rvalue,
290 ffi_raw *avalue);
291
292 void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
293 void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
294 size_t ffi_raw_size (ffi_cif *cif);
295
296 /* This is analogous to the raw API, except it uses Java parameter */
297 /* packing, even on 64-bit machines. I.e. on 64-bit machines */
298 /* longs and doubles are followed by an empty 64-bit word. */
299
300 void ffi_java_raw_call (ffi_cif *cif,
301 void (*fn)(void),
302 void *rvalue,
303 ffi_java_raw *avalue);
304
305 void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw);
306 void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args);
307 size_t ffi_java_raw_size (ffi_cif *cif);
308
309 /* ---- Definitions for closures ----------------------------------------- */
310
311 #if FFI_CLOSURES
312
313 #ifdef _MSC_VER
314 __declspec(align(8))
315 #endif
316 typedef struct {
317 #if 0
318 void *trampoline_table;
319 void *trampoline_table_entry;
320 #else
321 char tramp[FFI_TRAMPOLINE_SIZE];
322 #endif
323 ffi_cif *cif;
324 void (*fun)(ffi_cif*,void*,void**,void*);
325 void *user_data;
326 #ifdef __GNUC__
327 } ffi_closure __attribute__((aligned (8)));
328 #else
329 } ffi_closure;
330 # ifdef __sgi
331 # pragma pack 0
332 # endif
333 #endif
334
335 void *ffi_closure_alloc (size_t size, void **code);
336 void ffi_closure_free (void *);
337
338 ffi_status
339 ffi_prep_closure (ffi_closure*,
340 ffi_cif *,
341 void (*fun)(ffi_cif*,void*,void**,void*),
342 void *user_data);
343
344 ffi_status
345 ffi_prep_closure_loc (ffi_closure*,
346 ffi_cif *,
347 void (*fun)(ffi_cif*,void*,void**,void*),
348 void *user_data,
349 void*codeloc);
350
351 #ifdef __sgi
352 # pragma pack 8
353 #endif
354 typedef struct {
355 #if 0
356 void *trampoline_table;
357 void *trampoline_table_entry;
358 #else
359 char tramp[FFI_TRAMPOLINE_SIZE];
360 #endif
361 ffi_cif *cif;
362
363 #if !FFI_NATIVE_RAW_API
364
365 /* if this is enabled, then a raw closure has the same layout
366 as a regular closure. We use this to install an intermediate
367 handler to do the transaltion, void** -> ffi_raw*. */
368
369 void (*translate_args)(ffi_cif*,void*,void**,void*);
370 void *this_closure;
371
372 #endif
373
374 void (*fun)(ffi_cif*,void*,ffi_raw*,void*);
375 void *user_data;
376
377 } ffi_raw_closure;
378
379 typedef struct {
380 #if 0
381 void *trampoline_table;
382 void *trampoline_table_entry;
383 #else
384 char tramp[FFI_TRAMPOLINE_SIZE];
385 #endif
386
387 ffi_cif *cif;
388
389 #if !FFI_NATIVE_RAW_API
390
391 /* if this is enabled, then a raw closure has the same layout
392 as a regular closure. We use this to install an intermediate
393 handler to do the transaltion, void** -> ffi_raw*. */
394
395 void (*translate_args)(ffi_cif*,void*,void**,void*);
396 void *this_closure;
397
398 #endif
399
400 void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*);
401 void *user_data;
402
403 } ffi_java_raw_closure;
404
405 ffi_status
406 ffi_prep_raw_closure (ffi_raw_closure*,
407 ffi_cif *cif,
408 void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
409 void *user_data);
410
411 ffi_status
412 ffi_prep_raw_closure_loc (ffi_raw_closure*,
413 ffi_cif *cif,
414 void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
415 void *user_data,
416 void *codeloc);
417
418 ffi_status
419 ffi_prep_java_raw_closure (ffi_java_raw_closure*,
420 ffi_cif *cif,
421 void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
422 void *user_data);
423
424 ffi_status
425 ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*,
426 ffi_cif *cif,
427 void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
428 void *user_data,
429 void *codeloc);
430
431 #endif /* FFI_CLOSURES */
432
433 #if FFI_GO_CLOSURES
434
435 typedef struct {
436 void *tramp;
437 ffi_cif *cif;
438 void (*fun)(ffi_cif*,void*,void**,void*);
439 } ffi_go_closure;
440
441 ffi_status ffi_prep_go_closure (ffi_go_closure*, ffi_cif *,
442 void (*fun)(ffi_cif*,void*,void**,void*));
443
444 void ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue,
445 void **avalue, void *closure);
446
447 #endif /* FFI_GO_CLOSURES */
448
449 /* ---- Public interface definition -------------------------------------- */
450
451 ffi_status ffi_prep_cif(ffi_cif *cif,
452 ffi_abi abi,
453 unsigned int nargs,
454 ffi_type *rtype,
455 ffi_type **atypes);
456
457 ffi_status ffi_prep_cif_var(ffi_cif *cif,
458 ffi_abi abi,
459 unsigned int nfixedargs,
460 unsigned int ntotalargs,
461 ffi_type *rtype,
462 ffi_type **atypes);
463
464 void ffi_call(ffi_cif *cif,
465 void (*fn)(void),
466 void *rvalue,
467 void **avalue);
468
469 /* Useful for eliminating compiler warnings */
470 #define FFI_FN(f) ((void (*)(void))f)
471
472 /* ---- Definitions shared with assembly code ---------------------------- */
473
474 #endif
475
476 /* If these change, update src/mips/ffitarget.h. */
477 #define FFI_TYPE_VOID 0
478 #define FFI_TYPE_INT 1
479 #define FFI_TYPE_FLOAT 2
480 #define FFI_TYPE_DOUBLE 3
481 #if 1
482 #define FFI_TYPE_LONGDOUBLE 4
483 #else
484 #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
485 #endif
486 #define FFI_TYPE_UINT8 5
487 #define FFI_TYPE_SINT8 6
488 #define FFI_TYPE_UINT16 7
489 #define FFI_TYPE_SINT16 8
490 #define FFI_TYPE_UINT32 9
491 #define FFI_TYPE_SINT32 10
492 #define FFI_TYPE_UINT64 11
493 #define FFI_TYPE_SINT64 12
494 #define FFI_TYPE_STRUCT 13
495 #define FFI_TYPE_POINTER 14
496 #define FFI_TYPE_COMPLEX 15
497
498 /* This should always refer to the last type code (for sanity checks) */
499 #define FFI_TYPE_LAST FFI_TYPE_COMPLEX
500
501 #ifdef __cplusplus
502 }
503 #endif
504
505 #endif
506
507
508 #endif
OLDNEW
« no previous file with comments | « Modules/_ctypes/libffi_ios/include/ffitarget_x86_64.h ('k') | Modules/_ctypes/libffi_ios/java_raw_api.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+