This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,6 @@
_build
*.install
.merlin
duniverse
*.locked
_esy

View file

@ -0,0 +1,3 @@
version = 0.27.0
profile = conventional
parse-docstrings = true

View file

@ -0,0 +1,93 @@
### v5.2.0 (2025-10-22)
* Fix the compilation of the solo5 sublibrary with the host compiler
(#2 @dinosaure)
### v5.1.0 (2025-09-01)
* Add support for unikraft (#1 @shym @Firobe @fabbing)
### v5.0.0 (2025-01-30)
* Renamed to mirage-ptime (from mirage-clock), only the PCLOCK part
* Use Ptime.t directly in the interface
* use "dune variants" for the different implementations
### v4.2.0 (2022-03-27)
* Rename the freestanding toolchain to solo5 (@dinosaure, #51)
* Use ocamlformat (@samoht, #54)
### v4.1.0 (2022-02-01)
* Be able to build & instal the distribution via `opam` without the expected `dune`'s context (@TheLortex, @dinosaure, #49)
### v4.0.0 (2021-11-15)
* Remove Mirage_clock_lwt module (#48 @hannesm)
* Use caml_get_wall_clock instead of unix_gettime to avoid floating point
conversion roundtrip (#47 @hannesm)
### v3.1.0 (2020-11-19)
* Use implicit executable dependency for discover.exe
into the dune file (#46 @TheLortex)
* Fix cross-compilation on Android (#45 @EduardoRFS)
### v3.0.1 (2019-11-04)
* provide deprecated Mirage_clock_lwt for smooth transition (#44 @hannesm)
### v3.0.0 (2019-10-21)
* remove mirage-clock-lwt (#43 @hannesm)
* mirage-clock is no device anymore, drop lwt dependency (#43 @hannesm)
* raise lower OCaml bound to 4.06.0 (#43 @hannesm)
### v2.0.0 (2018-12-27)
* Constrain the clock type `t` to `unit` to improve compatability with
the webmachine CLOCK interface. All current implementations satisfy
this interface so there shouldn't be an issue, but bumping the
library major version number to reflect the interface change (#38 @hannesm)
* Port library to Dune from jbuilder and use `dune-release` and the builtin
`dune.configurator` to reduce the build dependency cone (#39 @avsm).
* Remove unused variable warnings (#39 @avsm).
* Update opam package metadata to 2.0 format (#39 @avsm).
* Fixes to the ocamldoc comment headers for odoc compatibility (@avsm)
### v1.4.1 (2018-08-03)
* mirage-clock-unix: fix integer overflow on 32 bit (#37, @mattgray)
### v1.4.0 (2017-07-25)
* Add support for windows to `mirage-clock-unix` (#32, @fdopen and @samoht)
### v1.3.0 (2017-06-19)
* port to Jbuilder
### v1.2.0 (2016-12-21)
* import `V1.MCLOCK` and `V1.PCLOCK` from `mirage-types` under `mirage-clock`
and `mirage-clock-lwt`
### v1.1.0 (2015-01-05)
* xen: pure OCaml implementation of `Clock.gmtime`
### v1.0.0 (2013-12-07)
* Remove unnecessary cstruct dependency.
* Install ocamlfind packages as `mirage-clock-xen` and `mirage-clock-unix`.
* Fix META file descriptions.
* Add Travis tests.
### v0.9.9 (2013-12-05)
* Initial public release, based on mirage/mirage-platform#0.9.8

View file

@ -0,0 +1,14 @@
Copyright (c) 2010 Anil Madhavapeddy <anil@recoil.org>
2014 Daniel C. Bünzli
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View file

@ -0,0 +1,19 @@
.PHONY: build clean test
build:
dune build @install
test:
dune runtest
install:
dune install
uninstall:
dune uninstall
doc:
dune build @doc
clean:
dune clean

View file

@ -0,0 +1,13 @@
## mirage-ptime -- a POSIX clock for MirageOS
This library implements portable support for an operating system timesource
that is compatible with the [MirageOS](https://mirageos.org) library interfaces
found in: <https://github.com/mirage/mirage>
It implements Mirage_ptime which is a clock that counts time since the Unix
epoch.
The following sources are used:
* The Unix version uses [Ptime_clock](https://erratique.ch/software/ptime),
* The freestanding version uses the paravirtual clock source from the hypervisor.

View file

@ -0,0 +1,3 @@
(lang dune 2.8)
(name mirage-ptime)
(version v5.2.0)

View file

@ -0,0 +1,4 @@
(test
(name portable)
(package mirage-ptime)
(libraries mirage-ptime))

View file

@ -0,0 +1,20 @@
let print_time () =
let now = Mirage_ptime.now () in
Format.printf "The time is %a.\n" (Ptime.pp_rfc3339 ()) now
let print_offset c =
match Mirage_ptime.current_tz_offset_s c with
| Some offset -> Printf.printf "The offset from UTC is %d minutes.\n" offset
| None -> Printf.printf "Clock UTC offset unavailable\n"
let print_period c =
match Mirage_ptime.period c with
| Some span -> Format.printf "The clock period is: %a\n" Ptime.Span.pp span
| None -> Printf.printf "Clock period unavailable\n"
let () =
print_time ();
print_time ();
print_time ();
print_offset ();
print_period ()

View file

@ -0,0 +1,29 @@
version: "5.2.0"
opam-version: "2.0"
maintainer: "hannes@mehnert.org"
authors: ["Anil Madhavapeddy" "Daniel C. Bünzli" "Matthew Gray" "Hannes Mehnert"]
license: "ISC"
tags: "org:mirage"
homepage: "https://github.com/mirage/mirage-ptime"
doc: "https://mirage.github.io/mirage-ptime/"
bug-reports: "https://github.com/mirage/mirage-ptime/issues"
synopsis: "Libraries and module types for portable clocks"
description: """
This library implements portable support for an operating system timesource
that is compatible with the [MirageOS](https://mirageos.org) library interfaces
found in: <https://github.com/mirage/mirage>
It implements a POSIX clock which counts time since the Unix epoch.
"""
depends: [
"ocaml" {>= "4.08.0"}
"dune" {>= "2.8"}
"ptime" {>= "1.1.0"}
]
build: [
["dune" "subst"] {dev}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
dev-repo: "git+https://github.com/mirage/mirage-ptime.git"
x-maintenance-intent: [ "(latest)" ]

View file

@ -0,0 +1,11 @@
(library
(name mirage_ptime_set)
(public_name mirage-ptime.set)
(modules mirage_ptime_set))
(library
(name mirage_ptime_mock)
(public_name mirage-ptime.mock)
(implements mirage-ptime)
(libraries mirage-ptime.set)
(modules mirage_ptime))

View file

@ -0,0 +1,21 @@
(*
* Copyright (c) 2015 Matt Gray <matthew.thomas.gray@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)
let now () = Ptime.v !Mirage_ptime_set.now
let now_d_ps () = !Mirage_ptime_set.now
let current_tz_offset_s () = !Mirage_ptime_set.tz_off
let period () = Option.map Ptime.Span.v !Mirage_ptime_set.period
let period_d_ps () = !Mirage_ptime_set.period

View file

@ -0,0 +1,6 @@
let now = ref (0, 0L)
let tz_off : int option ref = ref None
let period : (int * int64) option ref = ref None
let set (days, picos) = now := (days, picos)
let set_tz_offset v = tz_off := v
let set_period p = period := p

View file

@ -0,0 +1,25 @@
(library
(name mirage_ptime_solo5)
(public_name mirage-ptime.solo5)
(implements mirage-ptime)
(foreign_stubs
(language c)
(names mirage_ptime_stubs)))
(rule
(target mirage_ptime_stubs.c)
(enabled_if
(<> %{context_name} "solo5"))
(deps
(:src mirage_ptime_stubs.default.c))
(action
(copy %{src} %{target})))
(rule
(target mirage_ptime_stubs.c)
(enabled_if
(= %{context_name} "solo5"))
(deps
(:src mirage_ptime_stubs.solo5.c))
(action
(copy %{src} %{target})))

View file

@ -0,0 +1,38 @@
(*
* Copyright (c) 2015 Matt Gray <matthew.thomas.gray@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)
external time : unit -> int64 = "caml_get_wall_clock"
let nsec_per_day = Int64.mul 86_400L 1_000_000_000L
let ps_per_ns = 1_000L
let now_d_ps () =
let nsec = time () in
let days = Int64.div nsec nsec_per_day in
let rem_ns = Int64.rem nsec nsec_per_day in
let rem_ps = Int64.mul rem_ns ps_per_ns in
(Int64.to_int days, rem_ps)
let now () = Ptime.v (now_d_ps ())
let current_tz_offset_s () = None
(* According to
* https://github.com/mirage/mini-os/blob/edfd5aae6ec5ba7d0a8834a3e9dfe5e69424150a/arch/x86/time.c#L194
* the clock period is 1 microsecond
*)
let period = (0, 1_000_000L)
let period_d_ps () = Some period
let period () = Some (Ptime.Span.v period)

View file

@ -0,0 +1,11 @@
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/fail.h>
CAMLprim value
caml_get_wall_clock(value v_unit)
{
CAMLparam1(v_unit);
CAMLreturn(caml_copy_int64(0LL));
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2010 Anil Madhavapeddy <anil@recoil.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "solo5.h"
#include <sys/time.h>
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/fail.h>
CAMLprim value
caml_get_wall_clock(value v_unit)
{
CAMLparam1(v_unit);
CAMLreturn(caml_copy_int64(solo5_clock_wall()));
}

View file

@ -0,0 +1,6 @@
(library
(name mirage_ptime)
(public_name mirage-ptime)
(libraries ptime)
(virtual_modules mirage_ptime)
(default_implementation mirage-ptime.unix))

View file

@ -0,0 +1,44 @@
(*
* Copyright (c) 2015 Matt Gray <matthew.thomas.gray@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)
(** {1 POSIX clock} *)
val now : unit -> Ptime.t
(** [now_d_ps ()] is the current POSIX time. *)
val period : unit -> Ptime.span option
(** [period ()] is a positive POSIX time span representing the clock'd period
(if available). *)
(** {1 System time zone offset} *)
val current_tz_offset_s : unit -> int option
(** [current_tz_offset_s ()] is the clock's current local time zone offset to
UTC in seconds, if known. This is the duration local time - UTC time in
seconds. *)
(** {1 POSIX clock raw interface} *)
val now_d_ps : unit -> int * int64
(** [now_d_ps ()] is [(d, ps)] representing POSIX time occuring at [d] *
86'400e12 + [ps] POSIX picoseconds from the epoch 1970-01-01 00:00:00 UTC.
[ps] is in the range \[[0];[86_399_999_999_999_999L]\].
Raises {!Sys_error}, see {{!err}error handling} *)
val period_d_ps : unit -> (int * int64) option
(** [period_d_ps ()] is if available [Some (d, ps)] representing the clock's
picosecond period [d] * 86'400e12 + [ps]. [ps] is in the range
\[[0];[86_399_999_999_999_999L]\]. *)

View file

@ -0,0 +1,5 @@
(library
(name mirage_ptime_unikraft)
(public_name mirage-ptime.unikraft)
(implements mirage-ptime)
(libraries ptime.clock.os))

View file

@ -0,0 +1,17 @@
(*
* Copyright (c) 2015 Matt Gray <matthew.thomas.gray@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)
include Ptime_clock

View file

@ -0,0 +1,5 @@
(library
(name mirage_ptime_unix)
(public_name mirage-ptime.unix)
(implements mirage-ptime)
(libraries ptime.clock.os))

View file

@ -0,0 +1,17 @@
(*
* Copyright (c) 2015 Matt Gray <matthew.thomas.gray@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)
include Ptime_clock