I read Xen source code and saw something like this:
#define is_domain_direct_mapped(d) ((void)(d), 0)
is_domain_direct_mapped is then used in a if statement as follows (d is a pointer to a struct variable):
if( is_domain_direct_mapped(d) ) {...}
So after compiler replaces is_domain_direct_mapped with its definition, we have something like:
if( ((void)(d), 0) ) {...}
The above if statement is very weird to me. This is the first time I see this kind of statement. How is it supposed to work?
It’s meant to always produce 0
but also evaluate d
, in case it’s something with side-effects like p++
.
As for why you would want to always produce 0
: the implementation is different on ARM.
#define is_domain_direct_mapped(d) ((d) == hardware_domain && dom0_11_mapping)
Notice how d
is evaluated exactly once here too.
Some discussion from when this was first introduced as confirmation – Re: [Xen-devel] [PATCH v3 1/3] xen/x86: introduce is_domain_direct_mapped(d) as (0) on x86:
When I've implemented this defined in common/memory.c, Jan told me to use [1]:
#define is_domain_is_direct_mapped(d) ((void)(d), 0)
I suspect you want the same things here.
referencing Re: [v4] xen/arm: Allow balooning working with 1:1 memory mapping:
And you'll want to make sure (even if unlikely to be needed in practice) that you evaluate the macro argument exactly once in both flavors, i.e. in the case here
#define is_domain_direct_mapped(d) ((void)(d), 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With