Tim Van Patten | 7918ca9 | 2023-02-06 20:43:58 | [diff] [blame] | 1 | // Copyright 2023 The ChromiumOS Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // The GSC collector runs just after boot and grabs information about crashes in |
| 6 | // the Google Security Chip from `gsctool`. |
| 7 | // The GSC collector runs via the crash-boot-collect service. |
| 8 | |
| 9 | #ifndef CRASH_REPORTER_GSC_COLLECTOR_BASE_H_ |
| 10 | #define CRASH_REPORTER_GSC_COLLECTOR_BASE_H_ |
| 11 | |
Kendrake Tsui | f7254bd | 2023-07-13 08:33:02 | [diff] [blame] | 12 | #include <memory> |
Tim Van Patten | 7918ca9 | 2023-02-06 20:43:58 | [diff] [blame] | 13 | #include <string> |
| 14 | |
Kendrake Tsui | f7254bd | 2023-07-13 08:33:02 | [diff] [blame] | 15 | #include <base/memory/ref_counted.h> |
| 16 | #include <base/memory/scoped_refptr.h> |
| 17 | #include <metrics/metrics_library.h> |
| 18 | |
Tim Van Patten | 7918ca9 | 2023-02-06 20:43:58 | [diff] [blame] | 19 | #include "crash-reporter/crash_collector.h" |
| 20 | |
| 21 | // GSC Crash Collector Interface |
| 22 | class GscCollectorBase : public CrashCollector { |
| 23 | public: |
Kendrake Tsui | f7254bd | 2023-07-13 08:33:02 | [diff] [blame] | 24 | explicit GscCollectorBase( |
| 25 | const scoped_refptr< |
| 26 | base::RefCountedData<std::unique_ptr<MetricsLibraryInterface>>>& |
| 27 | metrics_lib); |
Tim Van Patten | 7918ca9 | 2023-02-06 20:43:58 | [diff] [blame] | 28 | GscCollectorBase(const GscCollectorBase&) = delete; |
| 29 | GscCollectorBase& operator=(const GscCollectorBase&) = delete; |
| 30 | |
| 31 | ~GscCollectorBase() override = default; |
| 32 | |
| 33 | enum class Status { |
| 34 | Success, |
| 35 | Fail, |
| 36 | }; |
| 37 | |
| 38 | // Collect any preserved GSC crash data. Returns true if there was |
| 39 | // a dump (even if there were problems storing the dump), false otherwise. |
| 40 | bool Collect(bool use_saved_lsb); |
| 41 | |
| 42 | virtual Status PersistGscCrashId(uint32_t crash_id); |
| 43 | |
| 44 | private: |
| 45 | virtual Status GetGscFlog(std::string* flog_output) = 0; |
Tim Van Patten | 7e627d2 | 2023-07-17 16:45:50 | [diff] [blame] | 46 | virtual Status GetGscClog(std::string* clog_output) = 0; |
| 47 | virtual Status GetGscCrashSignatureOffsetAndLength(size_t* offset_out, |
| 48 | size_t* size_out) = 0; |
| 49 | |
Tim Van Patten | 7918ca9 | 2023-02-06 20:43:58 | [diff] [blame] | 50 | Status ParseGscFlog(const std::string& gsctool_flog); |
| 51 | Status GetCrashId(const std::string& flog_line, uint32_t* crash_id); |
| 52 | Status GetPreviousGscCrashId(uint32_t* crash_id); |
Tim Van Patten | 7e627d2 | 2023-07-17 16:45:50 | [diff] [blame] | 53 | Status GetGscCrashSignature(std::string* signature_output); |
Tim Van Patten | 7918ca9 | 2023-02-06 20:43:58 | [diff] [blame] | 54 | |
| 55 | bool crash_detected_; |
| 56 | // The latest crash ID in the current GSC flog output. |
| 57 | uint32_t latest_crash_id_; |
| 58 | // The GSC crash ID of the last crash report. |
| 59 | uint32_t prev_crash_id_; |
| 60 | }; |
| 61 | |
| 62 | #endif // CRASH_REPORTER_GSC_COLLECTOR_BASE_H_ |