blob: f10a1f36938a30cc9a73834e997ab06535db1438 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Helper functions used only in tests
#include "rust_util.h"
#include "sync/rust_thread.h"
#include "sync/lock_and_signal.h"
// These functions are used in the unit tests for C ABI calls.
extern "C" CDECL uint32_t
rust_dbg_extern_identity_u32(uint32_t u) {
return u;
}
extern "C" CDECL uint64_t
rust_dbg_extern_identity_u64(uint64_t u) {
return u;
}
extern "C" CDECL double
rust_dbg_extern_identity_double(double u) {
return u;
}
extern "C" CDECL char
rust_dbg_extern_identity_u8(char u) {
return u;
}
extern "C" CDECL lock_and_signal *
rust_dbg_lock_create() {
return new lock_and_signal();
}
extern "C" CDECL void
rust_dbg_lock_destroy(lock_and_signal *lock) {
assert(lock);
delete lock;
}
extern "C" CDECL void
rust_dbg_lock_lock(lock_and_signal *lock) {
assert(lock);
lock->lock();
}
extern "C" CDECL void
rust_dbg_lock_unlock(lock_and_signal *lock) {
assert(lock);
lock->unlock();
}
extern "C" CDECL void
rust_dbg_lock_wait(lock_and_signal *lock) {
assert(lock);
lock->wait();
}
extern "C" CDECL void
rust_dbg_lock_signal(lock_and_signal *lock) {
assert(lock);
lock->signal();
}
typedef void *(*dbg_callback)(void*);
extern "C" CDECL void *
rust_dbg_call(dbg_callback cb, void *data) {
return cb(data);
}
extern "C" CDECL void rust_dbg_do_nothing() { }
struct TwoU8s {
uint8_t one;
uint8_t two;
};
extern "C" CDECL TwoU8s
rust_dbg_extern_return_TwoU8s() {
struct TwoU8s s;
s.one = 10;
s.two = 20;
return s;
}
extern "C" CDECL TwoU8s
rust_dbg_extern_identity_TwoU8s(TwoU8s u) {
return u;
}
struct TwoU16s {
uint16_t one;
uint16_t two;
};
extern "C" CDECL TwoU16s
rust_dbg_extern_return_TwoU16s() {
struct TwoU16s s;
s.one = 10;
s.two = 20;
return s;
}
extern "C" CDECL TwoU16s
rust_dbg_extern_identity_TwoU16s(TwoU16s u) {
return u;
}
struct TwoU32s {
uint32_t one;
uint32_t two;
};
extern "C" CDECL TwoU32s
rust_dbg_extern_return_TwoU32s() {
struct TwoU32s s;
s.one = 10;
s.two = 20;
return s;
}
extern "C" CDECL TwoU32s
rust_dbg_extern_identity_TwoU32s(TwoU32s u) {
return u;
}
struct TwoU64s {
uint64_t one;
uint64_t two;
};
extern "C" CDECL TwoU64s
rust_dbg_extern_return_TwoU64s() {
struct TwoU64s s;
s.one = 10;
s.two = 20;
return s;
}
extern "C" CDECL TwoU64s
rust_dbg_extern_identity_TwoU64s(TwoU64s u) {
return u;
}
struct TwoDoubles {
double one;
double two;
};
extern "C" CDECL TwoDoubles
rust_dbg_extern_identity_TwoDoubles(TwoDoubles u) {
return u;
}
// Generates increasing port numbers for network testing
extern "C" CDECL uintptr_t
rust_dbg_next_port(uintptr_t base_port) {
static lock_and_signal dbg_port_lock;
static uintptr_t next_offset = 0;
scoped_lock with(dbg_port_lock);
uintptr_t this_port = base_port + next_offset;
next_offset += 1;
return this_port;
}
extern "C" CDECL intptr_t
rust_get_test_int() {
return 1;
}
/* Debug helpers strictly to verify ABI conformance.
*
* FIXME (#2665): move these into a testcase when the testsuite
* understands how to have explicit C files included.
*/
struct quad {
uint64_t a;
uint64_t b;
uint64_t c;
uint64_t d;
};
struct floats {
double a;
uint8_t b;
double c;
};
extern "C" quad
rust_dbg_abi_1(quad q) {
quad qq = { q.c + 1,
q.d - 1,
q.a + 1,
q.b - 1 };
return qq;
}
extern "C" floats
rust_dbg_abi_2(floats f) {
floats ff = { f.c + 1.0,
0xff,
f.a - 1.0 };
return ff;
}
extern "C" int
rust_dbg_static_mut;
int rust_dbg_static_mut = 3;
extern "C" void
rust_dbg_static_mut_check_four() {
assert(rust_dbg_static_mut == 4);
}
|