Skip to content

Instantly share code, notes, and snippets.

@sgrove

sgrove/output Secret

Created February 7, 2016 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgrove/c36c548c5581ba56dac7 to your computer and use it in GitHub Desktop.
Save sgrove/c36c548c5581ba56dac7 to your computer and use it in GitHub Desktop.
Trying to run working mirage unix app using mirage xen
s@ubuntu:~/No.$ ls -lash
total 76K
4.0K drwxrwxr-x 5 s s 4.0K Feb 6 17:13 .
4.0K drwxr-xr-x 10 s s 4.0K Feb 6 16:44 ..
4.0K -rw-rw-r-- 1 s s 1.2K Feb 6 16:44 config.ml
4.0K -rw-rw-r-- 1 s s 3.6K Feb 6 16:44 data.ml
4.0K -rw-rw-r-- 1 s s 284 Feb 6 16:44 data.mli
4.0K -rw-rw-r-- 1 s s 2.8K Feb 6 16:44 dispatch.ml
4.0K -rw-rw-r-- 1 s s 340 Feb 6 16:44 dispatch.mli
4.0K -rw-rw-r-- 1 s s 1.3K Feb 6 16:44 generator.ml
4.0K -rw-rw-r-- 1 s s 40 Feb 6 16:44 generator.mli
4.0K drwxrwxr-x 8 s s 4.0K Feb 6 16:44 .git
4.0K -rw-rw-r-- 1 s s 133 Feb 6 16:44 .gitignore
4.0K -rw-rw-r-- 1 s s 1.1K Feb 6 16:44 LICENSE
4.0K -rw-rw-r-- 1 s s 1.9K Feb 6 17:12 Makefile
4.0K -rw-rw-r-- 1 s s 137 Feb 6 16:44 Makefile.user
4.0K -rw-rw-r-- 1 s s 82 Feb 6 16:44 .merlin
4.0K -rw-rw-r-- 1 s s 8 Feb 6 16:44 README.md
4.0K drwxrwxr-x 2 s s 4.0K Feb 6 16:58 secrets
4.0K drwxrwxr-x 3 s s 4.0K Feb 6 16:44 static
4.0K -rw-rw-r-- 1 s s 145 Feb 6 16:44 _tags
s@ubuntu:~/No.$ mirage describe
Name No
Root /home/s/No.
Keys dhcp=false (default), gateways=10.0.0.1 (default), interfaces=0.0.0.0 (default), ip=10.0.0.2 (default), lang=en (default), net=direct (default), netmask=255.255.255.0 (default), network=tap0 (default), socket= (default), target=unix (default), unix=false, use_headers=true (default), xen=false
s@ubuntu:~/No.$ mirage configure --xen
# Detecting depexts using flags: x86_64 linux ubuntu
# The following system packages are needed:
# - libgmp-dev
# - libxen-dev
# - m4
# - ncurses-dev
# - pkg-config
# - time
# The following new OS packages need to be installed: ncurses-dev
Not running as root, the following command will be run through "sudo":
apt-get install -qq -yy ncurses-dev
# OS packages installation successful
=-=- Synchronising pinned packages =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[functoria] https://github.com/mirage/functoria.git already up-to-date
[NOTE] Package containers is already installed (current version is 0.15).
[NOTE] Package crunch is already installed (current version is 1.4.0).
[NOTE] Package cstruct is already installed (current version is 1.7.1).
[NOTE] Package functoria is already installed (current version is ~unknown).
[NOTE] Package io-page is already installed (current version is 1.5.1).
[NOTE] Package lwt is already installed (current version is 2.5.1).
[NOTE] Package mirage-bootvar-xen is already installed (current version is 0.3).
[NOTE] Package mirage-clock-xen is already installed (current version is 1.1).
[NOTE] Package mirage-conduit is already installed (current version is 2.2.0).
[NOTE] Package mirage-console is already installed (current version is 2.1.3).
[NOTE] Package mirage-entropy-xen is already installed (current version is 0.3.0).
[NOTE] Package mirage-http is already installed (current version is 2.5.1).
[NOTE] Package mirage-net-xen is already installed (current version is 1.5.0).
[NOTE] Package mirage-types is already installed (current version is 2.6.0).
[NOTE] Package mirage-xen is already installed (current version is 2.3.3).
[NOTE] Package nocrypto is already installed (current version is 0.5.2).
[NOTE] Package sequence is already installed (current version is 0.6).
[NOTE] Package sexplib is already installed (current version is 113.00.00).
[NOTE] Package tcpip is already installed (current version is 2.6.1).
[NOTE] Package tls is already installed (current version is 0.7.0).
[NOTE] Package tyxml is already installed (current version is 3.6.0).
[NOTE] Package xen-evtchn is already installed (current version is 1.0.6).
[NOTE] Package xen-gnt is already installed (current version is 2.2.1).
[NOTE] Package xenstore is already installed (current version is 1.2.5).
[NOTE] Package zarith-xen is already installed (current version is 1.4).
s@ubuntu:~/No.$ ls -lash
total 1012K
4.0K drwxrwxr-x 6 s s 4.0K Feb 6 17:14 .
4.0K drwxr-xr-x 10 s s 4.0K Feb 6 16:44 ..
4.0K drwxrwxr-x 2 s s 4.0K Feb 6 17:13 _build
4.0K -rw-rw-r-- 1 s s 1.2K Feb 6 16:44 config.ml
4.0K -rw-rw-r-- 1 s s 3.6K Feb 6 16:44 data.ml
4.0K -rw-rw-r-- 1 s s 284 Feb 6 16:44 data.mli
4.0K -rw-rw-r-- 1 s s 2.8K Feb 6 16:44 dispatch.ml
4.0K -rw-rw-r-- 1 s s 340 Feb 6 16:44 dispatch.mli
4.0K -rw-rw-r-- 1 s s 1.3K Feb 6 16:44 generator.ml
4.0K -rw-rw-r-- 1 s s 40 Feb 6 16:44 generator.mli
4.0K drwxrwxr-x 8 s s 4.0K Feb 6 16:44 .git
4.0K -rw-rw-r-- 1 s s 133 Feb 6 16:44 .gitignore
4.0K -rw-rw-r-- 1 s s 2.6K Feb 6 17:14 key_gen.ml
4.0K -rw-rw-r-- 1 s s 1.1K Feb 6 16:44 LICENSE
4.0K -rw-rw-r-- 1 s s 69 Feb 6 17:14 log
8.0K -rw-rw-r-- 1 s s 7.1K Feb 6 17:14 main.ml
4.0K -rw-rw-r-- 1 s s 1.9K Feb 6 17:14 Makefile
4.0K -rw-rw-r-- 1 s s 137 Feb 6 16:44 Makefile.user
4.0K -rw-rw-r-- 1 s s 82 Feb 6 16:44 .merlin
4.0K -rw-rw-r-- 1 s s 1.4K Feb 6 17:14 No_libvirt.xml
4.0K -rwxr-xr-x 1 s s 1.3K Feb 6 17:14 No.xe
4.0K -rw-rw-r-- 1 s s 372 Feb 6 17:14 No.xl
4.0K -rw-rw-r-- 1 s s 375 Feb 6 17:14 No.xl.in
4.0K -rw-rw-r-- 1 s s 8 Feb 6 16:44 README.md
4.0K drwxrwxr-x 2 s s 4.0K Feb 6 16:58 secrets
4.0K drwxrwxr-x 3 s s 4.0K Feb 6 16:44 static
884K -rw-rw-r-- 1 s s 882K Feb 6 17:14 static1.ml
4.0K -rw-rw-r-- 1 s s 269 Feb 6 17:14 static1.mli
8.0K -rw-rw-r-- 1 s s 5.5K Feb 6 17:14 static2.ml
4.0K -rw-rw-r-- 1 s s 269 Feb 6 17:14 static2.mli
4.0K -rw-rw-r-- 1 s s 145 Feb 6 16:44 _tags
s@ubuntu:~/No.$ cat static2.ml
(* Generated by: ocaml-crunch
Creation date: Sun, 7 Feb 2016 01:14:00 GMT *)
module Internal = struct
let d_d7cf3dc70ac3f07d93affedbd2293c9c = "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDgN+7p6DhZR6ie\n32WIP7eorCybUWhORuAVR6voLUftOKfyAiNr38g27/VSDci79EOJEKm13Y6dPdUW\nY+SjlUc92VHuQWgObHZ7fmmlzj3/5/wrFEXZ59D+7ItZKP+9ljqTGGFKwTbWjJso\nziNQSKd16VEcDcmpFJyYANWw60Skvazq6mpjPJ2XtGvUlyYbUqON3A8EuTLWpkWa\nam18tOWUHvN6CX+aEre7POIF35sb00F1usMkLQecdJ2kg5xBbmt9kQgxxpFJ1Eaa\ngtAkSvVz9a3YN+njF3A2jqWlt3LEIqrLY8O/APutmTzAaGJfB5gaUaK/S8RNl//b\nvM2jdyo/AgMBAAECggEAT/YikfBrCAvyKpZo0ypGCTU9wzZJCIFmMLCasfZUDFmE\nK15v22y3LkBtMJIR4FXAMAVtQJp+3bzLXWzKgTwfaAM0oM9amKo9ptTyQFtI6RaG\na6aTMp7lfcRF/coNSkNlKEgtikdVkzYZr3e0SFFgx0Ap2ONh45aiMeM6UhnVJRqE\nfXcuk4TJFIDXJGB35KApWzZiK0qATjJXL5LnR6GwR0/Zz7BZVa5kU9Hf2EqTCiOE\nUa4i1qTE+n2ch1q8OUwYrGiDo+tLqlgH3FKyUL3uPIdCVrxQOR52iZT4UDzFhV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RWyx7Ew8W8wEzyhmh6r1uYDe/jDeaUJX52ddtYgbIDKd1sjOGzVmkSstQ\nZA==\n-----END CERTIFICATE-----\n"
let d_0bed2c51be859a946337ea811a0c2143 = "server.pem\nserver.key\n"
let file_chunks = function
| "server.pem" | "/server.pem" -> Some [ d_b4dc62ff8362fd9d06faaf8dd1597f4e; ]
| "server.key" | "/server.key" -> Some [ d_d7cf3dc70ac3f07d93affedbd2293c9c; ]
| ".gitignore" | "/.gitignore" -> Some [ d_0bed2c51be859a946337ea811a0c2143; ]
| _ -> None
let file_list = ["server.pem"; "server.key"; ".gitignore"; ]
let size = function
|"server.pem" |"/server.pem" -> Some 1229L
|"server.key" |"/server.key" -> Some 1704L
|".gitignore" |"/.gitignore" -> Some 22L
|_ -> None
end
open Lwt
type t = unit
type error =
| Unknown_key of string
type id = unit
type 'a io = 'a Lwt.t
type page_aligned_buffer = Cstruct.t
let id () = ()
let size () name =
match Internal.size name with
| None -> return (`Error (Unknown_key name))
| Some s -> return (`Ok s)
let filter_blocks offset len blocks =
List.rev (fst (List.fold_left (fun (acc, (offset, offset', len)) c ->
let len' = String.length c in
let acc, consumed =
if len = 0
then acc, 0
(* This is before the requested data *)
else if offset' + len' < offset
then acc, 0
(* This is after the requested data *)
else if offset + len < offset'
then acc, 0
(* Overlapping: we're inside the region but extend beyond it *)
else if offset <= offset' && (offset' + len') >= (offset + len)
then String.sub c (offset' - offset) len :: acc, len
(* Overlapping: we're outside the region but extend into it *)
else if offset' <= offset
then String.sub c (offset - offset') (len' - offset + offset') :: acc, (len' - offset + offset')
(* We're completely inside the region *)
else c :: acc, len' in
let offset' = offset' + len' in
let offset = offset + consumed in
let len = len - consumed in
acc, (offset, offset', len)
) ([], (offset, 0, len)) blocks))
let read () name offset len =
match Internal.file_chunks name with
| None -> return (`Error (Unknown_key name))
| Some c ->
let bufs = List.map (fun buf ->
let pg = Io_page.to_cstruct (Io_page.get 1) in
let len = String.length buf in
Cstruct.blit_from_string buf 0 pg 0 len;
Cstruct.sub pg 0 len
) (filter_blocks offset len c) in
return (`Ok bufs)
let return_ok = return (`Ok ())
let connect () = return_ok
let disconnect () = return_unit
s@ubuntu:~/No.$ make
ocamlbuild -use-ocamlfind -pkgs conduit.mirage,containers,cstruct,functoria.runtime,io-page,io-page.unix,lwt,lwt.syntax,mirage-bootvar,mirage-clock-xen,mirage-console.xen,mirage-http,mirage-net-xen,mirage-types,mirage-types.lwt,mirage.runtime,nocrypto.xen,sequence,sexplib,tcpip.arpv4,tcpip.ethif,tcpip.ipv4,tcpip.stack-direct,tcpip.tcp,tcpip.udp,tls.mirage,tyxml -tags "syntax(camlp4o),annot,bin_annot,strict_sequence,principal" -tag-line "<static*.*>: -syntax(camlp4o)" -cflag -g -lflags -g,-linkpkg,-dontlink,unix main.native.o
Finished, 27 targets (0 cached) in 00:00:01.
pkg-config --print-errors --exists mirage-xen
ld -d -static -nostdlib \
_build/main.native.o \
-L/home/s/.opam/4.02.3/lib/tcpip -ltcpip_xen_stubs \
-L/home/s/.opam/4.02.3/lib/mirage-entropy-xen -lmirage-entropy-xen_stubs \
-L/home/s/.opam/4.02.3/lib/nocrypto -lnocrypto_xen_stubs \
-L/home/s/.opam/4.02.3/lib/zarith -lzarith-xen -L/home/s/.opam/4.02.3/lib/gmp-xen -lgmp-xen \
-L/home/s/.opam/4.02.3/lib/io-page -lio_page_xen_stubs \
$(pkg-config --static --libs mirage-xen) \
/usr/lib/gcc/x86_64-linux-gnu/5/libgcc.a \
-o mir-No.xen
Build succeeded
s@ubuntu:~/No.$ sudo xl destroy No && sudo xl create -c No.xl
libxl: info: libxl.c:1691:devices_destroy_cb: forked pid 557 for destroy of domain 10
Parsing config from No.xl
Xen Minimal OS!
Initialising timer interface
Initialising console ... done.
getenv(OCAMLRUNPARAM) -> null
getenv(CAMLRUNPARAM) -> null
getenv(PATH) -> null
Unsupported function lseek called in Mini-OS kernel
Unsupported function lseek called in Mini-OS kernel
Unsupported function lseek called in Mini-OS kernel
getenv(OCAMLRUNPARAM) -> null
getenv(CAMLRUNPARAM) -> null
getenv(TMPDIR) -> null
getenv(TEMP) -> null
Netif: add resume hook
Fatal error: exception Xs_protocol.Enoent("read")
Raised at file "src/core/lwt.ml", line 789, characters 22-23
Called from file "lib/main.ml", line 58, characters 10-20
Called from file "main.ml", line 276, characters 5-10
Mirage exiting with status 2
Do_exit called!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment