Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
miasm2.jitter.jitcore_tcc.JitCore_Tcc Class Reference
+ Inheritance diagram for miasm2.jitter.jitcore_tcc.JitCore_Tcc:
+ Collaboration diagram for miasm2.jitter.jitcore_tcc.JitCore_Tcc:

Public Member Functions

def __init__
 
def deleteCB
 
def load
 
def __del__
 
def jitirblocs
 
def set_options
 
def add_disassembly_splits
 
def remove_disassembly_splits
 
def load
 
def get_bloc_min_max
 
def add_bloc_to_mem_interval
 
def add_bloc
 
def disbloc
 
def jit_call
 
def runbloc
 
def blocs2memrange
 
def del_bloc_in_range
 
def updt_automod_code
 
def automod_cb
 

Public Attributes

 jitted_block_delete_cb
 
 resolver
 
 exec_wrapper
 
 tcc_states
 
 ir_arch
 
 bs
 
 known_blocs
 
 lbl2jitbloc
 
 lbl2bloc
 
 log_mn
 
 log_regs
 
 log_newbloc
 
 segm_to_do
 
 job_done
 
 jitcount
 
 addr2obj
 
 addr2objref
 
 blocs_mem_interval
 
 disasm_cb
 
 split_dis
 
 addr_mod
 
 options
 

Static Public Attributes

int jitted_block_max_size = 10000
 

Detailed Description

Definition at line 91 of file jitcore_tcc.py.

Constructor & Destructor Documentation

def miasm2.jitter.jitcore_tcc.JitCore_Tcc.__init__ (   self,
  ir_arch,
  bs = None 
)
def miasm2.jitter.jitcore_tcc.JitCore_Tcc.__del__ (   self)

Definition at line 135 of file jitcore_tcc.py.

136  def __del__(self):
137  for tcc_state in self.tcc_states.values():
138  Jittcc.tcc_end(tcc_state)

Member Function Documentation

def miasm2.jitter.jitcore.JitCore.add_bloc (   self,
  b 
)
inherited
Add a bloc to JiT and JiT it.
@b: the bloc to add

Definition at line 102 of file jitcore.py.

103  def add_bloc(self, b):
104  """Add a bloc to JiT and JiT it.
105  @b: the bloc to add
106  """
107 
108  irblocs = self.ir_arch.add_bloc(b, gen_pc_updt = True)
109  b.irblocs = irblocs
110  self.jitirblocs(b.label, irblocs)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.add_bloc_to_mem_interval (   self,
  vm,
  bloc 
)
inherited

Definition at line 85 of file jitcore.py.

85 
86  def add_bloc_to_mem_interval(self, vm, bloc):
87  "Update vm to include bloc addresses in its memory range"
88 
89  self.blocs_mem_interval += interval([(bloc.ad_min, bloc.ad_max - 1)])
90 
91  vm.reset_code_bloc_pool()
92  for a, b in self.blocs_mem_interval:
93  vm.add_code_bloc(a, b + 1)

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.add_disassembly_splits (   self,
  args 
)
inherited
The disassembly engine will stop on address in args if they
are not at the block beginning

Definition at line 64 of file jitcore.py.

64 
65  def add_disassembly_splits(self, *args):
66  """The disassembly engine will stop on address in args if they
67  are not at the block beginning"""
68  self.split_dis.update(set(args))
def miasm2.jitter.jitcore.JitCore.automod_cb (   self,
  addr = 0,
  size = 0 
)
inherited

Definition at line 260 of file jitcore.py.

261  def automod_cb(self, addr=0, size=0):
262  self.addr_mod += interval([(addr, addr + size / 8 - 1)])
263  return None
def miasm2.jitter.jitcore.JitCore.blocs2memrange (   self,
  blocs 
)
inherited
Return an interval instance standing for blocs addresses
@blocs: list of asm_bloc instances

Definition at line 183 of file jitcore.py.

