1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_CHROME_CLEANER_OS_PROCESS_H_
6 #define CHROME_CHROME_CLEANER_OS_PROCESS_H_
7 
8 #include <windows.h>
9 
10 #include <set>
11 #include <string>
12 
13 #include "base/process/process_metrics_iocounters.h"
14 
15 namespace chrome_cleaner {
16 
17 // Contains system resource usage information of a process.
18 struct SystemResourceUsage {
19   base::IoCounters io_counters;
20   base::TimeDelta user_time;
21   base::TimeDelta kernel_time;
22   size_t peak_working_set_size;  // In bytes.
23 };
24 
25 // This returns a string instead of a base::FilePath because it is called from
26 // SandboxGetLoadedModules, which needs to handle invalid UTF-16 characters
27 // gracefully. (Technically Windows file paths can contain arbitrary 16-bit
28 // values that may not be valid UTF-16.)
29 // Provided handle should have PROCESS_QUERY_INFORMATION | PROCESS_VM_READ
30 // access rights.
31 // The function might not work when enumerating modules of x64 process from a
32 // x86 process.
33 bool GetLoadedModuleFileNames(HANDLE process,
34                               std::set<std::wstring>* module_names);
35 
36 // Retrieve process executable module in win32 path format.
37 // Provided handle must have PROCESS_QUERY_LIMITED_INFORMATION or
38 // PROCESS_QUERY_INFORMATION access right.
39 bool GetProcessExecutablePath(HANDLE process, std::wstring* path);
40 
41 // Retrieves system resource usage stats for the given process.
42 // Provided handle must have PROCESS_QUERY_LIMITED_INFORMATION or
43 // PROCESS_QUERY_INFORMATION access right.
44 bool GetSystemResourceUsage(HANDLE process, SystemResourceUsage* stats);
45 
46 }  // namespace chrome_cleaner
47 
48 #endif  // CHROME_CHROME_CLEANER_OS_PROCESS_H_
49