[PATCH 2/9] util: Make qemu_oom_check() a static function

2022-02-26 Thread Peter Maydell
The qemu_oom_check() function, which we define in both oslib-posix.c and oslib-win32.c, is now used only locally in that file; make it static. Signed-off-by: Peter Maydell --- include/qemu-common.h | 2 -- util/oslib-posix.c| 2 +- util/oslib-win32.c| 2 +- 3 files changed, 2 insertions(

[PATCH 1/9] hw/usb/redirect.c: Stop using qemu_oom_check()

2022-02-26 Thread Peter Maydell
qemu_oom_check() is a function which essentially says "if you pass me a NULL pointer then print a message then abort()". On POSIX systems the message includes strerror(errno); on Windows it includes the GetLastError() error value printed as an integer. Other than in the implementation of qemu_mem

[PATCH 0/9] Cleanup of qemu_oom_check() and qemu_memalign()

2022-02-26 Thread Peter Maydell
This series does some cleanup of the qemu_oom_check() and qemu_memalign() functions; I started looking at the first of these and found myself wanting to tidy some stuff relating to the second in the process. The TLDR is that this series removes qemu_oom_check() (which was mostly being misused), uni

[PATCH 7/9] util: Use meson checks for valloc() and memalign() presence

2022-02-26 Thread Peter Maydell
Instead of assuming that all CONFIG_BSD have valloc() and anything else is memalign(), explicitly check for those functions in meson.build and use the "is the function present" define. Tests for specific functionality are better than which-OS checks; this also lets us give a helpful error message

[PATCH 6/9] util: Share qemu_try_memalign() implementation between POSIX and Windows

2022-02-26 Thread Peter Maydell
The qemu_try_memalign() functions for POSIX and Windows used to be significantly different, but these days they are identical except for the actual allocation function called, and the POSIX version already has to have ifdeffery for different allocation functions. Move to a single implementation in

[PATCH 9/9] osdep: Move memalign-related functions to their own header

2022-02-26 Thread Peter Maydell
Move the various memalign-related functions out of osdep.h and into their own header, which we include only where they are used. While we're doing this, add some brief documentation comments. Signed-off-by: Peter Maydell --- include/qemu/memalign.h| 61 ++

[PATCH 3/9] util: Unify implementations of qemu_memalign()

2022-02-26 Thread Peter Maydell
We implement qemu_memalign() in both oslib-posix.c and oslib-win32.c, but the two versions are essentially the same: they call qemu_try_memalign(), and abort() after printing an error message if it fails. The only difference is that the win32 version prints the GetLastError() value whereas the POS

[PATCH 4/9] util/oslib-win32: Return NULL on qemu_try_memalign() with zero size

2022-02-26 Thread Peter Maydell
Currently if qemu_try_memalign() is asked to allocate 0 bytes, we assert. Instead return NULL; this is in line with the posix_memalign() API, and is valid to pass to _aligned_free() (which will do nothing). This change is a preparation for sharing the qemu_try_memalign() code between Windows and P

[PATCH 5/9] meson.build: Don't misdetect posix_memalign() on Windows

2022-02-26 Thread Peter Maydell
Currently we incorrectly think that posix_memalign() exists on Windows. This is because of a combination of: * the msys2/mingw toolchain/libc claim to have a __builtin_posix_memalign when there isn't a builtin of that name * meson will assume that if you have a __builtin_foo that counts f

[PATCH 8/9] util: Put qemu_vfree() in memalign.c

2022-02-26 Thread Peter Maydell
qemu_vfree() is the companion free function to qemu_memalign(); put it in memalign.c so the allocation and free functions are together. Signed-off-by: Peter Maydell --- util/memalign.c| 11 +++ util/oslib-posix.c | 6 -- util/oslib-win32.c | 6 -- 3 files changed, 11 insert

Re: [PATCH 1/9] hw/usb/redirect.c: Stop using qemu_oom_check()

2022-02-26 Thread Peter Maydell
On Sat, 26 Feb 2022 at 18:07, Peter Maydell wrote: Forgot to cc Gerd on this one as USB maintainer. Sorry.. > qemu_oom_check() is a function which essentially says "if you pass me > a NULL pointer then print a message then abort()". On POSIX systems > the message includes strerror(errno); on Wi

Re: [PATCH 1/9] hw/usb/redirect.c: Stop using qemu_oom_check()

2022-02-26 Thread Richard Henderson
On 2/26/22 08:07, Peter Maydell wrote: qemu_oom_check() is a function which essentially says "if you pass me a NULL pointer then print a message then abort()". On POSIX systems the message includes strerror(errno); on Windows it includes the GetLastError() error value printed as an integer. Oth

Re: [PATCH 2/9] util: Make qemu_oom_check() a static function

2022-02-26 Thread Richard Henderson
On 2/26/22 08:07, Peter Maydell wrote: The qemu_oom_check() function, which we define in both oslib-posix.c and oslib-win32.c, is now used only locally in that file; make it static. Signed-off-by: Peter Maydell --- include/qemu-common.h | 2 -- util/oslib-posix.c| 2 +- util/oslib-win32.

Re: [PATCH 3/9] util: Unify implementations of qemu_memalign()

2022-02-26 Thread Richard Henderson
On 2/26/22 08:07, Peter Maydell wrote: We implement qemu_memalign() in both oslib-posix.c and oslib-win32.c, but the two versions are essentially the same: they call qemu_try_memalign(), and abort() after printing an error message if it fails. The only difference is that the win32 version prints

Re: [PATCH 4/9] util/oslib-win32: Return NULL on qemu_try_memalign() with zero size

2022-02-26 Thread Richard Henderson
On 2/26/22 08:07, Peter Maydell wrote: Currently if qemu_try_memalign() is asked to allocate 0 bytes, we assert. Instead return NULL; this is in line with the posix_memalign() API, and is valid to pass to _aligned_free() (which will do nothing). This change is a preparation for sharing the qemu_

Re: [PATCH 5/9] meson.build: Don't misdetect posix_memalign() on Windows

2022-02-26 Thread Richard Henderson
On 2/26/22 08:07, Peter Maydell wrote: Currently we incorrectly think that posix_memalign() exists on Windows. This is because of a combination of: * the msys2/mingw toolchain/libc claim to have a __builtin_posix_memalign when there isn't a builtin of that name * meson will assume that

Re: [PATCH 4/9] util/oslib-win32: Return NULL on qemu_try_memalign() with zero size

2022-02-26 Thread Richard Henderson
On 2/26/22 08:07, Peter Maydell wrote: Currently if qemu_try_memalign() is asked to allocate 0 bytes, we assert. Instead return NULL; this is in line with the posix_memalign() API, and is valid to pass to _aligned_free() (which will do nothing). This change is a preparation for sharing the qemu_

Re: [PATCH 6/9] util: Share qemu_try_memalign() implementation between POSIX and Windows

2022-02-26 Thread Richard Henderson
On 2/26/22 08:07, Peter Maydell wrote: The qemu_try_memalign() functions for POSIX and Windows used to be significantly different, but these days they are identical except for the actual allocation function called, and the POSIX version already has to have ifdeffery for different allocation funct

Re: [PATCH 7/9] util: Use meson checks for valloc() and memalign() presence

2022-02-26 Thread Richard Henderson
On 2/26/22 08:07, Peter Maydell wrote: Instead of assuming that all CONFIG_BSD have valloc() and anything else is memalign(), explicitly check for those functions in meson.build and use the "is the function present" define. Tests for specific functionality are better than which-OS checks; this a

Re: [PATCH 8/9] util: Put qemu_vfree() in memalign.c

2022-02-26 Thread Richard Henderson
On 2/26/22 08:07, Peter Maydell wrote: qemu_vfree() is the companion free function to qemu_memalign(); put it in memalign.c so the allocation and free functions are together. Signed-off-by: Peter Maydell --- util/memalign.c| 11 +++ util/oslib-posix.c | 6 -- util/oslib-win3

Re: [PATCH 9/9] osdep: Move memalign-related functions to their own header

2022-02-26 Thread Richard Henderson
On 2/26/22 08:07, Peter Maydell wrote: Move the various memalign-related functions out of osdep.h and into their own header, which we include only where they are used. While we're doing this, add some brief documentation comments. Signed-off-by: Peter Maydell --- Reviewed-by: Richard Henderson