• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __VTS_SYSFUZZER_LIBMEASUREMENT_GCOV_BASIC_IO_H__
2 #define __VTS_SYSFUZZER_LIBMEASUREMENT_GCOV_BASIC_IO_H__
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 
8 namespace android {
9 namespace vts {
10 
11 struct block_info;
12 struct source_info;
13 
14 #define GCOV_DATA_MAGIC ((unsigned)0x67636461) /* "gcda" */
15 
16 #define GCOV_TAG_FUNCTION ((unsigned int)0x01000000)
17 #define GCOV_TAG_FUNCTION_LENGTH (3) /* or 2 */
18 #define GCOV_COUNTER_ARCS 0
19 #define GCOV_TAG_ARCS ((unsigned)0x01430000)
20 #define GCOV_TAG_ARCS_LENGTH(NUM) (1 + (NUM)*2)
21 #define GCOV_TAG_ARCS_NUM(LENGTH) (((LENGTH)-1) / 2)
22 #define GCOV_TAG_LINES ((unsigned)0x01450000)
23 #define GCOV_TAG_BLOCKS ((unsigned)0x01410000)
24 #define GCOV_TAG_BLOCKS_LENGTH(NUM) (NUM)
25 #define GCOV_TAG_BLOCKS_NUM(LENGTH) (LENGTH)
26 #define GCOV_TAG_OBJECT_SUMMARY ((unsigned)0xa1000000)
27 #define GCOV_TAG_COUNTER_NUM(LENGTH) ((LENGTH) / 2)
28 
29 #define GCOV_HISTOGRAM_SIZE 252
30 #define GCOV_HISTOGRAM_BITVECTOR_SIZE (GCOV_HISTOGRAM_SIZE + 31) / 32
31 #define GCOV_COUNTERS_SUMMABLE (GCOV_COUNTER_ARCS + 1)
32 
33 #define GCOV_TAG_IS_COUNTER(TAG) \
34   (!((TAG)&0xFFFF) && GCOV_COUNTER_FOR_TAG(TAG) < GCOV_COUNTERS)
35 
36 #define GCOV_TAG_MASK(TAG) (((TAG)-1) ^ (TAG))
37 
38 /* Return nonzero if SUB is an immediate subtag of TAG.  */
39 #define GCOV_TAG_IS_SUBTAG(TAG, SUB)                \
40   (GCOV_TAG_MASK(TAG) >> 8 == GCOV_TAG_MASK(SUB) && \
41    !(((SUB) ^ (TAG)) & ~GCOV_TAG_MASK(TAG)))
42 
43 /* Return nonzero if SUB is at a sublevel to TAG. */
44 #define GCOV_TAG_IS_SUBLEVEL(TAG, SUB) (GCOV_TAG_MASK(TAG) > GCOV_TAG_MASK(SUB))
45 
46 typedef long long gcov_type;
47 
48 enum { GCOV_COUNTERS };
49 
50 #define GCOV_VERSION ((unsigned)0x34303670) /* 406p */
51 
52 #define GCOV_TAG_BUILD_INFO ((unsigned)0xa7000000)
53 #define GCOV_TAG_PROGRAM_SUMMARY ((unsigned)0xa3000000)
54 
55 #define XCNEWVEC(T, N) ((T *)calloc((N), sizeof(T)))
56 
57 #define GCOV_TAG_COUNTER_BASE ((unsigned)0x01a10000)
58 #define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM)*2)
59 
60 /* Convert a counter index to a tag. */
61 #define GCOV_TAG_FOR_COUNTER(COUNT) \
62   (GCOV_TAG_COUNTER_BASE + ((unsigned)(COUNT) << 17))
63 
64 /* Convert a tag to a counter. */
65 #define GCOV_COUNTER_FOR_TAG(TAG) \
66   ((unsigned)(((TAG)-GCOV_TAG_COUNTER_BASE) >> 17))
67 
68 /* Check whether a tag is a counter tag.  */
69 #define GCOV_TAG_IS_COUNTER(TAG) \
70   (!((TAG)&0xFFFF) && GCOV_COUNTER_FOR_TAG(TAG) < GCOV_COUNTERS)
71 
72 #define GCOV_UNSIGNED2STRING(ARRAY, VALUE)                                 \
73   ((ARRAY)[0] = (char)((VALUE) >> 24), (ARRAY)[1] = (char)((VALUE) >> 16), \
74    (ARRAY)[2] = (char)((VALUE) >> 8), (ARRAY)[3] = (char)((VALUE) >> 0))
75 
76 #define GCOV_BLOCK_SIZE (1 << 10)
77 
78 typedef struct arc_info {
79   /* source and destination blocks.  */
80   struct block_info *src;
81   struct block_info *dst;
82 
83   /* transition counts.  */
84   gcov_type count;
85   /* used in cycle search, so that we do not clobber original counts.  */
86   gcov_type cs_count;
87 
88   unsigned int count_valid : 1;
89   unsigned int on_tree : 1;
90   unsigned int fake : 1;
91   unsigned int fall_through : 1;
92 
93   /* Arc to a catch handler. */
94   unsigned int is_throw : 1;
95 
96   /* Arc is for a function that abnormally returns.  */
97   unsigned int is_call_non_return : 1;
98 
99   /* Arc is for catch/setjmp. */
100   unsigned int is_nonlocal_return : 1;
101 
102   /* Is an unconditional branch. */
103   unsigned int is_unconditional : 1;
104 
105   /* Loop making arc.  */
106   unsigned int cycle : 1;
107 
108   /* Next branch on line.  */
109   struct arc_info *line_next;
110 
111   /* Links to next arc on src and dst lists.  */
112   struct arc_info *succ_next;
113   struct arc_info *pred_next;
114 } arc_t;
115 
116 struct gcov_var_t {
117   FILE* file;
118   unsigned start;  /* Position of first byte of block */
119   unsigned offset;  /* Read/write position within the block.  */
120   unsigned length;  /* Read limit in the block.  */
121   unsigned overread;  /* Number of words overread.  */
122   int error;  /* < 0 overflow, > 0 disk error.  */
123   int mode;  /* < 0 writing, > 0 reading */
124   int endian;  /* Swap endianness.  */
125   /* Holds a variable length block, as the compiler can write
126      strings and needs to backtrack.  */
127   size_t alloc;
128   unsigned* buffer;
129 };
130 
131 }  // namespace vts
132 }  // namespace android
133 
134 #endif
135