| 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 initial_buffer; | 246 OBJECT_NAME_INFORMATION* name = NULL; |
| 247 OBJECT_NAME_INFORMATION* name = &initial_buffer; | 247 ULONG size = 0; |
| 248 ULONG size = sizeof(initial_buffer); | |
| 249 // Query the name information a first time to get the size of the name. | 248 // Query the name information a first time to get the size of the name. |
| 250 NTSTATUS status = NtQueryObject(handle, ObjectNameInformation, name, size, | 249 NTSTATUS status = NtQueryObject(handle, ObjectNameInformation, name, size, |
| 251 &size); | 250 &size); |
| 252 | 251 |
| 253 scoped_ptr<OBJECT_NAME_INFORMATION> name_ptr; | 252 if (!size) |
| 254 if (size) { | 253 return false; |
| 255 name = reinterpret_cast<OBJECT_NAME_INFORMATION*>(new BYTE[size]); | |
| 256 name_ptr.reset(name); | |
| 257 | 254 |
| 258 // Query the name information a second time to get the name of the | 255 scoped_ptr<BYTE[]> name_ptr(new BYTE[size]); |
| 259 // object referenced by the handle. | 256 name = reinterpret_cast<OBJECT_NAME_INFORMATION*>(name_ptr.get()); |
| 260 status = NtQueryObject(handle, ObjectNameInformation, name, size, &size); | 257 |
| 261 } | 258 // Query the name information a second time to get the name of the |
| 259 // object referenced by the handle. |
| 260 status = NtQueryObject(handle, ObjectNameInformation, name, size, &size); |
| 262 | 261 |
| 263 if (STATUS_SUCCESS != status) | 262 if (STATUS_SUCCESS != status) |
| 264 return false; | 263 return false; |
| 265 | 264 |
| 266 path->assign(name->ObjectName.Buffer, name->ObjectName.Length / | 265 path->assign(name->ObjectName.Buffer, name->ObjectName.Length / |
| 267 sizeof(name->ObjectName.Buffer[0])); | 266 sizeof(name->ObjectName.Buffer[0])); |
| 268 return true; | 267 return true; |
| 269 } | 268 } |
| 270 | 269 |
| 271 bool GetNtPathFromWin32Path(const base::string16& path, | 270 bool GetNtPathFromWin32Path(const base::string16& path, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 ::InterlockedCompareExchangePointer( | 313 ::InterlockedCompareExchangePointer( |
| 315 reinterpret_cast<PVOID volatile*>(&ntdll), ntdll_local, NULL); | 314 reinterpret_cast<PVOID volatile*>(&ntdll), ntdll_local, NULL); |
| 316 | 315 |
| 317 } | 316 } |
| 318 | 317 |
| 319 CHECK_NT(ntdll); | 318 CHECK_NT(ntdll); |
| 320 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); | 319 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); |
| 321 *function_ptr = ::GetProcAddress(ntdll, name); | 320 *function_ptr = ::GetProcAddress(ntdll, name); |
| 322 CHECK_NT(*function_ptr); | 321 CHECK_NT(*function_ptr); |
| 323 } | 322 } |
| OLD | NEW |