Exemple #1
0
 def cur_task_callback(self, task):
     log_libmgr.info("current task: %s", task)
     if task:
         proc = task.process
         self.exec_ctx.set_process(proc)
         self.exec_impl.set_this_task(proc)
         self.dos_ctx.set_process(proc)
Exemple #2
0
 def cur_task_callback(self, task):
   log_libmgr.info("current task: %s", task)
   if task:
     proc = task.process
     self.exec_ctx.set_process(proc)
     self.exec_impl.set_this_task(proc)
     self.dos_ctx.set_process(proc)
Exemple #3
0
    def open_lib(
        self, full_name, version=0, cwd_lock=None, run_sp=None, progdir_lock=None
    ):
        """open a library

       return lib_base addr or 0
    """
        # get base name
        base_name = LibLoader.get_lib_base_name(full_name)
        log_libmgr.info(
            "open_lib: '%s' ver=%d -> base_name='%s'", full_name, version, base_name
        )
        # get lib params
        lib_cfg = self.cfg.get_cfg(full_name, base_name)
        log_libmgr.info("-> cfg: %s", lib_cfg)
        # handle mode
        mode = lib_cfg.get_create_mode()
        if mode == LibCfg.CREATE_MODE_OFF:
            return 0
        try_vlib, try_alib, fake = self._map_mode(mode)

        # try vamos first
        addr = 0
        vlib = None
        if try_vlib:
            # get presented version of lib
            lib_version = 0
            force_version = lib_cfg.get_force_version()
            if force_version is not None:
                lib_version = force_version
            log_libmgr.info("vlib: version=%d, fake=%s", lib_version, fake)
            # open vlib
            vlib = self.vlib_mgr.open_lib_name(
                base_name, version=lib_version, fake=fake, lib_cfg=lib_cfg
            )
            if vlib:
                addr = vlib.get_addr()
                log_libmgr.info("got vlib: @%06x", addr)

        # try amiga lib
        if try_alib and addr == 0:
            addr = self.alib_mgr.open_lib(full_name, cwd_lock, run_sp, progdir_lock)
            if addr > 0:
                log_libmgr.info("got alib: @%06x", addr)

        # got a lib? check version
        if addr > 0:
            save_addr = addr
            if version > 0:
                addr = self._check_version(full_name, addr, version)
            # lib is too old: close again
            if addr == 0:
                if vlib:
                    self.vlib_mgr.close_lib(vlib)
                else:
                    self.alib_mgr.close_lib(save_addr, run_sp=run_sp)

        # result lib base
        return addr
Exemple #4
0
  def open_lib(self, full_name, version=0, cwd_lock=None, run_sp=None,
               progdir_lock=None):
    """open a library

       return lib_base addr or 0
    """
    # get base name
    base_name = LibLoader.get_lib_base_name(full_name)
    log_libmgr.info("open_lib: '%s' ver=%d -> base_name='%s'",
                    full_name, version, base_name)
    # get lib params
    lib_cfg = self.cfg.get_cfg(full_name, base_name)
    log_libmgr.info("-> cfg: %s", lib_cfg)
    # handle mode
    mode = lib_cfg.get_create_mode()
    if mode == LibCfg.CREATE_MODE_OFF:
      return 0
    try_vlib, try_alib, fake = self._map_mode(mode)

    # try vamos first
    addr = 0
    vlib = None
    if try_vlib:
      # get presented version of lib
      lib_version = 0
      force_version = lib_cfg.get_force_version()
      if force_version is not None:
        lib_version = force_version
      log_libmgr.info("vlib: version=%d, fake=%s", lib_version, fake)
      # open vlib
      vlib = self.vlib_mgr.open_lib_name(base_name,
                                         version=lib_version,
                                         fake=fake,
                                         lib_cfg=lib_cfg)
      if vlib:
        addr = vlib.get_addr()
        log_libmgr.info("got vlib: @%06x", addr)

    # try amiga lib
    if try_alib and addr == 0:
      addr = self.alib_mgr.open_lib(full_name, cwd_lock, run_sp, progdir_lock)
      if addr > 0:
        log_libmgr.info("got alib: @%06x", addr)

    # got a lib? check version
    if addr > 0:
      save_addr = addr
      if version > 0:
        addr = self._check_version(full_name, addr, version)
      # lib is too old: close again
      if addr == 0:
        if vlib:
          self.vlib_mgr.close_lib(vlib)
        else:
          self.alib_mgr.close_lib(save_addr, run_sp=run_sp)

    # result lib base
    return addr
