From ae1a2fee1f4b5d6c47cea580dd887817d1872080 Mon Sep 17 00:00:00 2001 From: dinosaure Date: Wed, 17 Mar 2021 18:38:20 +0100 Subject: [PATCH 1/6] Upgrade the C layout of io-page according to MirageOS 3/4 --- .test-mirage.sh | 6 ++++++ .travis.yml | 9 +++++---- META.io-page.template | 3 +++ dune-project | 2 +- freestanding/Makefile | 23 +++++++++++++++++++++++ freestanding/dune | 14 ++++++++++++++ lib/dune | 5 ++++- unikernel/config.ml | 9 +++++++++ unikernel/unikernel.ml | 7 +++++++ 9 files changed, 72 insertions(+), 6 deletions(-) create mode 100755 .test-mirage.sh create mode 100644 META.io-page.template create mode 100644 freestanding/Makefile create mode 100644 freestanding/dune create mode 100644 unikernel/config.ml create mode 100644 unikernel/unikernel.ml diff --git a/.test-mirage.sh b/.test-mirage.sh new file mode 100755 index 0000000..31b6475 --- /dev/null +++ b/.test-mirage.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +set -ex + +opam install -y mirage +(cd unikernel && mirage configure -t hvt && make depends && mirage build && mirage clean && cd ..) || exit 1 diff --git a/.travis.yml b/.travis.yml index cc560c3..9ee6f9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,8 @@ env: global: - PINS="io-page.dev:." matrix: - - DISTRO="debian-stable" OCAML_VERSION=4.04 PACKAGE="io-page" - - DISTRO="alpine" OCAML_VERSION=4.06 PACKAGE="io-page" - - DISTRO="alpine" OCAML_VERSION=4.07 PACKAGE="io-page" - - DISTRO="alpine" OCAML_VERSION=4.08 PACKAGE="io-page" + - DISTRO="debian-stable" OCAML_VERSION=4.08 PACKAGE="io-page" + - DISTRO="alpine" OCAML_VERSION=4.08 PACKAGE="io-page" TESTS=false POST_INSTALL_HOOK=./.test-mirage.sh + - DISTRO="alpine" OCAML_VERSION=4.09 PACKAGE="io-page" + - DISTRO="alpine" OCAML_VERSION=4.10 PACKAGE="io-page" + - DISTRO="alpine" OCAML_VERSION=4.11 PACKAGE="io-page" diff --git a/META.io-page.template b/META.io-page.template new file mode 100644 index 0000000..fdbb97e --- /dev/null +++ b/META.io-page.template @@ -0,0 +1,3 @@ +# DUNE_GEN + +freestanding_linkopts = "-l:libiopage_freestanding_stubs.a" diff --git a/dune-project b/dune-project index 80380d8..1ac4481 100644 --- a/dune-project +++ b/dune-project @@ -1,2 +1,2 @@ -(lang dune 1.0) +(lang dune 2.6) (name io-page) diff --git a/freestanding/Makefile b/freestanding/Makefile new file mode 100644 index 0000000..153b8aa --- /dev/null +++ b/freestanding/Makefile @@ -0,0 +1,23 @@ +PKG_CONFIG_PATH := $(shell opam config var prefix)/lib/pkgconfig + +EXISTS := $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --exists ocaml-freestanding; echo $$?) + +.PHONY: all clean +all: libiopage_freestanding_stubs.a + +ifeq ($(EXISTS), 1) +libiopage_freestanding_stubs.a: + touch $@ +else +CC ?= cc +FREESTANDING_CFLAGS := $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags ocaml-freestanding) +CFLAGS := $(FREESTANDING_CFLAGS) + +OBJS=stub_alloc_pages.o stub_get_addr.o + +libiopage_freestanding_stubs.a: $(OBJS) + $(AR) r $@ $^ +endif + +clean: + $(RM) $(OBJS) libtcpip_freestanding_stubs.a diff --git a/freestanding/dune b/freestanding/dune new file mode 100644 index 0000000..74c7eb0 --- /dev/null +++ b/freestanding/dune @@ -0,0 +1,14 @@ +(copy_files# ../lib/*.c) + +(rule + (deps Makefile stub_alloc_pages.c stub_get_addr.c) + (targets libiopage_freestanding_stubs.a) + (action + (no-infer + (progn + (run %{make}))))) + +(install + (package io-page) + (section lib) + (files libiopage_freestanding_stubs.a)) diff --git a/lib/dune b/lib/dune index 9e8d910..a1e6e06 100644 --- a/lib/dune +++ b/lib/dune @@ -2,5 +2,8 @@ (name io_page) (public_name io-page) (libraries cstruct bigarray-compat) - (c_names stub_alloc_pages stub_get_addr) + (foreign_stubs + (language c) + (names stub_alloc_pages stub_get_addr) + (flags :standard)) (js_of_ocaml (javascript_files io-page.js))) diff --git a/unikernel/config.ml b/unikernel/config.ml new file mode 100644 index 0000000..30cac0d --- /dev/null +++ b/unikernel/config.ml @@ -0,0 +1,9 @@ +open Mirage + +let io_page = + foreign "Unikernel.Make" + (console @-> job) + +let () = + register "io-page" ~packages:[ package "io-page" ] + [ io_page $ default_console ] diff --git a/unikernel/unikernel.ml b/unikernel/unikernel.ml new file mode 100644 index 0000000..7c0084a --- /dev/null +++ b/unikernel/unikernel.ml @@ -0,0 +1,7 @@ +module Make (Console : Mirage_console.S) = struct + let log console fmt = Format.kasprintf (Console.log console) fmt + + let start console = + let v = Io_page.get_order 15 in + log console "addr: %nx." (Io_page.get_addr v) +end From bc37ae6820de8ad3723e0f5b680cbaeca184f8c9 Mon Sep 17 00:00:00 2001 From: dinosaure Date: Wed, 17 Mar 2021 18:43:02 +0100 Subject: [PATCH 2/6] Add constraints to be sure about old version of mirage-xen/ocaml-freestanding --- io-page.opam | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/io-page.opam b/io-page.opam index 429b2b4..27c5733 100644 --- a/io-page.opam +++ b/io-page.opam @@ -18,6 +18,10 @@ build: [ ["dune" "build" "-p" name "-j" jobs] ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] +conflicts: [ + "mirage-xen" {< "6.0.0"} + "ocaml-freestanding" {< "0.4.1"} +] dev-repo: "git+https://github.com/mirage/io-page.git" synopsis: "Support for efficient handling of I/O memory pages" description: """ From fd1b926ae7b33789a6a4c67ac7eeb8db8c2b7a2a Mon Sep 17 00:00:00 2001 From: dinosaure Date: Wed, 17 Mar 2021 18:43:38 +0100 Subject: [PATCH 3/6] Apply @fmt on dune files --- lib/dune | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/dune b/lib/dune index a1e6e06..49b89f3 100644 --- a/lib/dune +++ b/lib/dune @@ -6,4 +6,5 @@ (language c) (names stub_alloc_pages stub_get_addr) (flags :standard)) - (js_of_ocaml (javascript_files io-page.js))) + (js_of_ocaml + (javascript_files io-page.js))) From 8fc05d1c694d07b5152739af31ea4642921803a1 Mon Sep 17 00:00:00 2001 From: dinosaure Date: Wed, 17 Mar 2021 18:46:52 +0100 Subject: [PATCH 4/6] Add ocaml-freestanding and pkg-config as a dependency of io-page --- io-page.opam | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/io-page.opam b/io-page.opam index 27c5733..96cc667 100644 --- a/io-page.opam +++ b/io-page.opam @@ -7,6 +7,7 @@ homepage: "https://github.com/mirage/io-page" bug-reports: "https://github.com/mirage/io-page/issues" doc: "https://mirage.github.io/io-page/" depends: [ + "conf-pkg-config" {build} "ocaml" {>= "4.02.3"} "dune" "cstruct" {>= "2.0.0"} @@ -22,6 +23,9 @@ conflicts: [ "mirage-xen" {< "6.0.0"} "ocaml-freestanding" {< "0.4.1"} ] +depopts: [ + "ocaml-freestanding" +] dev-repo: "git+https://github.com/mirage/io-page.git" synopsis: "Support for efficient handling of I/O memory pages" description: """ From e2bf50acf01f27617eb101617ae09e74d6ab00ea Mon Sep 17 00:00:00 2001 From: dinosaure Date: Thu, 18 Mar 2021 03:47:13 +0100 Subject: [PATCH 5/6] Rename C functions to caml_mirage_iopage to avoid conflicts --- lib/io-page.js | 4 ++-- lib/io_page.ml | 4 ++-- lib/stub_alloc_pages.c | 2 +- lib/stub_get_addr.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/io-page.js b/lib/io-page.js index f83dc5f..339e45d 100644 --- a/lib/io-page.js +++ b/lib/io-page.js @@ -14,12 +14,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -//Provides: mirage_alloc_pages +//Provides: caml_mirage_iopage_alloc_pages //Requires: caml_ba_create_from //Requires: caml_ba_views //Requires: caml_ba_init_views //Requires: caml_ba_get_size -function mirage_alloc_pages(did_gc, npages) { +function caml_mirage_iopage_alloc_pages(did_gc, npages) { caml_ba_init_views(); var dims = [ npages * 4096 ]; var size = caml_ba_get_size(dims); diff --git a/lib/io_page.ml b/lib/io_page.ml index 2767d18..4ad9aa3 100644 --- a/lib/io_page.ml +++ b/lib/io_page.ml @@ -25,9 +25,9 @@ let page_alignment = 4096 let length t = Array1.dim t -external alloc_pages: bool -> int -> t = "mirage_alloc_pages" +external alloc_pages: bool -> int -> t = "caml_mirage_iopage_alloc_pages" -external c_get_addr : t -> nativeint = "mirage_get_addr" +external c_get_addr : t -> nativeint = "caml_mirage_iopage_get_addr" let get_addr t = c_get_addr t diff --git a/lib/stub_alloc_pages.c b/lib/stub_alloc_pages.c index 3a6fd77..3bee665 100644 --- a/lib/stub_alloc_pages.c +++ b/lib/stub_alloc_pages.c @@ -47,7 +47,7 @@ call free() whenever all sub-bigarrays are unreachable. */ CAMLprim value -mirage_alloc_pages(value did_gc, value n_pages) +caml_mirage_iopage_alloc_pages(value did_gc, value n_pages) { CAMLparam2(did_gc, n_pages); size_t len = Int_val(n_pages) * PAGE_SIZE; diff --git a/lib/stub_get_addr.c b/lib/stub_get_addr.c index b6f6872..519863b 100644 --- a/lib/stub_get_addr.c +++ b/lib/stub_get_addr.c @@ -36,7 +36,7 @@ #include CAMLprim value -mirage_get_addr(value page) +caml_mirage_iopage_get_addr(value page) { CAMLparam1(page); CAMLlocal1(nativeint); From cf1688373a553a1c514c912edb9c69efa356be9f Mon Sep 17 00:00:00 2001 From: dinosaure Date: Thu, 18 Mar 2021 04:03:31 +0100 Subject: [PATCH 6/6] Don't try to make the unikernel on alpine --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9ee6f9a..17c038c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ env: - PINS="io-page.dev:." matrix: - DISTRO="debian-stable" OCAML_VERSION=4.08 PACKAGE="io-page" - - DISTRO="alpine" OCAML_VERSION=4.08 PACKAGE="io-page" TESTS=false POST_INSTALL_HOOK=./.test-mirage.sh + - DISTRO="debian-stable" OCAML_VERSION=4.08 PACKAGE="io-page" TESTS=false POST_INSTALL_HOOK=./.test-mirage.sh - DISTRO="alpine" OCAML_VERSION=4.09 PACKAGE="io-page" - DISTRO="alpine" OCAML_VERSION=4.10 PACKAGE="io-page" - DISTRO="alpine" OCAML_VERSION=4.11 PACKAGE="io-page"