qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Use "void *" as parameter for functions that are used for ai


From: Thomas Huth
Subject: Re: [PATCH] Use "void *" as parameter for functions that are used for aio_set_event_notifier()
Date: Fri, 31 May 2024 07:10:23 +0200
User-agent: Mozilla Thunderbird

On 29/05/2024 20.22, Stefan Hajnoczi wrote:
On Wed, May 29, 2024 at 07:49:48PM +0200, Thomas Huth wrote:
aio_set_event_notifier() and aio_set_event_notifier_poll() in
util/aio-posix.c and util/aio-win32.c are casting function pointers of
functions that take an "EventNotifier *" pointer as parameter to function
pointers that take a "void *" pointer as parameter (i.e. the IOHandler
type). When those function pointers are later used to call the referenced
function, this triggers undefined behavior errors with the latest version
of Clang in Fedora 40 when compiling with the option "-fsanitize=undefined".
And this also prevents enabling the strict mode of CFI which is currently
disabled with -fsanitize-cfi-icall-generalize-pointers. Thus let us avoid
the problem by using "void *" as parameter in all spots where it is needed.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
  Yes, I know, the patch looks ugly ... but I don't see a better way to
  tackle this. If someone has a better idea, suggestions are welcome!

An alternative is adding EventNotifierHandler *io_read, *io_poll_ready,
*io_poll_begin, and *io_poll_end fields to EventNotifier so that
aio_set_event_notifier() and aio_set_event_notifier_poll() can pass
helper functions to the underlying aio_set_fd_handler() and
aio_set_fd_poll() APIs. These helper functions then invoke the
EventNotifier callbacks:

/* Helpers */
static void event_notifier_io_read(void *opaque)
{
     EventNotifier *notifier = opaque;
     notifier->io_read(notifier);
}

That's a nice idea, thanks, I'll give it a try!

 Thomas





reply via email to

[Prev in Thread] Current Thread [Next in Thread]