Exemple #5
0
 def expunge_lib(self, load_addr, run_sp=None):
     log_libmgr.info("[native] +expunge_lib: load=@%06x", load_addr)
     info = self.is_load_addr(load_addr)
     if not info:
         raise ValueError("expunge_lib: invalid lib_load=%06x" % load_addr)
     seglist = self.funcs.rem_library(load_addr, self.segloader, run_sp)
     self._rem_info(load_addr, info, seglist, False)
     log_libmgr.info("[native] -expunge_lib: seglist=%06x, info=%s", seglist, info)
     return seglist
Exemple #6
0
 def bootstrap_exec(self, exec_info=None):
     """setup exec vlib as first and essential lib"""
     version = 0
     lib_cfg = self.cfg.get_lib_cfg("exec.library")
     force_version = lib_cfg.get_force_version()
     if force_version is not None:
         version = force_version
         log_libmgr.info("exec: force version: %s", version)
     return self.vlib_mgr.bootstrap_exec(exec_info, version)
Exemple #7
0
 def close_lib(self, base_addr, run_sp=None):
     log_libmgr.info("[native] +close_lib: base=@%06x", base_addr)
     info = self.is_base_addr(base_addr)
     if not info:
         raise ValueError("close_lib: invalid lib_base=%06x" % base_addr)
     seglist = self.funcs.close_library(base_addr, self.segloader, run_sp)
     self._rem_info(base_addr, info, seglist, True)
     log_libmgr.info("[native] -close_lib: seglist=%06x, info=%s", seglist, info)
     return seglist
Exemple #8
0
 def bootstrap_exec(self, exec_info=None):
   """setup exec vlib as first and essential lib"""
   version = 0
   lib_cfg = self.cfg.get_lib_cfg("exec.library")
   force_version = lib_cfg.get_force_version()
   if force_version is not None:
     version = force_version
     log_libmgr.info("exec: force version: %s", version)
   return self.vlib_mgr.bootstrap_exec(exec_info, version)
Exemple #9
0
 def expunge_lib(self, load_addr, run_sp=None):
   log_libmgr.info("[native] +expunge_lib: load=@%06x", load_addr)
   info = self.is_load_addr(load_addr)
   if not info:
     raise ValueError("expunge_lib: invalid lib_load=%06x" % load_addr)
   seglist = self.funcs.rem_library(load_addr, self.segloader, run_sp)
   self._rem_info(load_addr, info, seglist, False)
   log_libmgr.info("[native] -expunge_lib: seglist=%06x, info=%s",
                   seglist, info)
   return seglist
Exemple #10
0
 def close_lib(self, base_addr, run_sp=None):
   log_libmgr.info("[native] +close_lib: base=@%06x", base_addr)
   info = self.is_base_addr(base_addr)
   if not info:
     raise ValueError("close_lib: invalid lib_base=%06x" % base_addr)
   seglist = self.funcs.close_library(base_addr, self.segloader, run_sp)
   self._rem_info(base_addr, info, seglist, True)
   log_libmgr.info("[native] -close_lib: seglist=%06x, info=%s",
                   seglist, info)
   return seglist
Exemple #11
0
    def expunge_devs(self, run_sp=None):
        """expunge all unused devs

        return number of libs _not_ expunged
        """
        log_libmgr.info("+expunge_devs")
        aleft = 0  # TBD
        vleft = self.vlib_mgr.expunge_devs()
        log_libmgr.info("-expunge_devs: aleft=%d, vleft=%d", aleft, vleft)
        return vleft
Exemple #12
0
  def expunge_devs(self, run_sp=None):
    """expunge all unused devs

       return number of libs _not_ expunged
    """
    log_libmgr.info("+expunge_devs")
    aleft = 0  # TBD
    vleft = self.vlib_mgr.expunge_devs()
    log_libmgr.info("-expunge_devs: aleft=%d, vleft=%d", aleft, vleft)
    return vleft
Exemple #13
0
    def expunge_libs(self, run_sp=None):
        """expunge all unused libs

        return number of libs _not_ expunged
        """
        log_libmgr.info("+expunge_libs")
        aleft = self.alib_mgr.expunge_libs(run_sp)
        vleft = self.vlib_mgr.expunge_libs()
        log_libmgr.info("-expunge_libs: aleft=%d, vleft=%d", aleft, vleft)
        return vleft + aleft
