Skip to content

Commit d1f725c

Browse files
committed
[Backtracing] Replace all the stdint types with Swift specific variants.
This is needed because we can't include `<stdint.h>` or `<inttypes.h>` on Darwin without dragging in the Darwin package. The previous solution was some icky `#define` nonsense. This is better. rdar://106234311
1 parent 106dd19 commit d1f725c

File tree

2 files changed

+88
-103
lines changed

2 files changed

+88
-103
lines changed

stdlib/public/SwiftShims/swift/shims/CrashInfo.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@
1818
#ifndef SWIFT_CRASHINFO_H
1919
#define SWIFT_CRASHINFO_H
2020

21+
#include "SwiftStdint.h"
22+
2123
#ifdef __cplusplus
2224
namespace swift {
2325
extern "C" {
2426
#endif
2527

2628
struct CrashInfo {
27-
uint64_t crashing_thread;
28-
uint64_t signal;
29-
uint64_t fault_address;
30-
uint64_t mctx;
29+
__swift_uint64_t crashing_thread;
30+
__swift_uint64_t signal;
31+
__swift_uint64_t fault_address;
32+
__swift_uint64_t mctx;
3133
};
3234

3335
#ifdef __cplusplus

stdlib/public/SwiftShims/swift/shims/_SwiftBacktracing.h

Lines changed: 82 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,6 @@
2222
#include "SwiftStdint.h"
2323
#include "Target.h"
2424

25-
// Replace the stdint types for the rest of this file; we have to use the
26-
// preprocessor for this, because e.g. __swift_int8_t might be a typedef of
27-
// int8_t, and so we can't re-typedef int8_t.
28-
//
29-
// Mainly we're doing this so CrashInfo.h can use the normal type names, but
30-
// it also avoids a lot of underscores later on in this file.
31-
#define int8_t __swift_int8_t
32-
#define uint8_t __swift_uint8_t
33-
#define int16_t __swift_int16_t
34-
#define uint16_t __swift_uint16_t
35-
#define int32_t __swift_int32_t
36-
#define uint32_t __swift_uint32_t
37-
#define int64_t __swift_int64_t
38-
#define uint64_t __swift_uint64_t
39-
#define intptr_t __swift_intptr_t
40-
#define uintptr_t __swift_uintptr_t
41-
4225
#include "CrashInfo.h"
4326

4427
#ifdef __cplusplus
@@ -97,80 +80,80 @@ struct __swift_backtrace_CFRange {
9780
};
9881

9982
typedef struct {
100-
uint8_t byte0;
101-
uint8_t byte1;
102-
uint8_t byte2;
103-
uint8_t byte3;
104-
uint8_t byte4;
105-
uint8_t byte5;
106-
uint8_t byte6;
107-
uint8_t byte7;
108-
uint8_t byte8;
109-
uint8_t byte9;
110-
uint8_t byte10;
111-
uint8_t byte11;
112-
uint8_t byte12;
113-
uint8_t byte13;
114-
uint8_t byte14;
115-
uint8_t byte15;
83+
__swift_uint8_t byte0;
84+
__swift_uint8_t byte1;
85+
__swift_uint8_t byte2;
86+
__swift_uint8_t byte3;
87+
__swift_uint8_t byte4;
88+
__swift_uint8_t byte5;
89+
__swift_uint8_t byte6;
90+
__swift_uint8_t byte7;
91+
__swift_uint8_t byte8;
92+
__swift_uint8_t byte9;
93+
__swift_uint8_t byte10;
94+
__swift_uint8_t byte11;
95+
__swift_uint8_t byte12;
96+
__swift_uint8_t byte13;
97+
__swift_uint8_t byte14;
98+
__swift_uint8_t byte15;
11699
} __swift_backtrace_CFUUIDBytes;
117100

118101
#endif // SWIFT_TARGET_OS_DARWIN
119102

120103
// .. Processor specifics ......................................................
121104

122105
struct x86_64_gprs {
123-
uint64_t _r[16];
124-
uint64_t rflags;
125-
uint16_t cs, fs, gs, _pad0;
126-
uint64_t rip;
127-
uint64_t valid;
106+
__swift_uint64_t _r[16];
107+
__swift_uint64_t rflags;
108+
__swift_uint16_t cs, fs, gs, _pad0;
109+
__swift_uint64_t rip;
110+
__swift_uint64_t valid;
128111
};
129112

130113
struct i386_gprs {
131-
uint32_t _r[8];
132-
uint32_t eflags;
133-
uint16_t segreg[6];
134-
uint32_t eip;
135-
uint32_t valid;
114+
__swift_uint32_t _r[8];
115+
__swift_uint32_t eflags;
116+
__swift_uint16_t segreg[6];
117+
__swift_uint32_t eip;
118+
__swift_uint32_t valid;
136119
};
137120

138121
struct arm64_gprs {
139-
uint64_t _x[32];
140-
uint64_t pc;
141-
uint64_t valid;
122+
__swift_uint64_t _x[32];
123+
__swift_uint64_t pc;
124+
__swift_uint64_t valid;
142125
};
143126

144127
struct arm_gprs {
145-
uint32_t _r[16];
146-
uint32_t valid;
128+
__swift_uint32_t _r[16];
129+
__swift_uint32_t valid;
147130
};
148131

149132
// .. Darwin specifics .........................................................
150133

151134
#if SWIFT_TARGET_OS_DARWIN
152135

153136
// From libproc
154-
int proc_name(int pid, void * buffer, uint32_t buffersize);
137+
int proc_name(int pid, void * buffer, __swift_uint32_t buffersize);
155138

156139
/* Darwin thread states. We can't import these from the system header because
157140
it uses all kinds of macros and the Swift importer can't cope with that.
158141
So declare them here in a form it can understand. */
159142
#define ARM_THREAD_STATE64 6
160143
struct darwin_arm64_thread_state {
161-
uint64_t _x[29];
162-
uint64_t fp;
163-
uint64_t lr;
164-
uint64_t sp;
165-
uint64_t pc;
166-
uint32_t cpsr;
167-
uint32_t __pad;
144+
__swift_uint64_t _x[29];
145+
__swift_uint64_t fp;
146+
__swift_uint64_t lr;
147+
__swift_uint64_t sp;
148+
__swift_uint64_t pc;
149+
__swift_uint32_t cpsr;
150+
__swift_uint32_t __pad;
168151
};
169152

170153
struct darwin_arm64_exception_state {
171-
uint64_t far;
172-
uint32_t esr;
173-
uint32_t exception;
154+
__swift_uint64_t far;
155+
__swift_uint32_t esr;
156+
__swift_uint32_t exception;
174157
};
175158

176159
struct darwin_arm64_mcontext {
@@ -181,34 +164,34 @@ struct darwin_arm64_mcontext {
181164

182165
#define x86_THREAD_STATE64 4
183166
struct darwin_x86_64_thread_state {
184-
uint64_t rax;
185-
uint64_t rbx;
186-
uint64_t rcx;
187-
uint64_t rdx;
188-
uint64_t rdi;
189-
uint64_t rsi;
190-
uint64_t rbp;
191-
uint64_t rsp;
192-
uint64_t r8;
193-
uint64_t r9;
194-
uint64_t r10;
195-
uint64_t r11;
196-
uint64_t r12;
197-
uint64_t r13;
198-
uint64_t r14;
199-
uint64_t r15;
200-
uint64_t rip;
201-
uint64_t rflags;
202-
uint64_t cs;
203-
uint64_t fs;
204-
uint64_t gs;
167+
__swift_uint64_t rax;
168+
__swift_uint64_t rbx;
169+
__swift_uint64_t rcx;
170+
__swift_uint64_t rdx;
171+
__swift_uint64_t rdi;
172+
__swift_uint64_t rsi;
173+
__swift_uint64_t rbp;
174+
__swift_uint64_t rsp;
175+
__swift_uint64_t r8;
176+
__swift_uint64_t r9;
177+
__swift_uint64_t r10;
178+
__swift_uint64_t r11;
179+
__swift_uint64_t r12;
180+
__swift_uint64_t r13;
181+
__swift_uint64_t r14;
182+
__swift_uint64_t r15;
183+
__swift_uint64_t rip;
184+
__swift_uint64_t rflags;
185+
__swift_uint64_t cs;
186+
__swift_uint64_t fs;
187+
__swift_uint64_t gs;
205188
};
206189

207190
struct darwin_x86_64_exception_state {
208-
uint16_t trapno;
209-
uint16_t cpu;
210-
uint32_t err;
211-
uint64_t faultvaddr;
191+
__swift_uint16_t trapno;
192+
__swift_uint16_t cpu;
193+
__swift_uint32_t err;
194+
__swift_uint64_t faultvaddr;
212195
};
213196

214197
struct darwin_x86_64_mcontext {
@@ -221,8 +204,8 @@ typedef unsigned int __swift_task_t;
221204
typedef unsigned int __swift_thread_t;
222205
typedef unsigned int __swift_kern_return_t;
223206
typedef unsigned char __swift_uuid_t[16];
224-
typedef uint64_t __swift_vm_address_t;
225-
typedef uint64_t __swift_vm_size_t;
207+
typedef __swift_uint64_t __swift_vm_address_t;
208+
typedef __swift_uint64_t __swift_vm_size_t;
226209
typedef int __swift_thread_state_flavor_t;
227210
typedef unsigned int __swift_natural_t;
228211
typedef __swift_natural_t __swift_msg_type_number_t;
@@ -273,23 +256,23 @@ _swift_backtrace_thread_get_state(__swift_thread_t target_act,
273256
not work how you expect, and are generally dangerous to use. */
274257
struct dyld_process_cache_info {
275258
__swift_uuid_t cacheUUID;
276-
uint64_t cacheBaseAddress;
259+
__swift_uint64_t cacheBaseAddress;
277260
__swift_bool noCache;
278261
__swift_bool privateCache;
279262
};
280263
typedef struct dyld_process_cache_info dyld_process_cache_info;
281264
typedef const struct dyld_process_info_base* dyld_process_info;
282265

283-
extern dyld_process_info _dyld_process_info_create(__swift_task_t task, uint64_t timestamp, __swift_kern_return_t* kernelError);
266+
extern dyld_process_info _dyld_process_info_create(__swift_task_t task, __swift_uint64_t timestamp, __swift_kern_return_t* kernelError);
284267
extern void _dyld_process_info_release(dyld_process_info info);
285268
extern void _dyld_process_info_retain(dyld_process_info info);
286269
extern void _dyld_process_info_get_cache(dyld_process_info info, dyld_process_cache_info* cacheInfo);
287-
extern void _dyld_process_info_for_each_image(dyld_process_info info, void (^callback)(uint64_t machHeaderAddress, const __swift_uuid_t uuid, const char* path));
288-
extern void _dyld_process_info_for_each_segment(dyld_process_info info, uint64_t machHeaderAddress, void (^callback)(uint64_t segmentAddress, uint64_t segmentSize, const char* segmentName));
270+
extern void _dyld_process_info_for_each_image(dyld_process_info info, void (^callback)(__swift_uint64_t machHeaderAddress, const __swift_uuid_t uuid, const char* path));
271+
extern void _dyld_process_info_for_each_segment(dyld_process_info info, __swift_uint64_t machHeaderAddress, void (^callback)(__swift_uint64_t segmentAddress, __swift_uint64_t segmentSize, const char* segmentName));
289272

290273
/* DANGER! CoreSymbolication is a private framework. This is all SPI. */
291-
typedef int32_t cpu_type_t;
292-
typedef int32_t cpu_subtype_t;
274+
typedef __swift_int32_t cpu_type_t;
275+
typedef __swift_int32_t cpu_subtype_t;
293276

294277
struct _CSArchitecture {
295278
cpu_type_t cpu_type;
@@ -331,20 +314,20 @@ typedef struct _CSBinaryImageInformation {
331314
CSArchitecture arch;
332315
const char *path;
333316
CSBinaryRelocationInformation *relocations;
334-
uint32_t relocationCount;
335-
uint32_t flags;
317+
__swift_uint32_t relocationCount;
318+
__swift_uint32_t flags;
336319
} CSBinaryImageInformation;
337320

338-
typedef uint64_t CSMachineTime;
321+
typedef __swift_uint64_t CSMachineTime;
339322

340323
static const CSMachineTime kCSBeginningOfTime = 0;
341324
static const CSMachineTime kCSEndOfTime = (1ull<<63) - 1;
342325
static const CSMachineTime kCSNow = (1ull<<63);
343326
static const CSMachineTime kCSAllTimes = (1ull<<63) + 1;
344327

345328
struct _CSTypeRef {
346-
uintptr_t _opaque_1;
347-
uintptr_t _opaque_2;
329+
__swift_uintptr_t _opaque_1;
330+
__swift_uintptr_t _opaque_2;
348331
};
349332

350333
typedef struct _CSTypeRef CSTypeRef;
@@ -364,7 +347,7 @@ typedef struct _CSNotificationData {
364347
CSSymbolicatorRef symbolicator;
365348
union {
366349
struct Ping {
367-
uint32_t value;
350+
__swift_uint32_t value;
368351
} ping;
369352

370353
struct DyldLoad {
@@ -377,7 +360,7 @@ typedef struct _CSNotificationData {
377360
} u;
378361
} CSNotificationData;
379362

380-
typedef void (^CSNotificationBlock)(uint32_t type, CSNotificationData data);
363+
typedef void (^CSNotificationBlock)(__swift_uint32_t type, CSNotificationData data);
381364

382365
struct _CSRange {
383366
__swift_vm_address_t location;

0 commit comments

Comments
 (0)