Skip to contentSkip to conversation

libxl: ocaml: guard x86-specific functions behind an ifdef

PATCH Superseded Anil Madhavapeddy 2 participants 4 messages Jan 9, 2014 – Jan 11, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: ocaml: guard x86-specific functions behind an ifdef

The various cpuid functions are not available on ARM, so this makes them raise an OCaml exception. Omitting the functions completely them results in a link failure in oxenstored due to the missing symbols, so this is preferable to the much bigger patch that would result from adding conditional compilation into the OCaml interfaces.

---
 tools/ocaml/libs/xc/xenctrl_stubs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/ocaml/libs/xc/xenctrl_stubs.c +12 -0
index f5cf0ed..76864cc 100644
@@ -714,6 +714,7 @@ CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid,
 {
 	CAMLparam4(xch, domid, input, config);
 	CAMLlocal2(array, tmp);
+#if defined(__i386__) || defined(__x86_64__)
 	int r;
 	unsigned int c_input[2];
 	char *c_config[4], *out_config[4];
@@ -742,17 +743,24 @@ CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid,
 			 c_input, (const char **)c_config, out_config);
 	if (r < 0)
 		failwith_xc(_H(xch));
+#else
+	failwith_xc(_H(xch));
+#endif
 	CAMLreturn(array);
 }
 
 CAMLprim value stub_xc_domain_cpuid_apply_policy(value xch, value domid)
 {
 	CAMLparam2(xch, domid);
+#if defined(__i386__) || defined(__x86_64__)
 	int r;
 
 	r = xc_cpuid_apply_policy(_H(xch), _D(domid));
 	if (r < 0)
 		failwith_xc(_H(xch));
+#else
+	failwith_xc(_H(xch));
+#endif
 	CAMLreturn(Val_unit);
 }
 
@@ -760,6 +768,7 @@ CAMLprim value stub_xc_cpuid_check(value xch, value input, value config)
 {
 	CAMLparam3(xch, input, config);
 	CAMLlocal3(ret, array, tmp);
+#if defined(__i386__) || defined(__x86_64__)
 	int r;
 	unsigned int c_input[2];
 	char *c_config[4], *out_config[4];
@@ -792,6 +801,9 @@ CAMLprim value stub_xc_cpuid_check(value xch, value input, value config)
 	Store_field(ret, 0, Val_bool(r));
 	Store_field(ret, 1, array);
 
+#else
+	failwith_xc(_H(xch));
+#endif
 	CAMLreturn(ret);
 }
 
Signature · 1 line
1.8.1.2
#1 lore raw
Quoted 26 lines · Anil Madhavapeddy

The various cpuid functions are not available on ARM, so this makes them raise an OCaml exception. Omitting the functions completely them results in a link failure in oxenstored due to the missing symbols, so this is preferable to the much bigger patch that would result from adding conditional compilation into the OCaml interfaces.

---
 tools/ocaml/libs/xc/xenctrl_stubs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/ocaml/libs/xc/xenctrl_stubs.c +1 -0
index f5cf0ed..76864cc 100644
@@ -714,6 +714,7 @@ CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid,
 {
 	CAMLparam4(xch, domid, input, config);
 	CAMLlocal2(array, tmp);
+#if defined(__i386__) || defined(__x86_64__)
 	int r;
 	unsigned int c_input[2];
 	char *c_config[4], *out_config[4];

tools/ocaml/libs/xc/xenctrl_stubs.c CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid, · line 747

Quoted 5 lines
tools/ocaml/libs/xc/xenctrl_stubs.c +2 -0
@@ -742,17 +743,24 @@ CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid,
 			 c_input, (const char **)c_config, out_config);
 	if (r < 0)
 		failwith_xc(_H(xch));
+#else
+	failwith_xc(_H(xch));

You probably want to set xc's last error so failwith_xc() gives an exception with a relevant error message.

~Andrew

Quoted 37 lines
tools/ocaml/libs/xc/xenctrl_stubs.c +9 -0
+#endif
 	CAMLreturn(array);
 }
 
 CAMLprim value stub_xc_domain_cpuid_apply_policy(value xch, value domid)
 {
 	CAMLparam2(xch, domid);
+#if defined(__i386__) || defined(__x86_64__)
 	int r;
 
 	r = xc_cpuid_apply_policy(_H(xch), _D(domid));
 	if (r < 0)
 		failwith_xc(_H(xch));
+#else
+	failwith_xc(_H(xch));
+#endif
 	CAMLreturn(Val_unit);
 }
 
