stack_trace_compressor.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. #ifndef GWP_ASAN_STACK_TRACE_COMPRESSOR_
  9. #define GWP_ASAN_STACK_TRACE_COMPRESSOR_
  10. #include <stddef.h>
  11. #include <stdint.h>
  12. // These functions implement stack frame compression and decompression. We store
  13. // the zig-zag encoded pointer difference between frame[i] and frame[i - 1] as
  14. // a variable-length integer. This can reduce the memory overhead of stack
  15. // traces by 50%.
  16. namespace gwp_asan {
  17. namespace compression {
  18. // For the stack trace in `Unpacked` with length `UnpackedSize`, pack it into
  19. // the buffer `Packed` maximum length `PackedMaxSize`. The return value is the
  20. // number of bytes that were written to the output buffer.
  21. size_t pack(const uintptr_t *Unpacked, size_t UnpackedSize, uint8_t *Packed,
  22. size_t PackedMaxSize);
  23. // From the packed stack trace in `Packed` of length `PackedSize`, write the
  24. // unpacked stack trace of maximum length `UnpackedMaxSize` into `Unpacked`.
  25. // Returns the number of full entries unpacked, or zero on error.
  26. size_t unpack(const uint8_t *Packed, size_t PackedSize, uintptr_t *Unpacked,
  27. size_t UnpackedMaxSize);
  28. } // namespace compression
  29. } // namespace gwp_asan
  30. #endif // GWP_ASAN_STACK_TRACE_COMPRESSOR_