Commit 014c8671 authored by George Hotz's avatar George Hotz

clean up heap

parent e0c8a8bb
...@@ -15,8 +15,8 @@ regs = ["at", "v0", "v1", "a0", "a1", "a2", "a3"] ...@@ -15,8 +15,8 @@ regs = ["at", "v0", "v1", "a0", "a1", "a2", "a3"]
SIZE = 16*1024*1024 SIZE = 16*1024*1024
# 0x40000000 heap_start = 0x20000000 # 0x20000000-0x30000000
heap_start = 1024*1024*1024 brk_start = 0x40000000 # 0x40000000-0x80000000
tfd = 10 tfd = 10
files = {} files = {}
...@@ -27,6 +27,7 @@ def hook_interrupt(uc, intno, user_data): ...@@ -27,6 +27,7 @@ def hook_interrupt(uc, intno, user_data):
if intno == 17: if intno == 17:
syscall_no = uc.reg_read(UC_MIPS_REG_V0) syscall_no = uc.reg_read(UC_MIPS_REG_V0)
uc.reg_write(UC_MIPS_REG_V0, 0) uc.reg_write(UC_MIPS_REG_V0, 0)
uc.reg_write(UC_MIPS_REG_A3, 0)
if syscall_no == 4004: if syscall_no == 4004:
# write # write
fd = uc.reg_read(UC_MIPS_REG_A0) fd = uc.reg_read(UC_MIPS_REG_A0)
...@@ -49,20 +50,41 @@ def hook_interrupt(uc, intno, user_data): ...@@ -49,20 +50,41 @@ def hook_interrupt(uc, intno, user_data):
elif syscall_no == 4194: elif syscall_no == 4194:
# rt_sigaction # rt_sigaction
return return
elif syscall_no == 4195:
# rt_sigprocmask
return
elif syscall_no == 4055: elif syscall_no == 4055:
# fcntl # fcntl
return return
elif syscall_no == 4220:
# fcntl64
return
elif syscall_no == 4249: elif syscall_no == 4249:
# epoll_ctl # epoll_ctl
return return
elif syscall_no == 4263: elif syscall_no == 4263:
# clock_gettime # clock_gettime
return return
elif syscall_no == 4326:
# epoll_create1
return
elif syscall_no == 4328:
# pipe2
return
elif syscall_no == 4206:
# sigaltstack
return
elif syscall_no == 4222:
# gettid
return
if syscall_no == 4005: if syscall_no == 4005:
filename = uc.reg_read(UC_MIPS_REG_A0) filename = uc.reg_read(UC_MIPS_REG_A0)
print('open("%s")' % uc.mem_read(filename, 0x100).split(b"\x00")[0].decode('utf-8')) print('open("%s")' % uc.mem_read(filename, 0x100).split(b"\x00")[0].decode('utf-8'))
uc.reg_write(UC_MIPS_REG_V0, 4) uc.reg_write(UC_MIPS_REG_V0, 4)
elif syscall_no == 4045:
print("brk", hex(brk_start))
uc.reg_write(UC_MIPS_REG_V0, brk_start)
elif syscall_no == 4288: elif syscall_no == 4288:
dfd = uc.reg_read(UC_MIPS_REG_A0) dfd = uc.reg_read(UC_MIPS_REG_A0)
filename = uc.reg_read(UC_MIPS_REG_A1) filename = uc.reg_read(UC_MIPS_REG_A1)
...@@ -91,7 +113,7 @@ def hook_interrupt(uc, intno, user_data): ...@@ -91,7 +113,7 @@ def hook_interrupt(uc, intno, user_data):
elif syscall_no == 4006: elif syscall_no == 4006:
fd = uc.reg_read(UC_MIPS_REG_A0) fd = uc.reg_read(UC_MIPS_REG_A0)
if fd >= 10: if fd >= 10:
print("close(%d)" % fd) #print("close(%d)" % fd)
files[fd].close() files[fd].close()
del files[fd] del files[fd]
uc.reg_write(UC_MIPS_REG_V0, 0) uc.reg_write(UC_MIPS_REG_V0, 0)
...@@ -101,7 +123,7 @@ def hook_interrupt(uc, intno, user_data): ...@@ -101,7 +123,7 @@ def hook_interrupt(uc, intno, user_data):
count = uc.reg_read(UC_MIPS_REG_A2) count = uc.reg_read(UC_MIPS_REG_A2)
# changing this works if we want smaller oracle # changing this works if we want smaller oracle
#count = 4 #count = 4
print("read", fd, hex(buf), count) #print("read", fd, hex(buf), count)
if fd == 4: if fd == 4:
val = b"2097152\n" val = b"2097152\n"
uc.mem_write(buf, val) uc.mem_write(buf, val)
...@@ -135,7 +157,6 @@ def hook_interrupt(uc, intno, user_data): ...@@ -135,7 +157,6 @@ def hook_interrupt(uc, intno, user_data):
for i,r in zip(mregs, regs): for i,r in zip(mregs, regs):
jj += "%s: %8x " % (r, uc.reg_read(i)) jj += "%s: %8x " % (r, uc.reg_read(i))
print(''.join(jj)) print(''.join(jj))
uc.reg_write(UC_MIPS_REG_A3, 0)
return True return True
print("interrupt", intno, hex(pc)) print("interrupt", intno, hex(pc))
...@@ -182,13 +203,12 @@ elf.seek(0) ...@@ -182,13 +203,12 @@ elf.seek(0)
# program memory (16 MB) # program memory (16 MB)
mu.mem_map(0, SIZE) mu.mem_map(0, SIZE)
# extra memory (16 MB) @ 0x1000000 # heap (256 MB) @ 0x20000000
# TODO: why do we need this?
mu.mem_map(SIZE, SIZE)
# heap (256 MB) @ 0x40000000
mu.mem_map(heap_start, 256*1024*1024) mu.mem_map(heap_start, 256*1024*1024)
# brk (1024 MB) @ 0x40000000
mu.mem_map(brk_start, 1024*1024*1024)
# regs at 0xC0000000 in merkle # regs at 0xC0000000 in merkle
elffile = ELFFile(elf) elffile = ELFFile(elf)
......
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