Exemple #14
0
  def expunge_libs(self, run_sp=None):
    """expunge all unused libs

       return number of libs _not_ expunged
    """
    log_libmgr.info("+expunge_libs")
    aleft = self.alib_mgr.expunge_libs(run_sp)
    vleft = self.vlib_mgr.expunge_libs()
    log_libmgr.info("-expunge_libs: aleft=%d, vleft=%d", aleft, vleft)
    return vleft + aleft
Exemple #15
0
 def _check_version(self, name, addr, open_ver):
     # check version
     lib = Library(self.mem, addr)
     lib_ver = lib.version
     if lib_ver < open_ver:
         log_libmgr.warning("lib '%s' has too low version: %d < %d", name,
                            lib_ver, open_ver)
         return 0
     else:
         log_libmgr.info("lib '%s' version %d ok for open version %d", name,
                         lib_ver, open_ver)
         return addr
Exemple #16
0
 def _check_version(self, name, addr, open_ver):
   # check version
   lib = Library(self.mem, addr)
   lib_ver = lib.version
   if lib_ver < open_ver:
     log_libmgr.warn("lib '%s' has too low version: %d < %d",
                     name, lib_ver, open_ver)
     return 0
   else:
     log_libmgr.info("lib '%s' version %d ok for open version %d",
                     name, lib_ver, open_ver)
     return addr
Exemple #17
0
    def close_lib(self, addr, run_sp=None):
        """close a library

        return True if lib was expunged, too
        """
        log_libmgr.info("close_lib: @%06x", addr)
        vlib = self.vlib_mgr.get_vlib_by_addr(addr)
        if vlib:
            return self.vlib_mgr.close_lib(vlib)
        elif self.alib_mgr.is_base_addr(addr):
            seglist = self.alib_mgr.close_lib(addr, run_sp)
            return seglist != 0
        else:
            log_libmgr.error("close: unknown lib @%06x!", addr)
Exemple #18
0
 def _setup_libcall_proxy(self, name, fd, base_addr, run_sp):
     type_name = self._get_proxy_type_name(name)
     # cached proxy?
     proxy_type = self.proxy_cache.get(type_name, None)
     if not proxy_type:
         log_libmgr.info("proxy: create libcall type '%s'", type_name)
         # no, create it
         proxy_type = self.proxy_gen.gen_proxy_for_libcall(type_name, fd)
         self.proxy_cache[type_name] = proxy_type
     # create instance
     ctx = LibCtx(self.lib_mgr.machine)
     log_libmgr.info("proxy: create libcall proxy %s@%08x", type_name,
                     base_addr)
     return proxy_type(ctx, base_addr, run_sp=run_sp)
Exemple #19
0
  def close_lib(self, addr, run_sp=None):
    """close a library

       return True if lib was expunged, too
    """
    log_libmgr.info("close_lib: @%06x", addr)
    vlib = self.vlib_mgr.get_vlib_by_addr(addr)
    if vlib:
      return self.vlib_mgr.close_lib(vlib)
    elif self.alib_mgr.is_base_addr(addr):
      seglist = self.alib_mgr.close_lib(addr, run_sp)
      return seglist != 0
    else:
      log_libmgr.error("close: unknown lib @%06x!", addr)
Exemple #20
0
  def expunge_lib(self, addr, run_sp=None):
    """expunge a library given by base address

       return True if lib was expunged
    """
    log_libmgr.info("expunge_lib: @%06x", addr)
    vlib = self.vlib_mgr.get_vlib_by_addr(addr)
    if vlib:
      return self.vlib_mgr.expunge_lib(vlib)
    elif self.alib_mgr.is_load_addr(addr):
      seglist = self.alib_mgr.expunge_lib(addr, run_sp)
      return seglist != 0
    else:
      log_libmgr.error("expunge: unknown lib @%06x!", addr)
Exemple #21
0
    def expunge_lib(self, addr, run_sp=None):
        """expunge a library given by base address

        return True if lib was expunged
        """
        log_libmgr.info("expunge_lib: @%06x", addr)
        vlib = self.vlib_mgr.get_vlib_by_addr(addr)
        if vlib:
            return self.vlib_mgr.expunge_lib(vlib)
        elif self.alib_mgr.is_load_addr(addr):
            seglist = self.alib_mgr.expunge_lib(addr, run_sp)
            return seglist != 0
        else:
            log_libmgr.error("expunge: unknown lib @%06x!", addr)
