Debian Codegraph @

tools/ocaml/libs/xb/xenbus_stubs.c

raw
1 /*
2 * Copyright (C) 2006-2007 XenSource Ltd.
3 * Copyright (C) 2008 Citrix Ltd.
4 * Author Vincent Hanquez <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; version 2.1 only. with the special
9 * exception on linking described in file LICENSE.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 */
16
17 #include <unistd.h>
18 #include <stdlib.h>
19 #include <sys/mman.h>
20 #include <string.h>
21 #include <errno.h>
22
23 #include <caml/mlvalues.h>
24 #include <caml/memory.h>
25 #include <caml/alloc.h>
26 #include <caml/custom.h>
27 #include <caml/fail.h>
28 #include <caml/callback.h>
29
30 #include <xenctrl.h>
31 #include <xen/io/xs_wire.h>
32
33 CAMLprim value stub_header_size(value unit)
34 {
35 return Val_int(sizeof(struct xsd_sockmsg));
36 }
37
38 CAMLprim value stub_header_of_string(value s)
39 {
40 CAMLparam1(s);
41 CAMLlocal1(ret);
42 const struct xsd_sockmsg *hdr;
43
44 if (caml_string_length(s) != sizeof(struct xsd_sockmsg))
45 caml_failwith("xb header incomplete");
46 ret = caml_alloc_tuple(4);
47 hdr = (const struct xsd_sockmsg *) String_val(s);
48 Store_field(ret, 0, Val_int(hdr->tx_id));
49 Store_field(ret, 1, Val_int(hdr->req_id));
50 Store_field(ret, 2, Val_int(hdr->type));
51 Store_field(ret, 3, Val_int(hdr->len));
52 CAMLreturn(ret);
53 }
54
55 CAMLprim value stub_string_of_header(value tid, value rid, value ty, value len)
56 {
57 CAMLparam4(tid, rid, ty, len);
58 CAMLlocal1(ret);
59 struct xsd_sockmsg xsd = {
60 .type = Int_val(ty),
61 .tx_id = Int_val(tid),
62 .req_id = Int_val(rid),
63 .len = Int_val(len),
64 };
65
66 ret = caml_alloc_string(sizeof(struct xsd_sockmsg));
67 memcpy((char *) String_val(ret), &xsd, sizeof(struct xsd_sockmsg));
68
69 CAMLreturn(ret);
70 }