Ejemplo n.º 1
0
 def setup(self, vamos_legacy):
     # create def cfg
     if self.lib_mgr_cfg is None:
         self.lib_mgr_cfg = LibMgrCfg()
     # create segment loader
     self.seg_loader = SegmentLoader(self.alloc, self.path_mgr)
     # setup contexts
     self.exec_ctx = ExecLibCtx(self.machine, self.alloc, self.seg_loader,
                                self.path_mgr)
     self.dos_ctx = DosLibCtx(self.machine, self.alloc, self.seg_loader,
                              self.path_mgr, vamos_legacy)
     # create lib mgr
     self.lib_mgr = LibManager(self.machine,
                               self.alloc,
                               self.seg_loader,
                               self.lib_mgr_cfg,
                               profiler_cfg=self.profiler_cfg)
     self.lib_mgr.add_ctx('exec.library', self.exec_ctx)
     self.lib_mgr.add_ctx('dos.library', self.dos_ctx)
     # add all vamos libs
     for name in vamos_libs:
         cls = vamos_libs[name]
         self.lib_mgr.add_impl_cls(name, cls)
     # finally bootstrap exec
     self.lib_mgr.bootstrap_exec()
     # return lib_mgr
     return self.lib_mgr
Ejemplo n.º 2
0
 def setup(self):
     # create def cfg
     if self.lib_mgr_cfg is None:
         self.lib_mgr_cfg = LibMgrCfg()
     # create segment loader
     self.seg_loader = SegmentLoader(self.alloc, self.path_mgr)
     # setup contexts
     odg_base = self.mem_map.get_old_dos_guard_base()
     self.exec_ctx = ExecLibCtx(self.machine, self.alloc, self.seg_loader,
                                self.path_mgr)
     self.dos_ctx = DosLibCtx(self.machine, self.alloc, self.seg_loader,
                              self.path_mgr, self.scheduler, odg_base)
     # create lib mgr
     self.lib_mgr = LibManager(self.machine,
                               self.alloc,
                               self.seg_loader,
                               self.lib_mgr_cfg,
                               main_profiler=self.main_profiler)
     self.lib_mgr.add_ctx('exec.library', self.exec_ctx)
     self.lib_mgr.add_ctx('dos.library', self.dos_ctx)
     # add all vamos libs
     for name in vamos_libs:
         cls = vamos_libs[name]
         self.lib_mgr.add_impl_cls(name, cls)
     # setup scheduler call back
     self.scheduler.set_cur_task_callback(self.cur_task_callback)
     # return lib_mgr
     return self.lib_mgr
Ejemplo n.º 3
0
def libnative_mgr_fail_test():
    machine, alloc, sp, mem, exec_lib = setup()

    # load

    class PathMgrMock:
        def ami_to_sys_path(self, lock, ami_path, mustExist=True):
            return None

    pm = PathMgrMock()
    segload = SegmentLoader(alloc, pm)
    mgr = ALibManager(machine, alloc, segload)
    # open_lib
    lib_base = mgr.open_lib("testnix.library", run_sp=sp)
    assert lib_base == 0
    # close lib
    with pytest.raises(ValueError):
        mgr.close_lib(lib_base, run_sp=sp)
    # expunge lib
    with pytest.raises(ValueError):
        mgr.expunge_lib(lib_base, run_sp=sp)
    # expunge lib
    left = mgr.shutdown(run_sp=sp)
    assert left == 0
    # cleanup
    exec_lib.free()
    assert alloc.is_all_free()
Ejemplo n.º 4
0
def libnative_libfuncs_close_library_test():
    machine = Machine()
    mem = machine.get_mem()
    cpu = machine.get_cpu()
    traps = machine.get_traps()
    sp = machine.get_ram_begin() - 4
    alloc = MemoryAlloc.for_machine(machine)
    segloader = SegmentLoader(alloc)
    # new lib
    lib = Library.alloc(alloc, name="my.library", id_string="bla", neg_size=36)
    lib.new_lib()
    # setup seglist
    seglist = SegList.alloc(alloc, [64])
    segloader.register_seglist(seglist.get_baddr())

    # setup expunge func

    def close_func(op, pc):
        # return my seglist
        cpu.w_reg(REG_D0, seglist.get_baddr())

    trap_id = traps.setup(close_func, auto_rts=True)
    exp_addr = lib.get_addr() - 12
    mem.w16(exp_addr, trap_id | 0xA000)
    # add lib
    lf = LibFuncs(machine, alloc)
    sl = lf.close_library(lib.get_addr(), segloader, run_sp=sp)
    assert seglist.get_baddr() == sl
    # cleanup
    lib.free()
    assert alloc.is_all_free()
    assert segloader.shutdown() == 0
