To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

MemoryDataScanner.scala 3.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package uvm.refimpl.mem.scanning

import uvm.refimpl._
import uvm.refimpl.itpr._
import uvm.refimpl.mem._
import uvm.types._
import com.typesafe.scalalogging.StrictLogging
import TypeSizes._
import com.typesafe.scalalogging.Logger
import org.slf4j.LoggerFactory

object MemoryDataScanner extends StrictLogging {

  val paranoiaLogger = Logger(LoggerFactory.getLogger(getClass.getName() + ".paranoia"))

Kunshan Wang's avatar
Kunshan Wang committed
16
17
18
19
  /**
   * Scan an allocation unit. In this implementation, heap objects, alloca cells and global
   * cells all have the same layout.
   */
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
  def scanAllocUnit(objRef: Word, iRef: Word, microVM: MicroVM, handler: RefFieldHandler) {
    val tag = HeaderUtils.getTag(objRef)
    val ty = HeaderUtils.getType(microVM, tag)
    scanField(ty, objRef, objRef, handler)
  }

  def scanField(ty: Type, objRef: Word, iRef: Word, handler: RefFieldHandler) {
    ty match {
      case t: TypeRef => {
        val toObj = MemorySupport.loadLong(iRef)
        logger.debug(s"Ref field ${iRef} -> ${toObj}")
        handler.fromMem(objRef, iRef, toObj, false, false)
      }
      case t: TypeIRef => {
        val toObj = MemorySupport.loadLong(iRef)
        logger.debug(s"IRef field ${iRef} -> ${toObj}")
        handler.fromMem(objRef, iRef, toObj, false, false)
      }
      case t: TypeWeakRef => {
        val toObj = MemorySupport.loadLong(iRef)
        logger.debug(s"WeakRef field ${iRef} -> ${toObj}")
        handler.fromMem(objRef, iRef, toObj, true, false)
      }
      case t: TypeTagRef64 => {
        val bits = MemorySupport.loadLong(iRef)
        if (paranoiaLogger.underlying.isDebugEnabled()) {
          paranoiaLogger.debug(s"Tagref bits ${bits}")
          if (OpHelper.tr64IsFp(bits)) {
            paranoiaLogger.debug(s"Tagref is FP: ${OpHelper.tr64ToFp(bits)}")
          } else if (OpHelper.tr64IsInt(bits)) {
            paranoiaLogger.debug(s"Tagref is Int: ${OpHelper.tr64ToInt(bits)}")
          } else if (OpHelper.tr64IsRef(bits)) {
            paranoiaLogger.debug(s"Tagref is Ref: ${OpHelper.tr64ToRef(bits)} tag: ${OpHelper.tr64ToTag(bits)}")
          }
        }
        if (OpHelper.tr64IsRef(bits)) {
          val toObj = OpHelper.tr64ToRef(bits)
          logger.debug(s"TagRef64 field ${iRef} -> ${toObj} tag: ${OpHelper.tr64ToTag(bits)}")
          handler.fromMem(objRef, iRef, toObj, false, true)
        }
      }
      case t: TypeStruct => {
        var fieldAddr = iRef
        for (fieldTy <- t.fieldTy) {
          val fieldAlign = TypeSizes.alignOf(fieldTy)
          fieldAddr = TypeSizes.alignUp(fieldAddr, fieldAlign)
          scanField(fieldTy, objRef, fieldAddr, handler)
          fieldAddr += TypeSizes.sizeOf(fieldTy)
        }
      }
      case t: TypeArray => {
        val elemTy = t.elemTy
        val elemSize = TypeSizes.sizeOf(elemTy)
        val elemAlign = TypeSizes.alignOf(elemTy)
        var elemAddr = iRef
        for (i <- 0L until t.len) {
          scanField(elemTy, objRef, elemAddr, handler)
          elemAddr = TypeSizes.alignUp(elemAddr + elemSize, elemAlign)
        }

      }
      case t: TypeHybrid => {
        val fixedTy = t.fixedTy
        val varTy = t.varTy
        val fixedSize = TypeSizes.sizeOf(fixedTy)
        val fixedAlign = TypeSizes.alignOf(fixedTy)
        val varSize = TypeSizes.sizeOf(varTy)
        val varAlign = TypeSizes.alignOf(varTy)
        var curAddr = iRef
        val varLength = HeaderUtils.getVarLength(iRef)
        scanField(fixedTy, objRef, curAddr, handler)
        curAddr = TypeSizes.alignUp(curAddr + fixedSize, fixedAlign)
        for (i <- 0L until varLength) {
          scanField(varTy, objRef, curAddr, handler)
          curAddr = TypeSizes.alignUp(curAddr + varSize, varAlign)
        }
      }
Kunshan Wang's avatar
Kunshan Wang committed
97
      case _ => // Ignore non-reference fields.
98
99
100
    }
  }
}