LLVM API Documentation
00001 //===- ASanStackFrameLayout.h - ComputeASanStackFrameLayout -----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This header defines ComputeASanStackFrameLayout and auxiliary data structs. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 #ifndef LLVM_TRANSFORMS_UTILS_ASANSTACKFRAMELAYOUT_H 00014 #define LLVM_TRANSFORMS_UTILS_ASANSTACKFRAMELAYOUT_H 00015 #include "llvm/ADT/SmallString.h" 00016 #include "llvm/ADT/SmallVector.h" 00017 00018 namespace llvm { 00019 00020 class AllocaInst; 00021 00022 // These magic constants should be the same as in 00023 // in asan_internal.h from ASan runtime in compiler-rt. 00024 static const int kAsanStackLeftRedzoneMagic = 0xf1; 00025 static const int kAsanStackMidRedzoneMagic = 0xf2; 00026 static const int kAsanStackRightRedzoneMagic = 0xf3; 00027 00028 // Input/output data struct for ComputeASanStackFrameLayout. 00029 struct ASanStackVariableDescription { 00030 const char *Name; // Name of the variable that will be displayed by asan 00031 // if a stack-related bug is reported. 00032 uint64_t Size; // Size of the variable in bytes. 00033 size_t Alignment; // Alignment of the variable (power of 2). 00034 AllocaInst *AI; // The actual AllocaInst. 00035 size_t Offset; // Offset from the beginning of the frame; 00036 // set by ComputeASanStackFrameLayout. 00037 }; 00038 00039 // Output data struct for ComputeASanStackFrameLayout. 00040 struct ASanStackFrameLayout { 00041 // Frame description, see DescribeAddressIfStack in ASan runtime. 00042 SmallString<64> DescriptionString; 00043 // The contents of the shadow memory for the stack frame that we need 00044 // to set at function entry. 00045 SmallVector<uint8_t, 64> ShadowBytes; 00046 size_t FrameAlignment; // Alignment for the entire frame. 00047 size_t FrameSize; // Size of the frame in bytes. 00048 }; 00049 00050 void ComputeASanStackFrameLayout( 00051 // The array of stack variables. The elements may get reordered and changed. 00052 SmallVectorImpl<ASanStackVariableDescription> &Vars, 00053 // AddressSanitizer's shadow granularity. Usually 8, may also be 16, 32, 64. 00054 size_t Granularity, 00055 // The minimal size of the left-most redzone (header). 00056 // At least 4 pointer sizes, power of 2, and >= Granularity. 00057 // The resulting FrameSize should be multiple of MinHeaderSize. 00058 size_t MinHeaderSize, 00059 // The result is put here. 00060 ASanStackFrameLayout *Layout); 00061 00062 } // llvm namespace 00063 00064 #endif // LLVM_TRANSFORMS_UTILS_ASANSTACKFRAMELAYOUT_H