2015-09-07 15:50:09 +08:00
|
|
|
/* Macro file for Coccinelle
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Paolo Bonzini <pbonzini@redhat.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or, at your
|
|
|
|
* option, any later version. See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Coccinelle only does limited parsing of headers, and chokes on some idioms
|
|
|
|
* defined in compiler.h and queue.h. Macros that Coccinelle must know about
|
|
|
|
* in order to parse .c files must be in a separate macro file---which is
|
|
|
|
* exactly what you're staring at now.
|
|
|
|
*
|
|
|
|
* To use this file, add the "--macro-file scripts/cocci-macro-file.h" to the
|
|
|
|
* Coccinelle command line.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* From qemu/compiler.h */
|
2022-04-20 21:26:02 +08:00
|
|
|
#define G_NORETURN __attribute__ ((__noreturn__))
|
2022-02-24 04:58:22 +08:00
|
|
|
#define G_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
2022-02-24 04:58:22 +08:00
|
|
|
#define G_GNUC_NULL_TERMINATED __attribute__((sentinel))
|
2019-05-07 19:55:02 +08:00
|
|
|
|
|
|
|
#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
|
|
|
|
# define QEMU_PACKED __attribute__((gcc_struct, packed))
|
|
|
|
#else
|
|
|
|
# define QEMU_PACKED __attribute__((packed))
|
|
|
|
#endif
|
2015-09-07 15:50:09 +08:00
|
|
|
|
|
|
|
#define cat(x,y) x ## y
|
|
|
|
#define cat2(x,y) cat(x,y)
|
|
|
|
#define QEMU_BUILD_BUG_ON(x) \
|
|
|
|
typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1] __attribute__((unused));
|
|
|
|
|
2022-02-21 00:39:25 +08:00
|
|
|
#define G_GNUC_PRINTF(n, m) __attribute__((format(gnu_printf, n, m)))
|
2015-09-07 15:50:09 +08:00
|
|
|
|
|
|
|
#define xglue(x, y) x ## y
|
|
|
|
#define glue(x, y) xglue(x, y)
|
|
|
|
#define stringify(s) tostring(s)
|
|
|
|
#define tostring(s) #s
|
|
|
|
|
|
|
|
#define typeof_field(type, field) typeof(((type *)0)->field)
|
|
|
|
#define type_check(t1,t2) ((t1*)0 - (t2*)0)
|
|
|
|
|
|
|
|
/* From qemu/queue.h */
|
|
|
|
|
|
|
|
#define QLIST_HEAD(name, type) \
|
|
|
|
struct name { \
|
|
|
|
struct type *lh_first; /* first element */ \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define QLIST_HEAD_INITIALIZER(head) \
|
|
|
|
{ NULL }
|
|
|
|
|
|
|
|
#define QLIST_ENTRY(type) \
|
|
|
|
struct { \
|
|
|
|
struct type *le_next; /* next element */ \
|
|
|
|
struct type **le_prev; /* address of previous next element */ \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Singly-linked List definitions.
|
|
|
|
*/
|
|
|
|
#define QSLIST_HEAD(name, type) \
|
|
|
|
struct name { \
|
|
|
|
struct type *slh_first; /* first element */ \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define QSLIST_HEAD_INITIALIZER(head) \
|
|
|
|
{ NULL }
|
|
|
|
|
|
|
|
#define QSLIST_ENTRY(type) \
|
|
|
|
struct { \
|
|
|
|
struct type *sle_next; /* next element */ \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simple queue definitions.
|
|
|
|
*/
|
|
|
|
#define QSIMPLEQ_HEAD(name, type) \
|
|
|
|
struct name { \
|
|
|
|
struct type *sqh_first; /* first element */ \
|
|
|
|
struct type **sqh_last; /* addr of last next element */ \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define QSIMPLEQ_HEAD_INITIALIZER(head) \
|
|
|
|
{ NULL, &(head).sqh_first }
|
|
|
|
|
|
|
|
#define QSIMPLEQ_ENTRY(type) \
|
|
|
|
struct { \
|
|
|
|
struct type *sqe_next; /* next element */ \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tail queue definitions.
|
|
|
|
*/
|
|
|
|
#define QTAILQ_HEAD(name, type) \
|
qemu/queue.h: reimplement QTAILQ without pointer-to-pointers
QTAILQ is a doubly linked list, with a pointer-to-pointer to the last
element from the head, and the previous element from each node.
But if you squint enough, QTAILQ becomes a combination of a singly-linked
forwards list, and another singly-linked list which goes backwards and
is circular. This is the idea that lets QTAILQ implement reverse
iteration: only, because the backwards list points inside the node,
accessing the previous element needs to go two steps back and one
forwards.
What this patch does is implement it in these terms, without actually
changing the in-memory layout at all. The coexistence of the two lists
is realized by making QTAILQ_HEAD and QTAILQ_ENTRY unions of the forwards
pointer and a generic QTailQLink node. Thq QTailQLink can walk the list in
both directions; the union is needed so that the forwards pointer can
have the correct type, as a sort of poor man's template. While there
are other ways to get the same layout without a union, this one has
the advantage of simpler operation in the debugger, because the fields
tqh_first and tqe_next still exist as before the patch. Those fields are
also used by scripts/qemugdb/mtree.py, so it's a good idea to preserve them.
The advantage of the new representation is that the two-back-one-forward
dance done by backwards accesses can be done all while operating on
QTailQLinks. No casting to the head struct is needed anymore because,
even though the QTailQLink's forward pointer is a void *, we can use
typeof to recover the correct type. This patch only changes the
implementation, not the interface. The next patch will remove the head
struct name from the backwards visit macros.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-12-06 19:01:53 +08:00
|
|
|
union name { \
|
|
|
|
struct type *tqh_first; /* first element */ \
|
|
|
|
QTailQLink tqh_circ; /* link for last element */ \
|
2015-09-07 15:50:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define QTAILQ_HEAD_INITIALIZER(head) \
|
qemu/queue.h: reimplement QTAILQ without pointer-to-pointers
QTAILQ is a doubly linked list, with a pointer-to-pointer to the last
element from the head, and the previous element from each node.
But if you squint enough, QTAILQ becomes a combination of a singly-linked
forwards list, and another singly-linked list which goes backwards and
is circular. This is the idea that lets QTAILQ implement reverse
iteration: only, because the backwards list points inside the node,
accessing the previous element needs to go two steps back and one
forwards.
What this patch does is implement it in these terms, without actually
changing the in-memory layout at all. The coexistence of the two lists
is realized by making QTAILQ_HEAD and QTAILQ_ENTRY unions of the forwards
pointer and a generic QTailQLink node. Thq QTailQLink can walk the list in
both directions; the union is needed so that the forwards pointer can
have the correct type, as a sort of poor man's template. While there
are other ways to get the same layout without a union, this one has
the advantage of simpler operation in the debugger, because the fields
tqh_first and tqe_next still exist as before the patch. Those fields are
also used by scripts/qemugdb/mtree.py, so it's a good idea to preserve them.
The advantage of the new representation is that the two-back-one-forward
dance done by backwards accesses can be done all while operating on
QTailQLinks. No casting to the head struct is needed anymore because,
even though the QTailQLink's forward pointer is a void *, we can use
typeof to recover the correct type. This patch only changes the
implementation, not the interface. The next patch will remove the head
struct name from the backwards visit macros.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-12-06 19:01:53 +08:00
|
|
|
{ .tqh_circ = { NULL, &(head).tqh_circ } }
|
2015-09-07 15:50:09 +08:00
|
|
|
|
|
|
|
#define QTAILQ_ENTRY(type) \
|
qemu/queue.h: reimplement QTAILQ without pointer-to-pointers
QTAILQ is a doubly linked list, with a pointer-to-pointer to the last
element from the head, and the previous element from each node.
But if you squint enough, QTAILQ becomes a combination of a singly-linked
forwards list, and another singly-linked list which goes backwards and
is circular. This is the idea that lets QTAILQ implement reverse
iteration: only, because the backwards list points inside the node,
accessing the previous element needs to go two steps back and one
forwards.
What this patch does is implement it in these terms, without actually
changing the in-memory layout at all. The coexistence of the two lists
is realized by making QTAILQ_HEAD and QTAILQ_ENTRY unions of the forwards
pointer and a generic QTailQLink node. Thq QTailQLink can walk the list in
both directions; the union is needed so that the forwards pointer can
have the correct type, as a sort of poor man's template. While there
are other ways to get the same layout without a union, this one has
the advantage of simpler operation in the debugger, because the fields
tqh_first and tqe_next still exist as before the patch. Those fields are
also used by scripts/qemugdb/mtree.py, so it's a good idea to preserve them.
The advantage of the new representation is that the two-back-one-forward
dance done by backwards accesses can be done all while operating on
QTailQLinks. No casting to the head struct is needed anymore because,
even though the QTailQLink's forward pointer is a void *, we can use
typeof to recover the correct type. This patch only changes the
implementation, not the interface. The next patch will remove the head
struct name from the backwards visit macros.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-12-06 19:01:53 +08:00
|
|
|
union { \
|
|
|
|
struct type *tqe_next; /* next element */ \
|
|
|
|
QTailQLink tqe_circ; /* link for prev element */ \
|
2015-09-07 15:50:09 +08:00
|
|
|
}
|
2016-05-18 17:11:55 +08:00
|
|
|
|
|
|
|
/* From glib */
|
|
|
|
#define g_assert_cmpint(a, op, b) g_assert(a op b)
|
|
|
|
#define g_assert_cmpuint(a, op, b) g_assert(a op b)
|
|
|
|
#define g_assert_cmphex(a, op, b) g_assert(a op b)
|
|
|
|
#define g_assert_cmpstr(a, op, b) g_assert(strcmp(a, b) op 0)
|