|
|
|||
File indexing completed on 2026-05-10 08:44:42
0001 //===- ASanStackFrameLayout.h - ComputeASanStackFrameLayout -----*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 // 0009 // This header defines ComputeASanStackFrameLayout and auxiliary data structs. 0010 // 0011 //===----------------------------------------------------------------------===// 0012 #ifndef LLVM_TRANSFORMS_UTILS_ASANSTACKFRAMELAYOUT_H 0013 #define LLVM_TRANSFORMS_UTILS_ASANSTACKFRAMELAYOUT_H 0014 #include "llvm/ADT/SmallString.h" 0015 #include "llvm/ADT/SmallVector.h" 0016 0017 namespace llvm { 0018 0019 class AllocaInst; 0020 0021 // These magic constants should be the same as in 0022 // in asan_internal.h from ASan runtime in compiler-rt. 0023 static const int kAsanStackLeftRedzoneMagic = 0xf1; 0024 static const int kAsanStackMidRedzoneMagic = 0xf2; 0025 static const int kAsanStackRightRedzoneMagic = 0xf3; 0026 static const int kAsanStackUseAfterReturnMagic = 0xf5; 0027 static const int kAsanStackUseAfterScopeMagic = 0xf8; 0028 0029 // Input/output data struct for ComputeASanStackFrameLayout. 0030 struct ASanStackVariableDescription { 0031 const char *Name; // Name of the variable that will be displayed by asan 0032 // if a stack-related bug is reported. 0033 uint64_t Size; // Size of the variable in bytes. 0034 size_t LifetimeSize; // Size in bytes to use for lifetime analysis check. 0035 // Will be rounded up to Granularity. 0036 uint64_t Alignment; // Alignment of the variable (power of 2). 0037 AllocaInst *AI; // The actual AllocaInst. 0038 size_t Offset; // Offset from the beginning of the frame; 0039 // set by ComputeASanStackFrameLayout. 0040 unsigned Line; // Line number. 0041 }; 0042 0043 // Output data struct for ComputeASanStackFrameLayout. 0044 struct ASanStackFrameLayout { 0045 uint64_t Granularity; // Shadow granularity. 0046 uint64_t FrameAlignment; // Alignment for the entire frame. 0047 uint64_t FrameSize; // Size of the frame in bytes. 0048 }; 0049 0050 ASanStackFrameLayout ComputeASanStackFrameLayout( 0051 // The array of stack variables. The elements may get reordered and changed. 0052 SmallVectorImpl<ASanStackVariableDescription> &Vars, 0053 // AddressSanitizer's shadow granularity. Usually 8, may also be 16, 32, 64. 0054 uint64_t Granularity, 0055 // The minimal size of the left-most redzone (header). 0056 // At least 4 pointer sizes, power of 2, and >= Granularity. 0057 // The resulting FrameSize should be multiple of MinHeaderSize. 0058 uint64_t MinHeaderSize); 0059 0060 // Compute frame description, see DescribeAddressIfStack in ASan runtime. 0061 SmallString<64> ComputeASanStackFrameDescription( 0062 const SmallVectorImpl<ASanStackVariableDescription> &Vars); 0063 0064 // Returns shadow bytes with marked red zones. This shadow represents the state 0065 // if the stack frame when all local variables are inside of the own scope. 0066 SmallVector<uint8_t, 64> 0067 GetShadowBytes(const SmallVectorImpl<ASanStackVariableDescription> &Vars, 0068 const ASanStackFrameLayout &Layout); 0069 0070 // Returns shadow bytes with marked red zones and after scope. This shadow 0071 // represents the state if the stack frame when all local variables are outside 0072 // of the own scope. 0073 SmallVector<uint8_t, 64> GetShadowBytesAfterScope( 0074 // The array of stack variables. The elements may get reordered and changed. 0075 const SmallVectorImpl<ASanStackVariableDescription> &Vars, 0076 const ASanStackFrameLayout &Layout); 0077 0078 } // llvm namespace 0079 0080 #endif // LLVM_TRANSFORMS_UTILS_ASANSTACKFRAMELAYOUT_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|