Overview / Security & product

crashreport

Error reports and their delivery. Context is recorded in a block preallocated at <code>Init</code>, and sending happens only with the user's consent.

Optional module: turn it on with -DETHEREAL_CRASHREPORT=ONInclude #include <ethereal/cpp/crashreport/capture.hpp>C layer

capture.hpp

#include <ethereal/cpp/crashreport/capture.hpp>

The in process preallocated block of the CrashReport module.

Breadcrumbs, fields and the log ring live here. They are written with no allocation and no lock, because the application calls them from normal code (target below 100 ns per write) and because the handler reads them when the machine is already broken.

Lock-free, one writer per slot. The breadcrumbs are a ring with an atomic counter. The fields use an even/odd seal so the reader only takes coherent snapshots. The log ring is the most valuable log artifact there is, because it survives a buffered write that never reached the disk.

class

CCaptureState

Ethereal::CrashReport#

The preallocated block. A single instance, created in 'Init'.

class CCaptureState final

No pointers to the heap inside: everything is inline, so the handler can read it from another process through a shared memory window. The size is fixed and documented (see 'crashreport_common.hpp').

constructor

CCaptureState

#
CCaptureState() noexcept;

Default constructor. Everything starts empty.

function

AddBreadcrumb

#
void AddBreadcrumb( const ETL_CHAR * pText ) noexcept;

Adds a breadcrumb. Lock-free, no allocation. Truncates at the limit.

pText
The text. Null writes an empty breadcrumb.
function

BreadcrumbsTotal

#
ETL_UINT64 BreadcrumbsTotal() const noexcept;

How many breadcrumbs were written in total (may exceed the capacity).

function

ReadBreadcrumb

#
bool ReadBreadcrumb( ETL_UINT32 uIndex, ETL_CHAR * pOut, ETL_UINT64 uCap ) const noexcept;

Reads the logical breadcrumb uIndex into pOut.

uIndex
0 is the oldest one still in the ring.
pOut
Output buffer.
uCap
Size of pOut.
false when uIndex is past what the ring still holds.
function

SetField

#
EStatus SetField( const ETL_CHAR * pKey, const ETL_CHAR * pValue ) noexcept;

Sets or updates a field. Lock-free, no allocation. The write is atomic (even/odd seal).

pKey
The key. Must not be empty.
pValue
The value.
EStatus::eBufferTooSmall when there is no free slot for a new key.
function

GetField

#
bool GetField( const ETL_CHAR * pKey, ETL_CHAR * pOut, ETL_UINT64 uCap ) const noexcept;

Reads the value of pKey into pOut, in a coherent snapshot.

pKey
The key.
pOut
Output buffer.
uCap
Size of pOut.
false when the key does not exist or a write kept running.
function

FieldCount

#
ETL_UINT32 FieldCount() const noexcept;

How many fields are in use.

function

ReadField

#
bool ReadField( ETL_UINT32 uIndex, ETL_CHAR * pKey, ETL_UINT64 uKeyCap, ETL_CHAR * pValue, ETL_UINT64 uValueCap ) const noexcept;

Reads field uIndex, key and value, in a coherent snapshot. Used to build the 'crash.json'.

uIndex
0 .. FieldCount() - 1.
pKey
Receives the key.
uKeyCap
Size of pKey.
pValue
Receives the value.
uValueCap
Size of pValue.
false when the index is out of range or a write kept running.
function

AddLogLine

#
void AddLogLine( const ETL_CHAR * pLine ) noexcept;

Appends a line to the log ring. Wraps around when full.

pLine
The line, without the '\n'.
function

ReadLogTail

#
ETL_UINT64 ReadLogTail( ETL_CHAR * pOut, ETL_UINT64 uCap ) const noexcept;

Copies the last bytes of the log ring into pOut.

pOut
Output buffer. Always terminated.
uCap
Size of pOut.
How many bytes were copied.
function

Clear

#
void Clear() noexcept;

Empties breadcrumbs, fields and the log ring.

crashreport_common.hpp

#include <ethereal/cpp/crashreport/crashreport_common.hpp>

Shared types of the CrashReport module: states, dump levels, delivery modes and the limits of the preallocated block.

A process that crashed cannot be trusted to report its own crash. When a handler runs, the heap may be corrupted, the stack exhausted and locks held by dead threads. Any allocation, any lock and any CRT call may hang or fail a second time.

For that reason the out of process handler is the primary design and the in process one is the fallback. A build without 'ETL_CRASHREPORT' has none of this, byte for byte.

This build of the module brings the in memory and logic core that can be measured without crashing on purpose: the preallocated block (breadcrumbs, fields, log ring), the signature and the repeat limiter, the secret scrubbing and the environment allowlist, the bounded queue and the consent gate, and the API surface. Installing the OS handlers (VEH, signals, Mach ports), the minidump and the separate process are the OS specific layer. See the README.

enum

EStatus

Ethereal::CrashReport#
C++
enum class   EStatus : ETL_UINT32
{
    /// @brief  Success.
    eOk = 0,

    /// @brief  An argument is null or out of range.
    eInvalidArgument,

    /// @brief  The output buffer is too small.
    eBufferTooSmall,

    /// @brief  Called before @ref CCrashHandler::Init.
    eNotInitialized,