184  def blocs2memrange(self, blocs):
185  """Return an interval instance standing for blocs addresses
186  @blocs: list of asm_bloc instances
187  """
188 
189  mem_range = interval()
190 
191  for b in blocs:
192  mem_range += interval([(b.ad_min, b.ad_max - 1)])
193 
194  return mem_range

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.del_bloc_in_range (   self,
  ad1,
  ad2 
)
inherited
Find and remove jitted bloc in range [ad1, ad2].
Return the list of bloc removed.
@ad1: First address
@ad2: Last address

Definition at line 207 of file jitcore.py.

208  def del_bloc_in_range(self, ad1, ad2):
209  """Find and remove jitted bloc in range [ad1, ad2].
210  Return the list of bloc removed.
211  @ad1: First address
212  @ad2: Last address
213  """
214 
215  # Find concerned blocs
216  modified_blocs = set()
217  for b in self.lbl2bloc.values():
218  if not b.lines:
219  continue
220  if b.ad_max <= ad1 or b.ad_min >= ad2:
221  # Bloc not modified
222  pass
223  else:
224  # Modified blocs
225  modified_blocs.add(b)
226 
227  # Generate interval to delete
228  del_interval = self.blocs2memrange(modified_blocs)
229 
230  # Remove interval from monitored interval list
231  self.blocs_mem_interval -= del_interval
232 
233  # Remove modified blocs
234  for b in modified_blocs:
235  try:
236  for irbloc in b.irblocs:
237 
238  # Remove offset -> jitted bloc link
239  if irbloc.label.offset in self.lbl2jitbloc:
240  del(self.lbl2jitbloc[irbloc.label.offset])
241 
242  except AttributeError:
243  # The bloc has never been translated in IR
244  if b.label.offset in self.lbl2jitbloc:
245  del(self.lbl2jitbloc[b.label.offset])
246 
247  # Remove label -> bloc link
248  del(self.lbl2bloc[b.label])
249 
250  return modified_blocs

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore_tcc.JitCore_Tcc.deleteCB (   self,
  offset 
)

Definition at line 103 of file jitcore_tcc.py.

104  def deleteCB(self, offset):
105  "Free the TCCState corresponding to @offset"
106  if offset in self.tcc_states:
107  Jittcc.tcc_end(self.tcc_states[offset])
108  del self.tcc_states[offset]
def miasm2.jitter.jitcore.JitCore.disbloc (   self,
  addr,
  cpu,
  vm 
)
inherited

Definition at line 111 of file jitcore.py.

112  def disbloc(self, addr, cpu, vm):
113  "Disassemble a new bloc and JiT it"
114 
115  # Get the bloc
116  if isinstance(addr, asmbloc.asm_label):
117  addr = addr.offset
118 
119  l = self.ir_arch.symbol_pool.getby_offset_create(addr)
120  cur_bloc = asmbloc.asm_bloc(l)
121 
122  # Disassemble it
123  try:
124  asmbloc.dis_bloc(self.ir_arch.arch, self.bs, cur_bloc, addr,
125  set(), self.ir_arch.symbol_pool, [],
126  follow_call=False, dontdis_retcall=False,
127  lines_wd=self.options["jit_maxline"],
128  # max 10 asm lines
129  attrib=self.ir_arch.attrib,
130  split_dis=self.split_dis)
131  except IOError:
132  # vm_exception_flag is set
133  pass
134 
135  # Logging
136  if self.log_newbloc:
137  print cur_bloc
138  if self.disasm_cb is not None:
139  self.disasm_cb(cur_bloc)
140 
141  # Check for empty blocks
142  if not cur_bloc.lines:
143  raise ValueError("Cannot JIT a block without any assembly line")
144 
145  # Update label -> bloc
146  self.lbl2bloc[l] = cur_bloc
147 
148  # Store min/max bloc address needed in jit automod code
149  self.get_bloc_min_max(cur_bloc)
150 
151  # JiT it
152  self.add_bloc(cur_bloc)
153 
154  # Update jitcode mem range
155  self.add_bloc_to_mem_interval(vm, cur_bloc)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.get_bloc_min_max (   self,
  cur_bloc 
)
inherited

Definition at line 78 of file jitcore.py.

