39 lines · c
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-exception6//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 store16// the zig-zag encoded pointer difference between frame[i] and frame[i - 1] as17// a variable-length integer. This can reduce the memory overhead of stack18// traces by 50%.19 20namespace gwp_asan {21namespace compression {22 23// For the stack trace in `Unpacked` with length `UnpackedSize`, pack it into24// the buffer `Packed` maximum length `PackedMaxSize`. The return value is the25// 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 the30// 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 compression36} // namespace gwp_asan37 38#endif // GWP_ASAN_STACK_TRACE_COMPRESSOR_39