@@ -760,6 +768,7 @@ CAMLprim value stub_xc_cpuid_check(value xch, value input, value config)
 {
 	CAMLparam3(xch, input, config);
 	CAMLlocal3(ret, array, tmp);
+#if defined(__i386__) || defined(__x86_64__)
 	int r;
 	unsigned int c_input[2];
 	char *c_config[4], *out_config[4];
@@ -792,6 +801,9 @@ CAMLprim value stub_xc_cpuid_check(value xch, value input, value config)
 	Store_field(ret, 0, Val_bool(r));
 	Store_field(ret, 1, array);
 
+#else
+	failwith_xc(_H(xch));
+#endif
 	CAMLreturn(ret);
 }
 
#2 lore raw
Quoted 27 lines · Andrew Cooper
Quoted 26 lines · Anil Madhavapeddy

The various cpuid functions are not available on ARM, so this makes them raise an OCaml exception. Omitting the functions completely them results in a link failure in oxenstored due to the missing symbols, so this is preferable to the much bigger patch that would result from adding conditional compilation into the OCaml interfaces.

---
 tools/ocaml/libs/xc/xenctrl_stubs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/ocaml/libs/xc/xenctrl_stubs.c +1 -0
index f5cf0ed..76864cc 100644
@@ -714,6 +714,7 @@ CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid,
 {
 	CAMLparam4(xch, domid, input, config);
 	CAMLlocal2(array, tmp);
+#if defined(__i386__) || defined(__x86_64__)
 	int r;
 	unsigned int c_input[2];
 	char *c_config[4], *out_config[4];
@@ -742,17 +743,24 @@ CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid,
Quoted 8 lines

tools/ocaml/libs/xc/xenctrl_stubs.c CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid, · line 747

Quoted 5 lines
tools/ocaml/libs/xc/xenctrl_stubs.c +2 -0
 			 c_input, (const char **)c_config, out_config);
 	if (r < 0)
 		failwith_xc(_H(xch));
+#else
+	failwith_xc(_H(xch));

You probably want to set xc's last error so failwith_xc() gives an exception with a relevant error message.

Yeah; I'm just stumbling through getting my Cubieboard2 dom0 to boot a VM at the moment, so I'll test out oxenstored when the compile finishes and resubmit the patch.

Signature · 1 line
Anil Madhavapeddy                                 http://anil.recoil.org
#3 lore raw
In reply to Andrew Cooper
Quoted 27 lines · Andrew Cooper
Quoted 26 lines · Anil Madhavapeddy

The various cpuid functions are not available on ARM, so this makes them raise an OCaml exception. Omitting the functions completely them results in a link failure in oxenstored due to the missing symbols, so this is preferable to the much bigger patch that would result from adding conditional compilation into the OCaml interfaces.

---
 tools/ocaml/libs/xc/xenctrl_stubs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/ocaml/libs/xc/xenctrl_stubs.c +1 -0
index f5cf0ed..76864cc 100644
@@ -714,6 +714,7 @@ CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid,
 {
 	CAMLparam4(xch, domid, input, config);
 	CAMLlocal2(array, tmp);
+#if defined(__i386__) || defined(__x86_64__)
 	int r;
 	unsigned int c_input[2];
 	char *c_config[4], *out_config[4];
@@ -742,17 +743,24 @@ CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid,
Quoted 8 lines

tools/ocaml/libs/xc/xenctrl_stubs.c CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid, · line 747

Quoted 5 lines
tools/ocaml/libs/xc/xenctrl_stubs.c +2 -0
 			 c_input, (const char **)c_config, out_config);
 	if (r < 0)
 		failwith_xc(_H(xch));
+#else
+	failwith_xc(_H(xch));

You probably want to set xc's last error so failwith_xc() gives an exception with a relevant error message.

After discussion with Dave Scott, we thought it best to just raise a normal Failure exception rather than the libxc ones. The functions aren't used by any of the libraries in-tree at the moment and oxenstored works for a simple VM start for me with v2 of the patch as well.

-anil