78 
79  def get_bloc_min_max(self, cur_bloc):
80  "Update cur_bloc to set min/max address"
81 
82  if cur_bloc.lines:
83  cur_bloc.ad_min = cur_bloc.lines[0].offset
84  cur_bloc.ad_max = cur_bloc.lines[-1].offset + cur_bloc.lines[-1].l

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore.JitCore.jit_call (   self,
  label,
  cpu,
  _vmmngr,
  breakpoints 
)
inherited
Call the function label with cpu and vmmngr states
@label: function's label
@cpu: JitCpu instance
@breakpoints: Dict instance of used breakpoints

Definition at line 156 of file jitcore.py.

157  def jit_call(self, label, cpu, _vmmngr, breakpoints):
158  """Call the function label with cpu and vmmngr states
159  @label: function's label
160  @cpu: JitCpu instance
161  @breakpoints: Dict instance of used breakpoints
162  """
163  return self.exec_wrapper(label, cpu, self.lbl2jitbloc.data, breakpoints)

+ Here is the caller graph for this function:

def miasm2.jitter.jitcore_tcc.JitCore_Tcc.jitirblocs (   self,
  label,
  irblocs 
)

Definition at line 139 of file jitcore_tcc.py.

140  def jitirblocs(self, label, irblocs):
141  f_name = "bloc_%s" % label.name
142  f_declaration = 'int %s(block_id * BlockDst, JitCpu* jitcpu)' % f_name
143  out = irblocs2C(self.ir_arch, self.resolver, label, irblocs,
144  gen_exception_code=True,
145  log_mn=self.log_mn,
146  log_regs=self.log_regs)
147  out = [f_declaration + '{'] + out + ['}\n']
148  c_code = out
149 
150  func_code = gen_C_source(self.ir_arch, c_code)
151 
152  # open('tmp_%.4d.c'%self.jitcount, "w").write(func_code)
153  self.jitcount += 1
154  tcc_state, mcode = jit_tcc_compil(f_name, func_code)
155  jcode = jit_tcc_code(mcode)
156  self.lbl2jitbloc[label.offset] = mcode
157  self.tcc_states[label.offset] = tcc_state
158  self.addr2obj[label.offset] = jcode
159  self.addr2objref[label.offset] = objref(jcode)
def irblocs2C
Definition: ir2C.py:408

+ Here is the call graph for this function:

def miasm2.jitter.jitcore.JitCore.load (   self,
  arch,
  attrib 
)
inherited

Definition at line 73 of file jitcore.py.

73 
74  def load(self, arch, attrib):
75  "Initialise the Jitter according to arch and attrib"
76 
77  raise NotImplementedError("Abstract class")
def miasm2.jitter.jitcore_tcc.JitCore_Tcc.load (   self)

Definition at line 109 of file jitcore_tcc.py.

110  def load(self):
111  # os.path.join(os.path.dirname(os.path.realpath(__file__)), "jitter")
112  lib_dir = os.path.dirname(os.path.realpath(__file__))
113  libs = []
114  libs.append(os.path.join(lib_dir, 'VmMngr.so'))
115  libs.append(os.path.join(lib_dir, 'arch/JitCore_%s.so' % (self.ir_arch.arch.name)))
116  libs = ';'.join(libs)
117  jittcc_path = Jittcc.__file__
118  include_dir = os.path.dirname(jittcc_path)
119  include_dir += ";" + os.path.join(include_dir, "arch")
120  # print include_dir
121 
122  # XXX HACK
123  # As debian/ubuntu have moved some include files using arch directory,
124  # TCC doesn't know them, so we get the info from GCC
125  # For example /usr/include/x86_64-linux-gnu which contains limits.h
126  p = Popen(["cc", "-Wp,-v", "-E", "-"],
127  stdout=PIPE, stderr=PIPE, stdin=PIPE)
128  p.stdin.close()
129  include_files = p.stderr.read().split('\n')
130  include_files = [x[1:]
131  for x in include_files if x.startswith(' /usr/include')]
132  include_files += [include_dir, get_python_inc()]
133  include_files = ";".join(include_files)
134  Jittcc.tcc_set_emul_lib_path(include_files, libs)
def miasm2.jitter.jitcore.JitCore.remove_disassembly_splits (   self,
  args 
)
inherited
The disassembly engine will no longer stop on address in args

