OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #include "util/win/nt_internals.h" |
| 16 |
| 17 #include "base/logging.h" |
| 18 |
| 19 namespace crashpad { |
| 20 |
| 21 NTSTATUS NtQuerySystemInformation( |
| 22 SYSTEM_INFORMATION_CLASS system_information_class, |
| 23 PVOID system_information, |
| 24 ULONG system_information_length, |
| 25 PULONG return_length) { |
| 26 static decltype(::NtQuerySystemInformation)* nt_query_system_information = |
| 27 reinterpret_cast<decltype(::NtQuerySystemInformation)*>(GetProcAddress( |
| 28 LoadLibrary(L"ntdll.dll"), "NtQuerySystemInformation")); |
| 29 DCHECK(nt_query_system_information); |
| 30 return nt_query_system_information(system_information_class, |
| 31 system_information, |
| 32 system_information_length, |
| 33 return_length); |
| 34 } |
| 35 |
| 36 NTSTATUS NtQueryInformationThread(HANDLE thread_handle, |
| 37 THREADINFOCLASS thread_information_class, |
| 38 PVOID thread_information, |
| 39 ULONG thread_information_length, |
| 40 PULONG return_length) { |
| 41 static decltype(::NtQueryInformationThread)* nt_query_information_thread = |
| 42 reinterpret_cast<decltype(::NtQueryInformationThread)*>(GetProcAddress( |
| 43 LoadLibrary(L"ntdll.dll"), "NtQueryInformationThread")); |
| 44 DCHECK(nt_query_information_thread); |
| 45 return nt_query_information_thread(thread_handle, |
| 46 thread_information_class, |
| 47 thread_information, |
| 48 thread_information_length, |
| 49 return_length); |
| 50 } |
| 51 |
| 52 // The 4th argument is CLIENT_ID*, but as we can't typedef that, we simply cast |
| 53 // to void* here. |
| 54 typedef NTSTATUS(WINAPI* NtOpenThreadFunction)( |
| 55 PHANDLE ThreadHandle, |
| 56 ACCESS_MASK DesiredAccess, |
| 57 POBJECT_ATTRIBUTES ObjectAttributes, |
| 58 const void* ClientId); |
| 59 |
| 60 template <class Traits> |
| 61 NTSTATUS NtOpenThread(PHANDLE thread_handle, |
| 62 ACCESS_MASK desired_access, |
| 63 POBJECT_ATTRIBUTES object_attributes, |
| 64 const process_types::CLIENT_ID<Traits>* client_id) { |
| 65 static NtOpenThreadFunction nt_open_thread = |
| 66 reinterpret_cast<NtOpenThreadFunction>( |
| 67 GetProcAddress(LoadLibrary(L"ntdll.dll"), "NtOpenThread")); |
| 68 DCHECK(nt_open_thread); |
| 69 return nt_open_thread(thread_handle, |
| 70 desired_access, |
| 71 object_attributes, |
| 72 static_cast<const void*>(client_id)); |
| 73 } |
| 74 |
| 75 // Explicit instantiations with the only 2 valid template arguments to avoid |
| 76 // putting the body of the function in the header. |
| 77 template NTSTATUS NtOpenThread<process_types::internal::Traits32>( |
| 78 PHANDLE thread_handle, |
| 79 ACCESS_MASK desired_access, |
| 80 POBJECT_ATTRIBUTES object_attributes, |
| 81 const process_types::CLIENT_ID<process_types::internal::Traits32>* |
| 82 client_id); |
| 83 |
| 84 template NTSTATUS NtOpenThread<process_types::internal::Traits64>( |
| 85 PHANDLE thread_handle, |
| 86 ACCESS_MASK desired_access, |
| 87 POBJECT_ATTRIBUTES object_attributes, |
| 88 const process_types::CLIENT_ID<process_types::internal::Traits64>* |
| 89 client_id); |
| 90 |
| 91 } // namespace crashpad |
OLD | NEW |