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