diff mbox series

[1/1] util/getauxval: Porting to FreeBSD getauxval feature

Message ID CA+XhMqyZ9yZjckTcYinCOYqb4ybE6z9vmgcJzue1WEGuZ0NTWA@mail.gmail.com
State New
Headers show
Series [1/1] util/getauxval: Porting to FreeBSD getauxval feature | expand

Commit Message

David Carlier May 24, 2020, 12:09 p.m. UTC
Hi here porting qemu_getauxval to FreeBSD. Thanks. Regards.

From 5be5e56a59631b28ed7b738d251dda252ba9b03e Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen@gmail.com>
Date: Sun, 24 May 2020 13:03:32 +0100
Subject: [PATCH] util/getauxval: FreeBSD has a similar auxilary vector API

Signed-off-by: David Carlier <devnexen@gmail.com>
---
 configure        | 6 ++++++
 util/getauxval.c | 6 ++++++
 2 files changed, 12 insertions(+)

Comments

Thomas Huth May 26, 2020, 7:21 a.m. UTC | #1
On 24/05/2020 14.09, David CARLIER wrote:
> Hi here porting qemu_getauxval to FreeBSD. Thanks. Regards.
> 
> From 5be5e56a59631b28ed7b738d251dda252ba9b03e Mon Sep 17 00:00:00 2001
> From: David Carlier <devnexen@gmail.com>
> Date: Sun, 24 May 2020 13:03:32 +0100
> Subject: [PATCH] util/getauxval: FreeBSD has a similar auxilary vector API
> 
> Signed-off-by: David Carlier <devnexen@gmail.com>
> ---
>  configure        | 6 ++++++
>  util/getauxval.c | 6 ++++++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/configure b/configure
> index 2fc05c4465..545fd2364f 100755
> --- a/configure
> +++ b/configure
> @@ -5824,7 +5824,13 @@ getauxval=no
>  cat > $TMPC << EOF
>  #include <sys/auxv.h>
>  int main(void) {
> +#if defined(__linux__)
>    return getauxval(AT_HWCAP) == 0;
> +#elif defined(__FreeBSD__)
> +  unsigned long a = 0;
> +  return elf_aux_info(AT_HWCAP, &a, sizeof(a)) == 0;
> +#endif
> +  return 1;
>  }
>  EOF
>  if compile_prog "" "" ; then

That configure check looks wrong. On other systems (i.e. non-Linux and
non-FreeBSD), this code snippet will now compile successfully and thus
the configure script sets getauxval=yes. I'd suggest you change it this
way instead:

 int main(void) {
+#if defined(__FreeBSD__)
+  unsigned long a = 0;
+  return elf_aux_info(AT_HWCAP, &a, sizeof(a)) == 0;
+#else
   return getauxval(AT_HWCAP) == 0;
+#endif
 }

... so that it still fails to compile by default on other systems.

 Thomas
David Carlier May 26, 2020, 7:37 a.m. UTC | #2
From 316cbdea0434a523c78d3f18fe7e6697577e4aae Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen@gmail.com>
Date: Tue, 26 May 2020 08:33:12 +0100
Subject: [PATCH] util/getauxval: Porting to FreeBSD the getauxval feature

FreeBSD has a similar API for auxiliary vector.

Signed-off-by: David Carlier <devnexen@gmail.com>
---
 configure        | 5 +++++
 util/getauxval.c | 6 ++++++
 2 files changed, 11 insertions(+)

diff --git a/configure b/configure
index 2fc05c4465..2c93867080 100755
--- a/configure
+++ b/configure
@@ -5824,7 +5824,12 @@ getauxval=no
 cat > $TMPC << EOF
 #include <sys/auxv.h>
 int main(void) {
+#if defined(__FreeBSD__)
+  unsigned long a = 0;
+  return elf_aux_info(AT_HWCAP, &a, sizeof(a)) == 0;
+#else
   return getauxval(AT_HWCAP) == 0;
+#endif
 }
 EOF
 if compile_prog "" "" ; then
diff --git a/util/getauxval.c b/util/getauxval.c
index 36afdfb9e6..373ed3899f 100644
--- a/util/getauxval.c
+++ b/util/getauxval.c
@@ -33,7 +33,13 @@

 unsigned long qemu_getauxval(unsigned long key)
 {
+#if defined(__linux__)
     return getauxval(key);
+#elif defined(__FreeBSD__)
+    unsigned long aux = 0;
+    elf_aux_info(key, &aux, sizeof(aux));
+    return aux;
+#endif
 }
 #elif defined(__linux__)
 #include "elf.h"
diff mbox series

Patch

diff --git a/configure b/configure
index 2fc05c4465..545fd2364f 100755
--- a/configure
+++ b/configure
@@ -5824,7 +5824,13 @@  getauxval=no
 cat > $TMPC << EOF
 #include <sys/auxv.h>
 int main(void) {
+#if defined(__linux__)
   return getauxval(AT_HWCAP) == 0;
+#elif defined(__FreeBSD__)
+  unsigned long a = 0;
+  return elf_aux_info(AT_HWCAP, &a, sizeof(a)) == 0;
+#endif
+  return 1;
 }
 EOF
 if compile_prog "" "" ; then
diff --git a/util/getauxval.c b/util/getauxval.c
index 36afdfb9e6..373ed3899f 100644
--- a/util/getauxval.c
+++ b/util/getauxval.c
@@ -33,7 +33,13 @@ 

 unsigned long qemu_getauxval(unsigned long key)
 {
+#if defined(__linux__)
     return getauxval(key);
+#elif defined(__FreeBSD__)
+    unsigned long aux = 0;
+    elf_aux_info(key, &aux, sizeof(aux));
+    return aux;
+#endif
 }
 #elif defined(__linux__)
 #include "elf.h"