Ejemplo n.º 1
0
def _populate_enums():
    module = sys.modules[__name__]
    ctx = libirpy.newctx()
    import hv6py.kernel.impl as hv6
    hv6._init_metadata(ctx)
    for k, v in ctx.metadata.items():
        if isinstance(v, tuple) and v[0] == 'DICompositeType':
            if v[1].get('tag') == 'DW_TAG_enumeration_type':
                name = v[1].get('name')
                size = v[1].get('size')
                elements = v[1].get('elements')

                if name is None or size is None or elements is None:
                    continue

                setattr(module, name + '_t', z3.BitVecSort(size))
                enum = {}

                for element in ctx.metadata.get(elements):
                    element = ctx.metadata.get(element)
                    assert element[0] == 'DIEnumerator'
                    element_name = element[1].get('name')
                    element_value = element[1].get('value')
                    enum[element_name] = z3.BitVecVal(element_value, size)

                setattr(module, name, type(name, (), enum))
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
Archivo: test.py Proyecto: ekiwi/irpy
    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