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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 348 } |
349 | 349 |
350 bool GetPathFromHandle(HANDLE handle, base::string16* path) { | 350 bool GetPathFromHandle(HANDLE handle, base::string16* path) { |
351 NtQueryObjectFunction NtQueryObject = NULL; | 351 NtQueryObjectFunction NtQueryObject = NULL; |
352 ResolveNTFunctionPtr("NtQueryObject", &NtQueryObject); | 352 ResolveNTFunctionPtr("NtQueryObject", &NtQueryObject); |
353 | 353 |
354 OBJECT_NAME_INFORMATION initial_buffer; | 354 OBJECT_NAME_INFORMATION initial_buffer; |
355 OBJECT_NAME_INFORMATION* name = &initial_buffer; | 355 OBJECT_NAME_INFORMATION* name = &initial_buffer; |
356 ULONG size = sizeof(initial_buffer); | 356 ULONG size = sizeof(initial_buffer); |
357 // Query the name information a first time to get the size of the name. | 357 // Query the name information a first time to get the size of the name. |
| 358 // Windows XP requires that the size of the buffer passed in here be != 0. |
358 NTSTATUS status = NtQueryObject(handle, ObjectNameInformation, name, size, | 359 NTSTATUS status = NtQueryObject(handle, ObjectNameInformation, name, size, |
359 &size); | 360 &size); |
360 | 361 |
361 scoped_ptr<OBJECT_NAME_INFORMATION> name_ptr; | 362 scoped_ptr<BYTE[]> name_ptr; |
362 if (size) { | 363 if (size) { |
363 name = reinterpret_cast<OBJECT_NAME_INFORMATION*>(new BYTE[size]); | 364 name_ptr.reset(new BYTE[size]); |
364 name_ptr.reset(name); | 365 name = reinterpret_cast<OBJECT_NAME_INFORMATION*>(name_ptr.get()); |
365 | 366 |
366 // Query the name information a second time to get the name of the | 367 // Query the name information a second time to get the name of the |
367 // object referenced by the handle. | 368 // object referenced by the handle. |
368 status = NtQueryObject(handle, ObjectNameInformation, name, size, &size); | 369 status = NtQueryObject(handle, ObjectNameInformation, name, size, &size); |
369 } | 370 } |
370 | 371 |
371 if (STATUS_SUCCESS != status) | 372 if (STATUS_SUCCESS != status) |
372 return false; | 373 return false; |
373 | 374 |
374 path->assign(name->ObjectName.Buffer, name->ObjectName.Length / | 375 path->assign(name->ObjectName.Buffer, name->ObjectName.Length / |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 ::InterlockedCompareExchangePointer( | 423 ::InterlockedCompareExchangePointer( |
423 reinterpret_cast<PVOID volatile*>(&ntdll), ntdll_local, NULL); | 424 reinterpret_cast<PVOID volatile*>(&ntdll), ntdll_local, NULL); |
424 | 425 |
425 } | 426 } |
426 | 427 |
427 CHECK_NT(ntdll); | 428 CHECK_NT(ntdll); |
428 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); | 429 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); |
429 *function_ptr = ::GetProcAddress(ntdll, name); | 430 *function_ptr = ::GetProcAddress(ntdll, name); |
430 CHECK_NT(*function_ptr); | 431 CHECK_NT(*function_ptr); |
431 } | 432 } |
OLD | NEW |