Exemple #22
0
    def shutdown(self):
        """cleanup libs

    try to expunge all libs and report still open ones
    """
        log_libmgr.info("[vamos] +shutdown")
        # dec exec's open cnt
        self.exec_lib.lib_node.dec_open_cnt()
        # now expunge all libs
        left_libs = self.expunge_libs()
        left_devs = self.expunge_devs()
        log_libmgr.info("[vamos] +shutdown: left libs=%d, devs=%d", left_libs,
                        left_devs)
        return left_libs + left_devs
Exemple #23
0
    def shutdown(self, run_sp=None):
        """cleanup libs

    try to expunge all libs and report still open ones
    """
        log_libmgr.info("+shutdown")
        aleft = self.alib_mgr.shutdown(run_sp)
        if aleft > 0:
            log_libmgr.warning("shutdown: can't expunge %d amiga libs/devs!", aleft)
        vleft = self.vlib_mgr.shutdown()
        if vleft > 0:
            log_libmgr.warning("shutdown: can't expunge %d vamos libs/devs!", vleft)
        left = vleft + aleft
        log_libmgr.info("-shutdwon: aleft=%d, vleft=%d", aleft, vleft)
        return left
Exemple #24
0
 def _setup_stub_proxy(self, vlib, base_addr):
     name = vlib.info.name
     type_name = self._get_proxy_type_name(name)
     # cached proxy?
     proxy_type = self.proxy_cache.get(type_name, None)
     if not proxy_type:
         log_libmgr.info("proxy: create stub type '%s'", type_name)
         # no, create it
         proxy_type = self.proxy_gen.gen_proxy_for_stub(
             type_name, vlib.fd, vlib.stub)
         self.proxy_cache[type_name] = proxy_type
     # create instance
     log_libmgr.info("proxy: create stub proxy %s@%08x", type_name,
                     base_addr)
     return proxy_type(vlib.ctx, base_addr)
Exemple #25
0
  def shutdown(self, run_sp=None):
    """cleanup libs

    try to expunge all libs and report still open ones
    """
    log_libmgr.info("+shutdown")
    aleft = self.alib_mgr.shutdown(run_sp)
    if aleft > 0:
      log_libmgr.warn("shutdown: can't expunge %d amiga libs/devs!", aleft)
    vleft = self.vlib_mgr.shutdown()
    if vleft > 0:
      log_libmgr.warn("shutdown: can't expunge %d vamos libs/devs!", vleft)
    left = vleft + aleft
    log_libmgr.info("-shutdwon: aleft=%d, vleft=%d", aleft, vleft)
    return left
Exemple #26
0
 def close_base_libs(self):
     log_libmgr.info("closing base libs...")
     # close dos
     self.lib_mgr.close_lib(self.dos_addr)
     log_libmgr.info("closed dos")
     # close exec
     self.lib_mgr.close_lib(self.exec_addr)
     log_libmgr.info("closed exec")
Exemple #27
0
 def close_base_libs(self):
   log_libmgr.info("closing base libs...")
   # close dos
   self.lib_mgr.close_lib(self.dos_addr)
   log_libmgr.info("closed dos")
   # close exec
   self.lib_mgr.close_lib(self.exec_addr)
   log_libmgr.info("closed exec")
Exemple #28
0
 def expunge_libs(self, run_sp=None):
   """return number of libs still left unexpunged"""
   log_libmgr.info("[native] +expunge_libs")
   left_libs = 0
   for lib_info in self.lib_infos:
     log_libmgr.info("expunging: %s", lib_info)
     load_addr = lib_info.get_load_addr()
     seglist = self.expunge_lib(load_addr, run_sp)
     if not seglist:
       left_libs += 1
   log_libmgr.info("[native] -expunge_libs: %d left", left_libs)
   return left_libs
Exemple #29
0
 def open_base_libs(self):
   log_libmgr.info("opening base libs...")
   # first bootstrap exec
   self.lib_mgr.bootstrap_exec()
   # open exec lib
   self.exec_addr = self.lib_mgr.open_lib('exec.library', 0)
   self.exec_vlib = self.lib_mgr.get_vlib_by_addr(self.exec_addr)
   self.exec_impl = self.exec_vlib.get_impl()
   log_libmgr.info("open base lib: exec: @%06x", self.exec_addr)
   # link exec to dos
   self.dos_ctx.set_exec_lib(self.exec_impl)
   # open dos lib
   self.dos_addr = self.lib_mgr.open_lib('dos.library', 0)
   self.dos_vlib = self.lib_mgr.get_vlib_by_addr(self.dos_addr)
   self.dos_impl = self.dos_vlib.get_impl()
   self.dos_ctx.set_dos_lib(self.dos_impl)
   log_libmgr.info("open base lib: dos:  @%06x", self.dos_addr)