    /// @brief  Already initialized.
    eAlreadyInitialized,

    /// @brief  There is no consent. Nothing leaves the machine.
    eNoConsent,

    /// @brief  The queue is full (see the limits policy).
    eQueueFull,

    /// @brief  The repeat limiter blocked this report (crash loop).
    eRateLimited,

    /// @brief  There are no pending reports.
    eEmpty,

    /// @brief  The step depends on OS specific work not implemented yet.
    eNotImplemented,

    /// @brief  The module was not compiled (no 'ETL_CRASHREPORT').
    eNotCompiled,

    /// @brief  No transport (or URL) is set. The module has no HTTP client.
    eNoTransport,

    /// @brief  The file system refused (create the folder, write, read, rename).
    eIoError,

    /// @brief  The transport failed, or the server answered with a status that
    ///             says to try again later. The reports stay in the queue.
    eTransportError,

    /// @brief  Refused: no license was accepted and the evaluation of this machine
    ///             has ended, or the license passed was refused (see
    ///             Bundle::UnlockBundle).
    eNotLicensed
};

Result of a call.

enum

EDumpLevel

Ethereal::CrashReport#
C++
enum class   EDumpLevel : ETL_UINT8
{
    /// @brief  Thread list and stacks. Target below 100 KB.
    eMinimal = 0,

    /// @brief  Plus modules, contexts and handles. Target below 2 MB.
    eNormal,

    /// @brief  Plus the memory referenced by registers and stack. Target below 20 MB.
    eWithIndirect,

    /// @brief  All memory, gigabytes. Only by explicit choice.
    eFull
};

How much memory the dump captures.

'Full' is never the default: it costs the user's upload bandwidth and almost certainly carries their private data.

enum

EDeliveryMode

Ethereal::CrashReport#
C++
enum class   EDeliveryMode : ETL_UINT8
{
    /// @brief  Ask before sending (the default). The prompt belongs to the integrator.
    eAskConsent = 0,

    /// @brief  Send silently. Only for internal or enterprise deployments with a policy.
    eSilentSend,

    /// @brief  Only write to the local queue or folder. Never send.
    eLocalOnly
};

How the report leaves the machine.

enum

ECrashKind

Ethereal::CrashReport#
C++
enum class   ECrashKind : ETL_UINT8
{
    /// @brief  Access violation.
    eAccessViolation = 0,

    /// @brief  Stack overflow.
    eStackOverflow,

    /// @brief  Pure virtual call.
    ePureVirtualCall,

    /// @brief  CRT invalid parameter.
    eInvalidParameter,

    /// @brief  std::abort.
    eAbort,

    /// @brief  std::terminate.
    eTerminate,

    /// @brief  Heap corruption.
    eHeapCorruption,

    /// @brief  __fastfail.
    eFastFail,

    /// @brief  Does not crash: produces a report and goes on.
    eNonFatal
};

Kind of crash to provoke in CCrashHandler::Test (end to end test).

const

CRASH_MAX_BREADCRUMBS

Ethereal::CrashReport#
constexpr ETL_UINT32 CRASH_MAX_BREADCRUMBS = 64u;

Ring of recent events.

const

CRASH_BREADCRUMB_LEN

Ethereal::CrashReport#
constexpr ETL_UINT32 CRASH_BREADCRUMB_LEN = 128u;

Bytes per breadcrumb.

const

CRASH_MAX_FIELDS

Ethereal::CrashReport#
constexpr ETL_UINT32 CRASH_MAX_FIELDS = 32u;

Key-value pairs.

const

CRASH_FIELD_KEY_LEN

Ethereal::CrashReport#
constexpr ETL_UINT32 CRASH_FIELD_KEY_LEN = 48u;

Bytes per field key.

const

CRASH_FIELD_VALUE_LEN

Ethereal::CrashReport#
constexpr ETL_UINT32 CRASH_FIELD_VALUE_LEN = 176u;

Bytes per field value.

const

CRASH_LOG_RING_BYTES

Ethereal::CrashReport#
constexpr ETL_UINT32 CRASH_LOG_RING_BYTES = 64u * 1024u;

Size of the in memory log ring.

const

CRASH_MAX_ATTACHMENTS

Ethereal::CrashReport#
constexpr ETL_UINT32 CRASH_MAX_ATTACHMENTS = 16u;

Files attached by path.

const

CRASH_PATH_LEN

Ethereal::CrashReport#
constexpr ETL_UINT32 CRASH_PATH_LEN = 260u;

Bytes per path.

const

CRASH_SIGNATURE_FRAMES

Ethereal::CrashReport#
constexpr ETL_UINT32 CRASH_SIGNATURE_FRAMES = 8u;

How many frames from the top the signature normalizes.

function

StatusName

Ethereal::CrashReport#
const ETL_CHAR * StatusName( EStatus eStatus ) noexcept;

Readable name of a state.

eStatus
The state.
A static string. Never null.
function

DumpLevelName

Ethereal::CrashReport#
const ETL_CHAR * DumpLevelName( EDumpLevel eLevel ) noexcept;

Readable name of a dump level.

eLevel
The level.
A static string. Never null.
function

CrashKindName

Ethereal::CrashReport#
const ETL_CHAR * CrashKindName( ECrashKind eKind ) noexcept;

