Beispiel #1
0
    def setUp(self):
        super(TestMacroType, self).setUp()
        name = type(self).__name__

        hdr = Header(name.lower() + ".h")
        hdr.add_type(Macro("QTAIL_ENTRY", args=["type"]))

        struct = Structure("StructA")
        struct.append_fields([
            Type["QTAIL_ENTRY"]("entry",
                                macro_initializer=Initializer({"type":
                                                               struct})),
            Pointer(struct)("next")
        ])
        hdr.add_type(struct)

        hdr_content = """\
/* {path} */
#ifndef INCLUDE_{fname_upper}_H
#define INCLUDE_{fname_upper}_H

#define QTAIL_ENTRY(type)

typedef struct StructA StructA;

struct StructA {{
    QTAIL_ENTRY(StructA) entry;
    StructA *next;
}};

#endif /* INCLUDE_{fname_upper}_H */
""".format(path=hdr.path, fname_upper=name.upper())

        self.files = [(hdr, hdr_content)]
Beispiel #2
0
    def setUp(self):
        super(TestNamelessStructure, self).setUp()
        name = type(self).__name__

        hdr = Header(name.lower() + ".h")
        hdr.add_type(Structure("a"))
        hdr.add_type(Structure("b", Type["int"]("f")))
        hdr.add_type(
            Structure(
                "c",
                Structure(None, Type["int"]("f2"),
                          Structure()("f3"))("f1")))

        hdr_content = """\
/* {path} */
#ifndef INCLUDE_{fname_upper}_H
#define INCLUDE_{fname_upper}_H

typedef struct a {{}} a;

typedef struct b {{
    int f;
}} b;

typedef struct c {{
    struct {{
        int f2;
        struct {{}} f3;
    }} f1;
}} c;

#endif /* INCLUDE_{fname_upper}_H */
""".format(path=hdr.path, fname_upper=name.upper())

        self.files = [(hdr, hdr_content)]
Beispiel #3
0
    def setUp(self):
        super(TestCrossDeclaration, self).setUp()

        src = Source(type(self).__name__.lower() + ".c")

        a = Structure("A")
        b = Structure("B")

        b.append_field(Pointer(a)("ref"))
        a.append_field(Pointer(b)("ref"))

        src.add_types([a, b])

        src_content = """\
/* {} */

typedef struct B B;

typedef struct A {{
    B *ref;
}} A;

struct B {{
    A *ref;
}};

""".format(src.path)

        self.files = [(src, src_content)]
Beispiel #4
0
    def setUp(self):
        super(TestForwardDeclaration, self).setUp()
        name = type(self).__name__

        src = Source(name.lower() + ".c")

        a = Structure("A")
        a.append_field(Pointer(a)("next"))

        b = Structure("B")
        b.append_field(Pointer(a)("next"))

        src.add_types([a, b])

        src_content = """\
/* {} */

typedef struct A A;

struct A {{
    A *next;
}};

typedef struct B {{
    A *next;
}} B;

""".format(src.path)

        self.files = [(src, src_content)]
Beispiel #5
0
    def setUp(self):
        super(TestRedirectionToDeclaration, self).setUp()
        name = type(self).__name__

        private_h = Header("private.h")
        private_h.add_type(Structure("Private"))

        public_h = Header("public.h")
        public_h.add_types([
            Type["Private"].gen_forward_declaration(),
            Function("public_func")
        ])

        private_c = Source("private.c")
        public_func_impl = Type["public_func"].gen_definition()
        private_c.add_type(public_func_impl)

        src = Source(name.lower() + ".c").add_global_variable(
            # It must internally re-direct pointer from type "Private"
            # to "Private.declaration", its forward declaration.
            Pointer(Type["Private"])("handler"))
        src.add_type(Pointer(public_func_impl, name="cb_ptr"))

        src_content = """\
/* %s */

#include "public.h"

typedef void (*cb_ptr)(void);
Private *handler __attribute__((unused));

""" % (name.lower() + ".c")

        self.files = [(src, src_content)]
