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 Asan instrumenter.
16 : #ifndef SYZYGY_INSTRUMENT_INSTRUMENTERS_ASAN_INSTRUMENTER_H_
17 : #define SYZYGY_INSTRUMENT_INSTRUMENTERS_ASAN_INSTRUMENTER_H_
18 :
19 : #include <string>
20 :
21 : #include "base/command_line.h"
22 : #include "syzygy/common/asan_parameters.h"
23 : #include "syzygy/instrument/instrumenters/instrumenter_with_agent.h"
24 : #include "syzygy/instrument/transforms/allocation_filter_transform.h"
25 : #include "syzygy/instrument/transforms/asan_transform.h"
26 : #include "syzygy/pe/image_filter.h"
27 : #include "syzygy/pe/pe_relinker.h"
28 :
29 : namespace instrument {
30 : namespace instrumenters {
31 :
32 : class AsanInstrumenter : public InstrumenterWithAgent {
33 : public:
34 : typedef InstrumenterWithAgent Super;
35 :
36 : AsanInstrumenter();
37 E : ~AsanInstrumenter() { }
38 :
39 : protected:
40 : // @name InstrumenterWithAgent overrides.
41 : // @{
42 : bool ImageFormatIsSupported(ImageFormat image_format) override;
43 : bool InstrumentPrepare() override;
44 : bool InstrumentImpl() override;
45 i : const char* InstrumentationMode() override { return "asan"; }
46 : // @}
47 :
48 : // @name Super overrides.
49 : // @{
50 : bool DoCommandLineParse(const base::CommandLine* command_line) override;
51 : // @}
52 :
53 : // @name Command-line parameters.
54 : // @{
55 : base::FilePath filter_path_;
56 : bool use_interceptors_;
57 : bool remove_redundant_checks_;
58 : bool use_liveness_analysis_;
59 : double instrumentation_rate_;
60 : bool asan_rtl_options_;
61 : bool hot_patching_;
62 : // @}
63 :
64 : // Valid if asan_rtl_options_ is true.
65 : common::InflatedAsanParameters asan_params_;
66 :
67 : // The transform for this agent.
68 : scoped_ptr<instrument::transforms::AsanTransform> asan_transform_;
69 :
70 : // The image filter (optional).
71 : scoped_ptr<pe::ImageFilter> filter_;
72 :
73 : // Path to the JSON configuration file for the AllocationFilter transform.
74 : // The AllocationFilter tranform is only applied if this config file is
75 : // specified.
76 : base::FilePath allocation_filter_config_file_path_;
77 :
78 : // The AllocationFilter transform.
79 : // TODO(sebmarchand): Write some integration tests for this.
80 : scoped_ptr<instrument::transforms::AllocationFilterTransform> af_transform_;
81 : };
82 :
83 : } // namespace instrumenters
84 : } // namespace instrument
85 :
86 : #endif // SYZYGY_INSTRUMENT_INSTRUMENTERS_ASAN_INSTRUMENTER_H_
|