Readable name of a crash kind.

eKind
The kind.
A static string. Never null.

handler.hpp

#include <ethereal/cpp/crashreport/handler.hpp>

The CrashReport API: the static crash handler.

Call 'Init' as early as possible, before the other subsystems, to catch a crash at startup. The documentation shows it as the first line of 'main'.

What this build really turns on: the in memory capture (breadcrumbs, fields, log ring), the signature and the repeat limiter, the bounded queue and the consent gate, and delivery. With a folder ('pReportDir'), each report is a 'report.etlcrash' on disk, the queue survives a restart, and 'UploadPending' sends through the transport seam.

Installing the OS handlers, the minidump and the separate process are still to be done (see the README). 'Test' with a real crash kind returns 'eNotImplemented' instead of faking it.

struct

IClock

Ethereal::CrashReport#
C++
struct   IClock
{
    /// @brief  Current time, Unix seconds.
    ///
    virtual ETL_INT64 NowUnix() ETL_NOEXCEPT = 0;

    /// @brief  Virtual destructor.
    ///
    virtual ~IClock() = default;
};

The clock. It comes from outside: the repeat limiter needs the current time, and the clock belongs to the integrator.

struct

SCrashParams

Ethereal::CrashReport#
C++
struct   SCrashParams   final
{
    /// @brief  Size of this struct, for versioning.
    ETL_UINT32        iStructSize = sizeof( SCrashParams );

    /// @brief  How reports leave the machine.
    EDeliveryMode    eDelivery = EDeliveryMode::eAskConsent;

    /// @brief  How much memory the dump captures.
    EDumpLevel        eDumpLevel = EDumpLevel::eNormal;

    /// @brief  Explicit padding.
    ETL_UINT8        uPadding[ 2 ] = {};

    /// @brief  Repeat limiter: reports per signature per window.
    ETL_UINT32        uRateCap = 5u;

    /// @brief  Repeat limiter window, in seconds.
    ETL_INT64        iRateWindowSeconds = 3600;

    /// @brief  Local queue limit, in reports.
    ETL_UINT32        uQueueMaxCount = 32u;

    /// @brief  Local queue limit, in bytes.
    ETL_UINT64        uQueueMaxBytes = 64ull * 1024ull * 1024ull;

    /// @brief  Register the common credential scrubbing patterns.
    ETL_UINT8        bScrubDefaults = 1u;

    /// @brief  Required clock (the limiter needs the current time).
    IClock *        pClock = nullptr;

    /// Delivery (added on 2026-09-28, all optional).

    /// @brief  Reports folder (UTF-8). With it, each report is a file
    ///             '<folder>/pending/<id>.etlcrash', and the queue is rebuilt on the
    ///             next 'Init'. Without it, the queue is only logical (it counts, but
    ///             keeps no bytes).
    const ETL_CHAR *    pReportDir = nullptr;

    /// @brief  The transport. The module has no HTTP client.
    ICrashTransport *    pTransport = nullptr;

    /// @brief  Where reports are sent.
    const ETL_CHAR *    pUploadUrl = nullptr;

    /// @brief  Product name, for the 'crash.json' and the upload fields.
    const ETL_CHAR *    pProduct = nullptr;

    /// @brief  Product version, for the 'crash.json' and the upload fields.
    const ETL_CHAR *    pVersion = nullptr;
};

How to set up the handler.

class

CCrashHandler

Ethereal::CrashReport#

The crash handler. Static: one instance per process, preallocated.

class CCrashHandler final
function

Init

#
static EStatus Init( const SCrashParams & Params ) noexcept;

Sets up the handler. With 'pReportDir', rebuilds the queue from disk.

Params
Handler parameters. 'pClock' is required.
eOk, eAlreadyInitialized, eInvalidArgument, eIoError, eBufferTooSmall, or eNotLicensed when the library is not licensed.
function

Shutdown

#
static EStatus Shutdown() noexcept;

Turns the handler off. Pending reports stay on disk.

function

IsInitialized

#
static bool IsInitialized() noexcept;

true between Init and Shutdown.

function

AddCustomField

#
static EStatus AddCustomField( const ETL_CHAR * pKey, const ETL_CHAR * pValue ) noexcept;

Sets or updates a field. Target below 100 ns, zero allocation.

pKey
The key.
pValue
The value.
eOk, eNotInitialized, eInvalidArgument or eBufferTooSmall.
function

AddBreadcrumb

#
static EStatus AddBreadcrumb( const ETL_CHAR * pText ) noexcept;

Adds a breadcrumb. Target below 100 ns, zero allocation.

pText
The text.
eOk or eNotInitialized.
function

AddFileAttachment

#
static EStatus AddFileAttachment( const ETL_CHAR * pPath, ETL_UINT64 uMaxBytes ) noexcept;

Registers a file to attach, up to uMaxBytes.

pPath
File path (UTF-8).
uMaxBytes
How many bytes to read at most.
eOk, eNotInitialized, eInvalidArgument or eBufferTooSmall.
function

AddLogLine

#
static EStatus AddLogLine( const ETL_CHAR * pLine ) noexcept;

Appends a line to the in memory log ring.

pLine
The line.
eOk or eNotInitialized.
function

AllowEnvironmentVariable

