1 : // Copyright 2013 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Declares the data structure that will be used by various pieces of the
16 : // instrumentation and trace agent's to collect data at runtime.
17 :
18 : #ifndef SYZYGY_COMMON_INDEXED_FREQUENCY_DATA_H_
19 : #define SYZYGY_COMMON_INDEXED_FREQUENCY_DATA_H_
20 :
21 : #include <windows.h>
22 :
23 : #include "base/basictypes.h"
24 : #include "syzygy/common/assertions.h"
25 :
26 m : namespace common {
27 :
28 : #pragma pack(push, 1)
29 :
30 : // This data structure is injected into an instrumented image in a read-write
31 : // section of its own. It will be initialized by the runtime client library
32 : // and is referred to by all of the instrumentation code.
33 m : struct IndexedFrequencyData {
34 m : enum DataType {
35 m : INVALID_DATA_TYPE = 0,
36 m : BASIC_BLOCK_ENTRY = 1,
37 m : COVERAGE = 2,
38 m : JUMP_TABLE = 3,
39 m : };
40 :
41 : // An identifier denoting the agent with which this frequency data
42 : // instrumentation is intended to work.
43 m : uint32 agent_id;
44 :
45 : // The version of the data structure and agent of the toolchain that
46 : // instrumented the binary. If this doesn't match the running client
47 : // library then the whole process should be aborted. This just a simple
48 : // counter which should be updated whenever a non-backwards compatible
49 : // change is made to the data structure or its usage.
50 m : uint32 version;
51 :
52 : // The TLS slot associated with this module (if any). This allows for the
53 : // frequency trace data to be managed on a per-thread basis, if desired by the
54 : // agent.
55 m : DWORD tls_index;
56 :
57 : // This points to an array of length 'num_entries' counter elements. At
58 : // link time it is initialized to point to statically allocated array that is
59 : // in the .data section of the image (this is done so that if capture is not
60 : // enabled the binary can still run without crashing). If a single process-
61 : // wide frequency table is needed, the agent may allocate a call-trace buffer
62 : // and redirect this pointer to point into it. Alternatively, it may allocate
63 : // any thread-specific context it requires and refer to this pointer as a
64 : // fall-back measure if tracing is disabled.
65 : //
66 : // The total size (in bytes) of the buffer pointed to by is
67 : // num_entries * frequency_size.
68 m : void* frequency_data;
69 :
70 : // The number of entries in the frequency table. This is required by the
71 : // runtime client library so it knows how big an array to allocate.
72 m : uint32 num_entries;
73 :
74 : // The number of bytes used for each element of frequency_data: 1, 4, or 8.
75 m : uint8 frequency_size;
76 :
77 : // Each module only needs to be registered once with the call-trace service.
78 : // Our hooks grab various entry points (e.g. TLS initializers and the image
79 : // entry points), so the initialization routine may be called repeatedly. We
80 : // use this to determine whether or not we should try initializing things.
81 : // Upon first entry this is protected by the loader lock and afterwards it
82 : // is only read, so synchronization is not an issue.
83 m : uint8 initialization_attempted;
84 :
85 : // The type of data associated with this module.
86 m : uint8 data_type;
87 m : };
88 m : COMPILE_ASSERT_IS_POD(IndexedFrequencyData);
89 :
90 : #pragma pack(pop)
91 :
92 : // The basic-block coverage agent ID.
93 m : extern const uint32 kBasicBlockCoverageAgentId;
94 :
95 : // The basic-block entry counting agent ID.
96 m : extern const uint32 kBasicBlockEntryAgentId;
97 :
98 : // The jump table counting agent ID.
99 m : extern const uint32 kJumpTableCountAgentId;
100 :
101 : // The basic-block trace agent version.
102 m : extern const uint32 kBasicBlockFrequencyDataVersion;
103 :
104 : // The jump table trace agent version.
105 m : extern const uint32 kJumpTableFrequencyDataVersion;
106 :
107 : // The name of the basic-block ranges stream added to the PDB by
108 : // any instrumentation employing basic-block trace data.
109 m : extern const char kBasicBlockRangesStreamName[];
110 :
111 m : } // namespace common
112 :
113 : #endif // SYZYGY_COMMON_INDEXED_FREQUENCY_DATA_H_
|