Ejemplo n.º 5
0
def loader_segload_test(binbuild):
    lib_file = binbuild.make_lib('simple')
    mem = MockMemory(fill=23)
    alloc = MemoryAlloc(mem)
    loader = SegmentLoader(mem, alloc)
    seg_list = loader.load_seg(lib_file)
    assert seg_list is not None
Ejemplo n.º 6
0
def loader_segload_sys_int_test(buildlibnix, mem_alloc):
    mem, alloc = mem_alloc
    lib_file = buildlibnix.make_lib('testnix')
    loader = SegmentLoader(alloc)
    info = loader.int_load_sys_seglist(lib_file)
    assert info
    info.seglist.free()
    assert alloc.is_all_free()
Ejemplo n.º 7
0
def load_lib(alloc, buildlibnix):
    lib_file = buildlibnix.make_lib("testnix")
    loader = SegmentLoader(alloc)
    info = loader.int_load_sys_seglist(lib_file)
    seg_list = info.seglist
    seg = seg_list.get_segment()
    addr = seg.get_addr()
    size = seg.get_size()
    end = seg.get_end()
    return seg_list, addr, size, end
Ejemplo n.º 8
0
def load_lib(mem, binbuild):
    lib_file = binbuild.make_lib('simple')
    alloc = MemoryAlloc(mem)
    loader = SegmentLoader(mem, alloc)
    seg_list = loader.load_seg(lib_file)
    seg0 = seg_list.get_segment(0)
    addr = seg0.get_addr()
    size = seg0.get_size()
    end = seg0.get_end()
    return addr, size, end
Ejemplo n.º 9
0
def loader_segload_register(mem_alloc):
    mem, alloc = mem_alloc
    loader = SegmentLoader(alloc)
    # my seglist
    seglist = SegList.alloc(mem, [64])
    baddr = seglist.get_baddr()
    loader.register_seglist(baddr)
    # unload registered seglist
    assert loader.unload_seglist(baddr)
    assert loader.shutdown() == 0
    assert alloc.is_all_free()
Ejemplo n.º 10
0
def load_lib(mem, buildlibnix):
    lib_file = buildlibnix.make_lib('testnix')
    alloc = MemoryAlloc(mem)
    loader = SegmentLoader(alloc)
    info = loader.int_load_sys_seglist(lib_file)
    seg_list = info.seglist
    seg = seg_list.get_segment()
    addr = seg.get_addr()
    size = seg.get_size()
    end = seg.get_end()
    return addr, size, end
Ejemplo n.º 11
0
def setup(profiler_cfg=None):
    machine = Machine()
    alloc = MemoryAlloc(machine.get_mem(), machine.get_ram_begin())
    mgr = VLibManager(machine, alloc, profiler_cfg=profiler_cfg)
    # setup ctx map
    cpu = machine.get_cpu()
    mem = machine.get_mem()
    cpu_type = machine.get_cpu_type()
    segloader = SegmentLoader(alloc)
    exec_ctx = ExecLibCtx(machine, alloc, segloader, None)
    mgr.add_ctx('exec.library', exec_ctx)
    return machine, alloc, mgr
Ejemplo n.º 12
0
def loader_segload_ami_int_test(buildlibnix, mem_alloc):
    mem, alloc = mem_alloc
    lib_file = buildlibnix.make_lib('testnix')

    class PathMgrMock:
        def ami_to_sys_path(self, lock, ami_path, mustExist=True):
            if ami_path == "blu":
                return lib_file

    pm = PathMgrMock()
    loader = SegmentLoader(alloc, path_mgr=pm)
    info = loader.int_load_ami_seglist("blu")
    assert info
    info.seglist.free()
    assert alloc.is_all_free()
Ejemplo n.º 13
0
def setup(path_mgr=None):
    machine = Machine()
    mem = machine.get_mem()
    alloc = MemoryAlloc.for_machine(machine)
    segload = SegmentLoader(alloc, path_mgr=path_mgr)
    loader = LibLoader(machine, alloc, segload)
    sp = machine.get_ram_begin() - 4
    # setup exec
    exec_lib = ExecLibrary.alloc(alloc, "exec.library", "bla", 520 * 6)
    exec_lib.setup()
    exec_lib.fill_funcs()
    exec_base = exec_lib.get_addr()
    mem.w32(4, exec_base)
    machine.set_zero_mem(0, exec_base)
    return loader, segload, alloc, mem, sp, exec_lib
