def final_spec(cspaces, obj_space, addr_spaces, elf_files, architecture): """ Generates a final CapDL spec file that can be given to a capdl loader application """ arch = lookup_architecture(architecture) for e in [item for sublist in elf_files for item in sublist]: name = os.path.basename(e) elf = ELF(e, name, architecture) cspace = cspaces[name] # Avoid inferring a TCB as we've already created our own. elf_spec = elf.get_spec(infer_tcb=False, infer_asid=False, pd=addr_spaces[name].vspace_root, addr_space=addr_spaces[name]) obj_space.merge(elf_spec) cspace.cnode.finalise_size(arch) # Fill in TCB object information. # TODO: This should be generalised with what is in the Camkes filters tcb = obj_space["tcb_%s" % name] progsymbol = elf.get_symbol_vaddr("progname") vsyscall = elf.get_symbol_vaddr("sel4_vsyscall") tcb.init = [0, 0, 0, 0, 2, progsymbol, 1, 0, 0, 32, vsyscall, 0, 0] tcb.addr = elf.get_symbol_vaddr("mainIpcBuffer") tcb.sp = elf.get_symbol_vaddr("stack") + elf.get_symbol_size("stack") tcb.ip = elf.get_entry_point() return obj_space
def final_spec(args, obj_space, cspaces, addr_spaces, targets, architecture): """ Generates a final CapDL spec file that can be given to a capdl loader application """ arch = lookup_architecture(architecture) for e, key in targets: name = os.path.basename(e) elf = ELF(e, name, architecture) cspace = cspaces[key] # Avoid inferring a TCB as we've already created our own. elf_spec = elf.get_spec(infer_tcb=False, infer_asid=False, pd=addr_spaces[key].vspace_root, addr_space=addr_spaces[key]) obj_space.merge(elf_spec, label=key) for slot, v in cspace.cnode.slots.items(): if v is not None and isinstance(v.referent, TCB): tcb = v.referent if 'cspace' in tcb and tcb['cspace'] and tcb['cspace'].referent is not cspace.cnode: # We exclude TCBs that refer to a different CSpace continue funcs = {"get_vaddr": lambda x: elf.get_symbol_vaddr(x)} tcb.ip = eval(str(tcb.ip), {"__builtins__": None}, funcs) tcb.sp = eval(str(tcb.sp), {"__builtins__": None}, funcs) tcb.addr = eval(str(tcb.addr), {"__builtins__": None}, funcs) tcb.init = eval(str(tcb.init), {"__builtins__": None}, funcs) if not args.fprovide_tcb_caps: del cspace.cnode[slot] cspace.cnode.finalise_size(arch=arch) return obj_space
def test_symbol_lookup(self): elf = ELF('resources/unstripped.bin') assert elf.get_arch() == 'x86' # Confirm that the address concurs with the one we get from objdump. assert elf.get_symbol_vaddr('_start') == 0x08048d48 elf = ELF('resources/stripped.bin') assert elf.get_arch() == 'x86' # We shouldn't be able to get the symbol from the stripped binary. try: vaddr = elf.get_symbol_vaddr('_start') assert not ( 'Symbol lookup on a stripped binary returned _start == 0x%0.8x' % vaddr) except: # Expected pass
#!/usr/bin/env python # # Copyright 2014, NICTA # # This software may be distributed and modified according to the terms of # the BSD 2-Clause license. Note that NO WARRANTY is provided. # See "LICENSE_BSD2.txt" for details. # # @TAG(NICTA_BSD) # from capdl import ELF elf = ELF('unstripped.bin') assert elf.get_arch() == 'x86' # Confirm that the address concurs with the one we get from objdump. assert elf.get_symbol_vaddr('_start') == 0x08048d48 elf = ELF('stripped.bin') assert elf.get_arch() == 'x86' # We shouldn't be able to get the symbol from the stripped binary. try: vaddr = elf.get_symbol_vaddr('_start') assert not ('Symbol lookup on a stripped binary returned _start == 0x%0.8x' % vaddr) except: # Expected pass
def final_spec(cspaces, obj_space, addr_spaces, elf_files, architecture, so_files): """ Generates a final CapDL spec file that can be given to a capdl loader application """ # cspaces : dict containes all the CSpaceAllocator for this app # obj_space : ObjectAllocator for all the objs in the spec # addr_spaces : dict containers all the AddressSpaceAllocator for this app print("In final_spec function") arch = lookup_architecture(architecture) # NOTE: handle shared lib so files here for e in [item for sublist in so_files for item in sublist]: name = os.path.basename(e) name = name[3:-3] print(name) elf = ELF(e, name, architecture) cspace = cspaces[name] print('the vspace root is ' + str(addr_spaces[name].vspace_root)) print('The addr space allocator is ' + str(addr_spaces[name])) # Avoid inferring a TCB as we've already created our own. elf_spec = elf.get_spec( infer_tcb=False, infer_asid=False, pd=addr_spaces[name].vspace_root, addr_space=addr_spaces[name] ) obj_space.merge(elf_spec) cspace.cnode.finalise_size(arch) # Fill in TCB object information. # NOTE: There will be a tcb for a shared lib file but handled in root task of capdl # loader # TODO: This should be generalised with what is in the Camkes filters tcb = obj_space["tcb_%s" % name] progsymbol = 0 vsyscall = 0 tcb.init = [0,0,0,0,2,progsymbol,1,0,0,32,vsyscall,0,0] tcb.addr = 0 tcb.sp = 0 tcb.ip = 0 for e in [item for sublist in elf_files for item in sublist]: name = os.path.basename(e) print(name) # path, name, arch elf = ELF(e, name, architecture) # find the cspace for current elf cspace = cspaces[name] print('the vspace root is ' + str(addr_spaces[name].vspace_root)) print('The addr space allocator is ' + str(addr_spaces[name])) # Avoid inferring a TCB as we've already created our own. elf_spec = elf.get_spec( infer_tcb=False, infer_asid=False, pd=addr_spaces[name].vspace_root, addr_space=addr_spaces[name] ) obj_space.merge(elf_spec) cspace.cnode.finalise_size(arch) # Fill in TCB object information. # TODO: This should be generalised with what is in the Camkes filters tcb = obj_space["tcb_%s" % name] progsymbol = elf.get_symbol_vaddr("progname") vsyscall = elf.get_symbol_vaddr("sel4_vsyscall") tcb.init = [0,0,0,0,2,progsymbol,1,0,0,32,vsyscall,0,0] tcb.addr = elf.get_symbol_vaddr("mainIpcBuffer"); tcb.sp = elf.get_symbol_vaddr("stack")+elf.get_symbol_size("stack"); tcb.ip = elf.get_entry_point() return obj_space
# # This software may be distributed and modified according to the terms of # the BSD 2-Clause license. Note that NO WARRANTY is provided. # See "LICENSE_BSD2.txt" for details. # # @TAG(DATA61_BSD) # from __future__ import absolute_import, division, print_function, \ unicode_literals from capdl import ELF elf = ELF('unstripped.bin') assert elf.get_arch() == 'x86' # Confirm that the address concurs with the one we get from objdump. assert elf.get_symbol_vaddr('_start') == 0x08048d48 elf = ELF('stripped.bin') assert elf.get_arch() == 'x86' # We shouldn't be able to get the symbol from the stripped binary. try: vaddr = elf.get_symbol_vaddr('_start') assert not ('Symbol lookup on a stripped binary returned _start == 0x%0.8x' % vaddr) except: # Expected pass