1 : // Copyright 2012 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 : // Process-related convenience utilities for agents.
16 :
17 : #ifndef SYZYGY_AGENT_COMMON_PROCESS_UTILS_H_
18 : #define SYZYGY_AGENT_COMMON_PROCESS_UTILS_H_
19 :
20 : #include <windows.h>
21 : #include <vector>
22 :
23 : // Forward declarations.
24 m : namespace trace {
25 m : namespace client {
26 m : class RpcSession;
27 m : class TraceFileSegment;
28 m : } // namespace client
29 m : } // namespace trace
30 :
31 m : namespace agent {
32 m : namespace common {
33 :
34 m : typedef std::vector<HMODULE> ModuleVector;
35 :
36 : // Retrieves a list of all modules in the process.
37 : // @param modules returns a vector containing all modules in the process.
38 : // @note that other threads in the process can be loading or unloading
39 : // libraries concurrently with calling this function and using its results.
40 : // Using the results from this function is therefore inherently racy, unless
41 : // running under the loader's lock, such as e.g. in a DllMain notification
42 : // or e.g. a TLS callback function.
43 m : void GetProcessModules(ModuleVector* modules);
44 :
45 : // Logs a TRACE_PROCESS_ATTACH_EVENT to the provided @p segment and @p session.
46 : // If there is insufficient room in @p segment, returns the buffer to @p service
47 : // and allocates a new one.
48 : // @param module the module to be logged.
49 : // @param session the session owning @p segment.
50 : // @param segment the segment in which the event will be written.
51 : // @returns true on success, false otherwise.
52 m : bool LogModule(HMODULE module,
53 m : trace::client::RpcSession* session,
54 m : trace::client::TraceFileSegment* segment);
55 :
56 m : } // namespace common
57 m : } // namespace agent
58 :
59 : #endif // SYZYGY_AGENT_COMMON_PROCESS_UTILS_H_
|