Skip to content

Commit

Permalink
dump pregoldenrun memory map; handle registerdumps
Browse files Browse the repository at this point in the history
  • Loading branch information
ks0777 committed Mar 22, 2023
1 parent 20b4e66 commit ba76fab
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v2

- name: install packages
run: sudo apt update; sudo apt upgrade -y; sudo apt install -y build-essential ninja-build libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev python3-tables python3-pandas python3-prctl python3-json5
run: sudo apt update; sudo apt upgrade -y; sudo apt install -y build-essential ninja-build libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev python3-tables python3-pandas python3-prctl python3-json5 python3-pyelftools

- name: Install latest stable Rust toolchain
uses: actions-rs/toolchain@v1
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ tables (tested 3.6.1)
python-prctl (tested 1.6.1)
numpy (tested 1.17.4)
json (tested 2.0.9), or json5 (tested 0.9.6)
pyelftools (tested 0.29)
```
These python3 libraries can either be installed using your linux-distribution's installation method or by using pip3.
JSON5 is strongly recommended as it allows integers to be represented as hexadecimal numbers.
Expand Down
28 changes: 25 additions & 3 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import subprocess
import time

from elftools.elf.elffile import ELFFile

try:
import json5 as json

Expand Down Expand Up @@ -251,7 +253,7 @@ def controller(
qemu_pre=None,
qemu_post=None,
logger_postprocess=None,
unicorn_emulation=False
unicorn_emulation=False,
):
"""
This function builds the unrolled fault structure, performs golden run and
Expand Down Expand Up @@ -284,7 +286,12 @@ def controller(
config_qemu, qemu_output, queue_output, faultlist, qemu_pre, qemu_post
)
pickle.dump(
(config_qemu["max_instruction_count"], pregoldenrun_data, goldenrun_data, faultlist),
(
config_qemu["max_instruction_count"],
pregoldenrun_data,
goldenrun_data,
faultlist,
),
lzma.open("bkup_goldenrun_results.xz", "wb"),
)
else:
Expand All @@ -295,6 +302,21 @@ def controller(
faultlist,
) = pickle.load(lzma.open("bkup_goldenrun_results.xz", "rb"))

if unicorn_emulation:
elffile = ELFFile(open(config_qemu["kernel"], "rb"))
for segment in elffile.iter_segments():
if segment["p_type"] == "PT_LOAD":
segment_data = segment.data()
pregoldenrun_data["memdumplist"].append(
{
"address": segment["p_vaddr"],
"len": len(segment_data),
"numpdumps": 1,
"dumps": [list(segment_data)],
}
)
break

p_logger = Process(
target=logger,
args=(
Expand Down Expand Up @@ -657,5 +679,5 @@ def process_arguments(args):
None, # qemu_pre
None, # qemu_post
None, # logger_postprocess
parguments["unicorn_emulation"], # enable unicorn emulation
parguments["unicorn_emulation"], # enable unicorn emulation
)
38 changes: 30 additions & 8 deletions faultclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,14 @@ def readout_tb_faulted(line):
return tbfaulted


def readout_memmap(line):
split = line.split("|")
memmap = {}
memmap["address"] = int(split[0], 16)
memmap["length"] = int(split[1], 16)
return memmap


def readout_data(
pipe,
index,
Expand All @@ -430,10 +438,12 @@ def readout_data(
memdumptmp = []
registerlist = []
tbfaultedlist = []
memmaplist = []
tbinfo = 0
tbexec = 0
meminfo = 0
memdump = 0
memmap = 0
endpoint = 0
end_reason = ""
max_ram_usage = 0
Expand Down Expand Up @@ -476,13 +486,15 @@ def readout_data(
split = line.split("]:")
architecture = split[1].strip()

elif "[Memory Map]" in line:
state = "memmap"
memmap = 1

elif "[END]" in line:
state = "none"
logger.info(
f"Data received now on post processing for Experiment {index}"
)
print(registerlist)
print(memdumplist)

if tbexec == 1:
if pdtbexeclist is not None:
Expand Down Expand Up @@ -540,6 +552,9 @@ def readout_data(
output["end_reason"] = end_reason
output["architecture"] = architecture

if memmap == 1:
output["memmaplist"] = memmaplist

if memdump == 1:
output["memdumplist"] = memdumplist

Expand All @@ -559,7 +574,7 @@ def readout_data(
regtype = "arm"
elif "[RiscV Registers]" in line:
state = "riscvregisters"
regtype = "riscv"
regtype = "riscv64"
elif "[TB Faulted]" in line:
state = "tbfaulted"
tbfaulted = 1
Expand Down Expand Up @@ -596,6 +611,8 @@ def readout_data(
registerlist.append(readout_riscv_registers(line))
elif "tbfaulted" in state:
tbfaultedlist.append(readout_tb_faulted(line))
elif "memmap" in state:
memmaplist.append(readout_memmap(line))
else:
logger.warning("In exp {} unknown state {}".format(index, line))
return max_ram_usage
Expand Down Expand Up @@ -652,8 +669,10 @@ def configure_qemu(control, config_qemu, num_faults, memorydump_list, index):
out = out + "$$ num_faults: {}\n".format(num_faults)

if index is -2:
out = out + "$$enable_memmap_dump\n"
out = out + "$$enable_full_mem_dump\n"
else:
out = out + "$$disable_memmap_dump\n"
out = out + "$$disable_full_mem_dump\n"

if "tb_exec_list" in config_qemu:
Expand Down Expand Up @@ -825,17 +844,20 @@ def python_worker_unicorn(
goldenrun_data["tbinfo"],
index,
)
output["tbexec"] = write_output_wrt_goldenrun("tbexec", pdtbexeclist, goldenrun_data)
output["tbexec"] = write_output_wrt_goldenrun(
"tbexec", pdtbexeclist, goldenrun_data
)
output["tbinfo"] = write_output_wrt_goldenrun("tbinfo", tblist, goldenrun_data)

output["armregisters"] = write_output_wrt_goldenrun("armregisters", pd.DataFrame(logs["registerlist"], dtype="UInt64"), goldenrun_data)
regtype = pregoldenrun_data["architecture"]
output[f"{regtype}registers"] = pd.DataFrame(
logs["registerlist"], dtype="UInt64"
).to_dict("records")

queue_output.put(output)

logger.info(
"Python worker for experiment {} done. Took {}s".format(
index, time.time() - t0
)
"Python worker for experiment {} done. Took {}s".format(index, time.time() - t0)
)

return
6 changes: 4 additions & 2 deletions faultplugin/memmapdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ struct FlatRange {

bool dump_memmap_information(Int128 start, Int128 len, const MemoryRegion *mr, hwaddr offset_in_region, void *opaque) {
g_autoptr(GString) out = g_string_new("");
g_string_printf(out, "$$ 0x%lx | 0x%lx \n", int128_get64(start), int128_get64(len));
plugin_write_to_data_pipe(out->str, out->len);
if (mr->ram) {
g_string_printf(out, "$$ 0x%lx | 0x%lx \n", int128_get64(start), int128_get64(len));
plugin_write_to_data_pipe(out->str, out->len);
}
return false;
}

Expand Down
7 changes: 6 additions & 1 deletion goldenrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ def run_goldenrun(
)
)

return [config_qemu["max_instruction_count"], experiments[0]["data"], experiment["data"], faultconfig]
return [
config_qemu["max_instruction_count"],
experiments[0]["data"],
experiment["data"],
faultconfig,
]


def find_insn_addresses_in_tb(insn_address, data):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pandas~=1.5
python-prctl==1.8.1
tables==3.7.0
json5==0.9.10
pyelftools==0.29

0 comments on commit ba76fab

Please sign in to comment.