mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
Since Ocaml 4.06.0, that made safe-string on by default, the compiler is allowed to perform optimisations on immutable strings. They should no longer be used as mutable buffers, and bytes should be used instead. The C stubs for Xs_ring have been updated to use bytes, and the interface rationalised mimicking the new Unix module in the standard library (the implementation of Unix.write_substring uses unsafe_of_string in the exact same way, and both the write implementations are using the bytes as an immutable payload for the write). Signed-off-by: Marcello Seri <marcello.seri@citrix.com> Acked-by: Christian Lindig <christian.lindig@citrix.com> Tested-by: Andrew Cooper <andrew.cooper3@citrix.com> Release-acked-by: Juergen Gross <jgross@suse.com>
49 lines
1.8 KiB
OCaml
49 lines
1.8 KiB
OCaml
(*
|
|
* Copyright (C) 2006-2007 XenSource Ltd.
|
|
* Copyright (C) 2008 Citrix Ltd.
|
|
* Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published
|
|
* by the Free Software Foundation; version 2.1 only. with the special
|
|
* exception on linking described in file LICENSE.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*)
|
|
|
|
module Server_feature = struct
|
|
type t =
|
|
| Reconnection
|
|
end
|
|
|
|
module Server_features = Set.Make(struct
|
|
type t = Server_feature.t
|
|
let compare = compare
|
|
end)
|
|
|
|
external read: Xenmmap.mmap_interface -> bytes -> int -> int = "ml_interface_read"
|
|
external write: Xenmmap.mmap_interface -> bytes -> int -> int = "ml_interface_write"
|
|
|
|
external _internal_set_server_features: Xenmmap.mmap_interface -> int -> unit = "ml_interface_set_server_features" [@@noalloc]
|
|
external _internal_get_server_features: Xenmmap.mmap_interface -> int = "ml_interface_get_server_features" [@@noalloc]
|
|
|
|
let write_substring mmap buff len =
|
|
write mmap (Bytes.unsafe_of_string buff) len
|
|
|
|
let get_server_features mmap =
|
|
(* NB only one feature currently defined above *)
|
|
let x = _internal_get_server_features mmap in
|
|
if x = 0
|
|
then Server_features.empty
|
|
else Server_features.singleton Server_feature.Reconnection
|
|
|
|
let set_server_features mmap set =
|
|
(* NB only one feature currently defined above *)
|
|
let x = if set = Server_features.empty then 0 else 1 in
|
|
_internal_set_server_features mmap x
|
|
|
|
external close: Xenmmap.mmap_interface -> unit = "ml_interface_close" [@@noalloc]
|