Exemple #30
0
 def open_base_libs(self):
     log_libmgr.info("opening base libs...")
     # first bootstrap exec
     self.lib_mgr.bootstrap_exec()
     # open exec lib
     self.exec_addr = self.lib_mgr.open_lib("exec.library", 0)
     self.exec_vlib = self.lib_mgr.get_vlib_by_addr(self.exec_addr)
     self.exec_impl = self.exec_vlib.get_impl()
     log_libmgr.info("open base lib: exec: @%06x", self.exec_addr)
     # link exec to dos
     self.dos_ctx.set_exec_lib(self.exec_impl)
     # open dos lib
     self.dos_addr = self.lib_mgr.open_lib("dos.library", 0)
     self.dos_vlib = self.lib_mgr.get_vlib_by_addr(self.dos_addr)
     self.dos_impl = self.dos_vlib.get_impl()
     self.dos_ctx.set_dos_lib(self.dos_impl)
     log_libmgr.info("open base lib: dos:  @%06x", self.dos_addr)
Exemple #31
0
 def open_base_libs(self):
     log_libmgr.info("opening base libs...")
     # open exec lib
     self.exec_addr = self.lib_mgr.open_lib('exec.library', 0)
     self.exec_vlib = self.lib_mgr.get_vlib_by_addr(self.exec_addr)
     self.exec_impl = self.exec_vlib.get_impl()
     log_libmgr.info("open base lib: exec: @%06x", self.exec_addr)
     # link exec to dos
     self.dos_ctx.set_exec_lib(self.exec_impl)
     # open dos lib
     self.dos_addr = self.lib_mgr.open_lib('dos.library', 0)
     self.dos_vlib = self.lib_mgr.get_vlib_by_addr(self.dos_addr)
     self.dos_impl = self.dos_vlib.get_impl()
     self.dos_ctx.set_dos_lib(self.dos_impl)
     log_libmgr.info("open base lib: dos:  @%06x", self.dos_addr)
     # set exec base @4
     log_libmgr.debug("setting execbase @4")
     self.machine.set_zero_mem(0, self.exec_addr)
Exemple #32
0
 def open_lib(self, lib_name, cwd_lock=None, run_sp=None, progdir_lock=None):
   log_libmgr.info("[native] +open_lib: lib_name='%s', cwd=%s, progdir=%s",
                   lib_name, cwd_lock, progdir_lock)
   # multict lib base name
   base_name = self.loader.get_lib_base_name(lib_name)
   # find library
   lib_info = self._find_info(base_name)
   log_libmgr.info("find: '%s' -> %s", base_name, lib_info)
   # not found... try to load it
   if not lib_info:
     log_libmgr.info("loading native lib: '%s'", lib_name)
     load_addr, seglist_baddr = self.loader.load_ami_lib(
         lib_name, cwd_lock, run_sp, progdir_lock)
     # even loading failed... abort
     if load_addr == 0:
       log_libmgr.info("[native] -open_lib: load failed!")
       return 0
     log_libmgr.info("loaded: @%06x  seglist: @%06x",
                     load_addr, seglist_baddr)
     info = self.segloader.get_info(seglist_baddr)
     log_libmgr.info("loaded: %s", info)
     # store original load addr and name in info
     lib_info = self._add_info(base_name, load_addr, seglist_baddr)
     loaded = True
   else:
     load_addr = lib_info.get_load_addr()
     loaded = False
   # got lib: open lib... may return new base!
   log_libmgr.debug("[native] call open lib: load_addr=%06x", load_addr)
   lib_base = self.funcs.open_library(load_addr, run_sp)
   # save base addr
   if lib_base > 0:
     lib_info.add_base_addr(lib_base)
   elif loaded:
     # remove lib info again
     self.lib_infos.remove(lib_info)
   log_libmgr.info("[native] -open_lib: load_addr=@%06x, lib_base=@%06x, %s",
                   load_addr, lib_base, lib_info)
   # return base
   return lib_base