#
static EStatus AllowEnvironmentVariable( const ETL_CHAR * pName ) noexcept;

Lets the environment variable pName into the 'crash.json'.

Never the whole environment: with no call to this, no variable goes out (the safe default).

pName
The variable name.
eOk, eNotInitialized, eInvalidArgument or eBufferTooSmall.
function

ReportNonFatal

#
static EStatus ReportNonFatal( const ETL_CHAR * pReason, std::span< const SFrame > Frames ) noexcept;

Captures a non fatal report from frames, and goes on.

Computes the signature, passes it through the repeat limiter and, when not blocked, puts the report in the local queue. It does not send. Sending is UploadPending, behind consent.

pReason
Reason, goes into the 'crash.json'.
Frames
Frames, top of the stack first.
EStatus::eRateLimited when the crash loop blocked it.
function

ReportNonFatal

#
static EStatus ReportNonFatal( const ETL_CHAR * pReason ) noexcept;

A version with no frames: the signature comes from the reason.

pReason
Reason, goes into the 'crash.json'.
As the version with frames.
function

Test

#
static EStatus Test( ECrashKind eKind ) noexcept;

Provokes a deliberate crash, to test the whole path.

Every integrator will turn this on and never know whether it works until a real crash. For ECrashKind::eNonFatal it produces a real report. The kinds that really crash depend on the OS handlers and return EStatus::eNotImplemented in this layer.

eKind
Kind of crash.
The result of the report, or eNotImplemented.
function

SetConsent

#
static void SetConsent( bool bGiven ) noexcept;

Records the user's answer to the prompt (which the integrator draws).

bGiven
true when the user agreed.
function

HasConsent

#
static bool HasConsent() noexcept;

true when consent was given.

function

PendingReportCount

#
static ETL_UINT64 PendingReportCount() noexcept;

Number of reports in the queue.

function

PendingReportPath

#
static EStatus PendingReportPath( ETL_UINT32 uIndex, ETL_CHAR * pOut, ETL_UINT64 uCap ) noexcept;

Path of pending report uIndex, to "see what will be sent". Only with 'pReportDir'.

uIndex
0 is the oldest.
pOut
Output buffer.
uCap
Size of pOut.
eOk, eNotInitialized, eInvalidArgument or eBufferTooSmall.
function

UploadPending

#
static EStatus UploadPending() noexcept;

Uploads the pending reports, oldest first.

Nothing leaves without consent: returns EStatus::eNoConsent before touching the network. Each report goes in a 'multipart/form-data' (the fields 'product', 'version', 'report_id' and the file 'report'). A 2xx answer deletes it. A 413 (too large for the server) deletes it too, because it will never fit. Any other answer stops the upload and leaves the rest in the queue for next time.

EStatus::eNoTransport without transport or URL. EStatus::eInvalidArgument without 'pReportDir' (no bytes to send). EStatus::eTransportError when it stopped halfway. EStatus::eNotLicensed when the library is not licensed: nothing is sent and the queue stays as it is.
function

DiscardPending

#
static EStatus DiscardPending() noexcept;

Deletes every pending report.

function

LastSignature

#
static ETL_UINT64 LastSignature() noexcept;

Signature of the last report. Zero when there was none.

function

CrashLoopCount

#
static ETL_UINT32 CrashLoopCount( ETL_UINT64 uSignature ) noexcept;

How many times signature uSignature occurred in the current window.

The most valuable seam of the package: the Updater health check reads this to roll back a release that always crashes.

uSignature
The signature.
The count.
function

Capture

#
static CCaptureState & Capture() noexcept;

The capture block, to "see what will be sent".

minidump.hpp

#include <ethereal/cpp/crashreport/minidump.hpp>

Minidump reader of the CrashReport module.

Reads the summary that goes into 'crash.json', which is also what the tests check.

The minidump is the Microsoft format, which Breakpad, Crashpad, Sentry and LLDB also use for Linux. 'dbghelp' writes it on Windows and the module itself on Linux. This file only reads it, from bytes that may come from anywhere, so every offset is checked against the size before use, and the reader runs in the fuzzer.

struct

SMinidumpSummary

Ethereal::CrashReport#
C++
struct   SMinidumpSummary   final
{
    /// @brief  Number of streams in the directory.
    ETL_UINT32    uStreams = 0u;

    /// @brief  Number of threads.
    ETL_UINT32    uThreads = 0u;

    /// @brief  Number of modules.
    ETL_UINT32    uModules = 0u;

    /// @brief  Number of memory ranges.
    ETL_UINT32    uMemoryRanges = 0u;

    /// @brief  2 = Windows NT, 0x8201 = Linux (the format values).
    ETL_UINT32    uPlatform = 0u;

    /// @brief  9 = AMD64.
    ETL_UINT16    uArchitecture = 0u;

    /// @brief  1 when there is an exception stream.
    ETL_UINT8    bHasException = 0u;

    /// @brief  1 when the exception carries an AMD64 context.
    ETL_UINT8    bHasContext = 0u;

    /// @brief  The thread that crashed.
    ETL_UINT32    uExceptionThread = 0u;

    /// @brief  Windows: the NTSTATUS code (0xC0000005...). Linux: the signal number.
    ETL_UINT32    uExceptionCode = 0u;

