util: fix to get configuration macros in util/mmap-alloc.c
PATCH 1/1 util: fix to get configuration macros in util/mmap-alloc.c
The CONFIG_LINUX symbol is always not defined in this file. This fixes that "config-host.h" header file is not included for getting macros.
--- util/mmap-alloc.c | 2 ++ 1 file changed, 2 insertions(+)
util/mmap-alloc.c +2 -0
@@ -10,6 +10,8 @@* later. See the COPYING file in the top-level directory. */ +#include "config-host.h" +#ifdef CONFIG_LINUX #include <linux/mman.h> #else /* !CONFIG_LINUX */
Signature · 1 line
2.17.1
Quoted 14 lines · Jingqi Liu
The
CONFIG_LINUXsymbol is always not defined in this file. This fixes that "config-host.h" header file is not included for getting macros.Signed-off-by Jingqi Liu <[email protected]>---
util/mmap-alloc.c| 2 ++1 file changed, 2 insertions(+)util/mmap-alloc.c +0
-0
util/mmap-alloc.c line 14
Quoted 5 lines
util/mmap-alloc.c +2
-0@@ -10,6 +10,8 @@* later. See the COPYING file in the top-level directory. */ +#include "config-host.h" +
According to CODING_STYLE.rst, qemu/osdep.h is the header file that should be included first, before all the other includes.
So the minimal fix would be moving qemu/osdep.h up here.
util/mmap-alloc.c line 17
Quoted 3 lines
util/mmap-alloc.c +0
-0#ifdef CONFIG_LINUX #include <linux/mman.h> #else /* !CONFIG_LINUX */
Introduced by commit 119906afa5ca610adb87c55ab0d8e53c9104bfc3
Jano
Quoted 4 lines
Signature · 1 line
2.17.1
Quoted 19 lines · Ján Tomko
Quoted 17 lines · Jingqi Liu
The
CONFIG_LINUXsymbol is always not defined in this file. This fixes that "config-host.h" header file is not included for getting macros.Signed-off-by Jingqi Liu <[email protected]>---
util/mmap-alloc.c| 2 ++1 file changed, 2 insertions(+)util/mmap-alloc.c +0
-0@@ -10,6 +10,8 @@* later. See the COPYING file in the top-level directory. */
Quoted 7 lines
util/mmap-alloc.c line 14
Quoted 2 lines
util/mmap-alloc.c +2
-0+#include "config-host.h" +According to
CODING_STYLE.rst,qemu/osdep.his the header file that should be included first, before all the other includes.So the minimal fix would be moving
qemu/osdep.hup here.
Yes, osdep must always be first.
Quoted 3 lines
util/mmap-alloc.c line 17
Quoted 3 lines
util/mmap-alloc.c +0
-0#ifdef CONFIG_LINUX #include <linux/mman.h> #else /* !CONFIG_LINUX */
Do we really need this? osdep.h will pull in sys/mman.h for you, which should define the MAP_* constants.
Also, you have no fallbmack for "I'm on Linux but the system headers don't define MAP_SHARED_VALIDATE or MAP_SYNC". Wouldn't it be better to just have #ifndef MAP_SYNC
#define MAP_SYNC 0
#endif
etc ?
thanks
-- PMM
Quoted 33 lines · Peter Maydell
Quoted 18 lines · Ján Tomko
Quoted 17 lines · Jingqi Liu
The
CONFIG_LINUXsymbol is always not defined in this file. This fixes that "config-host.h" header file is not included for getting macros.Signed-off-by Jingqi Liu <[email protected]>---
util/mmap-alloc.c| 2 ++1 file changed, 2 insertions(+)util/mmap-alloc.c +0
-0@@ -10,6 +10,8 @@* later. See the COPYING file in the top-level directory. */ Quoted 6 lines
util/mmap-alloc.c line 14
Quoted 2 lines
util/mmap-alloc.c +2
-0+#include "config-host.h" +According to
CODING_STYLE.rst,qemu/osdep.his the header file that should be included first, before all the other includes.So the minimal fix would be moving
qemu/osdep.hup here.Yes, osdep must always be first.
Quoted 3 lines
util/mmap-alloc.c line 17
Quoted 3 lines
util/mmap-alloc.c +0
-0#ifdef CONFIG_LINUX #include <linux/mman.h> #else /* !CONFIG_LINUX */ Do we really need this?
osdep.hwill pull insys/mman.hfor you, which should define the MAP_* constants.
Quoted 8 lines
Also, you have no fallbmack for "I'm on Linux but the system headers don't define
MAP_SHARED_VALIDATEorMAP_SYNC". Wouldn't it be better to just have #ifndefMAP_SYNC
#defineMAP_SYNC0
#endifetc ?
Thanks for your review.
The system headers bits/mman.h (which is included by sys/mman.h)
don't define MAP_SYNC and MAP_SHARED_VALIDATE on linux.
They're defined in linux-headers/asm-generic/mman-common.h ( which is included by linux/mman.h).
Another MAP_* macros are defined in both header files.
As you mentioned, if don't include linux/mman.h, just defines as following:
#ifndef MAP_SYNC
#define MAP_SYNC 0
#endif
The MAP_SYNC is always 0 since MAP_SYNC isn't defined in system header.
Thanks,
Jingqi
Quoted 3 lines
thanks
-- PMM
Quoted 33 lines · Peter Maydell
Quoted 18 lines · Ján Tomko
Quoted 17 lines · Jingqi Liu
The
CONFIG_LINUXsymbol is always not defined in this file. This fixes that "config-host.h" header file is not included for getting macros.Signed-off-by Jingqi Liu <[email protected]>---
util/mmap-alloc.c| 2 ++1 file changed, 2 insertions(+)util/mmap-alloc.c +0
-0@@ -10,6 +10,8 @@* later. See the COPYING file in the top-level directory. */ Quoted 6 lines
util/mmap-alloc.c line 14
Quoted 2 lines
util/mmap-alloc.c +2
-0+#include "config-host.h" +According to
CODING_STYLE.rst,qemu/osdep.his the header file that should be included first, before all the other includes.So the minimal fix would be moving
qemu/osdep.hup here.Yes, osdep must always be first.
Quoted 3 lines
util/mmap-alloc.c line 17
Quoted 3 lines
util/mmap-alloc.c +0
-0#ifdef CONFIG_LINUX #include <linux/mman.h> #else /* !CONFIG_LINUX */ Do we really need this?
osdep.hwill pull insys/mman.hfor you, which should define the MAP_* constants.
Quoted 8 lines
Also, you have no fallbmack for "I'm on Linux but the system headers don't define
MAP_SHARED_VALIDATEorMAP_SYNC". Wouldn't it be better to just have #ifndefMAP_SYNC
#defineMAP_SYNC0
#endifetc ?
osdep.h pulls in sys/mman.h, which defines the MAP_* constants
except for MAP_SYNC and MAP_SHARED_VALIDATE on Linux.
How about just adding the following code in util/mmap-alloc.c ?
#ifndef MAP_SYNC
#define MAP_SYNC 0x80000
#endif
#ifndef MAP_SYNC
#define MAP_SYNC 0x80000
#endif
#ifndef MAP_SHARED_VALIDATE
#define MAP_SHARED_VALIDATE 0x03
#endif
Thanks,
Jingqi
Quoted 3 lines
thanks
-- PMM
Quoted 42 lines · Jingqi
Quoted 40 lines · Peter Maydell
Quoted 18 lines · Ján Tomko
Quoted 17 lines · Jingqi Liu
The
CONFIG_LINUXsymbol is always not defined in this file. This fixes that "config-host.h" header file is not included for getting macros.Signed-off-by Jingqi Liu <[email protected]>---
util/mmap-alloc.c| 2 ++1 file changed, 2 insertions(+)util/mmap-alloc.c +0
-0@@ -10,6 +10,8 @@* later. See the COPYING file in the top-level directory. */ Quoted 6 lines
util/mmap-alloc.c line 14
Quoted 2 lines
util/mmap-alloc.c +2
-0+#include "config-host.h" +According to
CODING_STYLE.rst,qemu/osdep.his the header file that should be included first, before all the other includes.So the minimal fix would be moving
qemu/osdep.hup here.Yes, osdep must always be first.
Quoted 3 lines
util/mmap-alloc.c line 17
Quoted 3 lines
util/mmap-alloc.c +0
-0#ifdef CONFIG_LINUX #include <linux/mman.h> #else /* !CONFIG_LINUX */ Do we really need this?
osdep.hwill pull insys/mman.hfor you, which should define the MAP_* constants.Also, you have no fallbmack for "I'm on Linux but the system headers don't define
MAP_SHARED_VALIDATEorMAP_SYNC". Wouldn't it be better to just have #ifndefMAP_SYNC
#defineMAP_SYNC0
#endif
Quoted 4 lines
Quoted 1 line
etc ?
osdep.hpulls insys/mman.h, which defines the MAP_* constantsexcept for
MAP_SYNCandMAP_SHARED_VALIDATEon Linux.
Why not? Is this just "not yet in the version of glibc we're using", or is it a bug/missed feature in glibc that needs to be addressed there ?
Quoted 9 lines
How about just adding the following code in
util/mmap-alloc.c?#ifndef
MAP_SYNC
#defineMAP_SYNC0x80000
#endif#ifndef
MAP_SHARED_VALIDATE
#defineMAP_SHARED_VALIDATE0x03
#endif
You don't want to do that for non-Linux systems, so there you need to fall back to defining them to be 0.
Are there any systems (distros) where the standard system sys/mman.h does not define these new MAP_* constants but we still really really need to use them? If not, then we could just have the fallback-to-0 fallback everywhere.
thanks
-- PMM
Quoted 42 lines · Peter Maydell
Quoted 41 lines · Jingqi
Quoted 40 lines · Peter Maydell
Quoted 18 lines · Ján Tomko
Quoted 17 lines · Jingqi Liu
The
CONFIG_LINUXsymbol is always not defined in this file. This fixes that "config-host.h" header file is not included for getting macros.Signed-off-by Jingqi Liu <[email protected]>---
util/mmap-alloc.c| 2 ++1 file changed, 2 insertions(+)util/mmap-alloc.c +0
-0@@ -10,6 +10,8 @@* later. See the COPYING file in the top-level directory. */ Quoted 6 lines
util/mmap-alloc.c line 14
Quoted 2 lines
util/mmap-alloc.c +2
-0+#include "config-host.h" +According to
CODING_STYLE.rst,qemu/osdep.his the header file that should be included first, before all the other includes.So the minimal fix would be moving
qemu/osdep.hup here.Yes, osdep must always be first.
Quoted 3 lines
util/mmap-alloc.c line 17
Quoted 3 lines
util/mmap-alloc.c +0
-0#ifdef CONFIG_LINUX #include <linux/mman.h> #else /* !CONFIG_LINUX */ Do we really need this?
osdep.hwill pull insys/mman.hfor you, which should define the MAP_* constants.Also, you have no fallbmack for "I'm on Linux but the system headers don't define
MAP_SHARED_VALIDATEorMAP_SYNC". Wouldn't it be better to just have #ifndefMAP_SYNC
#defineMAP_SYNC0
#endif
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
etc ?
osdep.hpulls insys/mman.h, which defines the MAP_* constantsexcept for
MAP_SYNCandMAP_SHARED_VALIDATEon Linux.Why not? Is this just "not yet in the version of glibc we're using", or is it a bug/missed feature in glibc that needs to be addressed there ?
I'm using the version 2.27 of glibc.
I downloaded the version 2.28 of glibc source for compilation and installation.
I found MAP_SYNC and MAP_SHARED_VALIDATE are defined in this version.
Seems it's older glibc version issue.
Quoted 9 lines
Quoted 9 lines
How about just adding the following code in
util/mmap-alloc.c? #ifndefMAP_SYNC
#defineMAP_SYNC0x80000
#endif#ifndef
MAP_SHARED_VALIDATE
#defineMAP_SHARED_VALIDATE0x03
#endif
Quoted 7 lines
You don't want to do that for non-Linux systems, so there you need to fall back to defining them to be 0.
Are there any systems (distros) where the standard system
sys/mman.hdoes not define these new MAP_* constants but we still really really need to use them? If not, then we could just have the fallback-to-0 fallback everywhere.
Good point.
So as you mentioned, it would be better to just have the following code:
#ifndef MAP_SYNC
#define MAP_SYNC 0
#endif
#ifndef MAP_SHARED_VALIDATE
#define MAP_SHARED_VALIDATE 0
#endif
Thanks,
Jingqi
Quoted 3 lines
thanks
-- PMM
Quoted 81 lines · Jingqi
Quoted 42 lines · Peter Maydell
Quoted 41 lines · Jingqi
Quoted 40 lines · Peter Maydell
Quoted 18 lines · Ján Tomko
Quoted 17 lines · Jingqi Liu
The
CONFIG_LINUXsymbol is always not defined in this file. This fixes that "config-host.h" header file is not included for getting macros.Signed-off-by Jingqi Liu <[email protected]>---
util/mmap-alloc.c| 2 ++1 file changed, 2 insertions(+)util/mmap-alloc.c +0
-0@@ -10,6 +10,8 @@* later. See the COPYING file in the top-level directory. */ Quoted 6 lines
util/mmap-alloc.c line 14
Quoted 2 lines
util/mmap-alloc.c +2
-0+#include "config-host.h" +According to
CODING_STYLE.rst,qemu/osdep.his the header file that should be included first, before all the other includes.So the minimal fix would be moving
qemu/osdep.hup here.Yes, osdep must always be first.
Quoted 3 lines
util/mmap-alloc.c line 17
Quoted 3 lines
util/mmap-alloc.c +0
-0#ifdef CONFIG_LINUX #include <linux/mman.h> #else /* !CONFIG_LINUX */ Do we really need this?
osdep.hwill pull insys/mman.hfor you, which should define the MAP_* constants.Also, you have no fallbmack for "I'm on Linux but the system headers don't define
MAP_SHARED_VALIDATEorMAP_SYNC". Wouldn't it be better to just have #ifndefMAP_SYNC
#defineMAP_SYNC0
#endifQuoted 7 lines
Quoted 4 lines
Quoted 1 line
etc ?
osdep.hpulls insys/mman.h, which defines the MAP_* constantsexcept for
MAP_SYNCandMAP_SHARED_VALIDATEon Linux.Why not? Is this just "not yet in the version of glibc we're using", or is it a bug/missed feature in glibc that needs to be addressed there ?
I'm using the version 2.27 of glibc.
I downloaded the version 2.28 of glibc source for compilation and installation.
I found
MAP_SYNCandMAP_SHARED_VALIDATEare defined in this version.Seems it's older glibc version issue.
Quoted 9 lines
Quoted 9 lines
How about just adding the following code in
util/mmap-alloc.c? #ifndefMAP_SYNC
#defineMAP_SYNC0x80000
#endif#ifndef
MAP_SHARED_VALIDATE
#defineMAP_SHARED_VALIDATE0x03
#endifQuoted 7 lines
You don't want to do that for non-Linux systems, so there you need to fall back to defining them to be 0.
Are there any systems (distros) where the standard system
sys/mman.hdoes not define these new MAP_* constants but we still really really need to use them? If not, then we could just have the fallback-to-0 fallback everywhere.Good point.
So as you mentioned, it would be better to just have the following code:
Quoted 7 lines
#ifndef
MAP_SYNC
#defineMAP_SYNC0
#endif#ifndef
MAP_SHARED_VALIDATE
#defineMAP_SHARED_VALIDATE0
#endif
Won't this defeat the purpose of MAP_SHARED_VALIDATE?
We really have linux-headers/linux/mman.h for exactly this purpose.
Quoted 7 lines
Thanks,
Jingqi
Quoted 3 lines
thanks
-- PMM
Quoted 83 lines · Michael S. Tsirkin
Quoted 82 lines · Jingqi
Quoted 42 lines · Peter Maydell
Quoted 41 lines · Jingqi
Quoted 40 lines · Peter Maydell
Quoted 18 lines · Ján Tomko
Quoted 17 lines · Jingqi Liu
The
CONFIG_LINUXsymbol is always not defined in this file. This fixes that "config-host.h" header file is not included for getting macros.Signed-off-by Jingqi Liu <[email protected]>---
util/mmap-alloc.c| 2 ++1 file changed, 2 insertions(+)util/mmap-alloc.c +0
-0@@ -10,6 +10,8 @@* later. See the COPYING file in the top-level directory. */ Quoted 6 lines
util/mmap-alloc.c line 14
Quoted 2 lines
util/mmap-alloc.c +2
-0+#include "config-host.h" +According to
CODING_STYLE.rst,qemu/osdep.his the header file that should be included first, before all the other includes.So the minimal fix would be moving
qemu/osdep.hup here.Yes, osdep must always be first.
Quoted 3 lines
util/mmap-alloc.c line 17
Quoted 3 lines
util/mmap-alloc.c +0
-0#ifdef CONFIG_LINUX #include <linux/mman.h> #else /* !CONFIG_LINUX */ Do we really need this?
osdep.hwill pull insys/mman.hfor you, which should define the MAP_* constants.Also, you have no fallbmack for "I'm on Linux but the system headers don't define
MAP_SHARED_VALIDATEorMAP_SYNC". Wouldn't it be better to just have #ifndefMAP_SYNC
#defineMAP_SYNC0
#endifQuoted 7 lines
Quoted 4 lines
Quoted 1 line
etc ?
osdep.hpulls insys/mman.h, which defines the MAP_* constantsexcept for
MAP_SYNCandMAP_SHARED_VALIDATEon Linux.Why not? Is this just "not yet in the version of glibc we're using", or is it a bug/missed feature in glibc that needs to be addressed there ?
I'm using the version 2.27 of glibc.
I downloaded the version 2.28 of glibc source for compilation and installation.
I found
MAP_SYNCandMAP_SHARED_VALIDATEare defined in this version.Seems it's older glibc version issue.
Quoted 8 lines
Quoted 8 lines
How about just adding the following code in
util/mmap-alloc.c? #ifndefMAP_SYNC
#defineMAP_SYNC0x80000
#endif#ifndef
MAP_SHARED_VALIDATE
#defineMAP_SHARED_VALIDATE0x03
#endifQuoted 7 lines
You don't want to do that for non-Linux systems, so there you need to fall back to defining them to be 0.
Are there any systems (distros) where the standard system
sys/mman.hdoes not define these new MAP_* constants but we still really really need to use them? If not, then we could just have the fallback-to-0 fallback everywhere.Good point.
So as you mentioned, it would be better to just have the following code:
#ifndef
MAP_SYNC
#defineMAP_SYNC0
#endif
Quoted 6 lines
Quoted 3 lines
#ifndef
MAP_SHARED_VALIDATE
#defineMAP_SHARED_VALIDATE0
#endifWon't this defeat the purpose of
MAP_SHARED_VALIDATE?We really have
linux-headers/linux/mman.hfor exactly this purpose.
Yes, linux-headers/linux/mman.h has defined MAP_SYNC and MAP_SHARED_VALIDATE.
1) If '#include <linux/mman.h>' first then '#include qemu/osdep.h', it should be fine.
2) Peter mentioned osdep.h should go first.
It will cause redefinitions of other MAP_* macros after '#include <linux/mman.h>'.
This is where the conflict lies.
Any comments ?
Thanks,
Jingqi
Quoted 6 lines
Quoted 6 lines
Thanks,
Jingqi
Quoted 2 lines
thanks
-- PMM
Quoted 9 lines · Jingqi
1) If '#include <
linux/mman.h>' first then '#includeqemu/osdep.h', it should be fine.2) Peter mentioned
osdep.hshould go first.It will cause redefinitions of other MAP_* macros after '#include <
linux/mman.h>'.This is where the conflict lies.
osdep.h first, always. Other uses of linux-headers headers have presumably already dealt with this issue...
thanks
-- PMM
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Jingqi
1) If '#include <
linux/mman.h>' first then '#includeqemu/osdep.h', it should be fine.2) Peter mentioned
osdep.hshould go first.
Quoted 7 lines
Quoted 4 lines
It will cause redefinitions of other MAP_* macros after '#include <
linux/mman.h>'.This is where the conflict lies.
osdep.hfirst, always. Other uses of linux-headers headers have presumably already dealt with this issue...
Including linux/mman.h before sys/mman.h is just a workaround to the root cause: both headers really redefine each others' macros, but gcc hide the warnings if the warnings are generated inside system-provided headers.
I believe we should use -isystem for linux-headers insteaad of -I.
Signature · 1 line
Eduardo
Quoted 18 lines · Ján Tomko
Quoted 17 lines · Jingqi Liu
The
CONFIG_LINUXsymbol is always not defined in this file. This fixes that "config-host.h" header file is not included for getting macros.Signed-off-by Jingqi Liu <[email protected]>---
util/mmap-alloc.c| 2 ++1 file changed, 2 insertions(+)util/mmap-alloc.c +0
-0@@ -10,6 +10,8 @@* later. See the COPYING file in the top-level directory. */
Quoted 8 lines
util/mmap-alloc.c line 14
Quoted 2 lines
util/mmap-alloc.c +2
-0+#include "config-host.h" +According to
CODING_STYLE.rst,qemu/osdep.his the header file that should be included first, before all the other includes.So the minimal fix would be moving
qemu/osdep.hup here.
Thanks for your review.
I've tried to simply move "qemu/osdep.h" to the first line.
It caused many macros redefinition errors.
Quoted 6 lines
util/mmap-alloc.c line 17
Quoted 3 lines
util/mmap-alloc.c +0
-0#ifdef CONFIG_LINUX #include <linux/mman.h> #else /* !CONFIG_LINUX */Introduced by commit
119906afa5ca610adb87c55ab0d8e53c9104bfc3
I've checked this commit.
Thanks,
Jingqi
Quoted 7 lines
Jano
Quoted 4 lines
Signature · 1 line
2.17.1