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 entry thunk instrumenter.
16 : #ifndef SYZYGY_INSTRUMENT_INSTRUMENTERS_ENTRY_THUNK_INSTRUMENTER_H_
17 : #define SYZYGY_INSTRUMENT_INSTRUMENTERS_ENTRY_THUNK_INSTRUMENTER_H_
18 :
19 : #include <string>
20 :
21 : #include "base/command_line.h"
22 : #include "syzygy/instrument/instrumenters/instrumenter_with_agent.h"
23 : #include "syzygy/instrument/transforms/entry_thunk_transform.h"
24 : #include "syzygy/instrument/transforms/thunk_import_references_transform.h"
25 : #include "syzygy/pe/pe_relinker.h"
26 :
27 : namespace instrument {
28 : namespace instrumenters {
29 :
30 : class EntryThunkInstrumenter : public InstrumenterWithAgent {
31 : public:
32 : typedef InstrumenterWithAgent Super;
33 :
34 : // The mode for this instrumenter.
35 : enum Mode {
36 : INVALID_MODE,
37 : CALL_TRACE,
38 : PROFILE,
39 : };
40 :
41 : explicit EntryThunkInstrumenter(Mode instrumentation_mode);
42 E : ~EntryThunkInstrumenter() { }
43 :
44 : // Returns the instrumentation mode.
45 E : Mode instrumentation_mode() { return instrumentation_mode_; }
46 :
47 : protected:
48 : // The name of the agents for the different mode of instrumentation.
49 : static const char kAgentDllProfile[];
50 : static const char kAgentDllRpc[];
51 :
52 : // @name InstrumenterWithAgent overrides.
53 : // @{
54 : bool InstrumentPrepare() override;
55 : bool InstrumentImpl() override;
56 : const char* InstrumentationMode() override;
57 : // @}
58 :
59 : // @name Super overrides.
60 : // @{
61 : bool DoCommandLineParse(const base::CommandLine* command_line) override;
62 : // @}
63 :
64 : // @name Command-line parameters.
65 : // @{
66 : bool instrument_unsafe_references_;
67 : bool module_entry_only_;
68 : bool thunk_imports_;
69 : // @}
70 :
71 : // The instrumentation mode.
72 : Mode instrumentation_mode_;
73 :
74 : // The transforms for this agent.
75 : scoped_ptr<instrument::transforms::EntryThunkTransform>
76 : entry_thunk_transform_;
77 : scoped_ptr<instrument::transforms::ThunkImportReferencesTransform>
78 : import_thunk_tx_;
79 : };
80 :
81 : } // namespace instrumenters
82 : } // namespace instrument
83 :
84 : #endif // SYZYGY_INSTRUMENT_INSTRUMENTERS_ENTRY_THUNK_INSTRUMENTER_H_
|