def _open_vamos_fake_lib(self, sane_name, lib_cfg, ctx): """try to setup a fake lib from a given .fd file return new lib or None if creation failed""" # create empty lib lib = AmigaLibrary(sane_name, LibraryDef, lib_cfg) return self._open_vamos_lib(sane_name, lib, ctx)
def _open_vamos_lib(self, sane_name, lib_impl, lib_cfg, ctx): # create lib from impl struct = lib_impl.get_struct_def() is_base = lib_impl.is_base_lib() lib_ctx = self.ctx_map.get_ctx(sane_name) lib = AmigaLibrary(sane_name, struct, lib_cfg, is_base, lib_impl, lib_ctx, self.error_tracker) # now we need an fd file to know about the structure of the lib lib.fd = self._load_fd(sane_name) if lib.fd == None: self.lib_log("create_lib", "can't create vamos lib without FD file: %s" % sane_name, level=logging.ERROR) return None # configure logging of lib lib.config_logging(self.log_call, self.log_dummy_call, self.benchmark, self) # fill in structure from fd self._create_vamos_lib(lib, ctx) # register mappings in manager self._register_lib_name(lib) self._register_lib_base(lib, lib.addr_base) # usage count update lib.inc_usage() return lib
def _load_and_open_native_lib(self, name, sane_name, lib_cfg, ctx): """try to load and open native lib return new lib instance or None if lib was not found""" # create empty lib lib = AmigaLibrary(sane_name, LibraryStruct, lib_cfg) # determine file name from open_name, i.e. prepend LIBS: if no path is found load_name = self._get_load_lib_name(name) self.lib_log("load_lib", "trying to load amiga lib: '%s'" % load_name, level=logging.INFO) # pick current dir lock if available # this allows to resolve relative paths given in load_name cur_dir_lock = None proc = ctx.process if proc is not None: cur_dir_lock = proc.cwd_lock # map ami path of lib to sys_path sys_path = ctx.path_mgr.ami_to_sys_path(cur_dir_lock, load_name, searchMulti=True) # is native lib available in file system? if sys_path and os.path.exists(sys_path): self.lib_log("load_lib", "found amiga lib: '%s'" % load_name) # setup trampoline tr = Trampoline(ctx, "create_lib[%s]" % sane_name) self._create_native_lib(lib, sys_path, ctx, tr) self._open_native_lib_int(lib, ctx, tr) tr.final_rts() tr.done() # do we have an optional fd file for this lib? lib.fd = self._load_fd(sane_name) self._register_lib_name(lib) return lib else: return None
def open_lib(self, name, ver, ctx): """open a new library in memory return new AmigaLibrary instance that is setup or None if lib was not found Note: may prepare a trampoline to finish operation! """ # sanitize lib name sane_name = self._get_sane_lib_name(name) # is lib already opened? if sane_name in self.open_libs_name: self.lib_log("open_lib","opening already open lib: %s" % sane_name) lib = self.open_libs_name[sane_name] if lib.is_native: # call Open() tr = Trampoline(ctx,"open_lib[%s]" % sane_name) self._open_native_lib(lib, ctx, tr) tr.final_rts() tr.done() else: # handle usage count lib.inc_usage() # lib has to be openend else: # first check if its an internal vamos library if sane_name in self.vamos_libs: self.lib_log("open_lib","opening vamos lib: %s" % sane_name) lib = self.vamos_libs[sane_name] is_vamos_lib = True # otherwise create a new and empty AmigaLibrary else: self.lib_log("open_lib","create default lib: %s" % sane_name) lib_cfg = self.cfg.get_lib_config(sane_name) lib = AmigaLibrary(sane_name, LibraryDef, lib_cfg) is_vamos_lib = False # dump config of lib self._dump_lib_cfg(lib.config) # is lib mode = 'off' then reject open mode = lib.config.mode if mode == 'off': self.lib_log("open_lib","reject open: mode='off': %s" % sane_name, level=logging.WARN) return None # try to load an fd file for this lib lib.fd = self._load_fd(sane_name) # is native loading allowed? native_loaded = False native_allowed = mode in ('auto','amiga') if native_allowed: # now check if the library has a native counterpart # if yes then create memory layout with it load_name = self._get_load_lib_name(name) if ctx.seg_loader.can_load_seg(None,load_name): # setup trampoline tr = Trampoline(ctx,"create_lib[%s]" % sane_name) self._create_native_lib(lib, load_name, ctx, tr) self._open_native_lib(lib, ctx, tr) tr.final_rts() tr.done() native_loaded = True # no native lib available... # either its a vamos lib or we auto create one from an FD file if not native_loaded: # we need to have an FD file otherwise we can't create lib if lib.fd == None: self.lib_log("create_lib","can't create auto lib without FD file: %s" % sane_name, level=logging.ERROR) return None # if not 'auto' or 'vamos' then fail now if mode == 'amiga': self.lib_log("open_lib","can't open amiga lib: %s" % sane_name, level=logging.WARN) return None # create a (opt. fake/empty) vamos library self._create_vamos_lib(lib, ctx) self._register_open_lib(lib) lib.inc_usage() self.lib_log("open_lib","leaving open_lib(): %s" % lib, level=logging.DEBUG) return lib
def open_lib(self, name, ver, ctx): """open a new library in memory return new AmigaLibrary instance that is setup or None if lib was not found Note: may prepare a trampoline to finish operation! """ # sanitize lib name sane_name = self._get_sane_lib_name(name) # is lib already opened? if sane_name in self.open_libs_name: self.lib_log("open_lib","opening already open lib: %s" % sane_name) lib = self.open_libs_name[sane_name] if lib.is_native: # call Open() tr = Trampoline(ctx,"open_lib[%s]" % sane_name) self._open_native_lib(lib, ctx, tr) tr.final_rts() tr.done() else: # handle usage count lib.inc_usage() # lib has to be openend else: # first check if its an internal vamos library if sane_name in self.vamos_libs: self.lib_log("open_lib","opening vamos lib: %s" % sane_name) lib = self.vamos_libs[sane_name] is_vamos_lib = True # otherwise create a new and empty AmigaLibrary else: self.lib_log("open_lib","create default lib: %s" % sane_name) lib_cfg = self.cfg.get_lib_config(sane_name) lib = AmigaLibrary(sane_name, LibraryDef, lib_cfg) is_vamos_lib = False # dump config of lib self._dump_lib_cfg(lib.config) # is lib mode = 'off' then reject open mode = lib.config.mode if mode == 'off': self.lib_log("open_lib","reject open: mode='off': %s" % sane_name, level=logging.WARN) return None # try to load an fd file for this lib lib.fd = self._load_fd(sane_name) # is native loading allowed? native_loaded = False native_allowed = mode in ('auto','amiga') if native_allowed: # now check if the library has a native counterpart # if yes then create memory layout with it load_name = self._get_load_lib_name(name) if ctx.seg_loader.can_load_seg(None,load_name,local_path=True): # setup trampoline tr = Trampoline(ctx,"create_lib[%s]" % sane_name) self._create_native_lib(lib, load_name, ctx, tr) self._open_native_lib(lib, ctx, tr) tr.final_rts() tr.done() native_loaded = True # no native lib available... # either its a vamos lib or we auto create one from an FD file if not native_loaded: # we need to have an FD file otherwise we can't create lib if lib.fd == None: self.lib_log("create_lib","can't create auto lib without FD file: %s" % sane_name, level=logging.ERROR) return None # if not 'auto' or 'vamos' then fail now if mode == 'amiga': self.lib_log("open_lib","can't open amiga lib: %s" % sane_name, level=logging.WARN) return None # create a (opt. fake/empty) vamos library self._create_vamos_lib(lib, ctx) self._register_open_lib(lib,None) lib.inc_usage() self.lib_log("open_lib","leaving open_lib(): %s -> %06x" % (lib,lib.addr_base_open), level=logging.DEBUG) return lib