    /// @brief  Linux: the 'si_code'. Windows: the exception flags.
    ETL_UINT32    uExceptionFlags = 0u;

    /// @brief  Address of the exception.
    ETL_UINT64    uExceptionAddress = 0u;

    /// @brief  RIP and RSP of the exception context (zero without context).
    ETL_UINT64    uCrashRip = 0u;
    ETL_UINT64    uCrashRsp = 0u;
};

What a minidump says, in short.

struct

SMinidumpModule

Ethereal::CrashReport#
C++
struct   SMinidumpModule   final
{
    /// @brief  Base address.
    ETL_UINT64    uBase = 0u;

    /// @brief  Image size.
    ETL_UINT32    uSize = 0u;

    /// @brief  The build-id (Linux) or the PDB signature (Windows), in hexadecimal.
    ETL_CHAR    aId[ 72 ] = {};

    /// @brief  The path, in UTF-8, truncated.
    ETL_CHAR    aName[ CRASH_PATH_LEN ] = {};
};

A module of the minidump.

function

ReadMinidumpSummary

Ethereal::CrashReport#
EStatus ReadMinidumpSummary( std::span< const ETL_UINT8 > Bytes, SMinidumpSummary * pOut ) noexcept;

Reads the summary of a minidump.

Bytes
The whole minidump.
pOut
Receives the summary.
EStatus::eInvalidArgument when the bytes are not a well formed minidump (signature, directory or a stream out of bounds).
function

ReadMinidumpModule

Ethereal::CrashReport#
EStatus ReadMinidumpModule( std::span< const ETL_UINT8 > Bytes, ETL_UINT32 uIndex, SMinidumpModule * pOut ) noexcept;

Reads module uIndex of the module stream.

Bytes
The whole minidump.
uIndex
Module index.
pOut
Receives the module.
EStatus::eInvalidArgument when the dump is malformed or the index is out of range.

queue.hpp

#include <ethereal/cpp/crashreport/queue.hpp>

The bounded local queue and the consent gate of the CrashReport module.

Reports always go to the queue before any attempt to send. A crash at shutdown, or with no network, must not be lost. The queue is bounded in count and in bytes, and the oldest report gives way first. It survives a restart: pending reports are uploaded on the next start.

Nothing leaves the machine before consent, and the default is to ask. Silent sending exists as an explicit option for internal deployments where a policy already covers it.

This file holds the policy (the limits logic and the delivery decision), which can be measured without touching the disk. Writing the files and talking to the network are the I/O layer. See the README.

const

QUEUE_MAX_ENTRIES

Ethereal::CrashReport#
constexpr ETL_UINT32 QUEUE_MAX_ENTRIES = 64u;

Maximum number of reports the queue policy tracks.

class

CQueuePolicy

Ethereal::CrashReport#

The local queue policy: bounded, the oldest report gives way first.

class CQueuePolicy final
constructor

CQueuePolicy

#
CQueuePolicy() noexcept;

Default constructor. Empty queue with the default limits.

function

Init

#
void Init( ETL_UINT32 uMaxCount, ETL_UINT64 uMaxBytes ) noexcept;

Sets the limits and empties the queue.

uMaxCount
Maximum number of reports. Clamped to QUEUE_MAX_ENTRIES.
uMaxBytes
Maximum total bytes. Zero means no byte limit.
function

Add

#
EStatus Add( ETL_UINT64 uId, ETL_UINT64 uBytes, ETL_UINT64 * pEvicted, ETL_UINT32 uEvictedCap, ETL_UINT32 * pEvictedN ) noexcept;

Adds a report of uBytes with id uId.

Evicts the oldest reports until it fits. A single report larger than the byte limit is refused (the whole queue is not emptied for one that never fits).

uId
Report id.
uBytes
Report size.
pEvicted
Receives the evicted ids (up to uEvictedCap). May be null.
uEvictedCap
Size of pEvicted.
pEvictedN
Receives how many were evicted. May be null.
EStatus::eQueueFull when the report itself does not fit the limit.
function

Remove

#
bool Remove( ETL_UINT64 uId ) noexcept;

Removes report uId (for example, after a successful upload).

uId
Report id.
false when the id is not in the queue.
function

Count

#
ETL_UINT32 Count() const noexcept

Number of reports in the queue.

function

TotalBytes

#
ETL_UINT64 TotalBytes() const noexcept

Total bytes of the reports in the queue.

function

IdAt

#
ETL_UINT64 IdAt( ETL_UINT32 uIndex ) const noexcept;

Id at position uIndex.

uIndex
0 is the oldest.
The id, or zero when out of range.
function

Clear

#
void Clear() noexcept;

Empties the queue. The limits are kept.

function

MayDeliver

Ethereal::CrashReport#
bool MayDeliver( EDeliveryMode eMode, bool bConsentGiven ) noexcept;

Tells whether a report may leave the machine now, given the mode and the consent.

The rule in a single place: 'eLocalOnly' never leaves, 'eSilentSend' leaves, 'eAskConsent' leaves only with consent given. A test with a network interceptor confirms that nothing goes out before this returns true.

eMode
Delivery mode.
bConsentGiven
Whether the user gave consent.
true when the report may be sent.

report.hpp

#include <ethereal/cpp/crashreport/report.hpp>

