package vchan

  1. Overview
  2. Docs

Source file s.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
(*
 * Copyright (c) 2013,2014 Citrix Systems Inc
 *
 * 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.
 *)

module type CONFIGURATION = sig

  type t = {
    ring_ref: string;
    event_channel: string;
  } [@@deriving sexp]

  val write:
     client_domid:int -> port:Port.t
  -> t
  -> unit Lwt.t

  val read:
     server_domid:int -> port:Port.t
  -> t Lwt.t

  val delete:
     client_domid:int -> port:Port.t
  -> unit Lwt.t

end

module type MEMORY = sig
  type grant [@@deriving sexp]

  val grant_of_int32: int32 -> grant
  val int32_of_grant: grant -> int32

  type share [@@deriving sexp_of]

  val grants_of_share: share -> grant list
  val buf_of_share: share -> Io_page.t

  val share: domid:int -> npages:int -> rw:bool -> share

  val unshare: share -> unit Lwt.t

  type mapping [@@deriving sexp_of]

  val buf_of_mapping: mapping -> Io_page.t

  val map: domid:int -> grant:grant -> rw:bool -> mapping

  val mapv: grants:(int * grant) list -> rw:bool -> mapping

  val unmap: mapping -> unit

end

module type EVENTS = sig

  type port [@@deriving sexp_of]
  (** an identifier for a source of events. Ports are allocated by calls to
      [listen], then exchanged out-of-band (typically by xenstore) and
      finally calls to [connect] creates a channel between the two domains.
      Events are send and received over these channels. *)

  val port_of_string: string -> (port, [> `Msg of string ]) result
  val string_of_port: port -> string

  type channel [@@deriving sexp_of]
  (** a channel is the connection between two domains and is used to send
      and receive events. *)

  type event [@@deriving sexp_of]
  (** an event notification received from a remote domain. Events contain no
      data and may be coalesced. Domains which are blocked will be woken up
      by an event. *)

  val initial: event
  (** represents an event which 'fired' when the program started *)

  val recv: channel -> event -> event Lwt.t
  (** [recv channel event] blocks until the system receives an event
      newer than [event] on channel [channel]. If an event is received
      while we aren't looking then this will be remembered and the
      next call to [after] will immediately unblock. If the system
      is suspended and then resumed, all event channel bindings are invalidated
      and this function will fail with Generation.Invalid *)

  val send: channel -> unit
  (** [send channel] sends an event along [channel], to another domain
      which will be woken up *)

  val listen: int -> port * channel
  (** [listen domid] allocates a fresh port and event channel. The port
      may be supplied to [connect] *)

  val connect: int -> port -> channel
  (** [connect domid port] connects an event channel to [port] on [domid] *)

  val close: channel -> unit
  (** [close channel] closes this side of an event channel *)
end

module type ENDPOINT = sig
  type t [@@deriving sexp_of]
  (** Type of a vchan endpoint. *)

  type port [@@deriving sexp_of]
  (** Type of a vchan port name. *)

  val server :
    domid:int ->
    port:port ->
    ?read_size:int ->
    ?write_size:int ->
    unit -> t Lwt.t

  val client :
    domid:int ->
    port:port ->
    unit -> t Lwt.t

  include Mirage_flow.S
    with type flow = t
end
OCaml

Innovation. Community. Security.