OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "sandbox/win/src/win_utils.h" | 5 #include "sandbox/win/src/win_utils.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 return true; | 236 return true; |
237 } | 237 } |
238 | 238 |
239 return false; | 239 return false; |
240 } | 240 } |
241 | 241 |
242 bool GetPathFromHandle(HANDLE handle, base::string16* path) { | 242 bool GetPathFromHandle(HANDLE handle, base::string16* path) { |
243 NtQueryObjectFunction NtQueryObject = NULL; | 243 NtQueryObjectFunction NtQueryObject = NULL; |
244 ResolveNTFunctionPtr("NtQueryObject", &NtQueryObject); | 244 ResolveNTFunctionPtr("NtQueryObject", &NtQueryObject); |
245 | 245 |
246 OBJECT_NAME_INFORMATION* name = NULL; | 246 OBJECT_NAME_INFORMATION initial_buffer; |
247 ULONG size = 0; | 247 OBJECT_NAME_INFORMATION* name = &initial_buffer; |
| 248 ULONG size = sizeof(initial_buffer); |
248 // Query the name information a first time to get the size of the name. | 249 // Query the name information a first time to get the size of the name. |
249 NTSTATUS status = NtQueryObject(handle, ObjectNameInformation, name, size, | 250 NTSTATUS status = NtQueryObject(handle, ObjectNameInformation, name, size, |
250 &size); | 251 &size); |
251 | 252 |
252 if (!size) | 253 scoped_ptr<OBJECT_NAME_INFORMATION> name_ptr; |
253 return false; | 254 if (size) { |
| 255 name = reinterpret_cast<OBJECT_NAME_INFORMATION*>(new BYTE[size]); |
| 256 name_ptr.reset(name); |
254 | 257 |
255 scoped_ptr<BYTE[]> name_ptr(new BYTE[size]); | 258 // Query the name information a second time to get the name of the |
256 name = reinterpret_cast<OBJECT_NAME_INFORMATION*>(name_ptr.get()); | 259 // object referenced by the handle. |
257 | 260 status = NtQueryObject(handle, ObjectNameInformation, name, size, &size); |
258 // Query the name information a second time to get the name of the | 261 } |
259 // object referenced by the handle. | |
260 status = NtQueryObject(handle, ObjectNameInformation, name, size, &size); | |
261 | 262 |
262 if (STATUS_SUCCESS != status) | 263 if (STATUS_SUCCESS != status) |
263 return false; | 264 return false; |
264 | 265 |
265 path->assign(name->ObjectName.Buffer, name->ObjectName.Length / | 266 path->assign(name->ObjectName.Buffer, name->ObjectName.Length / |
266 sizeof(name->ObjectName.Buffer[0])); | 267 sizeof(name->ObjectName.Buffer[0])); |
267 return true; | 268 return true; |
268 } | 269 } |
269 | 270 |
270 bool GetNtPathFromWin32Path(const base::string16& path, | 271 bool GetNtPathFromWin32Path(const base::string16& path, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 ::InterlockedCompareExchangePointer( | 314 ::InterlockedCompareExchangePointer( |
314 reinterpret_cast<PVOID volatile*>(&ntdll), ntdll_local, NULL); | 315 reinterpret_cast<PVOID volatile*>(&ntdll), ntdll_local, NULL); |
315 | 316 |
316 } | 317 } |
317 | 318 |
318 CHECK_NT(ntdll); | 319 CHECK_NT(ntdll); |
319 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); | 320 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); |
320 *function_ptr = ::GetProcAddress(ntdll, name); | 321 *function_ptr = ::GetProcAddress(ntdll, name); |
321 CHECK_NT(*function_ptr); | 322 CHECK_NT(*function_ptr); |
322 } | 323 } |
OLD | NEW |