Ejemplo n.º 14
0
def loader_segload_sys_load_unload_test(buildlibnix, mem_alloc):
    mem, alloc = mem_alloc
    lib_file = buildlibnix.make_lib('testnix')
    loader = SegmentLoader(alloc)
    # load
    baddr = loader.load_sys_seglist(lib_file)
    assert baddr > 0
    info = loader.get_info(baddr)
    assert info.seglist.get_baddr() == baddr
    # unload
    ok = loader.unload_seglist(baddr)
    assert ok
    info = loader.get_info(baddr)
    assert info is None
    assert loader.shutdown() == 0
    assert alloc.is_all_free()
Ejemplo n.º 15
0
def setup(main_profiler=None, prof_names=None, prof_calls=False):
    machine = Machine()
    alloc = MemoryAlloc(machine.get_mem(), machine.get_ram_begin())
    mgr = VLibManager(machine,
                      alloc,
                      main_profiler=main_profiler,
                      prof_names=prof_names,
                      prof_calls=prof_calls)
    # setup ctx map
    cpu = machine.get_cpu()
    mem = machine.get_mem()
    cpu_type = machine.get_cpu_type()
    segloader = SegmentLoader(alloc)
    exec_ctx = ExecLibCtx(machine, alloc, segloader, None)
    mgr.add_ctx('exec.library', exec_ctx)
    mgr.add_impl_cls('exec.library', ExecLibrary)
    mgr.add_impl_cls('vamostest.library', VamosTestLibrary)
    mgr.add_impl_cls('vamostestdev.device', VamosTestDevice)
    return machine, alloc, mgr
Ejemplo n.º 16
0
def setup(path_mgr=None):
    machine = Machine()
    mem = machine.get_mem()
    alloc = MemoryAlloc.for_machine(machine)
    segload = SegmentLoader(alloc, path_mgr=path_mgr)
    loader = LibLoader(machine, alloc, segload)
    sp = machine.get_ram_begin() - 4
    # setup exec
    exec_lib = ExecLibrary.alloc(alloc,
                                 name="exec.library",
                                 id_string="bla",
                                 neg_size=520 * 6)
    assert exec_lib.LibNode.neg_size.val == 520 * 6
    exec_lib.new_lib()
    exec_lib.fill_funcs()
    exec_base = exec_lib.get_addr()
    mem.w32(4, exec_base)
    machine.set_zero_mem(0, exec_base)
    return loader, segload, alloc, mem, sp, exec_lib
Ejemplo n.º 17
0
def libnative_mgr_test(buildlibnix):
    if buildlibnix.flavor not in ("gcc", "gcc-dbg"):
        pytest.skip("only single base lib supported")
    log_libmgr.setLevel(logging.INFO)
    machine, alloc, sp, mem, exec_lib = setup()
    # load
    lib_file = buildlibnix.make_lib("testnix")

    class PathMgrMock:
        def ami_to_sys_path(self, lock, ami_path, mustExist=True):
            if ami_path == "LIBS:testnix.library":
                return lib_file

    pm = PathMgrMock()
    segload = SegmentLoader(alloc, pm)
    mgr = ALibManager(machine, alloc, segload)
    # open_lib
    lib_base = mgr.open_lib("testnix.library", run_sp=sp)
    assert lib_base > 0
    assert mgr.is_base_addr(lib_base)
    lib_info = mgr.get_lib_info_for_name("testnix.library")
    assert lib_info
    assert lib_info.is_base_addr(lib_base)
    assert lib_info.get_lib_fd()
    # close lib
    seglist = mgr.close_lib(lib_base, run_sp=sp)
    assert seglist == 0
    lib_info = mgr.get_lib_info_for_name("testnix.library")
    assert lib_info
    assert not lib_info.is_base_addr(lib_base)
    # expunge lib
    left = mgr.shutdown(run_sp=sp)
    assert left == 0
    assert not mgr.is_base_addr(lib_base)
    lib_info = mgr.get_lib_info_for_name("testnix.library")
    assert not lib_info
    # we have to manually clean the lib here (as Exec FreeMem() does not work)
    free_lib(mem, alloc, lib_base)
    # cleanup
    exec_lib.free()
    assert alloc.is_all_free()
