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 : // An identifier denoting the agent with which this frequency data
35 : // instrumentation is intended to work.
36 m : uint32 agent_id;
37 :
38 : // The version of the data structure and agent of the toolchain that
39 : // instrumented the binary. If this doesn't match the running client
40 : // library then the whole process should be aborted. This just a simple
41 : // counter which should be updated whenever a non-backwards compatible
42 : // change is made to the data structure or its usage.
43 m : uint32 version;
44 :
45 : // The TLS slot associated with this module (if any). This allows for the
46 : // frequency trace data to be managed on a per-thread basis, if desired by the
47 : // agent.
48 m : DWORD tls_index;
49 :
50 : // This points to an array of length 'num_entries' counter elements. At
51 : // link time it is initialized to point to statically allocated array that is
52 : // in the .data section of the image (this is done so that if capture is not
53 : // enabled the binary can still run without crashing). If a single process-
54 : // wide frequency table is needed, the agent may allocate a call-trace buffer
55 : // and redirect this pointer to point into it. Alternatively, it may allocate
56 : // any thread-specific context it requires and refer to this pointer as a
57 : // fall-back measure if tracing is disabled.
58 : //
59 : // The total size (in bytes) of the buffer pointed to by is
60 : // num_entries * frequency_size.
61 m : void* frequency_data;
62 :
63 : // The number of entries in the frequency table. This is required by the
64 : // runtime client library so it knows how big an array to allocate.
65 m : uint32 num_entries;
66 :
67 : // The number of bytes used for each element of frequency_data: 1, 4, or 8.
68 m : uint8 frequency_size;
69 :
70 : // Each module only needs to be registered once with the call-trace service.
71 : // Our hooks grab various entry points (e.g. TLS initializers and the image
72 : // entry points), so the initialization routine may be called repeatedly. We
73 : // use this to determine whether or not we should try initializing things.
74 : // Upon first entry this is protected by the loader lock and afterwards it
75 : // is only read, so synchronization is not an issue.
76 m : uint8 initialization_attempted;
77 m : };
78 m : COMPILE_ASSERT_IS_POD(IndexedFrequencyData);
79 :
80 : #pragma pack(pop)
81 :
82 : // The basic-block coverage agent ID.
83 m : extern const uint32 kBasicBlockCoverageAgentId;
84 :
85 : // The basic-block entry counting agent ID.
86 m : extern const uint32 kBasicBlockEntryAgentId;
87 :
88 : // The jump table counting agent ID.
89 m : extern const uint32 kJumpTableCountAgentId;
90 :
91 : // The basic-block trace agent version.
92 m : extern const uint32 kBasicBlockFrequencyDataVersion;
93 :
94 : // The jump table trace agent version.
95 m : extern const uint32 kJumpTableFrequencyDataVersion;
96 :
97 : // The name of the basic-block ranges stream added to the PDB by
98 : // any instrumentation employing basic-block trace data.
99 m : extern const char kBasicBlockRangesStreamName[];
100 :
101 m : } // namespace common
102 :
103 : #endif // SYZYGY_COMMON_INDEXED_FREQUENCY_DATA_H_
|