Mercurial > pub > dyncall > dyncall
annotate dyncallback/dyncall_args_x64.c @ 554:4d87bd4890b0
win64 callback dcbArgAggr() retval fix
author | Tassilo Philipp |
---|---|
date | Mon, 20 Jun 2022 15:42:55 +0200 |
parents | eef302b7a58d |
children | b36a738c8975 |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: dyncallback | |
5 File: dyncallback/dyncall_args_x64.c | |
6 Description: Callback's Arguments VM - Implementation for x64 | |
7 License: | |
8 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
9 Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>, |
0 | 10 Tassilo Philipp <tphilipp@potion-studios.com> |
11 | |
12 Permission to use, copy, modify, and distribute this software for any | |
13 purpose with or without fee is hereby granted, provided that the above | |
14 copyright notice and this permission notice appear in all copies. | |
15 | |
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
23 | |
24 */ | |
25 | |
26 | |
27 | |
28 #include "dyncall_args_x64.h" | |
29 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
30 #include <assert.h> |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
31 #include <string.h> |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
32 |
0 | 33 |
34 static int64* arg_i64(DCArgs* args) | |
35 { | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
36 args->reg_count.i += (args->reg_count.i == args->aggr_return_register); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
37 |
0 | 38 if (args->reg_count.i < numIntRegs) |
39 return &args->reg_data.i[args->reg_count.i++]; | |
40 else | |
41 return args->stack_ptr++; | |
42 } | |
43 | |
44 | |
45 static double* arg_f64(DCArgs* args) | |
46 { | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
47 #if defined(DC_WINDOWS) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
48 args->reg_count.f += (args->reg_count.f == args->aggr_return_register); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
49 #endif |
0 | 50 if (args->reg_count.f < numFloatRegs) |
51 return &args->reg_data.f[args->reg_count.f++]; | |
52 else | |
53 return (double*)args->stack_ptr++; | |
54 } | |
55 | |
56 | |
57 | |
58 DClonglong dcbArgLongLong (DCArgs* p) { return *arg_i64(p); } | |
59 DCint dcbArgInt (DCArgs* p) { return (int) dcbArgLongLong(p); } | |
60 DClong dcbArgLong (DCArgs* p) { return (long) dcbArgLongLong(p); } | |
61 DCchar dcbArgChar (DCArgs* p) { return (char) dcbArgLongLong(p); } | |
62 DCshort dcbArgShort (DCArgs* p) { return (short) dcbArgLongLong(p); } | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
63 DCbool dcbArgBool (DCArgs* p) { return dcbArgInt(p) != 0; } |
0 | 64 |
65 DCuint dcbArgUInt (DCArgs* p) { return (DCuint) dcbArgInt(p); } | |
66 DCuchar dcbArgUChar (DCArgs* p) { return (DCuchar) dcbArgChar(p); } | |
67 DCushort dcbArgUShort (DCArgs* p) { return (DCushort) dcbArgShort(p); } | |
68 DCulong dcbArgULong (DCArgs* p) { return (DCulong) dcbArgLong(p); } | |
69 DCulonglong dcbArgULongLong(DCArgs* p) { return (DCulonglong) dcbArgLongLong(p); } | |
70 | |
71 | |
72 DCpointer dcbArgPointer (DCArgs* p) { return (DCpointer) dcbArgLongLong(p); } | |
73 | |
74 DCdouble dcbArgDouble (DCArgs* p) { return *arg_f64(p); } | |
75 DCfloat dcbArgFloat (DCArgs* p) { return *(float*)arg_f64(p); } | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
76 |
544
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
77 DCpointer dcbArgAggr (DCArgs* p, DCpointer target) |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
78 { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
79 int i; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
80 DCaggr *ag = *(p->aggrs++); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
81 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
82 if(!ag) { |
536
c0df40c888ac
- dyncallback fixes related to C++ non-trivial aggregates (not final, but fixing most obvious things I missed)
Tassilo Philipp
parents:
533
diff
changeset
|
83 /* non-trivial aggr: retrieve as ptr, user is supposed to make copy */ |
544
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
84 return dcbArgPointer(p); |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
85 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
86 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
87 #if defined(DC_UNIX) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
88 DCRegCount_x64 n_regs = { p->reg_count.i, p->reg_count.f }; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
89 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
90 if(ag->sysv_classes[0] != SYSVC_MEMORY) { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
91 /* reclassify aggr w/ respect to remaining regs, might have been passed entirely via the stack */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
92 for(i=0; ag->sysv_classes[i] && i<DC_SYSV_MAX_NUM_CLASSES; ++i) { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
93 DCuchar clz = ag->sysv_classes[i]; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
94 n_regs.i += (clz == SYSVC_INTEGER); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
95 n_regs.f += (clz == SYSVC_SSE); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
96 /* @@@AGGR implement when implementing x87 types */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
97 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
98 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
99 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
100 if(ag->sysv_classes[0] == SYSVC_MEMORY || (n_regs.i > numIntRegs) || (n_regs.f > numFloatRegs)) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
101 { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
102 memcpy(target, p->stack_ptr, ag->size); |
549
0455834d29a1
- dyncallback: x64/sysv buffer overflow fix for aggregate args whose size isn't a multiple of 8
Tassilo Philipp
parents:
544
diff
changeset
|
103 p->stack_ptr = p->stack_ptr + ((ag->size + (sizeof(DClonglong)-1)) >> 3); /* advance to next full stack slot */ |
544
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
104 } |
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
105 else |
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
106 { |
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
107 for(i=0; ag->sysv_classes[i] && i<DC_SYSV_MAX_NUM_CLASSES; ++i) |
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
108 { |
551
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
109 size_t s = ag->size - i*8; |
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
110 s = s<8?s:8; |
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
111 |
544
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
112 switch (ag->sysv_classes[i]) |
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
113 { |
549
0455834d29a1
- dyncallback: x64/sysv buffer overflow fix for aggregate args whose size isn't a multiple of 8
Tassilo Philipp
parents:
544
diff
changeset
|
114 case SYSVC_INTEGER: |
551
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
115 { |
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
116 DClonglong l = dcbArgLongLong(p); |
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
117 memcpy((DClonglong*)target + i, &l, s); |
549
0455834d29a1
- dyncallback: x64/sysv buffer overflow fix for aggregate args whose size isn't a multiple of 8
Tassilo Philipp
parents:
544
diff
changeset
|
118 } |
0455834d29a1
- dyncallback: x64/sysv buffer overflow fix for aggregate args whose size isn't a multiple of 8
Tassilo Philipp
parents:
544
diff
changeset
|
119 break; |
0455834d29a1
- dyncallback: x64/sysv buffer overflow fix for aggregate args whose size isn't a multiple of 8
Tassilo Philipp
parents:
544
diff
changeset
|
120 |
0455834d29a1
- dyncallback: x64/sysv buffer overflow fix for aggregate args whose size isn't a multiple of 8
Tassilo Philipp
parents:
544
diff
changeset
|
121 case SYSVC_SSE: |
551
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
122 if(s == 8) |
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
123 *(((DCdouble*)target) + i) = dcbArgDouble(p); |
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
124 else if(s == 4) |
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
125 *(DCfloat*)(((DCdouble*)target) + i) = dcbArgFloat (p); |
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
126 else |
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
127 assert(DC_FALSE && "SYSV aggregate floating point slot mismatch (unexpected size of fp field)"); |
549
0455834d29a1
- dyncallback: x64/sysv buffer overflow fix for aggregate args whose size isn't a multiple of 8
Tassilo Philipp
parents:
544
diff
changeset
|
128 break; |
551
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
129 |
544
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
130 /* @@@AGGR implement when implementing x87 types */ |
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
131 default: |
551
eef302b7a58d
- amendment fix for buffer overflow (see commit 0455834d29a1), to also handle non-standard struct packing, + better asserts
Tassilo Philipp
parents:
549
diff
changeset
|
132 assert(DC_FALSE && "unsupported SYSV aggregate slot classification"); /* shouldn't be reached, as we check for unupported classes earlier */ |
544
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
133 } |
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
134 } |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
135 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
136 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
137 #else |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
138 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
139 switch (ag->size) { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
140 case 1: *(DCchar *)target = dcbArgChar (p); break; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
141 case 2: *(DCshort *)target = dcbArgShort (p); break; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
142 case 4: *(DClong *)target = dcbArgLong (p); break; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
143 case 8: *(DClonglong*)target = dcbArgLongLong(p); break; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
144 default: memcpy(target, dcbArgPointer(p), ag->size); break; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
145 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
146 #endif |
554 | 147 |
148 return target; | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
149 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
150 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
151 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
152 /* A 16 byte struct would be sufficient for System V (because at most two of the four registers can be full). */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
153 /* But then it's much more complicated to copy the result to the correct registers in assembly. */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
154 typedef struct { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
155 DClonglong r[2]; /* rax, rdx */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
156 DCdouble x[2]; /* xmm0, xmm1 */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
157 } DCRetRegs_SysV; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
158 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
159 void dcbReturnAggr(DCArgs *args, DCValue *result, DCpointer ret) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
160 { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
161 int i; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
162 DCaggr *ag = *(args->aggrs++); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
163 |
536
c0df40c888ac
- dyncallback fixes related to C++ non-trivial aggregates (not final, but fixing most obvious things I missed)
Tassilo Philipp
parents:
533
diff
changeset
|
164 if(!ag) { |
537
804df3409b51
- callback fix for non-trivial aggregate return values: allowing access to caller-reserved space user is supposed to copy non-triv object into
Tassilo Philipp
parents:
536
diff
changeset
|
165 /* non-trivial aggr: all we can do is to provide the ptr to the output space, user has to make copy */ |
544
111236b31c75
- C++ non-trivial aggregate-by-value handling:
Tassilo Philipp
parents:
537
diff
changeset
|
166 result->p = (DCpointer) args->reg_data.i[0]; |
536
c0df40c888ac
- dyncallback fixes related to C++ non-trivial aggregates (not final, but fixing most obvious things I missed)
Tassilo Philipp
parents:
533
diff
changeset
|
167 return; |
c0df40c888ac
- dyncallback fixes related to C++ non-trivial aggregates (not final, but fixing most obvious things I missed)
Tassilo Philipp
parents:
533
diff
changeset
|
168 } |
c0df40c888ac
- dyncallback fixes related to C++ non-trivial aggregates (not final, but fixing most obvious things I missed)
Tassilo Philipp
parents:
533
diff
changeset
|
169 |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
170 if (args->aggr_return_register >= 0) { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
171 DCpointer dest = (DCpointer) args->reg_data.i[args->aggr_return_register]; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
172 memcpy(dest, ret, ag->size); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
173 result->p = dest; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
174 } else { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
175 #if defined(DC_UNIX) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
176 /* a max of 2 regs are used in this case, out of rax, rdx, xmm0 and xmm1 */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
177 /* space for 4 qwords is pointed to by (DCRetRegs_SysV*)result */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
178 DClonglong *intRegs = ((DCRetRegs_SysV*)result)->r; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
179 DCdouble *sseRegs = ((DCRetRegs_SysV*)result)->x; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
180 for(i=0; ag->sysv_classes[i] && i<2/*guaranteed*/; ++i) { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
181 switch (ag->sysv_classes[i]) { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
182 case SYSVC_INTEGER: *(intRegs++) = ((DClonglong*)ret)[i]; break; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
183 case SYSVC_SSE: *(sseRegs++) = ((DCdouble *)ret)[i]; break; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
184 /* @@@AGGR implement when implementing x87 types, might lead to more than 2 regs (e.g. _m512) */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
185 default: assert(DC_FALSE && "Should never be reached because we check for unupported classes earlier"); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
186 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
187 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
188 #else |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
189 /* copy aggregate (guaranteed to be <= 8b by call conv, as no hidden ptr) into result */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
190 assert(ag->size <= 8 && "aggregate info mismatch for return type"); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
191 memcpy(result, ret, ag->size); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
192 #endif |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
193 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
194 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
195 |