def init_args(self, arg_str, fh): # Tripos makes the input line available as buffered input for ReadItem() fh.setbuf(arg_str) # alloc and fill arg buffer self.arg_len = len(arg_str) self.arg = self.ctx.alloc.alloc_memory(self.bin_basename + "_args", self.arg_len + 1) self.arg_base = self.arg.addr self.ctx.mem.w_cstr(self.arg_base, arg_str) log_proc.info("args: '%s' (%d)", arg_str[:-1], self.arg_len) log_proc.info(self.arg)
def init_stack(self, stack_size): self.stack_size = stack_size self.stack = self.ctx.alloc.alloc_memory(self.bin_basename + "_stack", self.stack_size) self.stack_base = self.stack.addr self.stack_end = self.stack_base + self.stack_size log_proc.info("stack: base=%06x end=%06x", self.stack_base, self.stack_end) log_proc.info(self.stack) # prepare stack # TOP: size # TOP-4: return from program self.stack_initial = self.stack_end - 4 self.ctx.mem.w32(self.stack_initial, self.stack_size) self.stack_initial -= 4
def init_cwd(self, cwd, cwd_lock): self.cwd = cwd if cwd is not None and cwd_lock is None: lock_mgr = self.ctx.dos_lib.lock_mgr dos_list = self.ctx.dos_lib.dos_list entry = dos_list.get_entry_by_name('root') lock = entry.locks[0] self.cwd_lock = lock_mgr.create_lock(lock, cwd, False) log_proc.info("current dir: cwd=%s create lock=%s", cwd, self.cwd_lock) self.cwd_shared = False else: self.cwd_lock = cwd_lock self.cwd_shared = True log_proc.info("current dir: cwd=%s shared lock=%s", cwd, self.cwd_lock)
def init_cli_struct(self, input_fh, output_fh, name): self.cli = self.ctx.alloc.alloc_struct(self.bin_basename + "_CLI", CLIStruct) self.cli.access.w_s("cli_DefaultStack", self.stack_size / 4) # in longs if input_fh != None: self.cli.access.w_s("cli_StandardInput", input_fh.b_addr) self.cli.access.w_s("cli_CurrentInput", input_fh.b_addr) if output_fh != None: self.cli.access.w_s("cli_StandardOutput", output_fh.b_addr) self.cli.access.w_s("cli_CurrentOutput", output_fh.b_addr) self.prompt = self.ctx.alloc.alloc_memory("cli_Prompt", 60) self.cmdname = self.ctx.alloc.alloc_memory("cli_CommandName", 104) self.cmdfile = self.ctx.alloc.alloc_memory("cli_CommandFile", 40) self.setname = self.ctx.alloc.alloc_memory("cli_SetName", 80) self.cli.access.w_s("cli_Prompt", self.prompt.addr) self.cli.access.w_s("cli_CommandName", self.cmdname.addr) self.cli.access.w_s("cli_CommandFile", self.cmdfile.addr) self.cli.access.w_s("cli_SetName", self.setname.addr) if name != None: self.ctx.mem.w_bstr(self.cmdname.addr, name) log_proc.info(self.cli)
def load_binary(self, lock, ami_bin_file, shell=False): self.bin_basename = self.ctx.path_mgr.ami_name_of_path( lock, ami_bin_file) self.bin_file = ami_bin_file sys_path = self.ctx.path_mgr.ami_command_to_sys_path( lock, ami_bin_file) if not sys_path or not os.path.exists(sys_path): log_proc.error("failed loading binary: %s", self.ctx.seg_loader.error) return False self.bin_seg_list = self.ctx.seg_loader.load_seg(sys_path) self.prog_start = self.bin_seg_list.prog_start # THOR: If this is a shell, then the seglist requires BCPL linkage and # initialization of the GlobVec. Fortunately, for the 3.9 shell all this # magic is not really required, and the BCPL call-in (we use) is at # offset +8 if shell: self.prog_start += 8 self.shell_start = self.prog_start log_proc.info("loaded binary: %s", self.bin_seg_list) for seg in self.bin_seg_list.segments: log_proc.info(seg) return True
def free_cwd(self): if self.cwd_lock is not None and not self.cwd_shared: log_proc.info("current_dir: free lock=%s", self.cwd_lock) lock_mgr = self.ctx.dos_lib.lock_mgr lock_mgr.release_lock(self.cwd_lock)