23
23
24
24
namespace __tsan {
25
25
26
- #if defined(__x86_64__)
27
- #define HAS_48_BIT_ADDRESS_SPACE 1
28
- #elif SANITIZER_IOSSIM // arm64 iOS simulators (order of #if matters)
29
- #define HAS_48_BIT_ADDRESS_SPACE 1
30
- #elif SANITIZER_IOS // arm64 iOS devices (order of #if matters)
31
- #define HAS_48_BIT_ADDRESS_SPACE 0
32
- #elif SANITIZER_MAC // arm64 macOS (order of #if matters)
33
- #define HAS_48_BIT_ADDRESS_SPACE 1
34
- #else
35
- #define HAS_48_BIT_ADDRESS_SPACE 0
36
- #endif
37
-
38
- #if !SANITIZER_GO
39
-
40
- #if HAS_48_BIT_ADDRESS_SPACE
41
26
/*
42
27
C/C++ on linux/x86_64 and freebsd/x86_64
43
28
0000 0000 1000 - 0080 0000 0000: main binary and/or MAP_32BIT mappings (512GB)
@@ -65,9 +50,8 @@ C/C++ on netbsd/amd64 can reuse the same mapping:
65
50
* Stack on NetBSD/amd64 has prereserved 128MB.
66
51
* Heap grows downwards (top-down).
67
52
* ASLR must be disabled per-process or globally.
68
-
69
53
*/
70
- struct Mapping {
54
+ struct Mapping48AddressSpace {
71
55
static const uptr kMetaShadowBeg = 0x300000000000ull ;
72
56
static const uptr kMetaShadowEnd = 0x340000000000ull ;
73
57
static const uptr kTraceMemBeg = 0x600000000000ull ;
@@ -87,8 +71,6 @@ struct Mapping {
87
71
static const uptr kVdsoBeg = 0xf000000000000000ull ;
88
72
};
89
73
90
- #define TSAN_MID_APP_RANGE 1
91
- #elif defined(__mips64)
92
74
/*
93
75
C/C++ on linux/mips64 (40-bit VMA)
94
76
0000 0000 00 - 0100 0000 00: - (4 GB)
@@ -105,7 +87,7 @@ fe00 0000 00 - ff00 0000 00: heap (4 GB)
105
87
ff00 0000 00 - ff80 0000 00: - (2 GB)
106
88
ff80 0000 00 - ffff ffff ff: modules and main thread stack (<2 GB)
107
89
*/
108
- struct Mapping40 {
90
+ struct MappingMips64_40 {
109
91
static const uptr kMetaShadowBeg = 0x4000000000ull ;
110
92
static const uptr kMetaShadowEnd = 0x5000000000ull ;
111
93
static const uptr kTraceMemBeg = 0xb000000000ull ;
@@ -125,9 +107,6 @@ struct Mapping40 {
125
107
static const uptr kVdsoBeg = 0xfffff00000ull ;
126
108
};
127
109
128
- #define TSAN_MID_APP_RANGE 1
129
- #define TSAN_RUNTIME_VMA 1
130
- #elif defined(__aarch64__) && defined(__APPLE__)
131
110
/*
132
111
C/C++ on Darwin/iOS/ARM64 (36-bit VMA, 64 GB VM)
133
112
0000 0000 00 - 0100 0000 00: - (4 GB)
@@ -141,7 +120,7 @@ C/C++ on Darwin/iOS/ARM64 (36-bit VMA, 64 GB VM)
141
120
0f00 0000 00 - 0fc0 0000 00: traces (3 GB)
142
121
0fc0 0000 00 - 1000 0000 00: -
143
122
*/
144
- struct Mapping {
123
+ struct MappingAppleAarch64 {
145
124
static const uptr kLoAppMemBeg = 0x0100000000ull ;
146
125
static const uptr kLoAppMemEnd = 0x0200000000ull ;
147
126
static const uptr kHeapMemBeg = 0x0200000000ull ;
@@ -159,13 +138,6 @@ struct Mapping {
159
138
static const uptr kVdsoBeg = 0x7000000000000000ull ;
160
139
};
161
140
162
- #elif defined(__aarch64__) && !defined(__APPLE__)
163
- // AArch64 supports multiple VMA which leads to multiple address transformation
164
- // functions. To support these multiple VMAS transformations and mappings TSAN
165
- // runtime for AArch64 uses an external memory read (vmaSize) to select which
166
- // mapping to use. Although slower, it make a same instrumented binary run on
167
- // multiple kernels.
168
-
169
141
/*
170
142
C/C++ on linux/aarch64 (39-bit VMA)
171
143
0000 0010 00 - 0100 0000 00: main binary
@@ -181,7 +153,7 @@ C/C++ on linux/aarch64 (39-bit VMA)
181
153
7c00 0000 00 - 7d00 0000 00: heap
182
154
7d00 0000 00 - 7fff ffff ff: modules and main thread stack
183
155
*/
184
- struct Mapping39 {
156
+ struct MappingAarch64_39 {
185
157
static const uptr kLoAppMemBeg = 0x0000001000ull ;
186
158
static const uptr kLoAppMemEnd = 0x0100000000ull ;
187
159
static const uptr kShadowBeg = 0x0800000000ull ;
@@ -216,7 +188,7 @@ C/C++ on linux/aarch64 (42-bit VMA)
216
188
3e000 0000 00 - 3f000 0000 00: heap
217
189
3f000 0000 00 - 3ffff ffff ff: modules and main thread stack
218
190
*/
219
- struct Mapping42 {
191
+ struct MappingAarch64_42 {
220
192
static const uptr kLoAppMemBeg = 0x00000001000ull ;
221
193
static const uptr kLoAppMemEnd = 0x01000000000ull ;
222
194
static const uptr kShadowBeg = 0x10000000000ull ;
@@ -236,7 +208,7 @@ struct Mapping42 {
236
208
static const uptr kVdsoBeg = 0x37f00000000ull ;
237
209
};
238
210
239
- struct Mapping48 {
211
+ struct MappingAarch64_48 {
240
212
static const uptr kLoAppMemBeg = 0x0000000001000ull ;
241
213
static const uptr kLoAppMemEnd = 0x0000200000000ull ;
242
214
static const uptr kShadowBeg = 0x0002000000000ull ;
@@ -256,17 +228,6 @@ struct Mapping48 {
256
228
static const uptr kVdsoBeg = 0xffff000000000ull ;
257
229
};
258
230
259
- // Indicates the runtime will define the memory regions at runtime.
260
- #define TSAN_RUNTIME_VMA 1
261
- // Indicates that mapping defines a mid range memory segment.
262
- #define TSAN_MID_APP_RANGE 1
263
- #elif defined(__powerpc64__)
264
- // PPC64 supports multiple VMA which leads to multiple address transformation
265
- // functions. To support these multiple VMAS transformations and mappings TSAN
266
- // runtime for PPC64 uses an external memory read (vmaSize) to select which
267
- // mapping to use. Although slower, it make a same instrumented binary run on
268
- // multiple kernels.
269
-
270
231
/*
271
232
C/C++ on linux/powerpc64 (44-bit VMA)
272
233
0000 0000 0100 - 0001 0000 0000: main binary
@@ -281,7 +242,7 @@ C/C++ on linux/powerpc64 (44-bit VMA)
281
242
0f50 0000 0000 - 0f60 0000 0000: -
282
243
0f60 0000 0000 - 1000 0000 0000: modules and main thread stack
283
244
*/
284
- struct Mapping44 {
245
+ struct MappingPPC64_44 {
285
246
static const uptr kMetaShadowBeg = 0x0b0000000000ull ;
286
247
static const uptr kMetaShadowEnd = 0x0d0000000000ull ;
287
248
static const uptr kTraceMemBeg = 0x0d0000000000ull ;
@@ -313,7 +274,7 @@ C/C++ on linux/powerpc64 (46-bit VMA)
313
274
3e00 0000 0000 - 3e80 0000 0000: -
314
275
3e80 0000 0000 - 4000 0000 0000: modules and main thread stack
315
276
*/
316
- struct Mapping46 {
277
+ struct MappingPPC64_46 {
317
278
static const uptr kMetaShadowBeg = 0x100000000000ull ;
318
279
static const uptr kMetaShadowEnd = 0x200000000000ull ;
319
280
static const uptr kTraceMemBeg = 0x200000000000ull ;
@@ -345,7 +306,7 @@ C/C++ on linux/powerpc64 (47-bit VMA)
345
306
7e00 0000 0000 - 7e80 0000 0000: -
346
307
7e80 0000 0000 - 8000 0000 0000: modules and main thread stack
347
308
*/
348
- struct Mapping47 {
309
+ struct MappingPPC64_47 {
349
310
static const uptr kMetaShadowBeg = 0x100000000000ull ;
350
311
static const uptr kMetaShadowEnd = 0x200000000000ull ;
351
312
static const uptr kTraceMemBeg = 0x200000000000ull ;
@@ -363,9 +324,6 @@ struct Mapping47 {
363
324
static const uptr kVdsoBeg = 0x7800000000000000ull ;
364
325
};
365
326
366
- // Indicates the runtime will define the memory regions at runtime.
367
- #define TSAN_RUNTIME_VMA 1
368
- #elif defined(__s390x__)
369
327
/*
370
328
C/C++ on linux/s390x
371
329
While the kernel provides a 64-bit address space, we have to restrict ourselves
@@ -380,7 +338,7 @@ a000 0000 0000 - b000 0000 0000: traces - 16TiB (max history * 128k threads)
380
338
b000 0000 0000 - be00 0000 0000: -
381
339
be00 0000 0000 - c000 0000 0000: heap - 2TiB (max supported by the allocator)
382
340
*/
383
- struct Mapping {
341
+ struct MappingS390x {
384
342
static const uptr kMetaShadowBeg = 0x900000000000ull ;
385
343
static const uptr kMetaShadowEnd = 0x980000000000ull ;
386
344
static const uptr kTraceMemBeg = 0xa00000000000ull ;
@@ -397,9 +355,6 @@ struct Mapping {
397
355
static const uptr kAppMemXor = 0x100000000000ull ;
398
356
static const uptr kVdsoBeg = 0xfffffffff000ull ;
399
357
};
400
- #endif
401
-
402
- #elif SANITIZER_GO && !SANITIZER_WINDOWS && HAS_48_BIT_ADDRESS_SPACE
403
358
404
359
/* Go on linux, darwin and freebsd on x86_64
405
360
0000 0000 1000 - 0000 1000 0000: executable
@@ -414,7 +369,7 @@ struct Mapping {
414
369
6200 0000 0000 - 8000 0000 0000: -
415
370
*/
416
371
417
- struct Mapping {
372
+ struct MappingGo48 {
418
373
static const uptr kMetaShadowBeg = 0x300000000000ull ;
419
374
static const uptr kMetaShadowEnd = 0x400000000000ull ;
420
375
static const uptr kTraceMemBeg = 0x600000000000ull ;
@@ -425,8 +380,6 @@ struct Mapping {
425
380
static const uptr kAppMemEnd = 0x00e000000000ull ;
426
381
};
427
382
428
- #elif SANITIZER_GO && SANITIZER_WINDOWS
429
-
430
383
/* Go on windows
431
384
0000 0000 1000 - 0000 1000 0000: executable
432
385
0000 1000 0000 - 00f8 0000 0000: -
@@ -439,7 +392,7 @@ struct Mapping {
439
392
07d0 0000 0000 - 8000 0000 0000: -
440
393
*/
441
394
442
- struct Mapping {
395
+ struct MappingGoWindows {
443
396
static const uptr kMetaShadowBeg = 0x076000000000ull ;
444
397
static const uptr kMetaShadowEnd = 0x07d000000000ull ;
445
398
static const uptr kTraceMemBeg = 0x056000000000ull ;
@@ -450,10 +403,6 @@ struct Mapping {
450
403
static const uptr kAppMemEnd = 0x00e000000000ull ;
451
404
};
452
405
453
- #elif SANITIZER_GO && defined(__powerpc64__)
454
-
455
- /* Only Mapping46 and Mapping47 are currently supported for powercp64 on Go. */
456
-
457
406
/* Go on linux/powerpc64 (46-bit VMA)
458
407
0000 0000 1000 - 0000 1000 0000: executable
459
408
0000 1000 0000 - 00c0 0000 0000: -
@@ -467,7 +416,7 @@ struct Mapping {
467
416
3800 0000 0000 - 4000 0000 0000: -
468
417
*/
469
418
470
- struct Mapping46 {
419
+ struct MappingGoPPC64_46 {
471
420
static const uptr kMetaShadowBeg = 0x240000000000ull ;
472
421
static const uptr kMetaShadowEnd = 0x340000000000ull ;
473
422
static const uptr kTraceMemBeg = 0x360000000000ull ;
@@ -491,7 +440,7 @@ struct Mapping46 {
491
440
6200 0000 0000 - 8000 0000 0000: -
492
441
*/
493
442
494
- struct Mapping47 {
443
+ struct MappingGoPPC64_47 {
495
444
static const uptr kMetaShadowBeg = 0x300000000000ull ;
496
445
static const uptr kMetaShadowEnd = 0x400000000000ull ;
497
446
static const uptr kTraceMemBeg = 0x600000000000ull ;
@@ -502,10 +451,6 @@ struct Mapping47 {
502
451
static const uptr kAppMemEnd = 0x00e000000000ull ;
503
452
};
504
453
505
- #define TSAN_RUNTIME_VMA 1
506
-
507
- #elif SANITIZER_GO && defined(__aarch64__)
508
-
509
454
/* Go on linux/aarch64 (48-bit VMA) and darwin/aarch64 (47-bit VMA)
510
455
0000 0000 1000 - 0000 1000 0000: executable
511
456
0000 1000 0000 - 00c0 0000 0000: -
@@ -518,8 +463,7 @@ struct Mapping47 {
518
463
6000 0000 0000 - 6200 0000 0000: traces
519
464
6200 0000 0000 - 8000 0000 0000: -
520
465
*/
521
-
522
- struct Mapping {
466
+ struct MappingGoAarch64 {
523
467
static const uptr kMetaShadowBeg = 0x300000000000ull ;
524
468
static const uptr kMetaShadowEnd = 0x400000000000ull ;
525
469
static const uptr kTraceMemBeg = 0x600000000000ull ;
@@ -530,10 +474,6 @@ struct Mapping {
530
474
static const uptr kAppMemEnd = 0x00e000000000ull ;
531
475
};
532
476
533
- // Indicates the runtime will define the memory regions at runtime.
534
- #define TSAN_RUNTIME_VMA 1
535
-
536
- #elif SANITIZER_GO && defined(__mips64)
537
477
/*
538
478
Go on linux/mips64 (47-bit VMA)
539
479
0000 0000 1000 - 0000 1000 0000: executable
@@ -547,7 +487,7 @@ Go on linux/mips64 (47-bit VMA)
547
487
6000 0000 0000 - 6200 0000 0000: traces
548
488
6200 0000 0000 - 8000 0000 0000: -
549
489
*/
550
- struct Mapping47 {
490
+ struct MappingGoMips64_47 {
551
491
static const uptr kMetaShadowBeg = 0x300000000000ull ;
552
492
static const uptr kMetaShadowEnd = 0x400000000000ull ;
553
493
static const uptr kTraceMemBeg = 0x600000000000ull ;
@@ -558,9 +498,6 @@ struct Mapping47 {
558
498
static const uptr kAppMemEnd = 0x00e000000000ull ;
559
499
};
560
500
561
- #define TSAN_RUNTIME_VMA 1
562
-
563
- #elif SANITIZER_GO && defined(__s390x__)
564
501
/*
565
502
Go on linux/s390x
566
503
0000 0000 1000 - 1000 0000 0000: executable and heap - 16 TiB
@@ -571,7 +508,7 @@ Go on linux/s390x
571
508
9800 0000 0000 - a000 0000 0000: -
572
509
a000 0000 0000 - b000 0000 0000: traces - 16TiB (max history * 128k threads)
573
510
*/
574
- struct Mapping {
511
+ struct MappingGoS390x {
575
512
static const uptr kMetaShadowBeg = 0x900000000000ull ;
576
513
static const uptr kMetaShadowEnd = 0x980000000000ull ;
577
514
static const uptr kTraceMemBeg = 0xa00000000000ull ;
@@ -582,10 +519,77 @@ struct Mapping {
582
519
static const uptr kAppMemEnd = 0x100000000000ull ;
583
520
};
584
521
522
+ #if defined(__x86_64__)
523
+ # define HAS_48_BIT_ADDRESS_SPACE 1
524
+ #elif SANITIZER_IOSSIM // arm64 iOS simulators (order of #if matters)
525
+ # define HAS_48_BIT_ADDRESS_SPACE 1
526
+ #elif SANITIZER_IOS // arm64 iOS devices (order of #if matters)
527
+ # define HAS_48_BIT_ADDRESS_SPACE 0
528
+ #elif SANITIZER_MAC // arm64 macOS (order of #if matters)
529
+ # define HAS_48_BIT_ADDRESS_SPACE 1
585
530
#else
586
- # error "Unknown platform"
531
+ # define HAS_48_BIT_ADDRESS_SPACE 0
587
532
#endif
588
533
534
+ #if !SANITIZER_GO
535
+
536
+ # if HAS_48_BIT_ADDRESS_SPACE
537
+ typedef Mapping48AddressSpace Mapping;
538
+ # define TSAN_MID_APP_RANGE 1
539
+ # elif defined(__mips64)
540
+ typedef MappingMips64_40 Mapping40;
541
+ # define TSAN_MID_APP_RANGE 1
542
+ # define TSAN_RUNTIME_VMA 1
543
+ # elif defined(__aarch64__) && defined(__APPLE__)
544
+ typedef MappingAppleAarch64 Mapping;
545
+ # elif defined(__aarch64__) && !defined(__APPLE__)
546
+ // AArch64 supports multiple VMA which leads to multiple address transformation
547
+ // functions. To support these multiple VMAS transformations and mappings TSAN
548
+ // runtime for AArch64 uses an external memory read (vmaSize) to select which
549
+ // mapping to use. Although slower, it make a same instrumented binary run on
550
+ // multiple kernels.
551
+ typedef MappingAarch64_39 Mapping39;
552
+ typedef MappingAarch64_42 Mapping42;
553
+ typedef MappingAarch64_48 Mapping48;
554
+ // Indicates the runtime will define the memory regions at runtime.
555
+ # define TSAN_RUNTIME_VMA 1
556
+ // Indicates that mapping defines a mid range memory segment.
557
+ # define TSAN_MID_APP_RANGE 1
558
+ # elif defined(__powerpc64__)
559
+ // PPC64 supports multiple VMA which leads to multiple address transformation
560
+ // functions. To support these multiple VMAS transformations and mappings TSAN
561
+ // runtime for PPC64 uses an external memory read (vmaSize) to select which
562
+ // mapping to use. Although slower, it make a same instrumented binary run on
563
+ // multiple kernels.
564
+ typedef MappingPPC64_44 Mapping44;
565
+ typedef MappingPPC64_46 Mapping46;
566
+ typedef MappingPPC64_47 Mapping47;
567
+ // Indicates the runtime will define the memory regions at runtime.
568
+ # define TSAN_RUNTIME_VMA 1
569
+ # elif defined(__s390x__)
570
+ typedef MappingS390x Mapping;
571
+ # endif
572
+ #elif SANITIZER_GO && !SANITIZER_WINDOWS && HAS_48_BIT_ADDRESS_SPACE
573
+ typedef MappingGo48 Mapping;
574
+ #elif SANITIZER_GO && SANITIZER_WINDOWS
575
+ typedef MappingGoWindows Mapping;
576
+ #elif SANITIZER_GO && defined(__powerpc64__)
577
+ /* Only Mapping46 and Mapping47 are currently supported for powercp64 on Go. */
578
+ typedef MappingGoPPC64_46 Mapping46;
579
+ typedef MappingGoPPC64_47 Mapping47;
580
+ # define TSAN_RUNTIME_VMA 1
581
+ #elif SANITIZER_GO && defined(__aarch64__)
582
+ typedef MappingGoAarch64 Mapping;
583
+ // Indicates the runtime will define the memory regions at runtime.
584
+ # define TSAN_RUNTIME_VMA 1
585
+ #elif SANITIZER_GO && defined(__mips64)
586
+ typedef MappingGoMips64_47 Mapping47;
587
+ # define TSAN_RUNTIME_VMA 1
588
+ #elif SANITIZER_GO && defined(__s390x__)
589
+ typedef MappingGoS390x Mapping;
590
+ #else
591
+ # error "Unknown platform"
592
+ #endif
589
593
590
594
#ifdef TSAN_RUNTIME_VMA
591
595
extern uptr vmaSize;
0 commit comments