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