OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/process/process_handle.h" | 5 #include "base/process/process_handle.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/win/scoped_handle.h" | 10 #include "base/win/scoped_handle.h" |
11 #include "base/win/windows_version.h" | 11 #include "base/win/windows_version.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 ProcessId GetCurrentProcId() { | 15 ProcessId GetCurrentProcId() { |
16 return ::GetCurrentProcessId(); | 16 return ::GetCurrentProcessId(); |
17 } | 17 } |
18 | 18 |
19 ProcessHandle GetCurrentProcessHandle() { | 19 ProcessHandle GetCurrentProcessHandle() { |
20 return ::GetCurrentProcess(); | 20 return ::GetCurrentProcess(); |
21 } | 21 } |
22 | 22 |
23 bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { | |
24 // We try to limit privileges granted to the handle. If you need this | |
25 // for test code, consider using OpenPrivilegedProcessHandle instead of | |
26 // adding more privileges here. | |
27 ProcessHandle result = OpenProcess(PROCESS_TERMINATE | | |
28 PROCESS_QUERY_INFORMATION | | |
29 SYNCHRONIZE, | |
30 FALSE, pid); | |
31 | |
32 if (result == NULL) | |
33 return false; | |
34 | |
35 *handle = result; | |
36 return true; | |
37 } | |
38 | |
39 void CloseProcessHandle(ProcessHandle process) { | 23 void CloseProcessHandle(ProcessHandle process) { |
40 CloseHandle(process); | 24 CloseHandle(process); |
41 } | 25 } |
42 | 26 |
43 ProcessId GetProcId(ProcessHandle process) { | 27 ProcessId GetProcId(ProcessHandle process) { |
44 // This returns 0 if we have insufficient rights to query the process handle. | 28 // This returns 0 if we have insufficient rights to query the process handle. |
45 return GetProcessId(process); | 29 return GetProcessId(process); |
46 } | 30 } |
47 | 31 |
48 bool GetProcessIntegrityLevel(ProcessHandle process, IntegrityLevel *level) { | 32 bool GetProcessIntegrityLevel(ProcessHandle process, IntegrityLevel *level) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 *level = HIGH_INTEGRITY; | 74 *level = HIGH_INTEGRITY; |
91 } else { | 75 } else { |
92 NOTREACHED(); | 76 NOTREACHED(); |
93 return false; | 77 return false; |
94 } | 78 } |
95 | 79 |
96 return true; | 80 return true; |
97 } | 81 } |
98 | 82 |
99 } // namespace base | 83 } // namespace base |
OLD | NEW |