Ejemplo n.º 18
0
def setup(path_mgr=None, cfg=None, profiler_cfg=None):
    log_libmgr.setLevel(logging.INFO)
    log_exec.setLevel(logging.INFO)
    machine = Machine()
    # machine.show_instr(True)
    sp = machine.get_ram_begin() - 4
    alloc = MemoryAlloc.for_machine(machine)
    segloader = SegmentLoader(alloc, path_mgr)
    mgr = LibManager(machine,
                     alloc,
                     segloader,
                     cfg=cfg,
                     profiler_cfg=profiler_cfg)
    # setup ctx map
    cpu = machine.get_cpu()
    mem = machine.get_mem()
    cpu_type = machine.get_cpu_type()
    exec_ctx = ExecLibCtx(machine, alloc, segloader, path_mgr)
    mgr.add_ctx('exec.library', exec_ctx)
    dos_ctx = DosLibCtx(machine, alloc, segloader, path_mgr, None, None)
    mgr.add_ctx('dos.library', dos_ctx)
    return machine, alloc, mgr, sp
Ejemplo n.º 19
0
def setup(path_mgr=None):
    log_libmgr.setLevel(logging.INFO)
    log_exec.setLevel(logging.INFO)
    machine = Machine()
    # machine.show_instr(True)
    sp = machine.get_ram_begin() - 4
    alloc = MemoryAlloc.for_machine(machine)
    segloader = SegmentLoader(alloc, path_mgr)
    cfg = LibMgrCfg()
    mgr = LibManager(machine, alloc, segloader, cfg)
    # setup ctx map
    cpu = machine.get_cpu()
    mem = machine.get_mem()
    cpu_type = machine.get_cpu_type()
    exec_ctx = ExecLibCtx(machine, alloc, segloader, path_mgr, mgr)
    mgr.add_ctx("exec.library", exec_ctx)
    mgr.add_impl_cls("exec.library", ExecLibrary)
    dos_ctx = DosLibCtx(machine, alloc, segloader, path_mgr, None, None)
    mgr.add_ctx("dos.library", dos_ctx)
    mgr.add_impl_cls("dos.library", DosLibrary)
    mgr.add_impl_cls("vamostest.library", VamosTestLibrary)
    mgr.add_impl_cls("vamostestdev.device", VamosTestDevice)
    return machine, alloc, mgr, sp, cfg
Ejemplo n.º 20
0
def setup_env(main_profiler=None, prof_names=None, prof_calls=False):
    machine = Machine()
    alloc = MemoryAlloc(machine.get_mem(), machine.get_ram_begin())
    mgr = VLibManager(
        machine,
        alloc,
        main_profiler=main_profiler,
        prof_names=prof_names,
        prof_calls=prof_calls,
    )
    # setup ctx map
    cpu = machine.get_cpu()
    mem = machine.get_mem()
    cpu_type = machine.get_cpu_type()
    segloader = SegmentLoader(alloc)
    exec_ctx = ExecLibCtx(machine, alloc, segloader, None, None)
    # add extra attr to ctx
    mgr.set_ctx_extra_attr("foo", "bar")
    mgr.add_ctx("exec.library", exec_ctx)
    mgr.add_impl_cls("exec.library", ExecLibrary)
    mgr.add_impl_cls("vamostest.library", VamosTestLibrary)
    mgr.add_impl_cls("vamostestdev.device", VamosTestDevice)
    return machine, alloc, mgr
Ejemplo n.º 21
0
def loader_segload_ami_load_unload_test(buildlibnix, mem_alloc):
    mem, alloc = mem_alloc
    lib_file = buildlibnix.make_lib('testnix')

    class PathMgrMock:
        def ami_to_sys_path(self, lock, ami_path, mustExist=True):
            if ami_path == "blu":
                return lib_file

    pm = PathMgrMock()
    loader = SegmentLoader(alloc, path_mgr=pm)
    # load
    baddr = loader.load_ami_seglist("blu")
    assert baddr > 0
    info = loader.get_info(baddr)
    assert info.seglist.get_baddr() == baddr
    # unload
    ok = loader.unload_seglist(baddr)
    assert ok
    info = loader.get_info(baddr)
    assert info is None
    assert loader.shutdown() == 0
    assert alloc.is_all_free()