1 : // Copyright 2012 Google Inc.
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 data structures and constants used by the various pieces of the
16 : // instrumentation and trace agent's that work with basic-blocks. For example,
17 : // this might include a coverage client and instrumentation (a single on/off
18 : // value for whether or not a basic-block was entered) or a thread-aware
19 : // basic-block entry counting client and instrumentation.
20 :
21 : #ifndef SYZYGY_COMMON_BASIC_BLOCK_FREQUENCY_DATA_H_
22 : #define SYZYGY_COMMON_BASIC_BLOCK_FREQUENCY_DATA_H_
23 :
24 : #include <windows.h>
25 :
26 : #include "base/basictypes.h"
27 :
28 m : namespace common {
29 :
30 : #pragma pack(push, 1)
31 :
32 : // This data structure is injected into an instrumented image in a read-write
33 : // section of its own. It will be initialized by the runtime client library
34 : // and is referred to by all of the instrumentation code.
35 m : struct BasicBlockFrequencyData {
36 : // An identifier denoting the agent with which this frequency data
37 : // instrumentation is intended to work.
38 m : uint32 agent_id;
39 :
40 : // The version of the data structure and agent of the toolcain that
41 : // instrumented the binary. If this doesn't match the running client
42 : // library then the whole process should be aborted. This just a simple
43 : // counter which should be updated whenever a non-backwards compatible
44 : // change is made to the data structure or its usage.
45 m : uint32 version;
46 :
47 : // The TLS slot associated with this module (if any). This allows for the
48 : // basic-block trace data to be managed on a per-thread basis, if desired
49 : // by the agent.
50 m : DWORD tls_index;
51 :
52 : // This points to an array of length 'num_basic_blocks' counter elements. At
53 : // link time it is initialized to point to statically allocated array that is
54 : // in the .data section of the image (this is done so that if capture is not
55 : // enabled the binary can still run without crashing). If a single process-
56 : // wide frequency table is needed, the agent may allocate a call-trace buffer
57 : // and redirect this pointer to point into it. Alternatively, it may allocate
58 : // any thread-specific context it requires and refer to this pointer as a
59 : // fall-back measure if tracing is disabled.
60 : //
61 : // The total size (in bytes) of the buffer pointed to by is
62 : // num_basic_blocks * frequency_size.
63 m : void* frequency_data;
64 :
65 : // The number of basic blocks in the instrumented image. This is required by
66 : // the runtime client library so it knows how big an array to allocate.
67 m : uint32 num_basic_blocks;
68 :
69 : // The number of bytes used for each element of frequency_data: 1, 4, or 8.
70 m : uint8 frequency_size;
71 :
72 : // Each module only needs to be registered once with the call-trace service.
73 : // Our hooks grab various entry points (e.g. TLS initializers and the image
74 : // entry points), so the initialization routine may be called repeatedly. We
75 : // use this to determine whether or not we should try initializing things.
76 : // Upon first entry this is protected by the loader lock and afterwards it
77 : // is only read, so synchronization is not an issue.
78 m : uint8 initialization_attempted;
79 m : };
80 :
81 : #pragma pack(pop)
82 :
83 : // The basic-block coverage agent ID.
84 m : extern const uint32 kBasicBlockCoverageAgentId;
85 :
86 : // The basic-block entry counting agent ID.
87 m : extern const uint32 kBasicBlockEntryAgentId;
88 :
89 : // The basic-block trace agent version.
90 m : extern const uint32 kBasicBlockFrequencyDataVersion;
91 :
92 : // This is the name of the data section added to an instrumented image by
93 : // the coverage client.
94 m : extern const char kBasicBlockFrequencySectionName[];
95 :
96 : // The characteristics given to the coverage instrumentation section.
97 m : extern const DWORD kBasicBlockFrequencySectionCharacteristics;
98 :
99 : // The name of the basic-block ranges stream added to the PDB by the
100 : // any instrumentation employing basic-block trace data.
101 m : extern const char kBasicBlockRangesStreamName[];
102 :
103 m : } // namespace common
104 :
105 : #endif // SYZYGY_COMMON_BASIC_BLOCK_FREQUENCY_DATA_H_
|