The report that leaves the machine: the 'report.etlcrash' container, the 'crash.json' inside it, the multipart body of the upload, and the transport seam.

None of this runs inside the handler. The handler only writes the dump and a raw snapshot. Packing happens later, in normal code (on the next start, or in 'ReportNonFatal'), where allocating and compressing is safe.

The container is simple on purpose: a magic, and entries with name, method, CRC32 and sizes. The reader trusts nothing (names, sizes, CRC) and runs in the fuzzer.

const

REPORT_MAX_ENTRIES

Ethereal::CrashReport#
constexpr ETL_UINT32 REPORT_MAX_ENTRIES = 64u;

Maximum number of entries in a container.

const

REPORT_NAME_LEN

Ethereal::CrashReport#
constexpr ETL_UINT32 REPORT_NAME_LEN = 128u;

Bytes per entry name, terminator included.

struct

SReportEntry

Ethereal::CrashReport#
C++
struct   SReportEntry   final
{
    /// @brief  Entry name. Must pass IsSafeEntryName.
    const ETL_CHAR *                pName = nullptr;

    /// @brief  The bytes.
    std::span< const ETL_UINT8 >    Data;

    /// @brief  Try to compress. Kept stored when compression does not help.
    bool                            bCompress = true;
};

An entry to put in the container.

struct

SReportItem

Ethereal::CrashReport#
C++
struct   SReportItem   final
{
    /// @brief  Entry name.
    ETL_CHAR    aName[ REPORT_NAME_LEN ] = {};

    /// @brief  0 = stored, 1 = raw deflate.
    ETL_UINT8    uMethod = 0u;

    /// @brief  CRC32 of the original bytes.
    ETL_UINT32    uCrc32 = 0u;

    /// @brief  Original size.
    ETL_UINT64    uRawSize = 0u;

    /// @brief  Stored size.
    ETL_UINT64    uStoredSize = 0u;

    /// @brief  Where the stored bytes start.
    ETL_UINT64    uOffset = 0u;
};

An entry read from the container (the index, the bytes stay where they are).

function

BuildReport

Ethereal::CrashReport#
EStatus BuildReport( std::span< const SReportEntry > Entries, std::vector< ETL_UINT8 > * pOut ) noexcept;

Builds the container. An entry that does not gain from compression is kept stored.

Entries
The entries.
pOut
Receives the container.
EStatus::eInvalidArgument with an unsafe, repeated or empty name, or with more than REPORT_MAX_ENTRIES entries.
function

ReadReportIndex

Ethereal::CrashReport#
EStatus ReadReportIndex( std::span< const ETL_UINT8 > Bytes, SReportItem * pItems, ETL_UINT32 uCap, ETL_UINT32 * pCount ) noexcept;

Reads the index of a container, checking every name and every size.

Bytes
The container.
pItems
Receives up to uCap entries.
uCap
Size of pItems.
pCount
Receives the number of entries in the container.
eOk, eInvalidArgument for a malformed container, or eBufferTooSmall when there are more entries than uCap.
function

ExtractReportItem

Ethereal::CrashReport#
EStatus ExtractReportItem( std::span< const ETL_UINT8 > Bytes, const SReportItem & Item, ETL_UINT64 uMaxRaw, std::vector< ETL_UINT8 > * pOut ) noexcept;

Extracts an entry (decompresses and checks the CRC32).

Bytes
The container.
Item
The entry, from ReadReportIndex.
uMaxRaw
Cap on the original size: a hostile container cannot make the reader reserve gigabytes by declaring a large size.
pOut
Receives the original bytes.
eOk, eInvalidArgument, or eBufferTooSmall when the size passes uMaxRaw.
function

IsSafeEntryName

Ethereal::CrashReport#
bool IsSafeEntryName( const ETL_CHAR * pName ) noexcept;

Tells whether an entry name is safe: relative, no '..', no '\', no ':', no root, only printable ASCII, and at most REPORT_NAME_LEN - 1 bytes.

pName
The name.
true when safe.
struct

SJsonPair

Ethereal::CrashReport#
C++
struct   SJsonPair   final
{
    /// @brief  The name.
    const ETL_CHAR *    pName = nullptr;

    /// @brief  The value.
    const ETL_CHAR *    pValue = nullptr;
};

A name-value pair already resolved (fields, environment, system).

struct

SReportInfo

Ethereal::CrashReport#
C++
struct   SReportInfo   final
{
    /// @brief  Report id.
    ETL_UINT64            uReportId = 0u;

    /// @brief  Crash signature.
    ETL_UINT64            uSignature = 0u;

    /// @brief  Time of the report, Unix seconds.
    ETL_INT64            iTimeUnix = 0;

    /// @brief  Product name.
    const ETL_CHAR *    pProduct = nullptr;

    /// @brief  Product version.
    const ETL_CHAR *    pVersion = nullptr;

    /// @brief  Reason given by the caller.
    const ETL_CHAR *    pReason = nullptr;

    /// @brief  "access-violation", "non-fatal"...
    const ETL_CHAR *    pKind = nullptr;

    /// @brief  "windows" / "linux"
    const ETL_CHAR *    pPlatform = nullptr;

    /// @brief  Dump level name.
    const ETL_CHAR *    pDumpLevel = nullptr;

