Skip to content

Commit

Permalink
tools/ocaml/libs/{xb, mmap}: use Data_abstract_val wrapper
Browse files Browse the repository at this point in the history
This is not strictly necessary since it is essentially a no-op
currently: a cast to void* and value*, even in OCaml 5.0.

However it does make it clearer that what we have here is not a regular
OCaml value, but one allocated with Abstract_tag or Custom_tag,
and follows the example from the manual more closely:
https://v2.ocaml.org/manual/intfc.html#ss:c-outside-head

It also makes it clearer that these modules have been reviewed for
compat with OCaml 5.0.

We cannot use OCaml finalizers here, because we want control over when to unmap
these pages from remote domains.
A follow-up commit will add use-after-free detection instead.

No functional change.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
---
Reason for inclusion in 4.17:
- make code follow best practice for upcoming OCaml 5.0 compiler (already in beta)

Changes since v2:
- add Acked-by line

Changes since v3:
- mention that use-after-free is fixed in another commit, and we cannot use
  finalizers here

Changes since v4:
- use Op_val
  • Loading branch information
edwintorok committed Dec 19, 2022
1 parent c8aaebc commit 9855ed2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tools/ocaml/libs/mmap/mmap_stubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ struct mmap_interface
int len;
};

#ifndef Data_abstract_val
#define Data_abstract_val(v) ((void*) Op_val(v))
#endif

#endif
2 changes: 1 addition & 1 deletion tools/ocaml/libs/mmap/xenmmap_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <caml/fail.h>
#include <caml/callback.h>

#define Intf_val(a) ((struct mmap_interface *) a)
#define Intf_val(a) ((struct mmap_interface *) Data_abstract_val(a))

static int mmap_interface_init(struct mmap_interface *intf,
int fd, int pflag, int mflag,
Expand Down
2 changes: 1 addition & 1 deletion tools/ocaml/libs/xb/xs_ring_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <sys/mman.h>
#include "mmap_stubs.h"

#define GET_C_STRUCT(a) ((struct mmap_interface *) a)
#define GET_C_STRUCT(a) ((struct mmap_interface *) Data_abstract_val(a))

/*
* Bytes_val has been introduced by Ocaml 4.06.1. So define our own version
Expand Down

0 comments on commit 9855ed2

Please sign in to comment.