1 // Copyright 2019 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/loader_lock.h" 16 17 #include <windows.h> 18 19 #include "build/build_config.h" 20 #include "util/win/process_structs.h" 21 22 namespace crashpad { 23 24 namespace { 25 26 #ifdef ARCH_CPU_64_BITS 27 using NativeTraits = process_types::internal::Traits64; 28 #else 29 using NativeTraits = process_types::internal::Traits32; 30 #endif // ARCH_CPU_64_BITS 31 32 using PEB = process_types::PEB<NativeTraits>; 33 using TEB = process_types::TEB<NativeTraits>; 34 using RTL_CRITICAL_SECTION = process_types::RTL_CRITICAL_SECTION<NativeTraits>; 35 GetTeb()36TEB* GetTeb() { 37 return reinterpret_cast<TEB*>(NtCurrentTeb()); 38 } 39 GetPeb()40PEB* GetPeb() { 41 return reinterpret_cast<PEB*>(GetTeb()->ProcessEnvironmentBlock); 42 } 43 44 } // namespace 45 IsThreadInLoaderLock()46bool IsThreadInLoaderLock() { 47 RTL_CRITICAL_SECTION* loader_lock = 48 reinterpret_cast<RTL_CRITICAL_SECTION*>(GetPeb()->LoaderLock); 49 return loader_lock->OwningThread == GetTeb()->ClientId.UniqueThread; 50 } 51 52 } // namespace crashpad 53