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 : #include "syzygy/common/dbghelp_util.h"
16 :
17 : #include <dbghelp.h>
18 :
19 : #include "base/logging.h"
20 : #include "syzygy/common/com_utils.h"
21 :
22 : namespace common {
23 :
24 : // A wrapper for SymInitialize. It looks like it has an internal race condition
25 : // that can occasionally fail, so we wrap it and retry a finite number of times.
26 : // Ugly, but necessary.
27 : bool SymInitialize(HANDLE process,
28 : const char* user_search_path,
29 E : bool invade_process) {
30 E : for (int retry_count = 0; retry_count < 3; ++retry_count) {
31 E : BOOL result = ::SymInitialize(process, user_search_path, invade_process);
32 E : if (result == TRUE)
33 E : return true;
34 :
35 i : DWORD error = ::GetLastError();
36 : // This corresponds to STATUS_INFO_LENGTH_MISMATCH, which is defined in
37 : // ntstatus.h. This doesn't like being included alongside windows.h.
38 i : if (error == 0xC0000004)
39 i : continue;
40 :
41 i : LOG(ERROR) << "SymInitialize failed: " << common::LogWe(error);
42 i : return false;
43 i : }
44 :
45 i : LOG(ERROR) << "SymInitialize failed repeatedly.";
46 i : return false;
47 E : }
48 :
49 : } // namespace common
|