ASanStackFrameLayout.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //===- ASanStackFrameLayout.h - ComputeASanStackFrameLayout -----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This header defines ComputeASanStackFrameLayout and auxiliary data structs.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_TRANSFORMS_UTILS_ASANSTACKFRAMELAYOUT_H
  14. #define LLVM_TRANSFORMS_UTILS_ASANSTACKFRAMELAYOUT_H
  15. #include "llvm/ADT/SmallString.h"
  16. #include "llvm/ADT/SmallVector.h"
  17. namespace llvm {
  18. class AllocaInst;
  19. // These magic constants should be the same as in
  20. // in asan_internal.h from ASan runtime in compiler-rt.
  21. static const int kAsanStackLeftRedzoneMagic = 0xf1;
  22. static const int kAsanStackMidRedzoneMagic = 0xf2;
  23. static const int kAsanStackRightRedzoneMagic = 0xf3;
  24. // Input/output data struct for ComputeASanStackFrameLayout.
  25. struct ASanStackVariableDescription {
  26. const char *Name; // Name of the variable that will be displayed by asan
  27. // if a stack-related bug is reported.
  28. uint64_t Size; // Size of the variable in bytes.
  29. size_t Alignment; // Alignment of the variable (power of 2).
  30. AllocaInst *AI; // The actual AllocaInst.
  31. size_t Offset; // Offset from the beginning of the frame;
  32. // set by ComputeASanStackFrameLayout.
  33. };
  34. // Output data struct for ComputeASanStackFrameLayout.
  35. struct ASanStackFrameLayout {
  36. // Frame description, see DescribeAddressIfStack in ASan runtime.
  37. SmallString<64> DescriptionString;
  38. // The contents of the shadow memory for the stack frame that we need
  39. // to set at function entry.
  40. SmallVector<uint8_t, 64> ShadowBytes;
  41. size_t FrameAlignment; // Alignment for the entire frame.
  42. size_t FrameSize; // Size of the frame in bytes.
  43. };
  44. void ComputeASanStackFrameLayout(
  45. // The array of stack variables. The elements may get reordered and changed.
  46. SmallVectorImpl<ASanStackVariableDescription> &Vars,
  47. // AddressSanitizer's shadow granularity. Usually 8, may also be 16, 32, 64.
  48. size_t Granularity,
  49. // The minimal size of the left-most redzone (header).
  50. // At least 4 pointer sizes, power of 2, and >= Granularity.
  51. // The resulting FrameSize should be multiple of MinHeaderSize.
  52. size_t MinHeaderSize,
  53. // The result is put here.
  54. ASanStackFrameLayout *Layout);
  55. } // llvm namespace
  56. #endif // LLVM_TRANSFORMS_UTILS_ASANSTACKFRAMELAYOUT_H