reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
//===-- dfsan_platform.h ----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is a part of DataFlowSanitizer.
//
// Platform specific information for DFSan.
//===----------------------------------------------------------------------===//

#ifndef DFSAN_PLATFORM_H
#define DFSAN_PLATFORM_H

namespace __dfsan {

#if defined(__x86_64__)
struct Mapping {
  static const uptr kShadowAddr = 0x10000;
  static const uptr kUnionTableAddr = 0x200000000000;
  static const uptr kAppAddr = 0x700000008000;
  static const uptr kShadowMask = ~0x700000000000;
};
#elif defined(__mips64)
struct Mapping {
  static const uptr kShadowAddr = 0x10000;
  static const uptr kUnionTableAddr = 0x2000000000;
  static const uptr kAppAddr = 0xF000008000;
  static const uptr kShadowMask = ~0xF000000000;
};
#elif defined(__aarch64__)
struct Mapping39 {
  static const uptr kShadowAddr = 0x10000;
  static const uptr kUnionTableAddr = 0x1000000000;
  static const uptr kAppAddr = 0x7000008000;
  static const uptr kShadowMask = ~0x7800000000;
};

struct Mapping42 {
  static const uptr kShadowAddr = 0x10000;
  static const uptr kUnionTableAddr = 0x8000000000;
  static const uptr kAppAddr = 0x3ff00008000;
  static const uptr kShadowMask = ~0x3c000000000;
};

struct Mapping48 {
  static const uptr kShadowAddr = 0x10000;
  static const uptr kUnionTableAddr = 0x8000000000;
  static const uptr kAppAddr = 0xffff00008000;
  static const uptr kShadowMask = ~0xfffff0000000;
};

extern int vmaSize;
# define DFSAN_RUNTIME_VMA 1
#else
# error "DFSan not supported for this platform!"
#endif

enum MappingType {
  MAPPING_SHADOW_ADDR,
  MAPPING_UNION_TABLE_ADDR,
  MAPPING_APP_ADDR,
  MAPPING_SHADOW_MASK
};

template<typename Mapping, int Type>
uptr MappingImpl(void) {
  switch (Type) {
    case MAPPING_SHADOW_ADDR: return Mapping::kShadowAddr;
    case MAPPING_UNION_TABLE_ADDR: return Mapping::kUnionTableAddr;
    case MAPPING_APP_ADDR: return Mapping::kAppAddr;
    case MAPPING_SHADOW_MASK: return Mapping::kShadowMask;
  }
}

template<int Type>
uptr MappingArchImpl(void) {
#ifdef __aarch64__
  switch (vmaSize) {
    case 39: return MappingImpl<Mapping39, Type>();
    case 42: return MappingImpl<Mapping42, Type>();
    case 48: return MappingImpl<Mapping48, Type>();
  }
  DCHECK(0);
  return 0;
#else
  return MappingImpl<Mapping, Type>();
#endif
}

ALWAYS_INLINE
uptr ShadowAddr() {
  return MappingArchImpl<MAPPING_SHADOW_ADDR>();
}

ALWAYS_INLINE
uptr UnionTableAddr() {
  return MappingArchImpl<MAPPING_UNION_TABLE_ADDR>();
}

ALWAYS_INLINE
uptr AppAddr() {
  return MappingArchImpl<MAPPING_APP_ADDR>();
}

ALWAYS_INLINE
uptr ShadowMask() {
  return MappingArchImpl<MAPPING_SHADOW_MASK>();
}

}  // namespace __dfsan

#endif