Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(702)

Side by Side Diff: base/process_util_win.cc

Issue 9703019: Fix error handling in OpenProcess wrappers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_util.h" 5 #include "base/process_util.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <io.h> 8 #include <io.h>
9 #include <windows.h> 9 #include <windows.h>
10 #include <userenv.h> 10 #include <userenv.h>
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return hinst; 184 return hinst;
185 } 185 }
186 186
187 bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { 187 bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) {
188 // We try to limit privileges granted to the handle. If you need this 188 // We try to limit privileges granted to the handle. If you need this
189 // for test code, consider using OpenPrivilegedProcessHandle instead of 189 // for test code, consider using OpenPrivilegedProcessHandle instead of
190 // adding more privileges here. 190 // adding more privileges here.
191 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | PROCESS_TERMINATE, 191 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | PROCESS_TERMINATE,
192 FALSE, pid); 192 FALSE, pid);
193 193
194 if (result == INVALID_HANDLE_VALUE) 194 if (result == NULL)
195 return false; 195 return false;
196 196
197 *handle = result; 197 *handle = result;
198 return true; 198 return true;
199 } 199 }
200 200
201 bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle) { 201 bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle) {
202 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | 202 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE |
203 PROCESS_TERMINATE | 203 PROCESS_TERMINATE |
204 PROCESS_QUERY_INFORMATION | 204 PROCESS_QUERY_INFORMATION |
205 PROCESS_VM_READ | 205 PROCESS_VM_READ |
206 SYNCHRONIZE, 206 SYNCHRONIZE,
207 FALSE, pid); 207 FALSE, pid);
208 208
209 if (result == INVALID_HANDLE_VALUE) 209 if (result == NULL)
210 return false; 210 return false;
211 211
212 *handle = result; 212 *handle = result;
213 return true; 213 return true;
214 } 214 }
215 215
216 bool OpenProcessHandleWithAccess(ProcessId pid, 216 bool OpenProcessHandleWithAccess(ProcessId pid,
217 uint32 access_flags, 217 uint32 access_flags,
218 ProcessHandle* handle) { 218 ProcessHandle* handle) {
219 ProcessHandle result = OpenProcess(access_flags, FALSE, pid); 219 ProcessHandle result = OpenProcess(access_flags, FALSE, pid);
220 220
221 if (result == INVALID_HANDLE_VALUE) 221 if (result == NULL)
222 return false; 222 return false;
223 223
224 *handle = result; 224 *handle = result;
225 return true; 225 return true;
226 } 226 }
227 227
228 void CloseProcessHandle(ProcessHandle process) { 228 void CloseProcessHandle(ProcessHandle process) {
229 CloseHandle(process); 229 CloseHandle(process);
230 } 230 }
231 231
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 1002
1003 PERFORMANCE_INFORMATION info; 1003 PERFORMANCE_INFORMATION info;
1004 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { 1004 if (!InternalGetPerformanceInfo(&info, sizeof(info))) {
1005 DLOG(ERROR) << "Failed to fetch internal performance info."; 1005 DLOG(ERROR) << "Failed to fetch internal performance info.";
1006 return 0; 1006 return 0;
1007 } 1007 }
1008 return (info.CommitTotal * system_info.dwPageSize) / 1024; 1008 return (info.CommitTotal * system_info.dwPageSize) / 1024;
1009 } 1009 }
1010 1010
1011 } // namespace base 1011 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698