Definition at line 69 of file jitcore.py.

69 
70  def remove_disassembly_splits(self, *args):
71  """The disassembly engine will no longer stop on address in args"""
72  self.split_dis.difference_update(set(args))
def miasm2.jitter.jitcore.JitCore.runbloc (   self,
  cpu,
  vm,
  lbl,
  breakpoints 
)
inherited
Run the bloc starting at lbl.
@cpu: JitCpu instance
@vm: VmMngr instance
@lbl: target label

Definition at line 164 of file jitcore.py.

165  def runbloc(self, cpu, vm, lbl, breakpoints):
166  """Run the bloc starting at lbl.
167  @cpu: JitCpu instance
168  @vm: VmMngr instance
169  @lbl: target label
170  """
171 
172  if lbl is None:
173  lbl = cpu.get_gpreg()[self.ir_arch.pc.name]
174 
175  if not lbl in self.lbl2jitbloc:
176  # Need to JiT the bloc
177  self.disbloc(lbl, cpu, vm)
178 
179  # Run the bloc and update cpu/vmmngr state
180  ret = self.jit_call(lbl, cpu, vm, breakpoints)
181 
182  return ret

+ Here is the call graph for this function:

def miasm2.jitter.jitcore.JitCore.set_options (   self,
  kwargs 
)
inherited

Definition at line 59 of file jitcore.py.

59 
60  def set_options(self, **kwargs):
61  "Set options relative to the backend"
62 
63  self.options.update(kwargs)
def miasm2.jitter.jitcore.JitCore.updt_automod_code (   self,
  vm 
)
inherited
Remove code jitted in range self.addr_mod
@vm: VmMngr instance

Definition at line 251 of file jitcore.py.

252  def updt_automod_code(self, vm):
253  """Remove code jitted in range self.addr_mod
254  @vm: VmMngr instance
255  """
256  for addr_start, addr_stop in self.addr_mod:
257  self.del_bloc_in_range(addr_start, addr_stop + 1)
258  self.__updt_jitcode_mem_range(vm)
259  self.addr_mod = interval()

+ Here is the call graph for this function:

Member Data Documentation

miasm2.jitter.jitcore.JitCore.addr2obj
inherited

Definition at line 49 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.addr2objref
inherited

Definition at line 50 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.addr_mod
inherited

Definition at line 54 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.blocs_mem_interval
inherited

Definition at line 51 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.bs
inherited

Definition at line 38 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.disasm_cb
inherited

Definition at line 52 of file jitcore.py.

miasm2.jitter.jitcore_tcc.JitCore_Tcc.exec_wrapper

Definition at line 99 of file jitcore_tcc.py.

miasm2.jitter.jitcore_tcc.JitCore_Tcc.ir_arch

Definition at line 101 of file jitcore_tcc.py.

miasm2.jitter.jitcore.JitCore.jitcount
inherited

Definition at line 48 of file jitcore.py.

miasm2.jitter.jitcore_tcc.JitCore_Tcc.jitted_block_delete_cb

Definition at line 96 of file jitcore_tcc.py.

int miasm2.jitter.jitcore.JitCore.jitted_block_max_size = 10000
staticinherited

Definition at line 29 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.job_done
inherited

Definition at line 47 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.known_blocs
inherited

Definition at line 39 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.lbl2bloc
inherited

Definition at line 42 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.lbl2jitbloc
inherited

Definition at line 40 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.log_mn
inherited

Definition at line 43 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.log_newbloc
inherited

Definition at line 45 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.log_regs
inherited

Definition at line 44 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.options
inherited

Definition at line 56 of file jitcore.py.

miasm2.jitter.jitcore_tcc.JitCore_Tcc.resolver

Definition at line 98 of file jitcore_tcc.py.

miasm2.jitter.jitcore.JitCore.segm_to_do
inherited

Definition at line 46 of file jitcore.py.

miasm2.jitter.jitcore.JitCore.split_dis
inherited

Definition at line 53 of file jitcore.py.

miasm2.jitter.jitcore_tcc.JitCore_Tcc.tcc_states

Definition at line 100 of file jitcore_tcc.py.


The documentation for this class was generated from the following file: