1//===-- stack_trace_compressor.h --------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef GWP_ASAN_STACK_TRACE_COMPRESSOR_
10#define GWP_ASAN_STACK_TRACE_COMPRESSOR_
11
12#include <stddef.h>
13#include <stdint.h>
14
15// These functions implement stack frame compression and decompression. We store
16// the zig-zag encoded pointer difference between frame[i] and frame[i - 1] as
17// a variable-length integer. This can reduce the memory overhead of stack
18// traces by 50%.
19
20namespace gwp_asan {
21namespace compression {
22
23// For the stack trace in `Unpacked` with length `UnpackedSize`, pack it into
24// the buffer `Packed` maximum length `PackedMaxSize`. The return value is the
25// number of bytes that were written to the output buffer.
26size_t pack(const uintptr_t *Unpacked, size_t UnpackedSize, uint8_t *Packed,
27 size_t PackedMaxSize);
28
29// From the packed stack trace in `Packed` of length `PackedSize`, write the
30// unpacked stack trace of maximum length `UnpackedMaxSize` into `Unpacked`.
31// Returns the number of full entries unpacked, or zero on error.
32size_t unpack(const uint8_t *Packed, size_t PackedSize, uintptr_t *Unpacked,
33 size_t UnpackedMaxSize);
34
35} // namespace compression
36} // namespace gwp_asan
37
38#endif // GWP_ASAN_STACK_TRACE_COMPRESSOR_
39

source code of compiler-rt/lib/gwp_asan/stack_trace_compressor.h