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