[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1 1/9] tools/ocaml: use common macros for manipulating mmap_interface


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Edwin Török <edvin.torok@xxxxxxxxxx>
  • Date: Thu, 27 Aug 2020 18:35:52 +0100
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Edwin Török <edvin.torok@xxxxxxxxxx>, "Christian Lindig" <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, "Ian Jackson" <ian.jackson@xxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Thu, 27 Aug 2020 17:37:14 +0000
  • Ironport-sdr: 95XsEbv5SdvEiFtxG5Upoatpn1CM22AS7cVFzFed/oySNFoo/z6PX/L8s029HAVNEQhrEa+xAI 4wu/+BXGsW4zf9sGBdGDCDtsWakXjzHVKZ/nISa3DpnQ7s/hLWjI0eEua/BM0o9bfaUU3+Ripl RP654pWgSrw0pyigRjbRymagJDAOO+QWqJfnaXz/iFcK9dhdUwEscL/Lu2XcNgERlw1gXmofVr xkabgG1HoQBlstMYqoaI1EFFVsv1mDKeSXuznSkMr1P5alZ6/RFcjg8vtB0Oyyfi1QUoNnT3nB tm8=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Signed-off-by: Edwin Török <edvin.torok@xxxxxxxxxx>
---
 tools/ocaml/libs/mmap/mmap_stubs.h    |  7 +++++++
 tools/ocaml/libs/mmap/xenmmap_stubs.c |  2 --
 tools/ocaml/libs/xb/xs_ring_stubs.c   | 14 +++++---------
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/tools/ocaml/libs/mmap/mmap_stubs.h 
b/tools/ocaml/libs/mmap/mmap_stubs.h
index 65e4239890..816ba6a724 100644
--- a/tools/ocaml/libs/mmap/mmap_stubs.h
+++ b/tools/ocaml/libs/mmap/mmap_stubs.h
@@ -30,4 +30,11 @@ struct mmap_interface
        int len;
 };
 
+#ifndef Data_abstract_val
+#define Data_abstract_val(v) ((void*) Op_val(v))
+#endif
+
+#define Intf_val(a) ((struct mmap_interface *) Data_abstract_val(a))
+#define Intf_data_val(a) (Intf_val(a)->addr)
+
 #endif
diff --git a/tools/ocaml/libs/mmap/xenmmap_stubs.c 
b/tools/ocaml/libs/mmap/xenmmap_stubs.c
index e2ce088e25..b811990a89 100644
--- a/tools/ocaml/libs/mmap/xenmmap_stubs.c
+++ b/tools/ocaml/libs/mmap/xenmmap_stubs.c
@@ -28,8 +28,6 @@
 #include <caml/fail.h>
 #include <caml/callback.h>
 
-#define Intf_val(a) ((struct mmap_interface *) a)
-
 static int mmap_interface_init(struct mmap_interface *intf,
                                int fd, int pflag, int mflag,
                                int len, int offset)
diff --git a/tools/ocaml/libs/xb/xs_ring_stubs.c 
b/tools/ocaml/libs/xb/xs_ring_stubs.c
index 7537a23949..9b6e3209fe 100644
--- a/tools/ocaml/libs/xb/xs_ring_stubs.c
+++ b/tools/ocaml/libs/xb/xs_ring_stubs.c
@@ -34,8 +34,6 @@
 
 #include "mmap_stubs.h"
 
-#define GET_C_STRUCT(a) ((struct mmap_interface *) a)
-
 /*
  * Bytes_val has been introduced by Ocaml 4.06.1. So define our own version
  * if needed.
@@ -51,12 +49,11 @@ CAMLprim value ml_interface_read(value ml_interface,
        CAMLparam3(ml_interface, ml_buffer, ml_len);
        CAMLlocal1(ml_result);
 
-       struct mmap_interface *interface = GET_C_STRUCT(ml_interface);
        unsigned char *buffer = Bytes_val(ml_buffer);
        int len = Int_val(ml_len);
        int result;
 
-       struct xenstore_domain_interface *intf = interface->addr;
+       struct xenstore_domain_interface *intf = Intf_data_val(ml_interface);
        XENSTORE_RING_IDX cons, prod; /* offsets only */
        int total_data, data;
        uint32_t connection;
@@ -110,12 +107,11 @@ CAMLprim value ml_interface_write(value ml_interface,
        CAMLparam3(ml_interface, ml_buffer, ml_len);
        CAMLlocal1(ml_result);
 
-       struct mmap_interface *interface = GET_C_STRUCT(ml_interface);
        const unsigned char *buffer = Bytes_val(ml_buffer);
        int len = Int_val(ml_len);
        int result;
 
-       struct xenstore_domain_interface *intf = interface->addr;
+       struct xenstore_domain_interface *intf = Intf_data_val(ml_interface);
        XENSTORE_RING_IDX cons, prod;
        int total_space, space;
        uint32_t connection;
@@ -165,7 +161,7 @@ exit:
 CAMLprim value ml_interface_set_server_features(value interface, value v)
 {
        CAMLparam2(interface, v);
-       struct xenstore_domain_interface *intf = GET_C_STRUCT(interface)->addr;
+       struct xenstore_domain_interface *intf = Intf_data_val(interface);
 
        intf->server_features = Int_val(v);
 
@@ -175,7 +171,7 @@ CAMLprim value ml_interface_set_server_features(value 
interface, value v)
 CAMLprim value ml_interface_get_server_features(value interface)
 {
        CAMLparam1(interface);
-       struct xenstore_domain_interface *intf = GET_C_STRUCT(interface)->addr;
+       struct xenstore_domain_interface *intf = Intf_data_val(interface);
 
        CAMLreturn(Val_int (intf->server_features));
 }
@@ -183,7 +179,7 @@ CAMLprim value ml_interface_get_server_features(value 
interface)
 CAMLprim value ml_interface_close(value interface)
 {
        CAMLparam1(interface);
-       struct xenstore_domain_interface *intf = GET_C_STRUCT(interface)->addr;
+       struct xenstore_domain_interface *intf = Intf_data_val(interface);
        int i;
 
        intf->req_cons = intf->req_prod = intf->rsp_cons = intf->rsp_prod = 0;
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.