[PATCH] tools: Use posix_memalign instead of valloc for NetBSD

Frediano Ziglio posted 1 patch 3 days, 3 hours ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20260430095521.8399-1-frediano.ziglio@cloud.com
tools/include/xenctrl.h     | 5 +++++
tools/libs/ctrl/xc_netbsd.c | 9 ++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)
[PATCH] tools: Use posix_memalign instead of valloc for NetBSD
Posted by Frediano Ziglio 3 days, 3 hours ago
More similar to other implementation.
posix_memalign was adde in NetBSD 8.0, released on July 17, 2018
and went out of support on May 4, 2024.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
---
 tools/include/xenctrl.h     | 5 +++++
 tools/libs/ctrl/xc_netbsd.c | 9 ++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index d5dbf69c89..f4316089e7 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -1390,6 +1390,11 @@ int xc_lockprof_query(xc_interface *xch,
                       uint64_t *time,
                       xc_hypercall_buffer_t *data);
 
+/**
+ * Allocate memory with a given alignment.
+ * The alignment must be a power of 2 and at least sizeof(void*).
+ * It returns NULL on error, errno is not set.
+ */
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
 
 /**
diff --git a/tools/libs/ctrl/xc_netbsd.c b/tools/libs/ctrl/xc_netbsd.c
index 1318d4d906..d27154dce9 100644
--- a/tools/libs/ctrl/xc_netbsd.c
+++ b/tools/libs/ctrl/xc_netbsd.c
@@ -60,7 +60,14 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
 
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
 {
-    return valloc(size);
+    int ret;
+    void *ptr;
+
+    ret = posix_memalign(&ptr, alignment, size);
+    if (ret != 0 || !ptr)
+        return NULL;
+
+    return ptr;
 }
 
 int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
-- 
2.43.0
Re: [PATCH] tools: Use posix_memalign instead of valloc for NetBSD
Posted by Roger Pau Monné 3 days, 2 hours ago
Adding Manuel that maintains the NetBSD xen-tools package.

On Thu, Apr 30, 2026 at 10:55:21AM +0100, Frediano Ziglio wrote:
> More similar to other implementation.
> posix_memalign was adde in NetBSD 8.0, released on July 17, 2018
> and went out of support on May 4, 2024.
> 
> Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
> ---
>  tools/include/xenctrl.h     | 5 +++++
>  tools/libs/ctrl/xc_netbsd.c | 9 ++++++++-
>  2 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
> index d5dbf69c89..f4316089e7 100644
> --- a/tools/include/xenctrl.h
> +++ b/tools/include/xenctrl.h
> @@ -1390,6 +1390,11 @@ int xc_lockprof_query(xc_interface *xch,
>                        uint64_t *time,
>                        xc_hypercall_buffer_t *data);
>  
> +/**
> + * Allocate memory with a given alignment.
> + * The alignment must be a power of 2 and at least sizeof(void*).
> + * It returns NULL on error, errno is not set.
> + */
>  void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
>  
>  /**
> diff --git a/tools/libs/ctrl/xc_netbsd.c b/tools/libs/ctrl/xc_netbsd.c
> index 1318d4d906..d27154dce9 100644
> --- a/tools/libs/ctrl/xc_netbsd.c
> +++ b/tools/libs/ctrl/xc_netbsd.c
> @@ -60,7 +60,14 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
>  
>  void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
>  {
> -    return valloc(size);
> +    int ret;
> +    void *ptr;
> +
> +    ret = posix_memalign(&ptr, alignment, size);
> +    if (ret != 0 || !ptr)
> +        return NULL;
> +
> +    return ptr;
>  }
>  
>  int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
> -- 
> 2.43.0
>
Re: [PATCH] tools: Use posix_memalign instead of valloc for NetBSD
Posted by Manuel Bouyer 2 days, 17 hours ago
On Thu, Apr 30, 2026 at 12:48:53PM +0200, Roger Pau Monné wrote:
> Adding Manuel that maintains the NetBSD xen-tools package.

thanks
AFAIK this patch is fine

-- 
Manuel Bouyer <bouyer@antioche.eu.org>
     NetBSD: 26 ans d'experience feront toujours la difference
--