xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Edwin Török" <edvin.torok@citrix.com>
To: <xen-devel@lists.xenproject.org>
Cc: "Edwin Török" <edvin.torok@citrix.com>,
	"Christian Lindig" <christian.lindig@citrix.com>,
	"David Scott" <dave@recoil.org>,
	"Ian Jackson" <iwj@xenproject.org>, "Wei Liu" <wl@xen.org>
Subject: [PATCH v2 09/17] tools/ocaml: use common macros for manipulating mmap_interface
Date: Tue, 11 May 2021 19:05:22 +0100	[thread overview]
Message-ID: <744b98946062028be059435fbe2b9ccc2009e1e8.1620755942.git.edvin.torok@citrix.com> (raw)
In-Reply-To: <cover.1620755942.git.edvin.torok@citrix.com>

Also expose these macros in a header file that can be reused by
the upcoming grant table code.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
---
 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 7a91fdee75..614c6e371d 100644
--- a/tools/ocaml/libs/xb/xs_ring_stubs.c
+++ b/tools/ocaml/libs/xb/xs_ring_stubs.c
@@ -35,8 +35,6 @@
 #include <sys/mman.h>
 #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.
@@ -52,12 +50,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;
@@ -111,12 +108,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;
@@ -166,7 +162,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);
 	if (intf == (void*)MAP_FAILED)
 		caml_failwith("Interface closed");
 
@@ -178,7 +174,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));
 }
@@ -186,7 +182,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



  parent reply	other threads:[~2021-05-11 18:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 18:05 [PATCH v2 00/17] live update and gnttab patches Edwin Török
2021-05-11 18:05 ` [PATCH v2 01/17] docs/designs/xenstore-migration.md: clarify that deletes are recursive Edwin Török
2021-05-11 18:05 ` [PATCH v2 02/17] tools/ocaml: add unit test skeleton with Dune build system Edwin Török
2021-05-11 18:05 ` [PATCH v2 03/17] tools/ocaml: vendor external dependencies for convenience Edwin Török
2021-05-11 18:05 ` [PATCH v2 04/17] tools/ocaml/xenstored: implement the live migration binary format Edwin Török
2021-05-11 18:05 ` [PATCH v2 05/17] tools/ocaml/xenstored: add binary dump format support Edwin Török
2021-05-11 18:05 ` [PATCH v2 06/17] tools/ocaml/xenstored: add support for binary format Edwin Török
2021-05-11 18:05 ` [PATCH v2 07/17] tools/ocaml/xenstored: validate config file before live update Edwin Török
2021-05-11 18:05 ` [PATCH v2 08/17] Add structured fuzzing unit test Edwin Török
2021-05-11 18:05 ` Edwin Török [this message]
2021-05-11 18:05 ` [PATCH v2 10/17] tools/ocaml/libs/mmap: allocate correct number of bytes Edwin Török
2021-05-11 18:05 ` [PATCH v2 11/17] tools/ocaml/libs/mmap: Expose stub_mmap_alloc Edwin Török
2021-05-11 18:05 ` [PATCH v2 12/17] tools/ocaml/libs/mmap: mark mmap/munmap as blocking Edwin Török
2021-05-11 18:05 ` [PATCH v2 13/17] tools/ocaml/libs/xb: import gnttab stubs from mirage Edwin Török
2021-05-11 18:05 ` [PATCH v2 14/17] tools/ocaml: safer Xenmmap interface Edwin Török
2021-05-11 18:05 ` [PATCH v2 15/17] tools/ocaml/xenstored: use gnttab instead of xenctrl's foreign_map_range Edwin Török
2021-05-11 18:05 ` [PATCH v2 16/17] tools/ocaml/xenstored: don't store domU's mfn of ring page Edwin Török
2021-05-11 18:05 ` [PATCH v2 17/17] tools/ocaml/libs/mmap: Clean up unused read/write Edwin Török
2021-05-12 13:06   ` Andrew Cooper
2021-05-11 18:12 ` [PATCH v2 00/17] live update and gnttab patches Edwin Torok
2021-05-11 20:05 ` Andrew Cooper
2021-05-12 10:10   ` Edwin Torok
2021-05-12 12:51     ` Andrew Cooper
2021-05-12 15:04       ` Edwin Torok

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=744b98946062028be059435fbe2b9ccc2009e1e8.1620755942.git.edvin.torok@citrix.com \
    --to=edvin.torok@citrix.com \
    --cc=christian.lindig@citrix.com \
    --cc=dave@recoil.org \
    --cc=iwj@xenproject.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).