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

Commit f3f2ce01 authored by Kunshan Wang's avatar Kunshan Wang
Browse files

reloc

parent 63af3f1e
......@@ -53,12 +53,15 @@ object BootImageWriter {
val AS_REF = "R"
val AS_IREF = "I"
val AS_TAGREF = "T"
val AS_FUNCREF = "F"
val IN_GLOBAL = "G"
val IN_HEAP = "H"
val TO_GLOBAL = "G"
val TO_HEAP = "H"
val TO_FUNC = "F"
val NO_OFFSET = 0L
/**
* Allocation record. For global and heap.
*
......@@ -133,6 +136,10 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
writeAllocRecs(globalGroup)
writeAllocRecs(heapGroup)
for (ar <- heapGroup.allocRecs) {
addrToHeapObjNum(ar.addr) = ar.num
}
scanForRelocs(globalGroup)
scanForRelocs(heapGroup)
......@@ -185,13 +192,43 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
val begin = alloc.addr
MemoryDataScanner.scanAllocUnit(begin, new MemoryFieldHandler {
def visitRefField(objRef: Word, iRef: Word, toObj: Word, isWeak: Boolean): Unit = {}
def visitIRefField(objRef: Word, iRef: Word, toObj: Word, toOffset: Word): Unit = {}
/** This function is called only when the tagref is holding a reference. */
def visitTagRefField(objRef: Word, iRef: Word, toObj: Word): Unit = {}
def visitFuncRefField(objRef: Word, iRef: Word, toFunc: Option[Function]): Unit = {}
def visitRefField(objRef: Word, iRef: Word, toObj: Word, isWeak: Boolean): Unit = if (toObj != 0L) {
val fieldOffset = iRef - objRef
val targetNum = addrToHeapObjNum(toObj)
val reloc = FieldRelocRecord(num, fieldOffset, AS_REF, TO_HEAP, targetNum, NO_OFFSET)
group.relocRecs += reloc
}
def visitIRefField(objRef: Word, iRef: Word, toObj: Word, toOffset: Word): Unit = if (toObj != 0L) {
val fieldOffset = iRef - objRef
val targetNum = addrToHeapObjNum(toObj)
val reloc = FieldRelocRecord(num, fieldOffset, AS_IREF, TO_HEAP, targetNum, toOffset)
group.relocRecs += reloc
} else {
val fieldOffset = iRef - objRef
val gcr = tcb.getGlobalCellRec(toOffset)
val targetNum = gcr.g.id.toLong
val targetAddr = gcr.begin
val targetOffset = toOffset - targetAddr
val reloc = FieldRelocRecord(num, fieldOffset, AS_IREF, TO_GLOBAL, targetNum, targetOffset)
group.relocRecs += reloc
}
def visitTagRefField(objRef: Word, iRef: Word, toObj: Word): Unit = if (toObj != 0L) {
val fieldOffset = iRef - objRef
val targetNum = addrToHeapObjNum(toObj)
val reloc = FieldRelocRecord(num, fieldOffset, AS_TAGREF, TO_HEAP, targetNum, NO_OFFSET)
group.relocRecs += reloc
}
def visitFuncRefField(objRef: Word, iRef: Word, toFunc: Option[Function]): Unit = toFunc.foreach { func =>
val fieldOffset = iRef - objRef
val targetNum = func.id.toLong
val reloc = FieldRelocRecord(num, fieldOffset, AS_FUNCREF, TO_FUNC, targetNum, NO_OFFSET)
group.relocRecs += reloc
}
// We already made sure in the transitive closure step that the following are all NULL.
def visitStackRefField(objRef: Word, iRef: Word, toStack: Option[InterpreterStack]): Unit = {}
def visitThreadRefField(objRef: Word, iRef: Word, toThread: Option[InterpreterThread]): Unit = {}
def visitFCRefField(objRef: Word, iRef: Word, toFCRef: Option[FrameCursor]): Unit = {}
......@@ -201,7 +238,11 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
}
private def writeRelocRecs(group: FileGroup): Unit = {
//???
tryWithResource(Files.newBufferedWriter(group.relocFile, StandardCharsets.UTF_8)) { writer =>
for (rr <- group.relocRecs) {
writer.write("%d,%d,%s,%s,%d,%d\n".format(rr.num, rr.fieldOffset, rr.fieldKind, rr.targetKind, rr.targetNum, rr.targetOffset))
}
}
}
private def writeIDNameMap(): Unit = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment