Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: chrome/browser/task_manager/sampling/shared_sampler_win.cc

Issue 2566423002: Fix SharedSampler to cope correctly with zero-thread processes. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/task_manager/sampling/shared_sampler.h" 5 #include "chrome/browser/task_manager/sampling/shared_sampler.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <winternl.h> 8 #include <winternl.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 snapshot->timestamp = base::TimeTicks::Now(); 450 snapshot->timestamp = base::TimeTicks::Now();
451 451
452 for (size_t offset = 0; offset < data_buffer.size(); ) { 452 for (size_t offset = 0; offset < data_buffer.size(); ) {
453 auto pi = reinterpret_cast<const SYSTEM_PROCESS_INFORMATION*>( 453 auto pi = reinterpret_cast<const SYSTEM_PROCESS_INFORMATION*>(
454 data_buffer.data() + offset); 454 data_buffer.data() + offset);
455 455
456 // Validate that the offset is valid and all needed data is within 456 // Validate that the offset is valid and all needed data is within
457 // the buffer boundary. 457 // the buffer boundary.
458 if (offset + sizeof(SYSTEM_PROCESS_INFORMATION) > data_buffer.size()) 458 if (offset + sizeof(SYSTEM_PROCESS_INFORMATION) > data_buffer.size())
459 break; 459 break;
460 if (offset + sizeof(SYSTEM_PROCESS_INFORMATION) + 460 if (pi->NumberOfThreads >= 0 &&
stanisc 2016/12/13 17:12:20 This is to prevent underflow when subtracting 1, r
Wez 2016/12/13 21:30:48 *facepalm* Beware late-night coding - fixed! Best
461 (pi->NumberOfThreads - 1) * sizeof(SYSTEM_THREAD_INFORMATION) > 461 (offset + sizeof(SYSTEM_PROCESS_INFORMATION) +
462 data_buffer.size()) 462 (pi->NumberOfThreads - 1) * sizeof(SYSTEM_THREAD_INFORMATION) >
463 data_buffer.size())) {
463 break; 464 break;
465 }
464 466
465 if (pi->ImageName.Buffer) { 467 if (pi->ImageName.Buffer) {
466 // Validate that the image name is within the buffer boundary. 468 // Validate that the image name is within the buffer boundary.
467 // ImageName.Length seems to be in bytes rather than characters. 469 // ImageName.Length seems to be in bytes rather than characters.
468 ULONG image_name_offset = 470 ULONG image_name_offset =
469 reinterpret_cast<BYTE*>(pi->ImageName.Buffer) - data_buffer.data(); 471 reinterpret_cast<BYTE*>(pi->ImageName.Buffer) - data_buffer.data();
470 if (image_name_offset + pi->ImageName.Length > data_buffer.size()) 472 if (image_name_offset + pi->ImageName.Length > data_buffer.size())
471 break; 473 break;
472 474
473 // Check if this is a chrome process. Ignore all other processes. 475 // Check if this is a chrome process. Ignore all other processes.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 callback_entry.second.on_physical_memory.Run(physical_bytes); 630 callback_entry.second.on_physical_memory.Run(physical_bytes);
629 } 631 }
630 } 632 }
631 633
632 // Reset refresh_results_ to trigger RefreshOnWorkerThread next time Refresh 634 // Reset refresh_results_ to trigger RefreshOnWorkerThread next time Refresh
633 // is called. 635 // is called.
634 refresh_flags_ = 0; 636 refresh_flags_ = 0;
635 } 637 }
636 638
637 } // namespace task_manager 639 } // namespace task_manager
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698