Beispiel #6
0
    def setUp(self):
        super(TestPointerReferences, self).setUp()
        name = type(self).__name__

        try:
            h = Header["type_a.h"]
        except:
            h = Header("type_a.h")
        h.add_type(Type("a", incomplete=False, base=False))

        src = Source(name.lower() + ".c").add_type(
            Structure("s",
                      Pointer(Type["a"])("next")))

        src_content = """\
/* {} */

#include "type_a.h"

typedef struct s {{
    a *next;
}} s;

""".format(src.path)

        self.files = [(src, src_content)]
Beispiel #7
0
    def setUp(self):
        super(TestAddingTypeToLockedHeader, self).setUp()
        name = type(self).__name__

        Header("some_types.h").add_type(Type("t"))

        # Without locking "some_types.h" header will be included in
        # "lockedheader.h".
        Header("lockedheader.h",
               locked=True).add_type(Structure("S",
                                               Pointer(Type["t"])("f")))

        hdr = Header(name.lower() + ".h")
        hdr.add_type(Pointer(Type["S"], name="ps"))

        hdr_content = """\
/* {path} */
#ifndef INCLUDE_{fname_upper}_H
#define INCLUDE_{fname_upper}_H

#include "some_types.h"
#include "lockedheader.h"

typedef S *ps;
#endif /* INCLUDE_{fname_upper}_H */
""".format(path=hdr.path, fname_upper=name.upper())

        self.files = [(hdr, hdr_content)]
Beispiel #8
0
    def setUp(self):
        super(TestMacroType, self).setUp()
        name = type(self).__name__

        Header("entry_macro.h").add_type(Macro("QTAIL_ENTRY", args=["type"]))
        Header("struct_end.h").add_type(Macro("END_STRUCT"))
        Header("header_init.h").add_type(Macro("INIT_HEADER"))

        hdr = Header(name.lower() + ".h")
        struct = Structure("StructA")
        struct.append_fields([
            Type["QTAIL_ENTRY"]("entry",
                                macro_initializer=Initializer({"type":
                                                               struct})),
            Pointer(struct)("next"), Type["END_STRUCT"].gen_type()
        ])
        hdr.add_type(struct)

        hdr.add_type(Type["INIT_HEADER"].gen_type())

        hdr_content = """\
/* {path} */
#ifndef INCLUDE_{fname_upper}_H
#define INCLUDE_{fname_upper}_H

#include "entry_macro.h"
#include "header_init.h"
#include "struct_end.h"

typedef struct StructA StructA;

struct StructA {{
    QTAIL_ENTRY(StructA) entry;
    StructA *next;
    END_STRUCT
}};

INIT_HEADER
#endif /* INCLUDE_{fname_upper}_H */
""".format(path=hdr.path, fname_upper=name.upper())

        self.files = [(hdr, hdr_content)]
Beispiel #9
0
    def setUp(self):
        super(TestForwardDeclarationHeader, self).setUp()
        name = type(self).__name__

        hdr = Header(name.lower() + ".h")
        src = Source(name.lower() + ".c")

        a = Structure("A")
        a.append_field(Pointer(a)("next"))

        b = Structure("B")
        b.append_field(Pointer(a)("next"))

        hdr.add_type(a)
        hdr_content = """\
/* {path} */
#ifndef INCLUDE_{fname_upper}_H
#define INCLUDE_{fname_upper}_H

typedef struct A A;

struct A {{
    A *next;
}};

#endif /* INCLUDE_{fname_upper}_H */
""".format(path=hdr.path, fname_upper=name.upper())

        src.add_type(b)
        src_content = """\
/* {} */

#include "{}"

typedef struct B {{
    A *next;
}} B;

""".format(src.path, hdr.path)

        self.files = [(hdr, hdr_content), (src, src_content)]
