Skip to content

Commit b7b45fe

Browse files
authored
Merge pull request #82 from mythril-hypervisor/adam-dev
Remove mythril_core/mythril_multiboot2 split
2 parents 196b652 + 685c9e8 commit b7b45fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+508
-703
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ jobs:
3636
submodules: true
3737
- name: Multiboot2 Image Build
3838
run: |
39-
RUSTFLAGS="-D warnings" make multiboot2
39+
RUSTFLAGS="-D warnings" make mythril

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/boot
22
/target
3+
mythril/target
34
_boot.img
45
**/*.rs.bk
56
debug.log

.mythril_githooks/pre-commit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
diff=$(cargo fmt -- --check)
3+
diff=$(make check-fmt)
44
result=$?
55

66
if [[ ${result} -ne 0 ]] ; then
@@ -10,4 +10,4 @@ EOF
1010
exit 1
1111
fi
1212

13-
exit 0
13+
exit 0

Cargo.toml

Lines changed: 0 additions & 11 deletions
This file was deleted.

Makefile

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
CARGO?=cargo
2-
MULTIBOOT2_TARGET?=multiboot2_target
32
BUILD_TYPE?=release
4-
DOCKER_IMAGE=adamschwalm/hypervisor-build:10
3+
DOCKER_IMAGE=adamschwalm/hypervisor-build:12
54

6-
multiboot2_binary = target/$(MULTIBOOT2_TARGET)/$(BUILD_TYPE)/mythril_multiboot2
7-
mythril_src = $(shell find mythril_* -type f -name '*.rs' -or -name '*.S' -or -name '*.ld' \
5+
mythril_binary = mythril/target/mythril_target/$(BUILD_TYPE)/mythril
6+
mythril_src = $(shell find mythril* -type f -name '*.rs' -or -name '*.S' -or -name '*.ld' \
87
-name 'Cargo.toml')
98
kernel = linux/arch/x86_64/boot/bzImage
109
seabios = seabios/out/bios.bin
@@ -16,22 +15,24 @@ ifneq (,$(filter qemu%, $(firstword $(MAKECMDGOALS))))
1615
$(eval $(QEMU_EXTRA):;@:)
1716
endif
1817

18+
CARGO_MANIFEST?=--manifest-path mythril/Cargo.toml
19+
1920
ifeq ($(BUILD_TYPE), release)
20-
CARGO_FLAGS := --release
21+
CARGO_BUILD_FLAGS := --release
2122
endif
2223

2324
.PHONY: all
24-
all: multiboot2 $(seabios) $(kernel)
25+
all: mythril $(seabios) $(kernel)
2526

26-
.PHONY: multiboot2
27-
multiboot2: $(multiboot2_binary)
27+
.PHONY: mythril
28+
mythril: $(mythril_binary)
2829

29-
.PHONY: multiboot2-debug
30-
multiboot2-debug: BUILD_TYPE=debug
31-
multiboot2-debug: $(multiboot2_binary)
30+
.PHONY: mythril-debug
31+
mythril-debug: BUILD_TYPE=debug
32+
mythril-debug: $(mythril_binary)
3233

3334
docker-%:
34-
docker run --rm -w $(CURDIR) -v $(CURDIR):$(CURDIR) \
35+
docker run --privileged -it --rm -w $(CURDIR) -v $(CURDIR):$(CURDIR) \
3536
-u $(shell id -u):$(shell id -g) $(DOCKER_IMAGE) \
3637
/bin/bash -c '$(MAKE) $*'
3738

@@ -44,35 +45,38 @@ $(kernel):
4445
make -C linux bzImage
4546

4647
.PHONY: qemu
47-
qemu: multiboot2 $(seabios) $(kernel)
48-
./scripts/mythril-run.sh $(multiboot2_binary) $(QEMU_EXTRA)
48+
qemu: mythril $(seabios) $(kernel)
49+
./scripts/mythril-run.sh $(mythril_binary) $(QEMU_EXTRA)
4950

5051
.PHONY: qemu-debug
51-
qemu-debug: multiboot2-debug $(seabios) $(kernel)
52-
./scripts/mythril-run.sh $(multiboot2_binary) \
52+
qemu-debug: mythril-debug $(seabios) $(kernel)
53+
./scripts/mythril-run.sh $(mythril_binary) \
5354
-gdb tcp::1234 -S $(QEMU_EXTRA)
5455

55-
$(multiboot2_binary): $(mythril_src)
56-
$(CARGO) build $(CARGO_FLAGS) -Z build-std=core,alloc \
57-
--target mythril_multiboot2/$(MULTIBOOT2_TARGET).json \
58-
--manifest-path mythril_multiboot2/Cargo.toml
56+
$(mythril_binary): $(mythril_src)
57+
$(CARGO) build $(CARGO_BUILD_FLAGS) $(CARGO_MANIFEST) \
58+
-Z build-std=core,alloc \
59+
--target mythril/mythril_target.json \
60+
61+
.PHONY: check-fmt
62+
check-fmt:
63+
$(CARGO) fmt $(CARGO_MANIFEST) --all -- --check
5964

6065
.PHONY: fmt
6166
fmt:
62-
$(CARGO) fmt --all -- --check
67+
$(CARGO) fmt $(CARGO_MANIFEST) --all
6368

6469
.PHONY: test_core
65-
test_core:
66-
$(CARGO) test \
67-
--manifest-path mythril_core/Cargo.toml \
68-
--lib
70+
test_common:
71+
$(CARGO) test $(CARGO_MANIFEST) --lib \
72+
--features=test \
6973

7074
.PHONY: test
71-
test: test_core
75+
test: test_common
7276

7377
.PHONY: clean
7478
clean:
75-
$(CARGO) clean
79+
$(CARGO) clean $(CARGO_MANIFEST)
7680
make -C seabios clean
7781
make -C linux clean
7882

@@ -89,7 +93,8 @@ $(git_hooks): $(git_hooks_src)
8993
help:
9094
@echo " Make Targets:"
9195
@echo " all build everything to run mythril, but do not start qemu"
92-
@echo " fmt run rustfmt"
96+
@echo " check-fmt run cargo fmt --check"
97+
@echo " fmt run cargo fmt"
9398
@echo " qemu run mythril in a VM"
9499
@echo " qemu-debug run mythril in a VM, but halt for a debugger connection"
95100
@echo " test run the mythril tests"

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using this image. For example, to build the multiboot application, run:
1212
make docker-all
1313
```
1414

15-
This will create the multiboot2 application in `target/multiboot2_target/release/mythril_multiboot2`.
15+
This will create the hypervisor in `mythril/target/mythril_target/release/mythril`.
1616
It will also compile the patched versions for seabios and the linux kernel that
1717
are currently required to use `mythril`. Unittests can be executed like:
1818

@@ -27,26 +27,26 @@ After running the build steps as described above, an initramfs must be added to
2727
can be executed with:
2828

2929
```
30-
make qemu
30+
make docker-qemu
3131
```
3232

3333
Note that this has only been tested on relatively recent versions of QEMU (v4.1.0+).
3434
Older versions may contain bugs that could cause issues running the image.
3535

3636
## Debugging
3737

38-
To debug mythril, first build the multiboot application as described above. Then
39-
run `make qemu-debug`. This will start start QEMU but not launch mythril. You can
40-
then run `gdb target/multiboot2_target/debug/mythril_multiboot2` to launch gdb with
41-
the debug info from the application. You can then attach to the qemu instance with
42-
`target remote localhost:1234`.
38+
To debug mythril, run `BUILD_TYPE=debug make qemu-debug`. This will build a debug version
39+
of the hypervisor then start start QEMU in a paused state. You can then run
40+
`gdb mythril/target/mythril_target/debug/mythril` to launch gdb with the debug info from
41+
the application. You can attach to the qemu instance with `target remote :1234`. Note that
42+
debugging the hypervisor is generally not supported under docker.
4343

4444
Because the virtualization is hardware accelerated, remember to use `hbreak` instead
4545
of `break` in gdb. For example, to put a breakpoint at the start of `kmain` and start
4646
mythril, run:
4747

4848
```
49-
(gdb) target remote localhost:1234
49+
(gdb) target remote :1234
5050
Remote debugging using localhost:1234
5151
0x000000000000fff0 in ?? ()
5252
(gdb) hbreak kmain

0 commit comments

Comments
 (0)