Skip to content

Commit

Permalink
lockable: Do not cast function pointers
Browse files Browse the repository at this point in the history
-fsanitize=undefined complains if function pointers are casted. It
also prevents enabling the strict mode of CFI which is currently
disabled with -fsanitize-cfi-icall-generalize-pointers.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2345
Signed-off-by: Akihiko Odaki <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
  • Loading branch information
akihikodaki authored and huth committed May 29, 2024
1 parent 2523baf commit a3b3ad7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions include/qemu/lockable.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,30 @@ qemu_null_lockable(void *x)
return NULL;
}

#define QML_FUNC_(name) \
static inline void qemu_lockable_ ## name ## _lock(void *x) \
{ \
qemu_ ## name ## _lock(x); \
} \
static inline void qemu_lockable_ ## name ## _unlock(void *x) \
{ \
qemu_ ## name ## _unlock(x); \
}

QML_FUNC_(mutex)
QML_FUNC_(rec_mutex)
QML_FUNC_(co_mutex)
QML_FUNC_(spin)

/*
* In C, compound literals have the lifetime of an automatic variable.
* In C++ it would be different, but then C++ wouldn't need QemuLockable
* either...
*/
#define QML_OBJ_(x, name) (&(QemuLockable) { \
.object = (x), \
.lock = (QemuLockUnlockFunc *) qemu_ ## name ## _lock, \
.unlock = (QemuLockUnlockFunc *) qemu_ ## name ## _unlock \
#define QML_OBJ_(x, name) (&(QemuLockable) { \
.object = (x), \
.lock = qemu_lockable_ ## name ## _lock, \
.unlock = qemu_lockable_ ## name ## _unlock \
})

/**
Expand Down

0 comments on commit a3b3ad7

Please sign in to comment.