diff --git a/README.md b/README.md index df58b0ee..2c7f5cdf 100644 --- a/README.md +++ b/README.md @@ -131,21 +131,6 @@ drv.resume() .expect("Failed to resume VM"); ~~~ -## C Interoperability - -It is possible to call *libmicrovmi* functions from C code. To this end, a header file has to be generated. -This requires the `cbindgen` tool which can be installed via the following command: - -~~~ -cargo install --force cbindgen -~~~ - -Command to generate `libmicrovmi.h`: - -~~~ -cbindgen --config cbindgen.toml --crate microvmi --output libmicrovmi.h -~~~ - ## References - [LibVMI C library](https://github.com/libvmi/libvmi): Simplified Virtual Machine Introspection diff --git a/c_examples/Makefile b/c_examples/Makefile new file mode 100644 index 00000000..16e709d5 --- /dev/null +++ b/c_examples/Makefile @@ -0,0 +1,23 @@ +CC = gcc +CFLAGS = -lmicrovmi -L../target/debug +CWD := $(shell pwd) + +.PHONY: all clean + +all: mem-dump pause regs-dump + +libmicrovmi.h: ../target/debug/libmicrovmi.so + cd ..; \ + cbindgen --config cbindgen.toml --crate microvmi --output "${CWD}/libmicrovmi.h" + +mem-dump: libmicrovmi.h mem-dump.c + $(CC) $(CFLAGS) -o mem-dump mem-dump.c + +pause: libmicrovmi.h pause.c + $(CC) $(CFLAGS) -o pause pause.c + +regs-dump: libmicrovmi.h regs-dump.c + $(CC) $(CFLAGS) -o regs-dump regs-dump.c + +clean: + rm -f libmicrovmi.h mem-dump pause regs-dump diff --git a/c_examples/README.md b/c_examples/README.md new file mode 100644 index 00000000..bb65ea56 --- /dev/null +++ b/c_examples/README.md @@ -0,0 +1,22 @@ +# C Interoperability + +It is possible to call *libmicrovmi* functions from C code. To this end, a header file has to be generated. +This requires the `cbindgen` tool which can be installed via the following command: + +~~~ +cargo install --force cbindgen +~~~ + +## Building the examples + +To build the examples just use the makefile located in `c_examples`. +It will also generate the header file for you provided you have installed cbindgen. +You just have to make sure that you have already built *libmicrovmi*. + +## Executing the examples + +Command to execute an example as an unprivileged user: + +~~~ +sudo LD_LIBRARY_PATH="$LD_LIBRARY_PATH:../target/debug" +~~~ \ No newline at end of file