Beispiel #10
0
    def setUp(self):
        super(TestGlobalHeadersInclusion, self).setUp()
        name = type(self).__name__

        hg = Header("global_types.h", is_global=True)
        hl = Header("local_types.h")

        hg.add_type(Type("GT", incomplete=False))
        hl.add_type(Type("LT", incomplete=False))

        hdr = Header(name.lower() + ".h").add_type(
            Structure("Fields", Type["GT"]("f1"), Type["LT"]("f2")))

        hdr_content = """\
/* {path} */
#ifndef INCLUDE_{fname_upper}_H
#define INCLUDE_{fname_upper}_H

#include "local_types.h"

typedef struct Fields {{
    GT f1;
    LT f2;
}} Fields;

#endif /* INCLUDE_{fname_upper}_H */
""".format(path=hdr.path, fname_upper=name.upper())

        src = Source(name.lower() + ".c").add_global_variable(
            Type["Fields"]("fv"))

        src_content = """\
/* {} */

#include <global_types.h>
#include "{}"

Fields fv __attribute__((unused));

""".format(src.path, hdr.path)

        self.files = [(hdr, hdr_content), (src, src_content)]
Beispiel #11
0
    def setUp(self):
        super(TestReferencingToTypeInAnotherHeader, self).setUp()
        name = type(self).__name__

        hdr = Header(name.lower() + ".h")

        h1 = Header("some_types.h")
        h2 = Header("another_some_types.h")

        h1.add_type(Type("f1", incomplete=False))
        h2.add_type(Type("f2", incomplete=False))

        # Without reference headers `another_some_types` and `some_types` would
        # be in alphabetical order.
        h2.add_reference(Type["f1"])

        s = Structure("S", Type["f1"]("field1"), Type["f2"]("field2"))
        hdr.add_type(s)

        hdr_content = """\
/* {path} */
#ifndef INCLUDE_{fname_upper}_H
#define INCLUDE_{fname_upper}_H

#include "some_types.h"
#include "another_some_types.h"

typedef struct S {{
    f1 field1;
    f2 field2;
}} S;

#endif /* INCLUDE_{fname_upper}_H */
""".format(path=hdr.path, fname_upper=name.upper())

        self.files = [(hdr, hdr_content)]
Beispiel #12
0
 def gen_state(self):
     s = Structure(self.qtn.for_struct_name + "State")
     for f in self.state_fields:
         s.append_field(f.type(f.name, array_size = f.num))
     return s
