| 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/handle_closer.h" | 5 #include "sandbox/win/src/handle_closer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 10 |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/memory/free_deleter.h" | 12 #include "base/memory/free_deleter.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
| 13 #include "sandbox/win/src/interceptors.h" | 14 #include "sandbox/win/src/interceptors.h" |
| 14 #include "sandbox/win/src/internal_types.h" | 15 #include "sandbox/win/src/internal_types.h" |
| 15 #include "sandbox/win/src/nt_internals.h" | 16 #include "sandbox/win/src/nt_internals.h" |
| 16 #include "sandbox/win/src/process_thread_interception.h" | 17 #include "sandbox/win/src/process_thread_interception.h" |
| 17 #include "sandbox/win/src/win_utils.h" | 18 #include "sandbox/win/src/win_utils.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 template<typename T> T RoundUpToWordSize(T v) { | 22 template<typename T> T RoundUpToWordSize(T v) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 90 |
| 90 return bytes_total; | 91 return bytes_total; |
| 91 } | 92 } |
| 92 | 93 |
| 93 bool HandleCloser::InitializeTargetHandles(TargetProcess* target) { | 94 bool HandleCloser::InitializeTargetHandles(TargetProcess* target) { |
| 94 // Do nothing on an empty list (global pointer already initialized to NULL). | 95 // Do nothing on an empty list (global pointer already initialized to NULL). |
| 95 if (handles_to_close_.empty()) | 96 if (handles_to_close_.empty()) |
| 96 return true; | 97 return true; |
| 97 | 98 |
| 98 size_t bytes_needed = GetBufferSize(); | 99 size_t bytes_needed = GetBufferSize(); |
| 99 scoped_ptr<size_t[]> local_buffer( | 100 std::unique_ptr<size_t[]> local_buffer( |
| 100 new size_t[bytes_needed / sizeof(size_t)]); | 101 new size_t[bytes_needed / sizeof(size_t)]); |
| 101 | 102 |
| 102 if (!SetupHandleList(local_buffer.get(), bytes_needed)) | 103 if (!SetupHandleList(local_buffer.get(), bytes_needed)) |
| 103 return false; | 104 return false; |
| 104 | 105 |
| 105 HANDLE child = target->Process(); | 106 HANDLE child = target->Process(); |
| 106 | 107 |
| 107 // Allocate memory in the target process without specifying the address | 108 // Allocate memory in the target process without specifying the address |
| 108 void* remote_data = ::VirtualAllocEx(child, NULL, bytes_needed, | 109 void* remote_data = ::VirtualAllocEx(child, NULL, bytes_needed, |
| 109 MEM_COMMIT, PAGE_READWRITE); | 110 MEM_COMMIT, PAGE_READWRITE); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 DCHECK_EQ(reinterpret_cast<size_t>(output), reinterpret_cast<size_t>(end)); | 169 DCHECK_EQ(reinterpret_cast<size_t>(output), reinterpret_cast<size_t>(end)); |
| 169 return output <= end; | 170 return output <= end; |
| 170 } | 171 } |
| 171 | 172 |
| 172 bool GetHandleName(HANDLE handle, base::string16* handle_name) { | 173 bool GetHandleName(HANDLE handle, base::string16* handle_name) { |
| 173 static NtQueryObject QueryObject = NULL; | 174 static NtQueryObject QueryObject = NULL; |
| 174 if (!QueryObject) | 175 if (!QueryObject) |
| 175 ResolveNTFunctionPtr("NtQueryObject", &QueryObject); | 176 ResolveNTFunctionPtr("NtQueryObject", &QueryObject); |
| 176 | 177 |
| 177 ULONG size = MAX_PATH; | 178 ULONG size = MAX_PATH; |
| 178 scoped_ptr<UNICODE_STRING, base::FreeDeleter> name; | 179 std::unique_ptr<UNICODE_STRING, base::FreeDeleter> name; |
| 179 NTSTATUS result; | 180 NTSTATUS result; |
| 180 | 181 |
| 181 do { | 182 do { |
| 182 name.reset(static_cast<UNICODE_STRING*>(malloc(size))); | 183 name.reset(static_cast<UNICODE_STRING*>(malloc(size))); |
| 183 DCHECK(name.get()); | 184 DCHECK(name.get()); |
| 184 result = QueryObject(handle, ObjectNameInformation, name.get(), | 185 result = QueryObject(handle, ObjectNameInformation, name.get(), |
| 185 size, &size); | 186 size, &size); |
| 186 } while (result == STATUS_INFO_LENGTH_MISMATCH || | 187 } while (result == STATUS_INFO_LENGTH_MISMATCH || |
| 187 result == STATUS_BUFFER_OVERFLOW); | 188 result == STATUS_BUFFER_OVERFLOW); |
| 188 | 189 |
| 189 if (NT_SUCCESS(result) && name->Buffer && name->Length) | 190 if (NT_SUCCESS(result) && name->Buffer && name->Length) |
| 190 handle_name->assign(name->Buffer, name->Length / sizeof(wchar_t)); | 191 handle_name->assign(name->Buffer, name->Length / sizeof(wchar_t)); |
| 191 else | 192 else |
| 192 handle_name->clear(); | 193 handle_name->clear(); |
| 193 | 194 |
| 194 return NT_SUCCESS(result); | 195 return NT_SUCCESS(result); |
| 195 } | 196 } |
| 196 | 197 |
| 197 } // namespace sandbox | 198 } // namespace sandbox |
| OLD | NEW |