| 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, |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 169 } |
| 170 | 170 |
| 171 return true; | 171 return true; |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace | 174 } // namespace |
| 175 | 175 |
| 176 ProcessReaderWin::Thread::Thread() | 176 ProcessReaderWin::Thread::Thread() |
| 177 : context(), | 177 : context(), |
| 178 id(0), | 178 id(0), |
| 179 teb(0), | 179 teb_address(0), |
| 180 teb_size(0), |
| 180 stack_region_address(0), | 181 stack_region_address(0), |
| 181 stack_region_size(0), | 182 stack_region_size(0), |
| 182 suspend_count(0), | 183 suspend_count(0), |
| 183 priority_class(0), | 184 priority_class(0), |
| 184 priority(0) { | 185 priority(0) { |
| 185 } | 186 } |
| 186 | 187 |
| 187 ProcessReaderWin::ProcessReaderWin() | 188 ProcessReaderWin::ProcessReaderWin() |
| 188 : process_(INVALID_HANDLE_VALUE), | 189 : process_(INVALID_HANDLE_VALUE), |
| 189 process_info_(), | 190 process_info_(), |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 sizeof(thread_basic_info), | 325 sizeof(thread_basic_info), |
| 325 nullptr); | 326 nullptr); |
| 326 if (!NT_SUCCESS(status)) { | 327 if (!NT_SUCCESS(status)) { |
| 327 NTSTATUS_LOG(ERROR, status) << "NtQueryInformationThread"; | 328 NTSTATUS_LOG(ERROR, status) << "NtQueryInformationThread"; |
| 328 continue; | 329 continue; |
| 329 } | 330 } |
| 330 | 331 |
| 331 // Read the TIB (Thread Information Block) which is the first element of the | 332 // Read the TIB (Thread Information Block) which is the first element of the |
| 332 // TEB, for its stack fields. | 333 // TEB, for its stack fields. |
| 333 process_types::NT_TIB<Traits> tib; | 334 process_types::NT_TIB<Traits> tib; |
| 334 thread.teb = thread_basic_info.TebBaseAddress; | 335 thread.teb_address = thread_basic_info.TebBaseAddress; |
| 335 if (ReadMemory(thread.teb, sizeof(tib), &tib)) { | 336 thread.teb_size = sizeof(process_types::TEB<Traits>); |
| 337 if (ReadMemory(thread.teb_address, sizeof(tib), &tib)) { |
| 336 WinVMAddress base = 0; | 338 WinVMAddress base = 0; |
| 337 WinVMAddress limit = 0; | 339 WinVMAddress limit = 0; |
| 338 // If we're reading a WOW64 process, then the TIB we just retrieved is the | 340 // If we're reading a WOW64 process, then the TIB we just retrieved is the |
| 339 // x64 one. The first word of the x64 TIB points at the x86 TIB. See | 341 // x64 one. The first word of the x64 TIB points at the x86 TIB. See |
| 340 // https://msdn.microsoft.com/en-us/library/dn424783.aspx | 342 // https://msdn.microsoft.com/en-us/library/dn424783.aspx |
| 341 if (is_64_reading_32) { | 343 if (is_64_reading_32) { |
| 342 process_types::NT_TIB<process_types::internal::Traits32> tib32; | 344 process_types::NT_TIB<process_types::internal::Traits32> tib32; |
| 343 thread.teb = tib.Wow64Teb; | 345 thread.teb_address = tib.Wow64Teb; |
| 344 if (ReadMemory(thread.teb, sizeof(tib32), &tib32)) { | 346 thread.teb_size = |
| 347 sizeof(process_types::TEB<process_types::internal::Traits32>); |
| 348 if (ReadMemory(thread.teb_address, sizeof(tib32), &tib32)) { |
| 345 base = tib32.StackBase; | 349 base = tib32.StackBase; |
| 346 limit = tib32.StackLimit; | 350 limit = tib32.StackLimit; |
| 347 } | 351 } |
| 348 } else { | 352 } else { |
| 349 base = tib.StackBase; | 353 base = tib.StackBase; |
| 350 limit = tib.StackLimit; | 354 limit = tib.StackLimit; |
| 351 } | 355 } |
| 352 | 356 |
| 353 // Note, "backwards" because of direction of stack growth. | 357 // Note, "backwards" because of direction of stack growth. |
| 354 thread.stack_region_address = limit; | 358 thread.stack_region_address = limit; |
| 355 if (limit > base) { | 359 if (limit > base) { |
| 356 LOG(ERROR) << "invalid stack range: " << base << " - " << limit; | 360 LOG(ERROR) << "invalid stack range: " << base << " - " << limit; |
| 357 thread.stack_region_size = 0; | 361 thread.stack_region_size = 0; |
| 358 } else { | 362 } else { |
| 359 thread.stack_region_size = base - limit; | 363 thread.stack_region_size = base - limit; |
| 360 } | 364 } |
| 361 } | 365 } |
| 362 threads_.push_back(thread); | 366 threads_.push_back(thread); |
| 363 } | 367 } |
| 364 } | 368 } |
| 365 | 369 |
| 366 } // namespace crashpad | 370 } // namespace crashpad |
| OLD | NEW |