A minimal QEMU Object Model (QOM) practice project written in C.
This repository is not trying to fully reimplement QEMU. The goal is to connect a few core QOM ideas with as little code as possible:
- type registration and inheritance
- object creation and destruction
- object trees and path resolution
- class property registration and string-based assignment
- a simplified
memory-backend-memfdexample object
The project currently builds successfully, runs a demo program, and passes its basic tests.
.
├── include/miniqom/
│ ├── error.h
│ ├── memory.h
│ ├── object.h
│ ├── property.h
│ └── type.h
├── src/
│ ├── main.c
│ ├── memory/
│ │ ├── hostmem.c
│ │ └── hostmem_memfd.c
│ └── qom/
│ ├── object.c
│ ├── property.c
│ └── type.c
├── tests/
│ └── test_qom.c
└── meson.build
The project includes a minimal but usable type registration system:
type_system_init()initializes the base typetype_register_static()registers a static typetype_get_by_name()looks up a type by nametype_get_parent()returns the parent typetype_get_info()returns the type metadatatype_get_class()returns the class object for a type
Type metadata is described by TypeInfo, including:
- type name
- parent type name
- instance size
- class initialization callback
- instance initialization callback
- instance finalization callback
The object layer provides these basic capabilities:
object_new()creates an object from a type nameobject_free()recursively frees an object treeobject_is_instance_of()checks whether an object belongs to a typeobject_add_child()creates a parent-child relationshipobject_resolve_path()resolves a path such as/objects/mem0
The property system converts string input into object field values:
- supports
bool,uint64_t, andstringproperty types - allows registering property setters on a class
- applies parsing and assignment through
object_property_set_from_string()
This follows the same broad idea as QEMU object configuration through properties, but in a much smaller and easier-to-read form.
The current code implements two example types:
memory-backendmemory-backend-memfd
They demonstrate:
- type inheritance
- parent and child property composition
- default value initialization
- conditional property validation
For example:
sizeis auint64_tmmocis a boolean propertyswap-storagecan only be set whenmmoc=onsealandhugetlbbelong tomemory-backend-memfd
You will need:
Configure the build directory the first time:
meson setup buildCompile:
meson compile -C buildRun the demo program:
./build/mini-qom-demoRun the tests:
meson test -C buildThe demo program creates a small object tree, sets several properties on mem0, and prints output like this:
<root> (object)
objects (object)
mem0 (memory-backend-memfd)
mem0: size=1073741824, share=1, mmoc=1, seal=0
This means:
- the root object contains
objects objectscontainsmem0- the dynamic type of
mem0ismemory-backend-memfd sizewas set to1Gmmocwas enabledsealwas explicitly disabled
tests/test_qom.c currently verifies:
memory-backend-memfdis an instance of the child type, the parent type, andobject- the path
/objects/mem0resolves correctly - setting
swap-storagefails whenmmoc=off - setting
swap-storagesucceeds after enablingmmoc "2G"is parsed correctly intouint64_t
This project is a good fit if you are learning about:
- the basic design of QEMU QOM
- lightweight object-oriented patterns in C
- how a type system, object tree, and property system work together
- how to reduce a large framework into a small, understandable subset
This is intentionally a practice project, so it stays small. It does not currently cover:
- dynamic type unloading
- reference counting
- thread safety
- more advanced property accessors
- device and bus models
- a more complete error propagation model
- the full object lifecycle details used by real QEMU
These are all reasonable directions for future expansion.
If you want to make it closer to real QEMU, you could:
- add object reference counting and weak-reference behavior
- support property reads, not only writes
- add more memory backends or device types
- expand the unit tests more systematically
- add traversal and pretty-print helper APIs for object trees
- introduce clearer module boundaries and error handling conventions
There is no explicit license file in the repository yet. If you plan to publish it, adding a LICENSE file would be a good next step.