annotate dyncallback/dyncall_callback_x86.c @ 533:71c884e610f0

- integration of patches from Raphael Luba, Thekla, Inc.: * integration of aggregate-by-value (struct, union) support patch for x64 (win and sysv) * windows/x64 asm additions to specify how stack unwinds (help for debuggers, exception handling, etc.) * see Changelog for details - new calling convention modes for thiscalls (platform agnostic, was specific before) * new signature character for platform agnostic thiscalls ('*' / DC_SIGCHAR_CC_THISCALL) - dcCallF(), dcVCallF(), dcArgF() and dcVArgF(): * added support for aggregates-by-value (wasn't part of patch) * change that those functions don't implicitly call dcReset() anymore, which was unflexible (breaking change) - added macros to feature test implementation for aggregate-by-value and syscall support - changed libdyncall_s.lib and libdyncallback_s.lib order in callback test makefiles, as some toolchains are picky about order - doc: * man page updates to describe aggregate interface * manual overview changes to highlight platforms with aggregate-by-value support - test/plain: replaced tests w/ old/stale sctruct interface with new aggregate one
author Tassilo Philipp
date Thu, 21 Apr 2022 13:35:47 +0200
parents ddfb9577a00e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: dyncallback
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: dyncallback/dyncall_callback_x86.c
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description: Callback - Implementation for x86
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
9 Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>,
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
152
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
27 #include "dyncall_callback.h"
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
28 #include "dyncall_alloc_wx.h"
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
29 #include "dyncall_thunk.h"
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 #include "dyncall_args_x86.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
32
152
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
33 /* Callback symbol. */
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
34 extern void dcCallbackThunkEntry();
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35
152
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
36 struct DCCallback
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
37 {
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
38 DCThunk thunk; /* offset 0, size 16 */
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
39 DCCallbackHandler* handler; /* offset 16 */
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
40 DCArgsVT* args_vt; /* offset 20 */
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
41 size_t stack_cleanup; /* offset 24 */
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
42 void* userdata; /* offset 28 */
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
43 };
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 /* compute stacksize for callee cleanup calling conventions:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 *
152
d48a8b8d2ef9 - integrated all headers containing DCCallback definition into the translation units used (arm64 already avoided this pointless header, so following that style)
cslag
parents: 0
diff changeset
48 * cdecl,stdcall,thiscall_ms,fastcall_ms,fastcall_gnu
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
51 static int dcbCleanupSize_x86_cdecl(const DCsigchar* signature)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 return 0;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
56 static int dcbCleanupSize_x86_std(const DCsigchar* signature)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 {
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
58 const DCsigchar* ptr = signature;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 int size = 0;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
60 DCsigchar ch;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 while( (ch = *ptr++) != DC_SIGCHAR_ENDARG ) {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 switch(ch) {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 case DC_SIGCHAR_BOOL:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 case DC_SIGCHAR_CHAR:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65 case DC_SIGCHAR_SHORT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66 case DC_SIGCHAR_INT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 case DC_SIGCHAR_LONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 case DC_SIGCHAR_POINTER:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 case DC_SIGCHAR_UCHAR:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 case DC_SIGCHAR_USHORT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71 case DC_SIGCHAR_UINT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 case DC_SIGCHAR_ULONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73 case DC_SIGCHAR_STRING:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74 case DC_SIGCHAR_FLOAT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75 size += 4;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77 case DC_SIGCHAR_DOUBLE:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
78 case DC_SIGCHAR_LONGLONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79 case DC_SIGCHAR_ULONGLONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
80 size += 8;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
81 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
83 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
84 return size;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
85 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
86
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
87 static int dcbCleanupSize_x86_this_ms(const DCsigchar* signature)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88 {
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
89 const DCsigchar* ptr = signature;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90 int size = 0;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
91 DCsigchar ch;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
92 while( (ch = *ptr++) != DC_SIGCHAR_ENDARG )
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
93 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
94 switch(ch)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
95 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96 case DC_SIGCHAR_BOOL:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
97 case DC_SIGCHAR_CHAR:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
98 case DC_SIGCHAR_SHORT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
99 case DC_SIGCHAR_INT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
100 case DC_SIGCHAR_LONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
101 case DC_SIGCHAR_POINTER:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
102 case DC_SIGCHAR_UCHAR:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
103 case DC_SIGCHAR_USHORT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
104 case DC_SIGCHAR_UINT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 case DC_SIGCHAR_ULONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
106 case DC_SIGCHAR_STRING:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
107 case DC_SIGCHAR_FLOAT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
108 size += 4;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
109 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
110 case DC_SIGCHAR_DOUBLE:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111 case DC_SIGCHAR_LONGLONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112 case DC_SIGCHAR_ULONGLONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113 size += 8;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
114 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
115 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
116 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
117 return size;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
118 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
119
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
120 static int dcbCleanupSize_x86_fast_ms(const DCsigchar* signature)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
121 {
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
122 const DCsigchar* ptr = signature;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
123 int size = 0;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
124 int regs = 0;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
125 DCsigchar ch;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
126 while( (ch = *ptr++) != DC_SIGCHAR_ENDARG )
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
127 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
128 switch(ch)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
129 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
130 case DC_SIGCHAR_BOOL:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
131 case DC_SIGCHAR_CHAR:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
132 case DC_SIGCHAR_SHORT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
133 case DC_SIGCHAR_INT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
134 case DC_SIGCHAR_LONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
135 case DC_SIGCHAR_POINTER:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
136 case DC_SIGCHAR_UCHAR:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
137 case DC_SIGCHAR_USHORT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
138 case DC_SIGCHAR_UINT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
139 case DC_SIGCHAR_ULONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
140 case DC_SIGCHAR_STRING:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
141 if (regs < 2) regs++;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
142 else size += 4;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
143 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
144 case DC_SIGCHAR_FLOAT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
145 size += 4;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
146 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
147 case DC_SIGCHAR_DOUBLE:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
148 size += 8;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
149 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
150 case DC_SIGCHAR_LONGLONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
151 case DC_SIGCHAR_ULONGLONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
152 size += 8;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
153 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
154 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
155 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
156 return size;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
157 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
158
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
159 static int dcbCleanupSize_x86_fast_gnu(const DCsigchar* signature)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
160 {
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
161 const DCsigchar* ptr = signature;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
162 DCsigchar ch;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
163 int size = 0;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
164 int regs = 0;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
165 while( (ch = *ptr++) != DC_SIGCHAR_ENDARG ) {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
166 switch(ch) {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
167 case DC_SIGCHAR_FLOAT:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
168 size += 4;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
169 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
170 case DC_SIGCHAR_DOUBLE:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
171 size += 8;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
172 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
173 case DC_SIGCHAR_LONGLONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
174 case DC_SIGCHAR_ULONGLONG:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
175 regs = 2;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
176 size += 8;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
177 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
178 default:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
179 if (regs < 2) regs++;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
180 else size += 4;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
181 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
182 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
183 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
184 return size;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
185 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
186
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
187
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
188 void dcbInitCallback2(DCCallback* pcb, const DCsigchar* signature, DCCallbackHandler* handler, void* userdata, DCaggr *const * aggrs)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
189 {
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
190 const DCsigchar* ptr;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
191 int mode;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
192 pcb->handler = handler;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
193 pcb->userdata = userdata;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
194
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
195 ptr = signature;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
196
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
197 /* x86 hints: */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
198
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
199 mode = DC_CALL_C_X86_CDECL;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
200
466
ddfb9577a00e introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents: 364
diff changeset
201 if(*ptr == DC_SIGCHAR_CC_PREFIX)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
202 {
466
ddfb9577a00e introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents: 364
diff changeset
203 mode = dcGetModeFromCCSigChar(ptr[1]);
ddfb9577a00e introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents: 364
diff changeset
204 ptr += 2;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
205 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
206
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
207 /* x86 configuration: */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
208
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
209 switch(mode) {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
210 case DC_CALL_C_X86_CDECL:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
211 pcb->args_vt = &dcArgsVT_default;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
212 pcb->stack_cleanup = dcbCleanupSize_x86_cdecl(ptr);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
213 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
214 case DC_CALL_C_X86_WIN32_STD:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
215 pcb->args_vt = &dcArgsVT_default;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
216 pcb->stack_cleanup = dcbCleanupSize_x86_std(ptr);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
217 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
218 case DC_CALL_C_X86_WIN32_FAST_MS:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
219 pcb->args_vt = &dcArgsVT_fast_ms;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
220 pcb->stack_cleanup = dcbCleanupSize_x86_fast_ms(ptr);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
221 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
222 case DC_CALL_C_X86_WIN32_FAST_GNU:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
223 pcb->args_vt = &dcArgsVT_fast_gnu;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
224 pcb->stack_cleanup = dcbCleanupSize_x86_fast_gnu(ptr);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
225 break;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
226 #if defined(DC_WINDOWS) && defined(DC__C_MSVC)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
227 case DC_CALL_C_DEFAULT_THIS:
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
228 #endif
364
3bdd326dc269 - Todo entries
Tassilo Philipp
parents: 358
diff changeset
229 case DC_CALL_C_X86_WIN32_THIS_MS:
3bdd326dc269 - Todo entries
Tassilo Philipp
parents: 358
diff changeset
230 pcb->args_vt = &dcArgsVT_this_ms;
3bdd326dc269 - Todo entries
Tassilo Philipp
parents: 358
diff changeset
231 pcb->stack_cleanup = dcbCleanupSize_x86_this_ms(ptr);
3bdd326dc269 - Todo entries
Tassilo Philipp
parents: 358
diff changeset
232 break;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
233 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
234
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
235 #if defined(DC_PLAN9)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
236 /* HACK for Plan9 - 'reuse' pcb->stack_cleanup as a flag
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
237 to indicate if return value is 64bit. The field is not
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
238 used anyways as the caller is responsible to clean up
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
239 the stack in Plan9. If set to '1' the callback kernel
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
240 takes into account an extra stack-parameter (pointer
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
241 to 64bit return value).
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
242 I thought of introducing a new field, but for one single
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
243 x86 calling convention out of many, it seemed overkill
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
244 to change the struct for everybody else. Maybe renaming
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
245 would be a good idea, though. ~ Tassilo
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
246 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
247 while(*ptr) {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
248 if(*ptr++ == DC_SIGCHAR_ENDARG) {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
249 pcb->stack_cleanup = (*ptr == DC_SIGCHAR_LONGLONG) || (*ptr == DC_SIGCHAR_ULONGLONG);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
250 break;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
251 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
252 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
253 #endif
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
254 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
255
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
256
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
257 DCCallback* dcbNewCallback2(const DCsigchar* signature, DCCallbackHandler* handler, void* userdata, DCaggr *const * aggrs)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
258 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
259 DCCallback* pcb;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
260 int err = dcAllocWX(sizeof(DCCallback), (void**) &pcb);
202
030fbb70aa1b - changed allocwx code:
Tassilo Philipp
parents: 152
diff changeset
261 if(err)
030fbb70aa1b - changed allocwx code:
Tassilo Philipp
parents: 152
diff changeset
262 return NULL;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
263
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
264 dcbInitCallback2(pcb, signature, handler, userdata, aggrs);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
265 dcbInitThunk(&pcb->thunk, dcCallbackThunkEntry);
202
030fbb70aa1b - changed allocwx code:
Tassilo Philipp
parents: 152
diff changeset
266
030fbb70aa1b - changed allocwx code:
Tassilo Philipp
parents: 152
diff changeset
267 err = dcInitExecWX(pcb, sizeof(DCCallback));
030fbb70aa1b - changed allocwx code:
Tassilo Philipp
parents: 152
diff changeset
268 if(err) {
030fbb70aa1b - changed allocwx code:
Tassilo Philipp
parents: 152
diff changeset
269 dcFreeWX(pcb, sizeof(DCCallback));
030fbb70aa1b - changed allocwx code:
Tassilo Philipp
parents: 152
diff changeset
270 return NULL;
030fbb70aa1b - changed allocwx code:
Tassilo Philipp
parents: 152
diff changeset
271 }
030fbb70aa1b - changed allocwx code:
Tassilo Philipp
parents: 152
diff changeset
272
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
273 return pcb;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
274 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
275