-
Notifications
You must be signed in to change notification settings - Fork 546
/
globals_shared.h
1956 lines (1763 loc) · 67.8 KB
/
globals_shared.h
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* **********************************************************
* Copyright (c) 2011-2017 Google, Inc. All rights reserved.
* Copyright (c) 2003-2010 VMware, Inc. All rights reserved.
* **********************************************************/
/*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of VMware, Inc. nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
/* Copyright (c) 2003-2007 Determina Corp. */
/*
* globals_shared.h
*
* definitions to be shared with core-external modules
*
*/
#ifndef _GLOBALS_SHARED_H_
#define _GLOBALS_SHARED_H_
/* if not Unix, we assume Windows */
#ifndef UNIX
# ifndef WINDOWS
# define WINDOWS
# endif
#endif
/* DR_API EXPORT TOFILE dr_defines.h */
/* DR_API EXPORT BEGIN */
/****************************************************************************
* GENERAL TYPEDEFS AND DEFINES
*/
/**
* @file dr_defines.h
* @brief Basic defines and type definitions.
*/
#ifdef API_EXPORT_ONLY
/* A client's target operating system and architecture must be specified. */
#if !defined(LINUX) && !defined(WINDOWS) && !defined(MACOS)
# error Target operating system unspecified: must define WINDOWS, LINUX, or MACOS
#endif
#endif
#ifdef API_EXPORT_ONLY
#if defined(X86_32) || defined(X86_64)
# define X86
# if (defined(X86_64) && defined(X86_32)) || defined(ARM_32) || defined(ARM_64)
# error Target architecture over-specified: must define only one
# endif
#elif defined(ARM_32)
# define ARM
# define AARCHXX
# if defined(X86_32) || defined(X86_64) || defined(ARM_64)
# error Target architecture over-specified: must define only one
# endif
#elif defined(ARM_64)
# define AARCH64
# define AARCHXX
# if defined(X86_32) || defined(X86_64) || defined(ARM_32)
# error Target architecture over-specified: must define only one
# endif
#else
# error Target architecture unknown: must define X86_32, X86_64, ARM_32, or ARM_64
#endif
#endif
#if (defined(X86_64) || defined(ARM_64)) && !defined(X64)
# define X64
#endif
#if (defined(LINUX) || defined(MACOS)) && !defined(UNIX)
# define UNIX
#endif
#ifdef API_EXPORT_ONLY
#ifdef WINDOWS
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <winbase.h>
#else
# include <stdio.h>
# include <stdlib.h>
#endif
#include <stdarg.h> /* for varargs */
#endif
/* DR_API EXPORT END */
/* Internally, ensure these defines are set */
#if defined(X86) && !defined(X64) && !defined(X86_32)
# define X86_32
#endif
#if defined(X86) && defined(X64) && !defined(X86_64)
# define X86_64
#endif
#include <limits.h> /* for USHRT_MAX */
#ifdef UNIX
# include <sys/types.h> /* Fix for case 5341. */
# include <signal.h>
#endif
/* DR_API EXPORT VERBATIM */
#ifdef WINDOWS
/* allow nameless struct/union */
# pragma warning(disable: 4201)
/* VS2005 warns about comparison operator results being cast to bool (i#523) */
# if _MSC_VER >= 1400 && _MSC_VER < 1500
# pragma warning(disable: 4244)
# endif
#endif
#ifdef WINDOWS
# define DR_EXPORT __declspec(dllexport)
# define LINK_ONCE __declspec(selectany)
# define ALIGN_VAR(x) __declspec(align(x))
# ifndef __cplusplus
# define inline __inline
# endif
# define INLINE_FORCED __forceinline
# define WEAK /* no equivalent, but .obj overrides .lib */
#else
/* We assume gcc is being used. If the client is using -fvisibility
* (in gcc >= 3.4) to not export symbols by default, setting
* USE_VISIBILITY_ATTRIBUTES will properly export.
*/
# ifdef USE_VISIBILITY_ATTRIBUTES
# define DR_EXPORT __attribute__ ((visibility ("default")))
# else
# define DR_EXPORT
# endif
# define LINK_ONCE __attribute__ ((weak))
# define ALIGN_VAR(x) __attribute__ ((aligned (x)))
# ifndef __cplusplus
# define inline __inline__
# endif
# define INLINE_FORCED inline
# define WEAK __attribute__ ((weak))
#endif
/* DR_API EXPORT END */
/* DR_API EXPORT BEGIN */
#ifdef AVOID_API_EXPORT
/* We want a consistent size so we stay away from MAX_PATH.
* MAX_PATH is 260 on Windows, but 4096 on Linux, should up this.
* XXX: should undef MAX_PATH and define it to an error-producing value
* and clean up all uses of it
*/
#endif
/**
* Maximum file path length define meant to replace platform-specific defines
* such as MAX_PATH and PATH_MAX.
* Currently, internal stack size limits prevent this from being much larger
* on UNIX.
*/
#ifdef WINDOWS
# define MAXIMUM_PATH 260
#else
# define MAXIMUM_PATH 512
#endif
/* DR_API EXPORT END */
/* DR_API EXPORT VERBATIM */
#ifndef NULL
# define NULL (0)
#endif
#ifndef __cplusplus
# ifndef DR_DO_NOT_DEFINE_bool
# ifdef DR__Bool_EXISTS
/* prefer _Bool as it avoids truncation casting non-zero to zero */
typedef _Bool bool;
# else
/* char-sized for compatibility with C++ */
typedef char bool;
# endif
# endif
# ifndef true
# define true (1)
# endif
# ifndef false
# define false (0)
# endif
#endif
/* on Windows where bool is char casting can truncate non-zero to zero
* so we use this macro
*/
#define CAST_TO_bool(x) (!!(x))
#ifndef DR_DO_NOT_DEFINE_uint
typedef unsigned int uint;
#endif
#ifndef DR_DO_NOT_DEFINE_ushort
typedef unsigned short ushort;
#endif
#ifndef DR_DO_NOT_DEFINE_byte
typedef unsigned char byte;
#endif
#ifndef DR_DO_NOT_DEFINE_sbyte
typedef signed char sbyte;
#endif
typedef byte * app_pc;
typedef void (*generic_func_t) ();
#ifdef WINDOWS
# ifndef DR_DO_NOT_DEFINE_uint64
typedef unsigned __int64 uint64;
# endif
# ifndef DR_DO_NOT_DEFINE_int64
typedef __int64 int64;
# endif
# ifdef X64
typedef __int64 ssize_t;
# else
typedef int ssize_t;
# endif
# define _SSIZE_T_DEFINED
# define INT64_FORMAT "I64"
#else /* Linux */
# ifdef X64
# ifndef DR_DO_NOT_DEFINE_uint64
typedef unsigned long int uint64;
# endif
# ifndef DR_DO_NOT_DEFINE_int64
typedef long int int64;
# endif
# define INT64_FORMAT "l"
# else
# ifndef DR_DO_NOT_DEFINE_uint64
typedef unsigned long long int uint64;
# endif
# ifndef DR_DO_NOT_DEFINE_int64
typedef long long int int64;
# endif
# define INT64_FORMAT "ll"
# endif
#endif
/* DR_API EXPORT END */
/* DR_API EXPORT BEGIN */
/* a register value: could be of any type; size is what matters. */
#ifdef X64
typedef uint64 reg_t;
#else
typedef uint reg_t;
#endif
/* integer whose size is based on pointers: ptr diff, mask, etc. */
typedef reg_t ptr_uint_t;
#ifdef X64
typedef int64 ptr_int_t;
#else
typedef int ptr_int_t;
#endif
/* for memory region sizes, use size_t */
/**
* Application offset from module base.
* PE32+ modules are limited to 2GB, but not ELF x64 med/large code model.
*/
typedef size_t app_rva_t;
#define PTR_UINT_0 ((ptr_uint_t)0U)
#define PTR_UINT_1 ((ptr_uint_t)1U)
#define PTR_UINT_MINUS_1 ((ptr_uint_t)-1)
#ifdef WINDOWS
typedef ptr_uint_t thread_id_t;
typedef ptr_uint_t process_id_t;
#elif defined(MACOS)
typedef uint64 thread_id_t;
typedef pid_t process_id_t;
#else /* Linux */
typedef pid_t thread_id_t;
typedef pid_t process_id_t;
#endif
#define INVALID_PROCESS_ID PTR_UINT_MINUS_1
#ifdef API_EXPORT_ONLY
#ifdef WINDOWS
/* since a FILE cannot be used outside of the DLL it was created in,
* we have to use HANDLE on Windows
* we hide the distinction behind the file_t type
*/
typedef HANDLE file_t;
/** The sentinel value for an invalid file_t. */
# define INVALID_FILE INVALID_HANDLE_VALUE
/* dr_get_stdout_file and dr_get_stderr_file return errors as
* INVALID_HANDLE_VALUE. We leave INVALID_HANDLE_VALUE as is,
* since it equals INVALID_FILE
*/
/** The file_t value for standard output. */
# define STDOUT (dr_get_stdout_file())
/** The file_t value for standard error. */
# define STDERR (dr_get_stderr_file())
/** The file_t value for standard input. */
# define STDIN (dr_get_stdin_file())
#endif
#endif
#ifdef UNIX
typedef int file_t;
/** The sentinel value for an invalid file_t. */
# define INVALID_FILE -1
/** Allow use of stdout after the application closes it. */
extern file_t our_stdout;
/** Allow use of stderr after the application closes it. */
extern file_t our_stderr;
/** Allow use of stdin after the application closes it. */
extern file_t our_stdin;
/** The file_t value for standard output. */
# define STDOUT our_stdout
/** The file_t value for standard error. */
# define STDERR our_stderr
/** The file_t value for standard error. */
# define STDIN our_stdin
#endif
#ifdef AVOID_API_EXPORT
/* Note that we considered using a 128-bit GUID for the client ID,
* but decided it was unnecessary since the client registration
* routine will complain about conflicting IDs. Also, we're storing
* this value in the registry, so no reason to make it any longer
* than we have to.
*/
#endif
/**
* ID used to uniquely identify a client. This value is set at
* client registration and passed to the client in dr_client_main().
*/
typedef uint client_id_t;
#ifdef API_EXPORT_ONLY
#ifndef DR_FAST_IR
/**
* Internal structure of opnd_t is below abstraction layer.
* But compiler needs to know field sizes to copy it around
*/
typedef struct {
# ifdef X64
uint black_box_uint;
uint64 black_box_uint64;
# else
uint black_box_uint[3];
# endif
} opnd_t;
/**
* Internal structure of instr_t is below abstraction layer, but we
* provide its size so that it can be used in stack variables
* instead of always allocated on the heap.
*/
typedef struct {
# ifdef X64
uint black_box_uint[26];
# else
uint black_box_uint[16];
# endif
} instr_t;
#else
struct _opnd_t;
typedef struct _opnd_t opnd_t;
struct _instr_t;
typedef struct _instr_t instr_t;
#endif /* !DR_FAST_IR */
#endif /* API_EXPORT_ONLY */
#ifndef IN
# define IN /* marks input param */
#endif
#ifndef OUT
# define OUT /* marks output param */
#endif
#ifndef INOUT
# define INOUT /* marks input+output param */
#endif
/* DR_API EXPORT END */
#ifdef X64
# define POINTER_MAX ULLONG_MAX
# ifndef SSIZE_T_MAX
# define SSIZE_T_MAX LLONG_MAX
# endif
# define POINTER_MAX_32BIT ((ptr_uint_t)UINT_MAX)
#else
# define POINTER_MAX UINT_MAX
# ifndef SSIZE_T_MAX
# define SSIZE_T_MAX INT_MAX
# endif
#endif
#define MAX_CLIENT_LIBS 16
/* FIXME: these macros double-evaluate their args -- if we can't trust
* compiler to do CSE, should we replace w/ inline functions? would need
* separate signed and unsigned versions
*/
#ifndef DR_DO_NOT_DEFINE_MAX_MIN
# define MAX(x,y) ((x) >= (y) ? (x) : (y))
# define MIN(x,y) ((x) <= (y) ? (x) : (y))
#endif
#define PTR_UINT_ABS(x) ((x) < 0 ? -(x) : (x))
/* check if all bits in mask are set in var */
#define TESTALL(mask, var) (((mask) & (var)) == (mask))
/* check if any bit in mask is set in var */
#define TESTANY(mask, var) (((mask) & (var)) != 0)
/* check if a single bit is set in var */
#define TEST TESTANY
#define BOOLS_MATCH(a, b) (!!(a) == !!(b))
/* macros to make conditional compilation look prettier */
#ifdef DEBUG
# define IF_DEBUG(x) x
# define _IF_DEBUG(x) , x
# define IF_DEBUG_(x) x ,
# define IF_DEBUG_ELSE(x, y) x
# define IF_DEBUG_ELSE_0(x) (x)
# define IF_DEBUG_ELSE_NULL(x) (x)
#else
# define IF_DEBUG(x)
# define _IF_DEBUG(x)
# define IF_DEBUG_(x)
# define IF_DEBUG_ELSE(x, y) y
# define IF_DEBUG_ELSE_0(x) 0
# define IF_DEBUG_ELSE_NULL(x) (NULL)
#endif
#ifdef INTERNAL
# define IF_INTERNAL(x) x
# define IF_INTERNAL_ELSE(x,y) x
#else
# define IF_INTERNAL(x)
# define IF_INTERNAL_ELSE(x,y) y
#endif
#ifdef WINDOWS
# define IF_WINDOWS(x) x
# define IF_WINDOWS_(x) x,
# define _IF_WINDOWS(x) , x
# ifdef X64
# define _IF_WINDOWS_X64(x) , x
# else
# define _IF_WINDOWS_X64(x)
# endif
# define IF_WINDOWS_ELSE_0(x) (x)
# define IF_WINDOWS_ELSE(x,y) (x)
# define IF_WINDOWS_ELSE_NP(x,y) x
# define IF_UNIX(x)
# define IF_UNIX_ELSE(x,y) y
# define IF_UNIX_(x)
# define _IF_UNIX(x)
#else
# define IF_WINDOWS(x)
# define IF_WINDOWS_(x)
# define _IF_WINDOWS(x)
# define _IF_WINDOWS_X64(x)
# define IF_WINDOWS_ELSE_0(x) (0)
# define IF_WINDOWS_ELSE(x,y) (y)
# define IF_WINDOWS_ELSE_NP(x,y) y
# define IF_UNIX(x) x
# define IF_UNIX_ELSE(x,y) x
# define IF_UNIX_(x) x,
# define _IF_UNIX(x) , x
#endif
#ifdef LINUX
# define IF_LINUX(x) x
# define IF_LINUX_ELSE(x,y) x
# define IF_LINUX_(x) x,
#else
# define IF_LINUX(x)
# define IF_LINUX_ELSE(x,y) y
# define IF_LINUX_(x)
#endif
#ifdef MACOS
# define IF_MACOS(x) x
# define IF_MACOS_ELSE(x,y) x
# define IF_MACOS_(x) x,
#else
# define IF_MACOS(x)
# define IF_MACOS_ELSE(x,y) y
# define IF_MACOS_(x)
#endif
#ifdef HAVE_MEMINFO_QUERY
# define IF_MEMQUERY(x) x
# define IF_MEMQUERY_(x) x,
# define IF_MEMQUERY_ELSE(x, y) x
# define IF_NO_MEMQUERY(x)
# define IF_NO_MEMQUERY_(x)
#else
# define IF_MEMQUERY(x)
# define IF_MEMQUERY_(x)
# define IF_MEMQUERY_ELSE(x, y) y
# define IF_NO_MEMQUERY(x) x
# define IF_NO_MEMQUERY_(x) x,
#endif
#ifdef VMX86_SERVER
# define IF_VMX86(x) x
# define IF_VMX86_ELSE(x,y) x
# define _IF_VMX86(x) , x
# define IF_NOT_VMX86(x)
#else
# define IF_VMX86(x)
# define IF_VMX86_ELSE(x,y) y
# define _IF_VMX86(x)
# define IF_NOT_VMX86(x) x
#endif
#ifdef UNIX
# ifdef HAVE_TLS
# define IF_HAVE_TLS_ELSE(x, y) x
# define IF_NOT_HAVE_TLS(x)
# else
# define IF_HAVE_TLS_ELSE(x, y) y
# define IF_NOT_HAVE_TLS(x) x
# endif
#else
/* Windows always has TLS. Better to generally define HAVE_TLS instead? */
# define IF_HAVE_TLS_ELSE(x, y) x
# define IF_NOT_HAVE_TLS(x)
#endif
#if defined(WINDOWS) && !defined(NOT_DYNAMORIO_CORE)
# define IF_WINDOWS_AND_CORE(x) x
#else
# define IF_WINDOWS_AND_CORE(x)
#endif
#ifdef PROGRAM_SHEPHERDING
# define IF_PROG_SHEP(x) x
#else
# define IF_PROG_SHEP(x)
#endif
#if defined(PROGRAM_SHEPHERDING) && defined(RCT_IND_BRANCH)
# define IF_RCT_IND_BRANCH(x) x
#else
# define IF_RCT_IND_BRANCH(x)
#endif
#if defined(PROGRAM_SHEPHERDING) && defined(RETURN_AFTER_CALL)
# define IF_RETURN_AFTER_CALL(x) x
# define IF_RETURN_AFTER_CALL_ELSE(x, y) x
#else
# define IF_RETURN_AFTER_CALL(x)
# define IF_RETURN_AFTER_CALL_ELSE(x, y) y
#endif
#ifdef HOT_PATCHING_INTERFACE
# define IF_HOTP(x) x
#else
# define IF_HOTP(x)
#endif
#ifdef CLIENT_INTERFACE
# define IF_CLIENT_INTERFACE(x) x
# define IF_NOT_CLIENT_INTERFACE(x)
# define IF_CLIENT_INTERFACE_ELSE(x, y) x
# define _IF_CLIENT_INTERFACE(x) , x
# define _IF_NOT_CLIENT_INTERFACE(x)
/* _IF_CLIENT_INTERFACE is too long */
# define _IF_CLIENT(x) , x
#else
# define IF_CLIENT_INTERFACE(x)
# define IF_NOT_CLIENT_INTERFACE(x) x
# define IF_CLIENT_INTERFACE_ELSE(x, y) y
# define _IF_CLIENT_INTERFACE(x)
# define _IF_NOT_CLIENT_INTERFACE(x) , x
# define _IF_CLIENT(x)
#endif
#ifdef CUSTOM_TRACES
# define IF_CUSTOM_TRACES(x) x
#else
# define IF_CUSTOM_TRACES(x)
#endif
#ifdef DR_APP_EXPORTS
# define IF_APP_EXPORTS(x) x
#else
# define IF_APP_EXPORTS(x)
#endif
#ifdef GBOP
# define IF_GBOP(x) x
#else
# define IF_GBOP(x)
#endif
#ifdef PROCESS_CONTROL
# define IF_PROC_CTL(x) x
#else
# define IF_PROC_CTL(x)
#endif
#ifdef KSTATS
# define IF_KSTATS(x) x
#else
# define IF_KSTATS(x)
#endif
#ifdef STATIC_LIBRARY
# define IF_STATIC_LIBRARY_ELSE(x,y) x
#else
# define IF_STATIC_LIBRARY_ELSE(x,y) y
#endif
#ifdef STANDALONE_UNIT_TEST
# define IF_UNIT_TEST_ELSE(x,y) x
#else
# define IF_UNIT_TEST_ELSE(x,y) y
#endif
/* DR_API EXPORT TOFILE dr_defines.h */
/* DR_API EXPORT BEGIN */
#ifdef X86
# define IF_X86(x) x
# define IF_X86_ELSE(x, y) x
# define IF_X86_(x) x,
# define _IF_X86(x) , x
# define IF_NOT_X86(x)
# define IF_NOT_X86_(x)
# define _IF_NOT_X86(x)
#else
# define IF_X86(x)
# define IF_X86_ELSE(x, y) y
# define IF_X86_(x)
# define _IF_X86(x)
# define IF_NOT_X86(x) x
# define IF_NOT_X86_(x) x,
# define _IF_NOT_X86(x) , x
#endif
#ifdef ARM
# define IF_ARM(x) x
# define IF_ARM_ELSE(x, y) x
# define IF_ARM_(x) x,
# define _IF_ARM(x) , x
# define IF_NOT_ARM(x)
# define _IF_NOT_ARM(x)
#else
# define IF_ARM(x)
# define IF_ARM_ELSE(x, y) y
# define IF_ARM_(x)
# define _IF_ARM(x)
# define IF_NOT_ARM(x) x
# define _IF_NOT_ARM(x) , x
#endif
#ifdef AARCH64
# define IF_AARCH64(x) x
# define IF_AARCH64_ELSE(x, y) x
# define IF_AARCH64_(x) x,
# define _IF_AARCH64(x) , x
# define IF_NOT_AARCH64(x)
# define _IF_NOT_AARCH64(x)
#else
# define IF_AARCH64(x)
# define IF_AARCH64_ELSE(x, y) y
# define IF_AARCH64_(x)
# define _IF_AARCH64(x)
# define IF_NOT_AARCH64(x) x
# define _IF_NOT_AARCH64(x) , x
#endif
#ifdef AARCHXX
# define IF_AARCHXX(x) x
# define IF_AARCHXX_ELSE(x, y) x
# define IF_AARCHXX_(x) x,
# define _IF_AARCHXX(x) , x
# define IF_NOT_AARCHXX(x)
# define _IF_NOT_AARCHXX(x)
#else
# define IF_AARCHXX(x)
# define IF_AARCHXX_ELSE(x, y) y
# define IF_AARCHXX_(x)
# define _IF_AARCHXX(x)
# define IF_NOT_AARCHXX(x) x
# define _IF_NOT_AARCHXX(x) , x
#endif
#ifdef ANDROID
# define IF_ANDROID(x) x
# define IF_ANDROID_ELSE(x, y) x
# define IF_NOT_ANDROID(x)
#else
# define IF_ANDROID(x)
# define IF_ANDROID_ELSE(x, y) y
# define IF_NOT_ANDROID(x) x
#endif
#ifdef X64
# define IF_X64(x) x
# define IF_X64_ELSE(x, y) x
# define IF_X64_(x) x,
# define _IF_X64(x) , x
# define IF_NOT_X64(x)
# define _IF_NOT_X64(x)
#else
# define IF_X64(x)
# define IF_X64_ELSE(x, y) y
# define IF_X64_(x)
# define _IF_X64(x)
# define IF_NOT_X64(x) x
# define _IF_NOT_X64(x) , x
#endif
#if defined(X86) && !defined(X64)
# define IF_X86_32(x) x
#else
# define IF_X86_32(x)
#endif
#if defined(X86) && defined(X64)
# define IF_X86_64(x) x
# define IF_X86_64_ELSE(x, y) x
# define IF_X86_64_(x) x,
# define _IF_X86_64(x) , x
# define IF_NOT_X86_64(x)
# define _IF_NOT_X86_64(x)
#else
# define IF_X86_64(x)
# define IF_X86_64_ELSE(x, y) y
# define IF_X86_64_(x)
# define _IF_X86_64(x)
# define IF_NOT_X86_64(x) x
# define _IF_NOT_X86_64(x) , x
#endif
#if defined(X64) || defined(ARM)
# define IF_X64_OR_ARM(x) x
# define IF_NOT_X64_OR_ARM(x)
#else
# define IF_X64_OR_ARM(x)
# define IF_NOT_X64_OR_ARM(x) x
#endif
/* DR_API EXPORT END */
typedef enum {
SYSLOG_INFORMATION = 0x1,
SYSLOG_WARNING = 0x2,
SYSLOG_ERROR = 0x4,
SYSLOG_CRITICAL = 0x8,
SYSLOG_NONE = 0x0,
SYSLOG_ALL = (SYSLOG_INFORMATION | SYSLOG_WARNING | SYSLOG_ERROR |
SYSLOG_CRITICAL),
} syslog_event_type_t;
#define DYNAMO_OPTION(opt) (ASSERT_OWN_READWRITE_LOCK(IS_OPTION_STRING(opt), \
&options_lock), dynamo_options.opt)
/* For use where we don't want ASSERT defines. Currently only used in FATAL_USAGE_ERROR
* so it can be used in files that require all asserts to be client asserts. */
#define DYNAMO_OPTION_NOT_STRING(opt) (dynamo_options.opt)
#if defined(INTERNAL) || defined(CLIENT_INTERFACE)
#define EXPOSE_INTERNAL_OPTIONS
#endif
#ifdef EXPOSE_INTERNAL_OPTIONS
/* Use only for experimental non-release options */
/* Internal option value can be set on the command line only in INTERNAL builds */
/* We should remove the ASSERT if we convert an internal option into non-internal */
# define INTERNAL_OPTION(opt) ((IS_OPTION_INTERNAL(opt)) ? (DYNAMO_OPTION(opt)) : \
(ASSERT_MESSAGE(CHKLVL_ASSERTS, \
"non-internal option argument "#opt, false), \
DYNAMO_OPTION(opt)))
#else
/* Use only for experimental non-release options,
default value is assumed and command line options are ignored */
/* We could use IS_OPTION_INTERNAL(opt) ? to determine whether an
* option is defined as INTERNAL in optionsx.h and have that be the
* only place to modify to transition between internal and external
* options. The compiler should be able to eliminate the
* inappropriate part of the constant expression, if the specific
* option is no longer defined as internal so we don't have to
* modify the code. Still I'd rather have explicit uses of
* DYNAMO_OPTION or INTERNAL_OPTION for now.
*/
# define INTERNAL_OPTION(opt) DEFAULT_INTERNAL_OPTION_VALUE(opt)
#endif /* EXPOSE_INTERNAL_OPTIONS */
#ifdef UNIX
#ifndef DR_DO_NOT_DEFINE_uint32
typedef unsigned int uint32;
#endif
/* Note: Linux paths are longer than the 260 limit on Windows,
yet we can't afford the 4K of PATH_MAX from <limits.h> */
typedef uint64 timestamp_t;
# define NAKED
# define ZHEX32_FORMAT_STRING "%08x"
# define HEX32_FORMAT_STRING "%x"
#else /* WINDOWS */
/* We no longer include windows.h here, in order to more easily include
* this file for types like reg_t in hotpatch_interface.h and not force
* hotpatch compilation to point at windows include directories.
* By not including it here we must define MAX_PATH and include windows.h
* for NOT_DYNAMORIO_CORE in options.c and drmarker.c for share/ compilation.
*/
# define MAX_PATH 260 /* from winbase.h */
#ifndef DR_DO_NOT_DEFINE_uint
typedef unsigned int uint;
#endif
#ifndef DR_DO_NOT_DEFINE_uint32
typedef unsigned int uint32;
#endif
/* NOTE : unsigned __int64 not convertible to double */
typedef unsigned __int64 uint64;
typedef __int64 int64;
# ifdef X64
typedef int64 ssize_t;
# else
typedef int ssize_t;
# endif
/* PR 232882: %I32x printf format code not supported on NT's ntdll */
# ifdef X64
# define ZHEX32_FORMAT_STRING "%08I32x"
# define HEX32_FORMAT_STRING "%I32x"
# else
# define ZHEX32_FORMAT_STRING "%08x"
# define HEX32_FORMAT_STRING "%x"
# endif
/* VC6 doesn't define the standard ULLONG_MAX */
# if _MSC_VER <= 1200 && !defined(ULLONG_MAX)
# define ULLONG_MAX _UI64_MAX
# endif
typedef uint64 timestamp_t;
# define NAKED __declspec( naked )
#endif
#define FIXED_TIMESTAMP_FORMAT "%10" INT64_FORMAT"u"
/* DR_API EXPORT TOFILE dr_defines.h */
/* DR_API EXPORT BEGIN */
#define UINT64_FORMAT_CODE INT64_FORMAT "u"
#define INT64_FORMAT_CODE INT64_FORMAT "d"
#define UINT64_FORMAT_STRING "%" UINT64_FORMAT_CODE
#define INT64_FORMAT_STRING "%" INT64_FORMAT_CODE
#define HEX64_FORMAT_STRING "%" INT64_FORMAT "x"
#define ZHEX64_FORMAT_STRING "%016" INT64_FORMAT "x"
#ifdef API_EXPORT_ONLY
#define ZHEX32_FORMAT_STRING "%08x"
#define HEX32_FORMAT_STRING "%x"
/* Convenience defines for cross-platform printing */
#ifdef X64
# define PFMT ZHEX64_FORMAT_STRING
# define PIFMT HEX64_FORMAT_STRING
# define SZFMT INT64_FORMAT_STRING
#else
# define PFMT ZHEX32_FORMAT_STRING
# define PIFMT HEX32_FORMAT_STRING
# define SZFMT "%d"
#endif
#endif
/* DR_API EXPORT END */
/* workaround for lack of defines stack and assumption in genapi.pl
* that ignored defines are outermost */
/* DR_API EXPORT BEGIN */
#ifdef API_EXPORT_ONLY
#define PFX "0x" PFMT /**< printf format code for pointers */
#define PIFX "0x" PIFMT /**< printf format code for pointer-sized integers */
#endif
#ifndef INFINITE
# define INFINITE 0xFFFFFFFF
#endif
/* DR_API EXPORT END */
/* Statistics are 64-bit for x64, 32-bit for x86, so we don't have overflow
* for pointer-sized stats.
* TODO PR 227994: use per-statistic types for variable bitwidths.
*/
#ifdef X64
typedef int64 stats_int_t;
#else
typedef int stats_int_t;
#endif
/* For printing pointers: we do not use %p as gcc prepends 0x and uses
* lowercase while cl does not prepend, puts leading 0's, and uses uppercase.
* Also, the C standard does not allow min width for %p.
* Two macros:
* - PFMT == Pointer Format == with leading zeros
* - PIFMT == Pointer Integer Format == no leading zeros
* Convenience macros to shrink long lines:
* - PFX == Pointer Format with leading 0x
* - PIFX == Pointer Integer Format with leading 0x
* For printing memory region sizes:
* - SZFMT == Size Format
* - SSZFMT == Signed Size Format
* For printing 32-bit integers as hex we use %x. We could use a macro
* there and then disallow %x, to try and avoid 64-bit printing bugs,
* but it wouldn't be a panacea.
*/
#define L_UINT64_FORMAT_STRING L"%" L_EXPAND_LEVEL(UINT64_FORMAT_CODE)
#ifdef X64
# define PFMT ZHEX64_FORMAT_STRING
# define PIFMT HEX64_FORMAT_STRING
# define SZFMT UINT64_FORMAT_STRING
# define SSZFMT INT64_FORMAT_STRING
# define SZFC UINT64_FORMAT_CODE
# define SSZFC INT64_FORMAT_CODE
#else
# define PFMT ZHEX32_FORMAT_STRING
# define PIFMT HEX32_FORMAT_STRING
# define SZFMT "%u"
# define SSZFMT "%d"
# define SZFC "u"
# define SSZFC "d"
#endif
#define L_PFMT L"%016" L_EXPAND_LEVEL(INT64_FORMAT)L"x"
#define PFX "0x" PFMT
#define PIFX "0x" PIFMT
/* DR_API EXPORT BEGIN */
/* printf codes for {thread,process}_id_t */
#ifdef WINDOWS
# define PIDFMT SZFMT /**< printf format code for process_id_t */
# define TIDFMT SZFMT /**< printf format code for thread_id_t */
#else
# define PIDFMT "%d" /**< printf format code for process_id_t */
# ifdef MACOS
# define TIDFMT UINT64_FORMAT_STRING /**< printf format code for thread_id_t */
# else
# define TIDFMT "%d" /**< printf format code for thread_id_t */
# endif
#endif
/* DR_API EXPORT END */
/* Maximum length of any registry parameter. Note that some are further
* restricted to MAXIMUM_PATH from their usage. */
#define MAX_REGISTRY_PARAMETER 512
#if defined(PARAMS_IN_REGISTRY) || !defined(CLIENT_INTERFACE)
/* Maximum length of option string in the registry */
# define MAX_OPTIONS_STRING 512
# define MAX_CONFIG_VALUE MAX_REGISTRY_PARAMETER
#else
/* Maximum length of option string from config file.
* For CLIENT_INTERFACE we need more than 512 bytes to fit multiple options
* w/ paths. However, we have stack buffers in config.c and options.c
* (look for MAX_OPTION_LENGTH there), so we can't make this too big
* unless we increase the default -stack_size even further.
* N.B.: there is a separate define in dr_config.h, DR_MAX_OPTIONS_LENGTH.
*/
# define MAX_OPTIONS_STRING 2048
# define MAX_CONFIG_VALUE MAX_OPTIONS_STRING
#endif
/* Maximum length of any individual list option's string */
#define MAX_LIST_OPTION_LENGTH MAX_OPTIONS_STRING
/* Maximum length of the path secified by a path option */
#define MAX_PATH_OPTION_LENGTH MAXIMUM_PATH
/* Maximum length of any individual option. */
#define MAX_OPTION_LENGTH MAX_OPTIONS_STRING
#define MAX_PARAMNAME_LENGTH 64
/* Arbitrary debugging-only module name length maximum */
#define MAX_MODNAME_INTERNAL 64
/* Maximum string representation of a DWORD:
* 0x80000000 = -2147483648 -> 11 characters + 1 for null termination
*/
#define MAX_DWORD_STRING_LENGTH 12
typedef char pathstring_t[MAX_PATH_OPTION_LENGTH];
/* The liststring_t type is assumed to contain ;-separated values that are