def execute(name, real_params, *args): module = __import__(name) # import name, a py file params = [] for i in args: if isinstance(i, tuple): i = i[0] params.append(libirpy.util.FreshBitVec('param', i)) def nop(*args, **kwargs): pass ctx = libirpy.newctx() libirpy.initctx(ctx, module) ctx['globals']['@llvm_lifetime_start'] = nop ctx['globals']['@llvm_lifetime_end'] = nop ctx['globals']['@llvm_lifetime_start_p0i8'] = nop ctx['globals']['@llvm_lifetime_end_p0i8'] = nop expr = ctx.call("@test", *params) subst = [] for v, sym in zip(real_params, params): subst.append((sym, v)) # real params and symbolic params res = z3.simplify(z3.substitute( expr, subst)) # substitution, z3.simplify remove symbolic symbols; # since all symbols are substituted; it simplifies to output return res
def newctx(): ctx = libirpy.newctx() # If we don't need the values of any constants we don't have to # initialize them, slightly faster execution time. ctx.eval.declare_global_constant = ctx.eval.declare_global_variable libirpy.initctx(ctx, counter) return ctx
def newctx(): ctx = libirpy.newctx() # If we don't need the values of any constants we don't have to # initialize them, slightly faster execution time. ctx.eval.declare_global_constant = ctx.eval.declare_global_variable libirpy.initctx(ctx, hv6) ctx.globals['#tlbinv'] = util.FreshFunction('tlbinv', dt.pid_t, dt.bool_t) ctx.globals['#iotlbinv'] = util.FreshBool('iotlbinv') ctx.globals['@panic'] = panic ctx.globals['@bzero'] = bzero ctx.globals['@memset'] = memset ctx.globals['@memcpy'] = memcpy ctx.globals['@putchar'] = putchar ctx.globals['@hvm_set_cr3'] = hvm_set_cr3 ctx.globals['@hvm_copy'] = hvm_copy ctx.globals['@hvm_flush'] = hvm_flush ctx.globals['@hvm_set_timer'] = hvm_set_timer ctx.globals['@hvm_set_io_bitmap'] = hvm_set_io_bitmap ctx.globals['@hvm_invalidate_tlb'] = hvm_invalidate_tlb ctx.globals['@hvm_switch'] = hvm_switch ctx.globals['@pdb'] = pdb ctx.globals['@syslog'] = syslog ### after ctx.globals['@libs_cprintf'] = libs_cprintf # iommu fns ctx.globals['@iommu_set_dev_root'] = iommu_set_dev_root ctx.globals['@iommu_get_dev_root'] = iommu_get_dev_root ctx.globals['@iommu_set_intremap'] = iommu_set_intremap ctx.globals['@iommu_reset_intremap'] = iommu_reset_intremap ctx.globals['@iommu_reset_dev_root'] = iommu_reset_dev_root ctx.globals['@iommu_flush'] = iommu_flush ctx.globals['@iommu_hack_root'] = iommu_hack_root ctx.globals['@iommu_entry'] = iommu_entry ctx.globals['@ms_to_cycles'] = ms_to_cycles # Provide the "integer value" of some globals ctx.ptr_to_int[ctx.globals['@pages']._ref._name] = util.FreshBitVec( '(uintptr)@pages', 64) ctx.ptr_to_int[ctx.globals['@proc_table']._ref._name] = util.FreshBitVec( '(uintptr)@proc_table', 64) ctx.ptr_to_int[ ctx.globals['@page_desc_table']._ref._name] = util.FreshBitVec( '(uintptr)@page_desc_table', 64) ctx.ptr_to_int[ctx.globals['@file_table']._ref._name] = util.FreshBitVec( '(uintptr)@file_table', 64) ctx.ptr_to_int[ctx.globals['@devices']._ref._name] = util.FreshBitVec( '(uintptr)@devices', 64) ctx.ptr_to_int[ctx.globals['@devices']._ref._name] = util.FreshBitVec( '(uintptr)@devices', 64) ctx.ptr_to_int[ctx.globals['@dmapages']._ref._name] = util.FreshBitVec( '(uintptr)@dmapages', 64) return ctx
def newctx(): ctx = libirpy.newctx() # If we don't need the values of any constants we don't have to # initialize them, slightly faster execution time. ctx.eval.declare_global_constant = ctx.eval.declare_global_variable libirpy.initctx(ctx, impl) ctx.globals['@panic'] = panic ctx.globals['@bzero'] = bzero ctx.globals['@memset'] = memset ctx.globals['@memcpy'] = memcpy ctx.globals['@putchar'] = putchar ctx.globals['@pdb'] = pdb ctx.globals['@syslog'] = syslog ctx.globals['@ms_to_cycles'] = ms_to_cycles return ctx
def _irpy(self, name, *args): module = __import__(name) params = [] for i in args: if isinstance(i, tuple): i = i[0] params.append(libirpy.util.FreshBitVec('param', i)) def nop(*args, **kwargs): pass ctx = libirpy.newctx() libirpy.initctx(ctx, module) ctx['globals']['@llvm_lifetime_start'] = nop ctx['globals']['@llvm_lifetime_end'] = nop ctx['globals']['@llvm_lifetime_start_p0i8'] = nop ctx['globals']['@llvm_lifetime_end_p0i8'] = nop expr = ctx.call("@test", *params) return expr, params