ยปCore Development>Code coverage>Modules/_ctypes/libffi/src/powerpc/ffi.c

Python code coverage for Modules/_ctypes/libffi/src/powerpc/ffi.c

#countcontent
1n/a/* -----------------------------------------------------------------------
2n/a ffi.c - Copyright (C) 2013 IBM
3n/a Copyright (C) 2011 Anthony Green
4n/a Copyright (C) 2011 Kyle Moffett
5n/a Copyright (C) 2008 Red Hat, Inc
6n/a Copyright (C) 2007, 2008 Free Software Foundation, Inc
7n/a Copyright (c) 1998 Geoffrey Keating
8n/a
9n/a PowerPC Foreign Function Interface
10n/a
11n/a Permission is hereby granted, free of charge, to any person obtaining
12n/a a copy of this software and associated documentation files (the
13n/a ``Software''), to deal in the Software without restriction, including
14n/a without limitation the rights to use, copy, modify, merge, publish,
15n/a distribute, sublicense, and/or sell copies of the Software, and to
16n/a permit persons to whom the Software is furnished to do so, subject to
17n/a the following conditions:
18n/a
19n/a The above copyright notice and this permission notice shall be included
20n/a in all copies or substantial portions of the Software.
21n/a
22n/a THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
23n/a OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24n/a MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25n/a IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
26n/a OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27n/a ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28n/a OTHER DEALINGS IN THE SOFTWARE.
29n/a ----------------------------------------------------------------------- */
30n/a
31n/a#include "ffi.h"
32n/a#include "ffi_common.h"
33n/a#include "ffi_powerpc.h"
34n/a
35n/a#if HAVE_LONG_DOUBLE_VARIANT
36n/a/* Adjust ffi_type_longdouble. */
37n/avoid FFI_HIDDEN
38n/affi_prep_types (ffi_abi abi)
39n/a{
40n/a# if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
41n/a# ifdef POWERPC64
42n/a ffi_prep_types_linux64 (abi);
43n/a# else
44n/a ffi_prep_types_sysv (abi);
45n/a# endif
46n/a# endif
47n/a}
48n/a#endif
49n/a
50n/a/* Perform machine dependent cif processing */
51n/affi_status FFI_HIDDEN
52n/affi_prep_cif_machdep (ffi_cif *cif)
53n/a{
54n/a#ifdef POWERPC64
55n/a return ffi_prep_cif_linux64 (cif);
56n/a#else
57n/a return ffi_prep_cif_sysv (cif);
58n/a#endif
59n/a}
60n/a
61n/affi_status FFI_HIDDEN
62n/affi_prep_cif_machdep_var (ffi_cif *cif,
63n/a unsigned int nfixedargs MAYBE_UNUSED,
64n/a unsigned int ntotalargs MAYBE_UNUSED)
65n/a{
66n/a#ifdef POWERPC64
67n/a return ffi_prep_cif_linux64_var (cif, nfixedargs, ntotalargs);
68n/a#else
69n/a return ffi_prep_cif_sysv (cif);
70n/a#endif
71n/a}
72n/a
73n/avoid
74n/affi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
75n/a{
76n/a /* The final SYSV ABI says that structures smaller or equal 8 bytes
77n/a are returned in r3/r4. A draft ABI used by linux instead returns
78n/a them in memory.
79n/a
80n/a We bounce-buffer SYSV small struct return values so that sysv.S
81n/a can write r3 and r4 to memory without worrying about struct size.
82n/a
83n/a For ELFv2 ABI, use a bounce buffer for homogeneous structs too,
84n/a for similar reasons. */
85n/a unsigned long smst_buffer[8];
86n/a extended_cif ecif;
87n/a
88n/a ecif.cif = cif;
89n/a ecif.avalue = avalue;
90n/a
91n/a ecif.rvalue = rvalue;
92n/a if ((cif->flags & FLAG_RETURNS_SMST) != 0)
93n/a ecif.rvalue = smst_buffer;
94n/a /* Ensure that we have a valid struct return value.
95n/a FIXME: Isn't this just papering over a user problem? */
96n/a else if (!rvalue && cif->rtype->type == FFI_TYPE_STRUCT)
97n/a ecif.rvalue = alloca (cif->rtype->size);
98n/a
99n/a#ifdef POWERPC64
100n/a ffi_call_LINUX64 (&ecif, -(long) cif->bytes, cif->flags, ecif.rvalue, fn);
101n/a#else
102n/a ffi_call_SYSV (&ecif, -cif->bytes, cif->flags, ecif.rvalue, fn);
103n/a#endif
104n/a
105n/a /* Check for a bounce-buffered return value */
106n/a if (rvalue && ecif.rvalue == smst_buffer)
107n/a {
108n/a unsigned int rsize = cif->rtype->size;
109n/a#ifndef __LITTLE_ENDIAN__
110n/a /* The SYSV ABI returns a structure of up to 4 bytes in size
111n/a left-padded in r3. */
112n/a# ifndef POWERPC64
113n/a if (rsize <= 4)
114n/a memcpy (rvalue, (char *) smst_buffer + 4 - rsize, rsize);
115n/a else
116n/a# endif
117n/a /* The SYSV ABI returns a structure of up to 8 bytes in size
118n/a left-padded in r3/r4, and the ELFv2 ABI similarly returns a
119n/a structure of up to 8 bytes in size left-padded in r3. */
120n/a if (rsize <= 8)
121n/a memcpy (rvalue, (char *) smst_buffer + 8 - rsize, rsize);
122n/a else
123n/a#endif
124n/a memcpy (rvalue, smst_buffer, rsize);
125n/a }
126n/a}
127n/a
128n/a
129n/affi_status
130n/affi_prep_closure_loc (ffi_closure *closure,
131n/a ffi_cif *cif,
132n/a void (*fun) (ffi_cif *, void *, void **, void *),
133n/a void *user_data,
134n/a void *codeloc)
135n/a{
136n/a#ifdef POWERPC64
137n/a return ffi_prep_closure_loc_linux64 (closure, cif, fun, user_data, codeloc);
138n/a#else
139n/a return ffi_prep_closure_loc_sysv (closure, cif, fun, user_data, codeloc);
140n/a#endif
141n/a}