Skip to content

Commit

Permalink
Warn about self-modifying code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarah Mount committed Sep 1, 2016
1 parent cd11c9a commit d5a026e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
11 changes: 6 additions & 5 deletions revelation/elf_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def load_program(elf, mem, coreids, alignment=0, ext_base=0x8e000000,
pydgin.elf.elf_reader().
"""
sections = elf.get_sections()
entrypoint = -1
code_blocks = []
for coreid in coreids:
coreid_mask = coreid << 20
for section in sections:
Expand All @@ -20,9 +20,10 @@ def load_program(elf, mem, coreids, alignment=0, ext_base=0x8e000000,
start_addr = section.addr
for index, data in enumerate(section.data):
mem.write(start_addr + index, 1, ord(data), quiet=True)
if section.name == '.text':
entrypoint = intmask(section.addr)
if section.name == '.text' or section.name == 'NEW_LIB_RO':
entry_point = intmask(start_addr)
end_point = entry_point + len(section.data)
code_blocks.append((entry_point, end_point))
if section.name == '.data':
mem.data_section = section.addr
assert entrypoint >= 0
return
return code_blocks
6 changes: 4 additions & 2 deletions revelation/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ def init_state(self, elf_file, filename, testbin, is_test=False):
zfill(str(f_col + col), 2)))
self.states[coreid] = State(self.memory, self.debug,
logger=self.logger, coreid=coreid)
load_program(elf, self.memory, coreids, ext_base=self.ext_base,
ext_size=self.ext_size)
code_blocks = load_program(elf, self.memory, coreids, ext_base=self.ext_base,
ext_size=self.ext_size)
for section in code_blocks:
self.memory.code_blocks.append(section)
self.states[coreids[0]].set_first_core(True)
if self.profile:
timer = time.time()
Expand Down
4 changes: 4 additions & 0 deletions revelation/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self, block_size=2**20, logger=None):
self.addr_mask = block_size - 1
self.block_mask = 0xffffffff ^ self.addr_mask
self.block_dict = {}
self.code_blocks = []

def add_block(self, block_addr):
self.block_dict[block_addr] = _BlockMemory(size=self.block_size)
Expand Down Expand Up @@ -118,6 +119,9 @@ def write(self, start_addr, num_bytes, value, from_core=0x808, quiet=False):
if is_local_address(start_addr):
start_addr |= (from_core << 20)
coreid_mask = start_addr & 0xfff00000
for start, end in self.code_blocks:
if start_addr >= start and (start_addr + num_bytes) <= end:
print 'WARNING: self-modifying code @', pad_hex(start_addr)
if start_addr & 0xfffff == 0xf042c: # ILATST
ilat = self.read(coreid_mask | 0xf0428, 4) & 0x3ff
ilat |= (value & ((2 << 10) - 1))
Expand Down
26 changes: 24 additions & 2 deletions revelation/test/test_compiled_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,30 @@
('print_large_float.elf', 'd = 1.84467440737095516e+19\n'
'd - 1 = 1.84467440737095516e+19\n'),
('read_file.elf', 'Hello, world!\n'),
('selfmod.elf', 'Hello\nWorld\n'),
('selfmod2.elf', 'Hello\nWorld\n'),
('selfmod.elf', 'Hello\n'
'WARNING: self-modifying code @ 80800350\n'
'WARNING: self-modifying code @ 80800354\n'
'WARNING: self-modifying code @ 80800358\n'
'WARNING: self-modifying code @ 8080035c\n'
'WARNING: self-modifying code @ 80800360\n'
'WARNING: self-modifying code @ 80800364\n'
'WARNING: self-modifying code @ 80800368\n'
'WARNING: self-modifying code @ 8080036c\n'
'WARNING: self-modifying code @ 80800370\n'
'WARNING: self-modifying code @ 80800374\n'
'World\n'),
('selfmod2.elf', 'Hello\n'
'WARNING: self-modifying code @ 80800350\n'
'WARNING: self-modifying code @ 80800354\n'
'WARNING: self-modifying code @ 80800358\n'
'WARNING: self-modifying code @ 8080035c\n'
'WARNING: self-modifying code @ 80800360\n'
'WARNING: self-modifying code @ 80800364\n'
'WARNING: self-modifying code @ 80800368\n'
'WARNING: self-modifying code @ 8080036c\n'
'WARNING: self-modifying code @ 80800370\n'
'WARNING: self-modifying code @ 80800374\n'
'World\n'),
('setilat.elf', 'User interrupt set by ILATST.\n'),
('testset.elf', 'Before testset:\na: 0\tb: 1\n'
'After testset:\na: 10\tb: 1\n'
Expand Down

0 comments on commit d5a026e

Please sign in to comment.