]> xenbits.xensource.com Git - xen.git/commitdiff
tools/ocaml: Fix redefinition errors
authorCostin Lupu <costin.lupu@cs.pub.ro>
Tue, 8 Jun 2021 12:35:29 +0000 (15:35 +0300)
committerJulien Grall <jgrall@amazon.com>
Fri, 9 Jul 2021 15:00:09 +0000 (16:00 +0100)
If PAGE_SIZE is already defined in the system (e.g. in /usr/include/limits.h
header) then gcc will trigger a redefinition error because of -Werror. This
patch replaces usage of PAGE_* macros with XC_PAGE_* macros in order to avoid
confusion between control domain page granularity (PAGE_* definitions) and
guest domain page granularity (which is what we are dealing with here).

Same issue applies for redefinitions of Val_none and Some_val macros which
can be already define in the OCaml system headers (e.g.
/usr/lib/ocaml/caml/mlvalues.h).

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Julien Grall <jgrall@amazon.com>
Acked-by: Ian Jackson <iwj@xenproject.org>
Tested-by: Dario Faggioli <dfaggioli@suse.com>
tools/ocaml/libs/xc/xenctrl_stubs.c
tools/ocaml/libs/xentoollog/xentoollog_stubs.c
tools/ocaml/libs/xl/xenlight_stubs.c

index 6e4bc567f533638f0be9ddfb0883d91ce4b7a04e..a6756c4a8c2b09426948a4cb97c47045189388a8 100644 (file)
 
 #include "mmap_stubs.h"
 
-#define PAGE_SHIFT             12
-#define PAGE_SIZE               (1UL << PAGE_SHIFT)
-#define PAGE_MASK               (~(PAGE_SIZE-1))
-
 #define _H(__h) ((xc_interface *)(__h))
 #define _D(__d) ((uint32_t)Int_val(__d))
 
+#ifndef Val_none
 #define Val_none (Val_int(0))
+#endif
 
 #define string_of_option_array(array, index) \
        ((Field(array, index) == Val_none) ? NULL : String_val(Field(Field(array, index), 0)))
@@ -819,7 +817,7 @@ CAMLprim value stub_xc_domain_memory_increase_reservation(value xch,
        CAMLparam3(xch, domid, mem_kb);
        int retval;
 
-       unsigned long nr_extents = ((unsigned long)(Int64_val(mem_kb))) >> (PAGE_SHIFT - 10);
+       unsigned long nr_extents = ((unsigned long)(Int64_val(mem_kb))) >> (XC_PAGE_SHIFT - 10);
 
        uint32_t c_domid = _D(domid);
        caml_enter_blocking_section();
@@ -925,7 +923,7 @@ CAMLprim value stub_pages_to_kib(value pages)
 {
        CAMLparam1(pages);
 
-       CAMLreturn(caml_copy_int64(Int64_val(pages) << (PAGE_SHIFT - 10)));
+       CAMLreturn(caml_copy_int64(Int64_val(pages) << (XC_PAGE_SHIFT - 10)));
 }
 
 
index bf64b211c2c901fcd1878234c31ff38467f2bf80..e4306a0c2f8f03407a5c195de5b3d0350e9faf44 100644 (file)
@@ -53,8 +53,12 @@ static char * dup_String_val(value s)
 #include "_xtl_levels.inc"
 
 /* Option type support as per http://www.linux-nantes.org/~fmonnier/ocaml/ocaml-wrapping-c.php */
+#ifndef Val_none
 #define Val_none Val_int(0)
+#endif
+#ifndef Some_val
 #define Some_val(v) Field(v,0)
+#endif
 
 static value Val_some(value v)
 {
index 352a00134d7084ed633f6d149558e97df198b1c5..45b8af61c74ad8fbda1ef4b9f7027eba1183621f 100644 (file)
@@ -227,8 +227,12 @@ static value Val_string_list(libxl_string_list *c_val)
 }
 
 /* Option type support as per http://www.linux-nantes.org/~fmonnier/ocaml/ocaml-wrapping-c.php */
+#ifndef Val_none
 #define Val_none Val_int(0)
+#endif
+#ifndef Some_val
 #define Some_val(v) Field(v,0)
+#endif
 
 static value Val_some(value v)
 {