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
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
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
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
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
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)
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)
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) # finally shutdown profiler self.profiler.shutdown() return left_libs + left_devs
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
def open_lib(self, full_name, open_ver=0, lock=None, run_sp=None, mode=None, version=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, open_ver, base_name) # get lib params mode, version = self._get_lib_params(full_name, base_name, mode, version) log_libmgr.info("params: mode=%s, version=%d", mode, version) # handle mode if mode == self.MODE_OFF: return 0 try_vlib, try_alib, fake = self._map_mode(mode) # try vamos first addr = 0 vlib = None if try_vlib: vlib = self.vlib_mgr.open_lib_name(base_name, version=version, fake=fake) 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, lock, run_sp) if addr > 0: log_libmgr.info("got alib: @%06x", addr) # got a lib? check version if addr > 0: save_addr = addr if open_ver > 0: addr = self._check_version(full_name, addr, open_ver) # 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
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
def _dump_lib_cfg(self, lib_name, lib_cfg): items = ["for_lib='%s'" % lib_name, "use_cfg='%s'" % lib_cfg.name] for key in lib_cfg._keys: items.append("%s=%s" % (key, getattr(lib_cfg, key))) log_libmgr.info(" ".join(items))
def open_lib(self, lib_name, lock=None, run_sp=None): log_libmgr.info("[native] +open_lib: lib_name='%s'", lib_name) # 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, lock, run_sp) # 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! 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