Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d8fe1f7

Browse files
committed
* Fix remaining bits of issue 17192 for 3.4 - these changes
were missing from a messed up merge during the libffi 3.0.13 import. the diffs from upstream libffi 3.0.13 are now small.
2 parents 6897267 + 5dc268e commit d8fe1f7

16 files changed

Lines changed: 418 additions & 231 deletions

File tree

Modules/_ctypes/libffi/src/m68k/sysv.S

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
sysv.S - Copyright (c) 2012 Alan Hourihane
44
Copyright (c) 1998, 2012 Andreas Schwab
5-
Copyright (c) 2008 Red Hat, Inc.
6-
7-
m68k Foreign Function Interface
5+
Copyright (c) 2008 Red Hat, Inc.
6+
Copyright (c) 2012 Thorsten Glaser
7+
8+
m68k Foreign Function Interface
89

910
Permission is hereby granted, free of charge, to any person obtaining
1011
a copy of this software and associated documentation files (the
@@ -168,8 +169,28 @@ retstruct1:
168169

169170
retstruct2:
170171
btst #7,%d2
171-
jbeq noretval
172+
jbeq retsint8
172173
move.w %d0,(%a1)
174+
jbra epilogue
175+
176+
retsint8:
177+
btst #8,%d2
178+
jbeq retsint16
179+
| NOTE: On the mc68000, extb is not supported. 8->16, then 16->32.
180+
#if !defined(__mc68020__) && !defined(__mc68030__) && !defined(__mc68040__) && !defined(__mc68060__) && !defined(__mcoldfire__)
181+
ext.w %d0
182+
ext.l %d0
183+
#else
184+
extb.l %d0
185+
#endif
186+
move.l %d0,(%a1)
187+
jbra epilogue
188+
189+
retsint16:
190+
btst #9,%d2
191+
jbeq noretval
192+
ext.l %d0
193+
move.l %d0,(%a1)
173194

174195
noretval:
175196
epilogue:
@@ -201,15 +222,18 @@ CALLFUNC(ffi_closure_SYSV):
201222
lsr.l #1,%d0
202223
jne 1f
203224
jcc .Lcls_epilogue
225+
| CIF_FLAGS_INT
204226
move.l -12(%fp),%d0
205227
.Lcls_epilogue:
228+
| no CIF_FLAGS_*
206229
unlk %fp
207230
rts
208231
1:
209232
lea -12(%fp),%a0
210233
lsr.l #2,%d0
211234
jne 1f
212235
jcs .Lcls_ret_float
236+
| CIF_FLAGS_DINT
213237
move.l (%a0)+,%d0
214238
move.l (%a0),%d1
215239
jra .Lcls_epilogue
@@ -224,6 +248,7 @@ CALLFUNC(ffi_closure_SYSV):
224248
lsr.l #2,%d0
225249
jne 1f
226250
jcs .Lcls_ret_ldouble
251+
| CIF_FLAGS_DOUBLE
227252
#if defined(__MC68881__) || defined(__HAVE_68881__)
228253
fmove.d (%a0),%fp0
229254
#else
@@ -242,17 +267,37 @@ CALLFUNC(ffi_closure_SYSV):
242267
jra .Lcls_epilogue
243268
1:
244269
lsr.l #2,%d0
245-
jne .Lcls_ret_struct2
270+
jne 1f
246271
jcs .Lcls_ret_struct1
272+
| CIF_FLAGS_POINTER
247273
move.l (%a0),%a0
248274
move.l %a0,%d0
249275
jra .Lcls_epilogue
250276
.Lcls_ret_struct1:
251277
move.b (%a0),%d0
252278
jra .Lcls_epilogue
253-
.Lcls_ret_struct2:
279+
1:
280+
lsr.l #2,%d0
281+
jne 1f
282+
jcs .Lcls_ret_sint8
283+
| CIF_FLAGS_STRUCT2
254284
move.w (%a0),%d0
255285
jra .Lcls_epilogue
286+
.Lcls_ret_sint8:
287+
move.l (%a0),%d0
288+
| NOTE: On the mc68000, extb is not supported. 8->16, then 16->32.
289+
#if !defined(__mc68020__) && !defined(__mc68030__) && !defined(__mc68040__) && !defined(__mc68060__) && !defined(__mcoldfire__)
290+
ext.w %d0
291+
ext.l %d0
292+
#else
293+
extb.l %d0
294+
#endif
295+
jra .Lcls_epilogue
296+
1:
297+
| CIF_FLAGS_SINT16
298+
move.l (%a0),%d0
299+
ext.l %d0
300+
jra .Lcls_epilogue
256301
CFI_ENDPROC()
257302

258303
.size CALLFUNC(ffi_closure_SYSV),.-CALLFUNC(ffi_closure_SYSV)

Modules/_ctypes/libffi/src/mips/ffi.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,16 @@ ffi_prep_closure_loc (ffi_closure *closure,
670670
if (cif->abi != FFI_O32 && cif->abi != FFI_O32_SOFT_FLOAT)
671671
return FFI_BAD_ABI;
672672
fn = ffi_closure_O32;
673-
#else /* FFI_MIPS_N32 */
674-
if (cif->abi != FFI_N32 && cif->abi != FFI_N64)
673+
#else
674+
#if _MIPS_SIM ==_ABIN32
675+
if (cif->abi != FFI_N32
676+
&& cif->abi != FFI_N32_SOFT_FLOAT)
677+
return FFI_BAD_ABI;
678+
#else
679+
if (cif->abi != FFI_N64
680+
&& cif->abi != FFI_N64_SOFT_FLOAT)
675681
return FFI_BAD_ABI;
682+
#endif
676683
fn = ffi_closure_N32;
677684
#endif /* FFI_MIPS_O32 */
678685

Modules/_ctypes/libffi/src/powerpc/ffi.c

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ enum {
4848

4949
FLAG_RETURNS_128BITS = 1 << (31-27), /* cr6 */
5050

51+
FLAG_SYSV_SMST_R4 = 1 << (31-26), /* use r4 for FFI_SYSV 8 byte
52+
structs. */
53+
FLAG_SYSV_SMST_R3 = 1 << (31-25), /* use r3 for FFI_SYSV 4 byte
54+
structs. */
55+
5156
FLAG_ARG_NEEDS_COPY = 1 << (31- 7),
5257
#ifndef __NO_FPRS__
5358
FLAG_FP_ARGUMENTS = 1 << (31- 6), /* cr1.eq; specified by ABI */
@@ -367,7 +372,13 @@ ffi_prep_args_SYSV (extended_cif *ecif, unsigned *const stack)
367372
/* Check that we didn't overrun the stack... */
368373
FFI_ASSERT (copy_space.c >= next_arg.c);
369374
FFI_ASSERT (gpr_base.u <= stacktop.u - ASM_NEEDS_REGISTERS);
375+
/* The assert below is testing that the number of integer arguments agrees
376+
with the number found in ffi_prep_cif_machdep(). However, intarg_count
377+
is incremeneted whenever we place an FP arg on the stack, so account for
378+
that before our assert test. */
370379
#ifndef __NO_FPRS__
380+
if (fparg_count > NUM_FPR_ARG_REGISTERS)
381+
intarg_count -= fparg_count - NUM_FPR_ARG_REGISTERS;
371382
FFI_ASSERT (fpr_base.u
372383
<= stacktop.u - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS);
373384
#endif
@@ -664,9 +675,11 @@ ffi_prep_cif_machdep (ffi_cif *cif)
664675
switch (type)
665676
{
666677
#ifndef __NO_FPRS__
678+
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
667679
case FFI_TYPE_LONGDOUBLE:
668680
flags |= FLAG_RETURNS_128BITS;
669681
/* Fall through. */
682+
#endif
670683
case FFI_TYPE_DOUBLE:
671684
flags |= FLAG_RETURNS_64BITS;
672685
/* Fall through. */
@@ -684,18 +697,35 @@ ffi_prep_cif_machdep (ffi_cif *cif)
684697
break;
685698

686699
case FFI_TYPE_STRUCT:
687-
/*
688-
* The final SYSV ABI says that structures smaller or equal 8 bytes
689-
* are returned in r3/r4. The FFI_GCC_SYSV ABI instead returns them
690-
* in memory.
691-
*
692-
* NOTE: The assembly code can safely assume that it just needs to
693-
* store both r3 and r4 into a 8-byte word-aligned buffer, as
694-
* we allocate a temporary buffer in ffi_call() if this flag is
695-
* set.
696-
*/
697-
if (cif->abi == FFI_SYSV && size <= 8)
698-
flags |= FLAG_RETURNS_SMST;
700+
if (cif->abi == FFI_SYSV)
701+
{
702+
/* The final SYSV ABI says that structures smaller or equal 8 bytes
703+
are returned in r3/r4. The FFI_GCC_SYSV ABI instead returns them
704+
in memory. */
705+
706+
/* Treat structs with size <= 8 bytes. */
707+
if (size <= 8)
708+
{
709+
flags |= FLAG_RETURNS_SMST;
710+
/* These structs are returned in r3. We pack the type and the
711+
precalculated shift value (needed in the sysv.S) into flags.
712+
The same applies for the structs returned in r3/r4. */
713+
if (size <= 4)
714+
{
715+
flags |= FLAG_SYSV_SMST_R3;
716+
flags |= 8 * (4 - size) << 8;
717+
break;
718+
}
719+
/* These structs are returned in r3 and r4. See above. */
720+
if (size <= 8)
721+
{
722+
flags |= FLAG_SYSV_SMST_R3 | FLAG_SYSV_SMST_R4;
723+
flags |= 8 * (8 - size) << 8;
724+
break;
725+
}
726+
}
727+
}
728+
699729
intarg_count++;
700730
flags |= FLAG_RETVAL_REFERENCE;
701731
/* Fall through. */

Modules/_ctypes/libffi/src/sparc/ffi.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* -----------------------------------------------------------------------
2-
ffi.c - Copyright (c) 2011 Anthony Green
2+
ffi.c - Copyright (c) 2011, 2013 Anthony Green
33
Copyright (c) 1996, 2003-2004, 2007-2008 Red Hat, Inc.
44
55
SPARC Foreign Function Interface
@@ -376,6 +376,10 @@ extern int ffi_call_v8(void *, extended_cif *, unsigned,
376376
unsigned, unsigned *, void (*fn)(void));
377377
#endif
378378

379+
#ifndef __GNUC__
380+
void ffi_flush_icache (void *, size_t);
381+
#endif
382+
379383
void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
380384
{
381385
extended_cif ecif;
@@ -417,7 +421,7 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
417421
/* behind "call", so we alloc some executable space for it. */
418422
/* l7 is used, we need to make sure v8.S doesn't use %l7. */
419423
unsigned int *call_struct = NULL;
420-
ffi_closure_alloc(32, &call_struct);
424+
ffi_closure_alloc(32, (void **)&call_struct);
421425
if (call_struct)
422426
{
423427
unsigned long f = (unsigned long)fn;
@@ -432,10 +436,14 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
432436
call_struct[5] = 0x01000000; /* nop */
433437
call_struct[6] = 0x81c7e008; /* ret */
434438
call_struct[7] = 0xbe100017; /* mov %l7, %i7 */
439+
#ifdef __GNUC__
435440
asm volatile ("iflush %0; iflush %0+8; iflush %0+16; iflush %0+24" : :
436441
"r" (call_struct) : "memory");
437442
/* SPARC v8 requires 5 instructions for flush to be visible */
438443
asm volatile ("nop; nop; nop; nop; nop");
444+
#else
445+
ffi_flush_icache (call_struct, 32);
446+
#endif
439447
ffi_call_v8(ffi_prep_args_v8, &ecif, cif->bytes,
440448
cif->flags, rvalue, call_struct);
441449
ffi_closure_free(call_struct);
@@ -513,13 +521,17 @@ ffi_prep_closure_loc (ffi_closure* closure,
513521
closure->user_data = user_data;
514522

515523
/* Flush the Icache. closure is 8 bytes aligned. */
524+
#ifdef __GNUC__
516525
#ifdef SPARC64
517526
asm volatile ("flush %0; flush %0+8" : : "r" (closure) : "memory");
518527
#else
519528
asm volatile ("iflush %0; iflush %0+8" : : "r" (closure) : "memory");
520529
/* SPARC v8 requires 5 instructions for flush to be visible */
521530
asm volatile ("nop; nop; nop; nop; nop");
522531
#endif
532+
#else
533+
ffi_flush_icache (closure, 16);
534+
#endif
523535

524536
return FFI_OK;
525537
}

Modules/_ctypes/libffi/src/x86/ffi64.c

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* -----------------------------------------------------------------------
2-
ffi64.c - Copyright (c) 20011 Anthony Green
2+
ffi64.c - Copyright (c) 2013 The Written Word, Inc.
3+
Copyright (c) 2011 Anthony Green
34
Copyright (c) 2008, 2010 Red Hat, Inc.
45
Copyright (c) 2002, 2007 Bo Thorsen <[email protected]>
56
@@ -37,17 +38,29 @@
3738
#define MAX_GPR_REGS 6
3839
#define MAX_SSE_REGS 8
3940

40-
#ifdef __INTEL_COMPILER
41+
#if defined(__INTEL_COMPILER)
4142
#define UINT128 __m128
4243
#else
44+
#if defined(__SUNPRO_C)
45+
#include <sunmedia_types.h>
46+
#define UINT128 __m128i
47+
#else
4348
#define UINT128 __int128_t
4449
#endif
50+
#endif
51+
52+
union big_int_union
53+
{
54+
UINT32 i32;
55+
UINT64 i64;
56+
UINT128 i128;
57+
};
4558

4659
struct register_args
4760
{
4861
/* Registers for argument passing. */
4962
UINT64 gpr[MAX_GPR_REGS];
50-
UINT128 sse[MAX_SSE_REGS];
63+
union big_int_union sse[MAX_SSE_REGS];
5164
};
5265

5366
extern void ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags,
@@ -471,16 +484,33 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
471484
{
472485
case X86_64_INTEGER_CLASS:
473486
case X86_64_INTEGERSI_CLASS:
474-
reg_args->gpr[gprcount] = 0;
475-
memcpy (&reg_args->gpr[gprcount], a, size < 8 ? size : 8);
487+
/* Sign-extend integer arguments passed in general
488+
purpose registers, to cope with the fact that
489+
LLVM incorrectly assumes that this will be done
490+
(the x86-64 PS ABI does not specify this). */
491+
switch (arg_types[i]->type)
492+
{
493+
case FFI_TYPE_SINT8:
494+
*(SINT64 *)&reg_args->gpr[gprcount] = (SINT64) *((SINT8 *) a);
495+
break;
496+
case FFI_TYPE_SINT16:
497+
*(SINT64 *)&reg_args->gpr[gprcount] = (SINT64) *((SINT16 *) a);
498+
break;
499+
case FFI_TYPE_SINT32:
500+
*(SINT64 *)&reg_args->gpr[gprcount] = (SINT64) *((SINT32 *) a);
501+
break;
502+
default:
503+
reg_args->gpr[gprcount] = 0;
504+
memcpy (&reg_args->gpr[gprcount], a, size < 8 ? size : 8);
505+
}
476506
gprcount++;
477507
break;
478508
case X86_64_SSE_CLASS:
479509
case X86_64_SSEDF_CLASS:
480-
reg_args->sse[ssecount++] = *(UINT64 *) a;
510+
reg_args->sse[ssecount++].i64 = *(UINT64 *) a;
481511
break;
482512
case X86_64_SSESF_CLASS:
483-
reg_args->sse[ssecount++] = *(UINT32 *) a;
513+
reg_args->sse[ssecount++].i32 = *(UINT32 *) a;
484514
break;
485515
default:
486516
abort();

Modules/_ctypes/libffi/src/x86/ffitarget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ typedef unsigned long long ffi_arg;
6161
typedef long long ffi_sarg;
6262
#endif
6363
#else
64-
#if defined __x86_64__ && !defined __LP64__
64+
#if defined __x86_64__ && defined __ILP32__
6565
#define FFI_SIZEOF_ARG 8
66+
#define FFI_SIZEOF_JAVA_RAW 4
6667
typedef unsigned long long ffi_arg;
6768
typedef long long ffi_sarg;
6869
#else

0 commit comments

Comments
 (0)