1 : // Copyright 2015 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 : // This file exports ReportCrashWithProtobuf, which is an optional API that
16 : // instrumented processes may export (from their executable module) in order to
17 : // handle SyzyASAN reports. The exit code from this method is used to verify
18 : // SyzyASAN functionality in instrument_integration_test.cc .
19 :
20 : #include <windows.h>
21 :
22 : #include "base/environment.h"
23 : #include "syzygy/crashdata/crashdata.h"
24 : #include "syzygy/crashdata/json.h"
25 :
26 E : void Exit(UINT code) {
27 E : ::TerminateProcess(::GetCurrentProcess(), code);
28 E : }
29 :
30 : extern "C" void __declspec(dllexport)
31 : ReportCrashWithProtobuf(EXCEPTION_POINTERS* info,
32 : const char* protobuf,
33 E : size_t protobuf_length) {
34 : // Bail if there was no protobuf.
35 E : if (protobuf == nullptr || protobuf_length == 0)
36 i : Exit(97);
37 :
38 : // Parse the protobuf and bail if that fails.
39 E : crashdata::Value value;
40 E : if (!value.ParseFromArray(protobuf, protobuf_length))
41 i : ::Exit(97);
42 :
43 : // A useful debugging hack.
44 E : scoped_ptr<base::Environment> env(base::Environment::Create());
45 E : if (env->HasVar("SYZYGY_ASAN_DUMP_PROTOBUF_ON_CRASH")) {
46 i : std::string json;
47 i : crashdata::ToJson(true, &value, &json);
48 i : ::printf("%s", json.c_str());
49 i : }
50 :
51 E : Exit(98);
52 E : }
|