Beispiel #13
0
def define_only_qemu_2_6_0_types():
    # According to Qemu inclusion policy, each source file must include
    # qemu/osdep.h. This could be met using different ways. For now add a
    # reference to a fake type inside osdep.h.
    # TODO: the tweak must be handled using version API.
    osdep_fake_type = Type("FAKE_TYPE_IN_QEMU_OSDEP")

    if not get_vp("tcg_enabled is macro"):
        Header.lookup("qemu-common.h").add_types(
            [Function("tcg_enabled", ret_type=Type.lookup("bool"))])

    Header.lookup("tcg.h").add_types([
        Type("TCGv_i32"),
        Type("TCGv_i64"),
        Type("TCGv_ptr"),
        Type("TCGv_env"),
        Type("TCGv"),
        Function("tcg_global_mem_new_i32"),
        Function("tcg_global_mem_new_i64"),
        Function("tcg_op_buf_full")
    ])

    Header.lookup("tcg-op.h").add_types([
        Function("tcg_gen_insn_start"),
        Function("tcg_gen_goto_tb"),
        Function("tcg_gen_exit_tb")
    ])

    Header.lookup("tcg-op.h").add_types([
        # HLTTemp is a fake type intended to mark
        # variables which are to be replaced by this tool
        # preprocessor (still in progress)
        # HLTTemp is then converted to some existing QEMU types
        Type("HLTTemp")
    ])

    Header.lookup("qemu/osdep.h").add_types([osdep_fake_type])

    Header.lookup("exec/hwaddr.h").add_types([Type("hwaddr", False)
                                              ]).add_reference(osdep_fake_type)

    Header.lookup("exec/cpu-defs.h").add_types([
        Type("target_ulong", False),
    ])

    Header.lookup("exec/cpu_ldst.h").add_types([
        Function("cpu_ldub_code", ret_type=Type.lookup("uint8_t")),
        Function("cpu_lduw_code", ret_type=Type.lookup("uint16_t")),
        Function("cpu_ldl_code", ret_type=Type.lookup("uint32_t")),
        Function("cpu_ldq_code", ret_type=Type.lookup("uint64_t")),
    ])

    Header.lookup("qom/object.h").add_types([
        Type("ObjectClass", False),
        Type("Object", False),
        Structure(
            "TypeInfo",
            fields=[
                # These are required fields only
                Pointer(Type.lookup("const char")).gen_var("name"),
                Pointer(Type.lookup("const char")).gen_var("parent"),
                Pointer(Type.lookup("void")).gen_var("class_init")
            ]),
        Type("Type", False),
        Type("TypeImpl", False),
        Function(name="type_register_static",
                 ret_type=Type.lookup("TypeImpl"),
                 args=[Type.lookup("TypeInfo").gen_var("info", pointer=True)]),
        Function(name="type_register",
                 ret_type=Type.lookup("TypeImpl"),
                 args=[Type.lookup("TypeInfo").gen_var("info", pointer=True)]),
        Function("object_get_typename"),
        Function("object_property_set_str"),
        Function("object_property_set_link"),
        Function("object_property_set_bool"),
        Function("object_property_set_int"),
        Function("object_class_by_name"),
        Function("object_class_dynamic_cast"),
        Function("object_class_is_abstract")
    ]).add_reference(osdep_fake_type)

    Header.lookup("qom/cpu.h").add_types([
        Type("CPUState", False),
        Type("CPUClass", False),
        Type("vaddr", False),
        Type("MMUAccessType", False),
        Type("CPUBreakpoint", False),
        Function("qemu_init_vcpu",
                 args=[Type.lookup("CPUState").gen_var("cpu", pointer=True)]),
        Function("cpu_exec_realizefn"),
        Function("cpu_reset"),
        Function("cpu_generic_init")
    ]).add_reference(osdep_fake_type)

    Header.lookup("qapi/error.h").add_types([Type("Error")
                                             ]).add_reference(osdep_fake_type)

    Header.lookup("disas/bfd.h").add_types([Type("disassemble_info", False)
                                            ]).add_reference(osdep_fake_type)

    Header.lookup("qemu/fprintf-fn.h").add_types(
        [Type("fprintf_function", False)]).add_reference(osdep_fake_type)

    Header.lookup("exec/exec-all.h").add_types([
        Type("TranslationBlock", False),
        Function("tlb_fill",
                 args=[
                     Type.lookup("CPUState").gen_var("cs", pointer=True),
                     Type.lookup("target_ulong").gen_var("addr"),
                     Type.lookup("MMUAccessType").gen_var("access_type"),
                     Type.lookup("int").gen_var("mmu_idx"),
                     Type.lookup("uintptr_t").gen_var("retaddr")
                 ],
                 used_types=[]),
        Function("cpu_exec_init",
                 args=[
                     Type.lookup("CPUState").gen_var("cs", pointer=True),
                     Pointer(Pointer(Type.lookup("Error"))).gen_var("errp")
                 ]),
        Function("gen_intermediate_code"),
        Function("cpu_restore_state"),
        Function("cpu_loop_exit"),
        Function("cpu_loop_exit_restore"),
        Function("tlb_set_page")
    ]).add_reference(osdep_fake_type)

    Header.lookup("exec/gen-icount.h").add_types(
        [Function("gen_tb_start"),
         Function("gen_tb_end")])

    Header.lookup("exec/address-spaces.h").add_types(
        [Function("get_system_memory")]).add_reference(osdep_fake_type)

    Header.lookup("exec/memory.h").add_types([
        Type("MemoryRegion", False),
        Function(name="MemoryRegionOps_read",
                 ret_type=Type.lookup("uint64_t"),
                 args=[
                     Type.lookup("void").gen_var("opaque", pointer=True),
                     Type.lookup("hwaddr").gen_var("offset"),
                     Type.lookup("unsigned").gen_var("size")
                 ]),
        Function(name="MemoryRegionOps_write",
                 ret_type=Type.lookup("void"),
                 args=[
                     Type.lookup("void").gen_var("opaque", pointer=True),
                     Type.lookup("hwaddr").gen_var("offset"),
                     Type.lookup("uint64_t").gen_var("value"),
                     Type.lookup("unsigned").gen_var("size")
                 ]),
        Structure("MemoryRegionOps", [
            Type.lookup("MemoryRegionOps_read").gen_var("read"),
            Type.lookup("MemoryRegionOps_write").gen_var("write"),
        ]),
        Function(
            name="memory_region_init_io",
            args=[
                Type.lookup("MemoryRegion").gen_var("mr", pointer=True),
                # struct
                Type.lookup("Object").gen_var("owner", pointer=True),
                # const
                Type.lookup("MemoryRegionOps").gen_var("ops", pointer=True),
                Type.lookup("void").gen_var("opaque", pointer=True),
                Type.lookup("const char").gen_var("name", pointer=True),
                Type.lookup("uint64_t").gen_var("size")
            ]),
        Function("memory_region_init"),
        Function("memory_region_init_alias"),
        Function("memory_region_init_ram"),
        Function("memory_region_add_subregion_overlap"),
        Function("memory_region_add_subregion")
    ]).add_reference(osdep_fake_type)

    Header.lookup("exec/gdbstub.h").add_types([
        Function(name="gdb_get_reg8"),
        Function(name="gdb_get_reg16"),
        Function(name="gdb_get_reg32"),
        Function(name="gdb_get_reg64")
    ]).add_reference(osdep_fake_type)

    Header.lookup("exec/ioport.h").add_types(
        [Type("pio_addr_t", incomplete=False)]).add_reference(osdep_fake_type)

    Header.lookup("hw/boards.h").add_types(
        [Structure("MachineClass"),
         Structure("MachineState")]).add_reference(osdep_fake_type)

    Header.lookup("hw/sysbus.h").add_types([
        Type("SysBusDevice", False),
        Type("qemu_irq", False),
        Function(name="sysbus_init_mmio",
                 ret_type=Type.lookup("void"),
                 args=[
                     Type.lookup("SysBusDevice").gen_var("dev", pointer=True),
                     Type.lookup("MemoryRegion").gen_var("memory",
                                                         pointer=True)
                 ]),
        Function(name="sysbus_init_irq",
                 ret_type=Type.lookup("void"),
                 args=[
                     Type.lookup("SysBusDevice").gen_var("dev", pointer=True),
                     Type.lookup("qemu_irq").gen_var("p", pointer=True)
                 ]),
        Function(name="sysbus_add_io",
                 ret_type=Type.lookup("void"),
                 args=[
                     Type.lookup("SysBusDevice").gen_var("dev", pointer=True),
                     Type.lookup("hwaddr").gen_var("addr"),
                     Type.lookup("MemoryRegion").gen_var("mem", pointer=True)
                 ]),
        Function(name="sysbus_init_ioports",
                 ret_type=Type.lookup("void"),
                 args=[
                     Type.lookup("SysBusDevice").gen_var("dev", pointer=True),
                     Type.lookup("pio_addr_t").gen_var("dev"),
                     Type.lookup("pio_addr_t").gen_var("dev")
                 ]),
        Function("sysbus_mmio_map"),
        Function("sysbus_connect_irq")
    ]).add_reference(osdep_fake_type)

    Header.lookup("hw/irq.h").add_types([
        Function(name="qemu_irq_handler",
                 ret_type=Type.lookup("void"),
                 args=[
                     Type.lookup("void").gen_var("opaque", pointer=True),
                     Type.lookup("int").gen_var("n"),
                     Type.lookup("int").gen_var("level")
                 ]),
        Function("qemu_irq_split")
    ]).add_reference(osdep_fake_type)

    Header.lookup("hw/qdev-core.h").add_types([
        Type("DeviceClass", False),
        Type("DeviceState", False),
        Type("Property", False),
        Function(name="qdev_init_gpio_in",
                 ret_type=Type.lookup("void"),
                 args=[
                     Type.lookup("DeviceState").gen_var("dev", pointer=True),
                     Type.lookup("qemu_irq_handler").gen_var("handler"),
                     Type.lookup("int").gen_var("n")
                 ]),
        Pointer(
            Function(name="device_realize pointee",
                     args=[
                         Type.lookup("DeviceState").gen_var("dev",
                                                            pointer=True),
                         Pointer(Type.lookup("Error")).gen_var("errp",
                                                               pointer=True)
                     ]),
            name="DeviceRealize",
        ),
        Function(name="qdev_create"),
        Function(name="qdev_init_nofail"),
        Function(name="qdev_get_child_bus"),
        Structure(name="BusState"),
        Function(name="qdev_get_gpio_in"),
        Function(name="qdev_get_gpio_in_named"),
        Function(name="qdev_connect_gpio_out"),
        Function(name="qdev_connect_gpio_out_named")
    ]).add_reference(osdep_fake_type)

    Header.lookup("migration/vmstate.h").add_types([
        Type("VMStateDescription", False),
        Type("VMStateField", False),
        Function("vmstate_register_ram_global")
    ]).add_reference(osdep_fake_type)

    Header.lookup("qemu/module.h").add_reference(osdep_fake_type)

    Header.lookup("hw/pci/pci.h").add_types([
        Type("PCIDevice", False),
        Type("PCIDeviceClass", False),
        Function("pci_create_multifunction"),
        Type("PCIIOMMUFunc"),
    ]).add_reference(osdep_fake_type)

    Header.lookup("hw/pci/msi.h").add_types([
        Function(name="msi_uninit",
                 ret_type=Type.lookup("void"),
                 args=[Type.lookup("PCIDevice").gen_var("dev", pointer=True)])
    ]).add_reference(osdep_fake_type)

    Header.lookup("hw/pci/pci_bus.h").add_types([
        Type("PCIBus", incomplete=True)
    ]).add_references([Type.lookup("PCIIOMMUFunc"), osdep_fake_type])
    Header.lookup("hw/pci/pci_host.h").add_reference(osdep_fake_type)

    Header.lookup("qemu/typedefs.h").add_types([
        # BlockBackend is defined in internal block_int.h. Its fields may not
        # be accessed outside internal code. Methods from block-backend.h must
        # be used instead.
        Structure("BlockBackend"),
        Structure("I2CBus")  # the structure is defined in .c file
    ]).add_reference(osdep_fake_type)

    Header.lookup("qemu/bswap.h").add_types(
        [Function("bswap64"),
         Function("bswap32"),
         Function("bswap16")]).add_reference(osdep_fake_type)

    Header.lookup("hw/ide/internal.h").add_types(
        [Structure("IDEDMA")]).add_reference(osdep_fake_type)

    Header.lookup("hw/ide/ahci.h").add_references(
        [Type.lookup("IDEDMA"), osdep_fake_type])

    Header.lookup("hw/block/flash.h").add_references(
        [Type.lookup("VMStateDescription"), osdep_fake_type])

    Header.lookup("qemu/timer.h").add_types([
        Structure("QEMUTimer"),
        Function("timer_new_ns"),
        Function("timer_del"),
        Function("timer_free"),
        Type("QEMU_CLOCK_VIRTUAL")  # It is enumeration entry...
    ]).add_references([osdep_fake_type])

    Header.lookup("qemu/main-loop.h").add_types([
        Function("IOCanReadHandler",
                 ret_type=Type.lookup("int"),
                 args=[Pointer(Type.lookup("void")).gen_var("opaque")]),
        Function("IOReadHandler",
                 args=[
                     Pointer(Type.lookup("void")).gen_var("opaque"),
                     Pointer(Type.lookup("uint8_t"),
                             const=True).gen_var("buf"),
                     Type.lookup("int").gen_var("size")
                 ])
    ]).add_references([osdep_fake_type])

    if get_vp()["v2.8 chardev"]:
        chardev_types = [
            Function("qemu_chr_fe_set_handlers"),
            Structure("CharBackend")
        ]
    else:
        chardev_types = [
            Function("qemu_chr_add_handlers"),
            Structure("CharDriverState")
        ]

    Header.lookup(get_vp("header with IOEventHandler")).add_types([
        Function("IOEventHandler",
                 args=[
                     Pointer(Type.lookup("void")).gen_var("opaque"),
                     Type.lookup("int").gen_var("event")
                 ])
    ] + chardev_types).add_references([osdep_fake_type])

    Header.lookup("sysemu/block-backend.h").add_types([
        Structure("BlockDevOps"),
    ]).add_references([osdep_fake_type])

    Header.lookup("hw/isa/isa.h").add_types([Type("IsaDmaTransferHandler")])

    if get_vp()["include/hw/isa/i8257.h have IsaDmaTransferHandler reference"]:
        Header.lookup(get_vp()["i8257.h path"]).add_references([
            Type.lookup("IsaDmaTransferHandler"),
            Type.lookup("MemoryRegion")
        ])

    Header.lookup("net/net.h").add_types([
        Type("qemu_macaddr_default_if_unset"),
        Type("qemu_format_nic_info_str"),
        Type("qemu_new_nic"),
        Type("qemu_del_nic"),
        Type("qemu_get_queue"),
        Structure("NICConf"),
        Type("NICState"),
        Type("NetClientState"),
        Function("NetCanReceive",
                 ret_type=Type.lookup("int"),
                 args=[Pointer(Type.lookup("NetClientState")).gen_var("nc")]),
        Function("NetReceive",
                 ret_type=Type.lookup("ssize_t"),
                 args=[
                     Pointer(Type.lookup("NetClientState")).gen_var("nc"),
                     Pointer(Type.lookup("const uint8_t")).gen_var("buf"),
                     Type.lookup("size_t").gen_var("size")
                 ]),
        Function("LinkStatusChanged",
                 args=[Pointer(Type.lookup("NetClientState")).gen_var("nc")]),
        Function("NetCleanup",
                 args=[Pointer(Type.lookup("NetClientState")).gen_var("nc")]),
        Structure(
            "NetClientInfo",
            fields=[
                # "type" field type is enum NetClientDriver, but enum is not
                # supported by model
                Type.lookup("int").gen_var("type"),
                Type.lookup("size_t").gen_var("size"),
                Type.lookup("NetReceive").gen_var("receive"),
                Type.lookup("NetCanReceive").gen_var("can_receive"),
                Type.lookup("NetCleanup").gen_var("cleanup"),
                Type.lookup("LinkStatusChanged").gen_var("link_status_changed")
                # There are other fields but they are not needed.
            ]),
        Macro("NET_CLIENT_DRIVER_NIC")  # This is an enum item actually. It
        # is defined in auto generated "qapi-types.h" which is not presented in
        # registry but is included by "net.h" indirectly.
    ]).add_references([osdep_fake_type])

    Header.lookup("exec/helper-proto.h").add_type(Macro("HELPER_PROTO_H"))

    Header.lookup("disas/bfd.h").add_types([
        Type("bfd_vma", False),
        Type("bfd_byte", False),
        Type("const bfd_tyte", False),
        Function("bfd_getl64",
                 ret_type=Type.lookup("bfd_vma"),
                 args=[
                     Pointer(Type.lookup("const bfd_tyte")).gen_var(
                         "addr", pointer=True)
                 ]),
        Function("bfd_getl32",
                 ret_type=Type.lookup("bfd_vma"),
                 args=[
                     Pointer(Type.lookup("const bfd_tyte")).gen_var(
                         "addr", pointer=True)
                 ]),
        Function("bfd_getb32",
                 ret_type=Type.lookup("bfd_vma"),
                 args=[
                     Pointer(Type.lookup("const bfd_tyte")).gen_var(
                         "addr", pointer=True)
                 ]),
        Function("bfd_getl16",
                 ret_type=Type.lookup("bfd_vma"),
                 args=[
                     Pointer(Type.lookup("const bfd_tyte")).gen_var(
                         "addr", pointer=True)
                 ]),
        Function("bfd_getb16",
                 ret_type=Type.lookup("bfd_vma"),
                 args=[
                     Pointer(Type.lookup("const bfd_tyte")).gen_var(
                         "addr", pointer=True)
                 ])
    ])

    Header.lookup("disas/disas.h").add_types([Function("lookup_symbol")])
    Header.lookup("qemu/log.h").add_types([
        Function("qemu_loglevel_mask"),
        Function("qemu_log_in_addr_range"),
        Function("qemu_log_lock"),
        Function("qemu_log_unlock"),
        Function("qemu_log")
    ])
    Header.lookup("exec/log.h").add_types([Function("log_target_disas")])