| 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/exception_handler_server.h" | 15 #include "util/win/exception_handler_server.h" |
| 16 | 16 |
| 17 #include <string.h> | 17 #include <string.h> |
| 18 | 18 |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/numerics/safe_conversions.h" |
| 20 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
| 21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 23 #include "minidump/minidump_file_writer.h" | 24 #include "minidump/minidump_file_writer.h" |
| 24 #include "snapshot/crashpad_info_client_options.h" | 25 #include "snapshot/crashpad_info_client_options.h" |
| 25 #include "snapshot/win/process_snapshot_win.h" | 26 #include "snapshot/win/process_snapshot_win.h" |
| 26 #include "util/file/file_writer.h" | 27 #include "util/file/file_writer.h" |
| 27 #include "util/misc/tri_state.h" | 28 #include "util/misc/tri_state.h" |
| 28 #include "util/misc/uuid.h" | 29 #include "util/misc/uuid.h" |
| 29 #include "util/win/registration_protocol_win.h" | 30 #include "util/win/registration_protocol_win.h" |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 // we're running as a different user, it may be that we will fail to open | 345 // we're running as a different user, it may be that we will fail to open |
| 345 // the process, but the client will be able to, so we make a second attempt | 346 // the process, but the client will be able to, so we make a second attempt |
| 346 // having impersonated the client. | 347 // having impersonated the client. |
| 347 HANDLE client_process = OpenProcess( | 348 HANDLE client_process = OpenProcess( |
| 348 kXPProcessAllAccess, false, message.registration.client_process_id); | 349 kXPProcessAllAccess, false, message.registration.client_process_id); |
| 349 if (!client_process) { | 350 if (!client_process) { |
| 350 if (!ImpersonateNamedPipeClient(service_context.pipe())) { | 351 if (!ImpersonateNamedPipeClient(service_context.pipe())) { |
| 351 PLOG(ERROR) << "ImpersonateNamedPipeClient"; | 352 PLOG(ERROR) << "ImpersonateNamedPipeClient"; |
| 352 return false; | 353 return false; |
| 353 } | 354 } |
| 354 HANDLE client_process = OpenProcess( | 355 client_process = OpenProcess( |
| 355 kXPProcessAllAccess, false, message.registration.client_process_id); | 356 kXPProcessAllAccess, false, message.registration.client_process_id); |
| 356 PCHECK(RevertToSelf()); | 357 PCHECK(RevertToSelf()); |
| 357 if (!client_process) { | 358 if (!client_process) { |
| 358 LOG(ERROR) << "failed to open " << message.registration.client_process_id; | 359 LOG(ERROR) << "failed to open " << message.registration.client_process_id; |
| 359 return false; | 360 return false; |
| 360 } | 361 } |
| 361 } | 362 } |
| 362 | 363 |
| 363 internal::ClientData* client; | 364 internal::ClientData* client; |
| 364 { | 365 { |
| 365 base::AutoLock lock(*service_context.clients_lock()); | 366 base::AutoLock lock(*service_context.clients_lock()); |
| 366 client = | 367 client = |
| 367 new internal::ClientData(service_context.port(), | 368 new internal::ClientData(service_context.port(), |
| 368 service_context.delegate(), | 369 service_context.delegate(), |
| 369 ScopedKernelHANDLE(client_process), | 370 ScopedKernelHANDLE(client_process), |
| 370 message.registration.exception_information, | 371 message.registration.exception_information, |
| 371 &OnDumpEvent, | 372 &OnDumpEvent, |
| 372 &OnProcessEnd); | 373 &OnProcessEnd); |
| 373 service_context.clients()->insert(client); | 374 service_context.clients()->insert(client); |
| 374 } | 375 } |
| 375 | 376 |
| 376 // Duplicate the events back to the client so they can request a dump. | 377 // Duplicate the events back to the client so they can request a dump. |
| 377 ServerToClientMessage response; | 378 ServerToClientMessage response; |
| 378 response.registration.request_report_event = reinterpret_cast<uint32_t>( | 379 response.registration.request_report_event = |
| 379 DuplicateEvent(client->process(), client->dump_requested_event())); | 380 base::checked_cast<uint32_t>(reinterpret_cast<uintptr_t>( |
| 381 DuplicateEvent(client->process(), client->dump_requested_event()))); |
| 380 | 382 |
| 381 if (!LoggingWriteFile(service_context.pipe(), &response, sizeof(response))) | 383 if (!LoggingWriteFile(service_context.pipe(), &response, sizeof(response))) |
| 382 return false; | 384 return false; |
| 383 | 385 |
| 384 return false; | 386 return false; |
| 385 } | 387 } |
| 386 | 388 |
| 387 // static | 389 // static |
| 388 DWORD __stdcall ExceptionHandlerServer::PipeServiceProc(void* ctx) { | 390 DWORD __stdcall ExceptionHandlerServer::PipeServiceProc(void* ctx) { |
| 389 internal::PipeServiceContext* service_context = | 391 internal::PipeServiceContext* service_context = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 void __stdcall ExceptionHandlerServer::OnProcessEnd(void* ctx, BOOLEAN) { | 424 void __stdcall ExceptionHandlerServer::OnProcessEnd(void* ctx, BOOLEAN) { |
| 423 // This function is executed on the thread pool. | 425 // This function is executed on the thread pool. |
| 424 internal::ClientData* client = reinterpret_cast<internal::ClientData*>(ctx); | 426 internal::ClientData* client = reinterpret_cast<internal::ClientData*>(ctx); |
| 425 base::AutoLock lock(*client->lock()); | 427 base::AutoLock lock(*client->lock()); |
| 426 | 428 |
| 427 // Post back to the main thread to have it delete this client record. | 429 // Post back to the main thread to have it delete this client record. |
| 428 PostQueuedCompletionStatus(client->port(), 0, ULONG_PTR(client), nullptr); | 430 PostQueuedCompletionStatus(client->port(), 0, ULONG_PTR(client), nullptr); |
| 429 } | 431 } |
| 430 | 432 |
| 431 } // namespace crashpad | 433 } // namespace crashpad |
| OLD | NEW |