Skip to content

Commit 99744a1

Browse files
committed
Add crate README files
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
1 parent 4c60e1d commit 99744a1

5 files changed

Lines changed: 118 additions & 8 deletions

File tree

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@
66

77
Build virtualization solutions on top of a lightweight hypervisor using Rust:
88
- Full Hypervisor Framework support.
9-
- Rusty API.
109
- Supports Apple Silicon.
10+
- Rusty API.
11+
12+
This repository contains the following crates:
13+
| Name | Description |
14+
| --- | --- |
15+
| [hv-sys](./hv-sys) | Unsafe bindings generated with bindgen |
16+
| [hv](./hv) | High level API to access Hypervisor Framework |
17+
18+
[Apple Documentation](https://developer.apple.com/documentation/hypervisor)
1119

12-
[Documentation](https://developer.apple.com/documentation/hypervisor)
20+
### Current list of things to do:
21+
- Make high level API safer.
22+
- Expand documentation.
23+
- Add more examples.
1324

1425
## Requirements
1526

hv-sys/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ edition = "2018"
55
description = "Unsafe bindings for Hypervisor Framework generated with bindgen"
66
authors = ["Maksym Pavlenko <pavlenko.maksym@gmail.com>"]
77
repository = "https://github.com/mxpv/hv"
8-
license-file = "../LICENSE"
9-
readme = "../README.md"
10-
11-
[dependencies]
8+
license = "Apache-2.0"
9+
readme = "README.md"
10+
keywords = ["hypervisor", "virtualization", "microvm", "macos", "apple"]
11+
categories = ["os::macos-apis", "api-bindings", "hardware-support"]
1212

1313
[build-dependencies]
1414
bindgen = "0.58"

hv-sys/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# hv-sys
2+
3+
[![CI](https://github.com/mxpv/hv/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/mxpv/hv/actions/workflows/ci.yml)
4+
5+
Unsafe `-sys` crate with raw, unsafe bindings for [Hypervisor Framework](https://developer.apple.com/documentation/hypervisor), automatically generated with `bindgen`.
6+
7+
Please don't use this crate directly, have a look on [hv](https://crates.io/crates/hv) crate instead.
8+
It offers high level safer Rust API to access Hypervisor Framework.
9+
10+
Also please see the [repository](https://github.com/mxpv/hv) for ongoing work, questions, submit bugs, etc.
11+
12+
## Usage
13+
14+
Add the following to your `Cargo.toml`:
15+
```toml
16+
[dependencies]
17+
hv-sys = "0.1"
18+
```

hv/Cargo.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ edition = "2018"
55
description = "High level Rust bidings to Hypervisor Framework"
66
authors = ["Maksym Pavlenko <pavlenko.maksym@gmail.com>"]
77
repository = "https://github.com/mxpv/hv"
8-
license-file = "../LICENSE"
9-
readme = "../README.md"
8+
license = "Apache-2.0"
9+
readme = "README.md"
10+
keywords = ["hypervisor", "virtualization", "microvm", "macos", "apple"]
11+
categories = ["os::macos-apis", "api-bindings", "hardware-support"]
1012

1113
[dependencies]
1214
bitflags = "1.2"
@@ -18,3 +20,11 @@ libc = "0.2"
1820
[features]
1921
hv_10_15 = []
2022
default = ["hv_10_15"]
23+
24+
# Query basic caps
25+
[[example]]
26+
name = "caps"
27+
28+
# Apple Silicon
29+
[[example]]
30+
name = "as"

hv/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# hv
2+
3+
[![CI](https://github.com/mxpv/hv/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/mxpv/hv/actions/workflows/ci.yml)
4+
5+
`hv` is a high level Rust bindings for Hypervisor Framework.
6+
7+
Build virtualization solutions on top of a lightweight hypervisor using Rust:
8+
- Full Hypervisor Framework support.
9+
- Supports Apple Silicon.
10+
- Rusty API.
11+
12+
Please also see the [repository](https://github.com/mxpv/hv) for latest changes and updates.
13+
14+
## Requirements
15+
16+
### Hypervisor Framework
17+
18+
At runtime, determine whether the Hypervisor APIs are available on a particular machine with the `sysctl`:
19+
20+
```bash
21+
$ sysctl kern.hv_support
22+
kern.hv_support: 1
23+
```
24+
25+
In order to use Hypervisor API your app must have `com.apple.security.hypervisor` entitlement.
26+
Refer to [example.entitlements](example.entitlements) for example of how entitlement file might look like.
27+
28+
Use the following command to self sign your binary for local development:
29+
30+
```bash
31+
$ codesign --sign - --force --entitlements=example.entitlements ./binary
32+
```
33+
34+
### Rust
35+
36+
Developed and tested on latest stable Rust (1.53.0+).
37+
38+
Be sure to have [Xcode](https://developer.apple.com/xcode/) installed and don't forget to `xcode-select --install`,
39+
otherwise `bindgen` may fail to find Hypervisor headers.
40+
41+
## Usage
42+
43+
This crate uses [hv-sys]()
44+
45+
## Example
46+
47+
Here is basic "Hello world" example on Apple Silicon:
48+
```rust
49+
// Init VM
50+
hv::Vm::create_vm(ptr::null_mut())?;
51+
52+
// Initialize guest memory
53+
hv::Vm::map(load_addr, GUEST_ADDR as _, MEM_SIZE as _, hv::Memory::READ)?;
54+
55+
// Create VCPU
56+
let cpu = hv::Vm::create_cpu()?;
57+
58+
// Set regs
59+
cpu.set_reg(Reg::PC, GUEST_ADDR)?;
60+
cpu.set_reg(Reg::X1, GUEST_RESULT_ADDR)?;
61+
62+
// Run CPU
63+
loop {
64+
cpu.run()?;
65+
66+
let info = cpu.exit_info();
67+
println!("{:?}", info);
68+
69+
break;
70+
}
71+
```

0 commit comments

Comments
 (0)