    /// @brief  true for a fatal crash.
    bool                bFatal = false;

    /// @brief  The limiter only let the count through.
    bool                bCountOnly = false;

    /// @brief  true when the report carries a dump.
    bool                bHasDump = false;

    /// @brief  NTSTATUS or signal number.
    ETL_UINT32            uExceptionCode = 0u;

    /// @brief  Address of the exception.
    ETL_UINT64            uExceptionAddress = 0u;

    /// @brief  Occurrences of the signature in the current window.
    ETL_UINT32            uCrashLoopCount = 0u;

    /// @brief  Custom fields.
    std::span< const SJsonPair >            Fields;

    /// @brief  Allowed environment variables.
    std::span< const SJsonPair >            Environment;

    /// @brief  System information.
    std::span< const SJsonPair >            System;

    /// @brief  Breadcrumbs, oldest first.
    std::span< const ETL_CHAR * const >        Breadcrumbs;

    /// @brief  Names of the other entries.
    std::span< const ETL_CHAR * const >        Files;
};

What goes into the 'crash.json'.

function

BuildCrashJson

Ethereal::CrashReport#
EStatus BuildCrashJson( const SReportInfo & Info, std::string * pOut ) noexcept;

Writes the 'crash.json' (UTF-8, with JSON escapes).

Outside text is not trusted, and a control byte comes out as '\u00XX'.

Info
What goes into the JSON.
pOut
Receives the JSON.
eOk, eInvalidArgument, or eBufferTooSmall when out of memory.
struct

ICrashTransport

Ethereal::CrashReport#
C++
struct   ICrashTransport
{
    ///
    /// Post
    ///
    /// @brief  Sends one request.
    ///
    /// @param pUrl                Target URL.
    /// @param pContentType        Value of the Content-Type header.
    /// @param Body                Request body.
    /// @param pHttpStatus        Receives the HTTP status of the answer (0 when there was none).
    ///
    /// @return  @ref EStatus::eOk when the request was made (whatever the HTTP status).
    ///
    virtual EStatus Post( const ETL_CHAR * pUrl, const ETL_CHAR * pContentType,
                          std::span< const ETL_UINT8 > Body,
                          ETL_UINT32 * pHttpStatus ) ETL_NOEXCEPT = 0;

    /// @brief  Virtual destructor.
    ///
    virtual ~ICrashTransport() = default;
};

The transport.

The module has no HTTP client: the integrator plugs in their own, as in the Updater. 'Post' is only called after the consent gate.

function

BuildMultipart

Ethereal::CrashReport#
EStatus BuildMultipart( std::span< const SJsonPair > Fields, const ETL_CHAR * pFileField, const ETL_CHAR * pFileName, std::span< const ETL_UINT8 > File, const ETL_CHAR * pBoundary, std::vector< ETL_UINT8 > * pBody, std::string * pContentType ) noexcept;

Builds a 'multipart/form-data' body: the text fields and one file.

