LLVM  9.0.0svn
ASanStackFrameLayout.h
Go to the documentation of this file.
1 //===- ASanStackFrameLayout.h - ComputeASanStackFrameLayout -----*- 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 // This header defines ComputeASanStackFrameLayout and auxiliary data structs.
10 //
11 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_TRANSFORMS_UTILS_ASANSTACKFRAMELAYOUT_H
13 #define LLVM_TRANSFORMS_UTILS_ASANSTACKFRAMELAYOUT_H
14 #include "llvm/ADT/SmallString.h"
15 #include "llvm/ADT/SmallVector.h"
16 
17 namespace llvm {
18 
19 class AllocaInst;
20 
21 // These magic constants should be the same as in
22 // in asan_internal.h from ASan runtime in compiler-rt.
23 static const int kAsanStackLeftRedzoneMagic = 0xf1;
24 static const int kAsanStackMidRedzoneMagic = 0xf2;
25 static const int kAsanStackRightRedzoneMagic = 0xf3;
26 static const int kAsanStackUseAfterReturnMagic = 0xf5;
27 static const int kAsanStackUseAfterScopeMagic = 0xf8;
28 
29 // Input/output data struct for ComputeASanStackFrameLayout.
31  const char *Name; // Name of the variable that will be displayed by asan
32  // if a stack-related bug is reported.
33  uint64_t Size; // Size of the variable in bytes.
34  size_t LifetimeSize; // Size in bytes to use for lifetime analysis check.
35  // Will be rounded up to Granularity.
36  size_t Alignment; // Alignment of the variable (power of 2).
37  AllocaInst *AI; // The actual AllocaInst.
38  size_t Offset; // Offset from the beginning of the frame;
39  // set by ComputeASanStackFrameLayout.
40  unsigned Line; // Line number.
41 };
42 
43 // Output data struct for ComputeASanStackFrameLayout.
45  size_t Granularity; // Shadow granularity.
46  size_t FrameAlignment; // Alignment for the entire frame.
47  size_t FrameSize; // Size of the frame in bytes.
48 };
49 
51  // The array of stack variables. The elements may get reordered and changed.
53  // AddressSanitizer's shadow granularity. Usually 8, may also be 16, 32, 64.
54  size_t Granularity,
55  // The minimal size of the left-most redzone (header).
56  // At least 4 pointer sizes, power of 2, and >= Granularity.
57  // The resulting FrameSize should be multiple of MinHeaderSize.
58  size_t MinHeaderSize);
59 
60 // Compute frame description, see DescribeAddressIfStack in ASan runtime.
63 
64 // Returns shadow bytes with marked red zones. This shadow represents the state
65 // if the stack frame when all local variables are inside of the own scope.
68  const ASanStackFrameLayout &Layout);
69 
70 // Returns shadow bytes with marked red zones and after scope. This shadow
71 // represents the state if the stack frame when all local variables are outside
72 // of the own scope.
74  // The array of stack variables. The elements may get reordered and changed.
76  const ASanStackFrameLayout &Layout);
77 
78 } // llvm namespace
79 
80 #endif // LLVM_TRANSFORMS_UTILS_ASANSTACKFRAMELAYOUT_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static const int kAsanStackMidRedzoneMagic
SmallString< 64 > ComputeASanStackFrameDescription(const SmallVectorImpl< ASanStackVariableDescription > &Vars)
static const int kAsanStackLeftRedzoneMagic
static const int kAsanStackUseAfterReturnMagic
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
SmallVector< uint8_t, 64 > GetShadowBytesAfterScope(const SmallVectorImpl< ASanStackVariableDescription > &Vars, const ASanStackFrameLayout &Layout)
static const int kAsanStackRightRedzoneMagic
ASanStackFrameLayout ComputeASanStackFrameLayout(SmallVectorImpl< ASanStackVariableDescription > &Vars, size_t Granularity, size_t MinHeaderSize)
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
static const int kAsanStackUseAfterScopeMagic
an instruction to allocate memory on the stack
Definition: Instructions.h:59
SmallVector< uint8_t, 64 > GetShadowBytes(const SmallVectorImpl< ASanStackVariableDescription > &Vars, const ASanStackFrameLayout &Layout)