Skip to content

Commit

Permalink
provide makefile and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorian Eikenberg committed Jan 21, 2020
1 parent 0956964 commit 967db34
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions c_examples/Makefile
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions c_examples/README.md
Original file line number Diff line number Diff line change
@@ -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" <example> <vm_name>
~~~

0 comments on commit 967db34

Please sign in to comment.