Fields
Text fields.
pFileField
Form field name of the file.
pFileName
File name sent in the part.
File
File bytes.
pBoundary
The boundary (only [0-9A-Za-z'()+_,-./:=?], up to 70). It must not appear in the data: this is checked, and refused when it does.
pBody
Receives the body.
pContentType
Receives "multipart/form-data; boundary=...".
eOk, eInvalidArgument, or eBufferTooSmall when out of memory.

scrub.hpp

#include <ethereal/cpp/crashreport/scrub.hpp>

Secret scrubbing and the environment allowlist of the CrashReport module.

Privacy is a product requirement here. A memory dump carries what was in memory: passwords, tokens, customer records. The customers sell to the EU and to Brazil, and they will be asked about this at purchase time.

  • Scrubbing overwrites registered patterns in the buffer before packing.
  • The environment allowlist lets through only the chosen names, never the whole environment, which routinely carries tokens and credentials.

Scrubbing a whole memory dump is best effort. The real mitigation is not collecting a whole memory dump (EDumpLevel::eMinimal).

const

SCRUB_MAX_PATTERNS

Ethereal::CrashReport#
constexpr ETL_UINT32 SCRUB_MAX_PATTERNS = 32u;

Maximum number of registered patterns.

const

SCRUB_PATTERN_LEN

Ethereal::CrashReport#
constexpr ETL_UINT32 SCRUB_PATTERN_LEN = 48u;

Bytes per pattern, terminator included.

const

SCRUB_FILL

Ethereal::CrashReport#
constexpr ETL_CHAR SCRUB_FILL = '*';

The byte that replaces the secret.

class

CScrubber

Ethereal::CrashReport#

Overwrites secrets in a buffer before it is packed.

class CScrubber final

The padding of this type is intended (alignment). See 'ETL_BEGIN_INTENDED_PADDING'.

constructor

CScrubber

#
CScrubber() noexcept;

Default constructor. No patterns.

function

AddPattern

#
EStatus AddPattern( const ETL_CHAR * pPattern, bool bPrefix ) noexcept;

Registers a literal pattern to erase wherever it appears.

pPattern
The pattern. Truncated to SCRUB_PATTERN_LEN - 1 bytes.
bPrefix
When true, erases the pattern and the value that follows it (the run of bytes that are not space, quotes or ';'). This catches 'token=SECRET' and not only the word 'token='.
eOk, eInvalidArgument for an empty pattern, or eBufferTooSmall when the table is full.
function

AddDefaults

#
void AddDefaults() noexcept;

Registers the set of common credential patterns (Bearer, api_key, x-api-key and others). Matching is case sensitive.

function

Scrub

#
ETL_UINT32 Scrub( std::span< ETL_UINT8 > Buffer ) const noexcept;

Walks the buffer and overwrites each occurrence.

Buffer
The buffer, changed in place.
How many occurrences were erased.
function

PatternCount

#
ETL_UINT32 PatternCount() const noexcept

Number of registered patterns.

const

ENV_MAX_ALLOWED

Ethereal::CrashReport#
constexpr ETL_UINT32 ENV_MAX_ALLOWED = 32u;
const

ENV_NAME_LEN

Ethereal::CrashReport#
constexpr ETL_UINT32 ENV_NAME_LEN = 64u;

Bytes per name, terminator included.

class

CEnvAllowlist

Ethereal::CrashReport#

Only the chosen environment variable names go through.

class CEnvAllowlist final

Never the whole environment. The default is an empty list, and an empty list lets nothing through, which is the safe default.

The padding of this type is intended (alignment). See 'ETL_BEGIN_INTENDED_PADDING'.

constructor

CEnvAllowlist

#
CEnvAllowlist() noexcept;

Default constructor. Empty list.

function

Allow

#
EStatus Allow( const ETL_CHAR * pName ) noexcept;

Adds an allowed name.

pName
The variable name. Truncated to ENV_NAME_LEN - 1 bytes.
eOk, eInvalidArgument for an empty name, or eBufferTooSmall when the list is full.
function

IsAllowed

#
bool IsAllowed( const ETL_CHAR * pName ) const noexcept;

Tells whether the name is in the list (exact, case sensitive).

pName
The variable name.
true when allowed.
function

Count

#
ETL_UINT32 Count() const noexcept

Number of allowed names.

signature.hpp

#include <ethereal/cpp/crashreport/signature.hpp>

Crash signature and deduplication of the CrashReport module.

Normalizes the top N frames (module + offset), drops the frames of the handler itself, and hashes the result.

Stable across builds where the crash is really the same: it normalizes to module relative offsets and never hashes an absolute address. It feeds the repeat limiter (a crash loop does not send 500 equal reports), the grouping on the server, and the signal the Updater auto rollback consumes.

struct

SFrame

Ethereal::CrashReport#
C++
struct   SFrame   final
{
    /// @brief  Hash of the module name (0 = unknown).
    ETL_UINT64    uModuleHash = 0u;

    /// @brief  Offset inside the module.
    ETL_UINT64    uOffset     = 0u;

    /// @brief  1 when this is a frame of the handler itself (it is dropped).
    ETL_UINT8    bIsHandler  = 0u;
};

A stack frame, already normalized to module + offset.

No absolute address. The offset is relative to the module base, and the module is identified by a hash of its name. Both are the same across runs and across machines for the same binary.

function

ComputeSignature

Ethereal::CrashReport#
ETL_UINT64 ComputeSignature( std::span< const SFrame > Frames ) noexcept;

Computes the signature from the top frames.

Drops the frames marked as handler frames, takes the first CRASH_SIGNATURE_FRAMES useful ones, and hashes (module, offset) of each.

Frames
The frames, top of the stack first.
The 64 bit hash. Zero only when there is no useful frame.
const

RATE_MAX_SIGNATURES

Ethereal::CrashReport#
constexpr ETL_UINT32 RATE_MAX_SIGNATURES = 32u;

How many distinct signatures the limiter tracks at the same time.

enum

ERateDecision

Ethereal::CrashReport#
C++
enum class   ERateDecision : ETL_UINT8
{
    /// @brief  Send the whole report.
    eSend = 0,

    /// @brief  The cap was passed in this window: send only a count, not a payload.
    eSendCountOnly,

    /// @brief  The count was already sent in this window. Send nothing else.
    eSuppress
};

What the limiter decided about a report.

class

CRateLimiter

Ethereal::CrashReport#

Blocks a crash loop: at most uCap reports per signature per window.

class CRateLimiter final

Fixed size, no heap: a table of slots. When it fills up, the oldest slot gives way, so a new crash is never left untracked because of an old one.

constructor

CRateLimiter

#
CRateLimiter() noexcept;

Default constructor. 5 reports per hour until Init.

function

Init

#
void Init( ETL_UINT32 uCap, ETL_INT64 iWindowSeconds ) noexcept;

Sets the cap and the window, and empties the table.

uCap
Whole reports per signature per window.
iWindowSeconds
Window size, in seconds.
function

Observe

#
ERateDecision Observe( ETL_UINT64 uSignature, ETL_INT64 iNowUnix ) noexcept;

Records one occurrence of the signature and says what to do.

uSignature
The signature.
iNowUnix
Current time, Unix seconds.
The decision.
function

CountFor

#
ETL_UINT32 CountFor( ETL_UINT64 uSignature, ETL_INT64 iNowUnix ) const noexcept;

Occurrences of this signature in the current window.

uSignature
The signature.
iNowUnix
Current time, Unix seconds.
The count, zero when unknown or the window expired.