blob: 2114450c8eda76d55d0a89fab1d2948c5e005780 [file] [log] [blame]
Tim Van Patten7918ca92023-02-06 20:43:581// 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 Tsuif7254bd2023-07-13 08:33:0212#include <memory>
Tim Van Patten7918ca92023-02-06 20:43:5813#include <string>
14
Kendrake Tsuif7254bd2023-07-13 08:33:0215#include <base/memory/ref_counted.h>
16#include <base/memory/scoped_refptr.h>
17#include <metrics/metrics_library.h>
18
Tim Van Patten7918ca92023-02-06 20:43:5819#include "crash-reporter/crash_collector.h"
20
21// GSC Crash Collector Interface
22class GscCollectorBase : public CrashCollector {
23 public:
Kendrake Tsuif7254bd2023-07-13 08:33:0224 explicit GscCollectorBase(
25 const scoped_refptr<
26 base::RefCountedData<std::unique_ptr<MetricsLibraryInterface>>>&
27 metrics_lib);
Tim Van Patten7918ca92023-02-06 20:43:5828 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 Patten7e627d22023-07-17 16:45:5046 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 Patten7918ca92023-02-06 20:43:5850 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 Patten7e627d22023-07-17 16:45:5053 Status GetGscCrashSignature(std::string* signature_output);
Tim Van Patten7918ca92023-02-06 20:43:5854
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_