Skip to contentSkip to conversation

os-posix: include sys/mman.h

PATCH In review Paolo Bonzini 2 participants 2 messages Jun 6, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 os-posix: include sys/mman.h

qemu/osdep.h checks whether MAP_ANONYMOUS is defined, but this check is bogus without a previous inclusion of sys/mman.h. Include it in sysemu/os-posix.h and remove it from everywhere else.

---
 audio/ossaudio.c                        | 1 -
 block/qcow2-cache.c                     | 1 -
 bsd-user/elfload.c                      | 1 -
 bsd-user/main.c                         | 1 -
 bsd-user/mmap.c                         | 1 -
 bsd-user/syscall.c                      | 1 -
 contrib/ivshmem-server/ivshmem-server.c | 1 -
 exec.c                                  | 1 -
 hw/block/xen_disk.c                     | 1 -
 hw/char/xen_console.c                   | 1 -
 hw/display/xenfb.c                      | 1 -
 hw/i386/kvm/pci-assign.c                | 1 -
 hw/misc/ivshmem.c                       | 2 --
 hw/misc/pc-testdev.c                    | 1 -
 hw/net/xen_nic.c                        | 1 -
 hw/usb/xen-usb.c                        | 1 -
 hw/vfio/common.c                        | 1 -
 hw/vfio/pci.c                           | 1 -
 hw/virtio/virtio-balloon.c              | 4 ----
 hw/xen/xen_backend.c                    | 1 -
 hw/xen/xen_pt_msi.c                     | 1 -
 include/qemu/osdep.h                    | 2 --
 include/sysemu/os-posix.h               | 1 +
 kvm-all.c                               | 1 -
 linux-user/elfload.c                    | 1 -
 linux-user/flatload.c                   | 1 -
 linux-user/main.c                       | 1 -
 linux-user/mmap.c                       | 1 -
 linux-user/strace.c                     | 1 -
 linux-user/syscall.c                    | 1 -
 migration/postcopy-ram.c                | 1 -
 net/netmap.c                            | 1 -
 os-posix.c                              | 1 -
 qemu-char.c                             | 1 -
 scripts/clean-includes                  | 4 +++-
 target-arm/kvm.c                        | 1 -
 target-arm/kvm32.c                      | 1 -
 target-arm/kvm64.c                      | 1 -
 target-i386/kvm.c                       | 1 -
 target-mips/kvm.c                       | 1 -
 target-ppc/kvm.c                        | 1 -
 target-s390x/kvm.c                      | 1 -
 tests/i440fx-test.c                     | 1 -
 tests/ivshmem-test.c                    | 1 -
 tests/vhost-user-bridge.c               | 1 -
 tests/vhost-user-test.c                 | 1 -
 translate-all.c                         | 2 --
 util/memfd.c                            | 2 --
 util/mmap-alloc.c                       | 1 -
 util/osdep.c                            | 4 ----
 util/oslib-posix.c                      | 1 -
 xen-hvm.c                               | 1 -
 xen-mapcache.c                          | 1 -
 53 files changed, 4 insertions(+), 62 deletions(-)
audio/ossaudio.c +0 -1
index a0d9cda..0edd7ea 100644
@@ -22,7 +22,6 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
-#include <sys/mman.h>
 #include <sys/ioctl.h>
 #include <sys/soundcard.h>
 #include "qemu-common.h"
block/qcow2-cache.c +0 -1
index 0fe8eda..4f4ce31 100644
@@ -26,7 +26,6 @@
 #include "qemu/osdep.h"
 
 #if defined(CONFIG_MADVISE) || defined(CONFIG_POSIX_MADVISE)
-#include <sys/mman.h>
 #endif
 
 #include "block/block_int.h"
bsd-user/elfload.c +0 -1
index 898ee05..41a1309 100644
@@ -1,7 +1,6 @@
 /* This is the Linux kernel elf-loading code, ported into user space */
 
 #include "qemu/osdep.h"
-#include <sys/mman.h>
 
 #include "qemu.h"
 #include "disas/disas.h"
bsd-user/main.c +0 -1
index 9f592be..abe9a26 100644
@@ -18,7 +18,6 @@
  */
 #include "qemu/osdep.h"
 #include <machine/trap.h>
-#include <sys/mman.h>
 
 #include "qemu.h"
 #include "qemu/path.h"
bsd-user/mmap.c +0 -1
index 6ab5334..610f91b 100644
@@ -17,7 +17,6 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
-#include <sys/mman.h>
 
 #include "qemu.h"
 #include "qemu-common.h"
bsd-user/syscall.c +0 -1
index 47cf865..a9fe869 100644
@@ -19,7 +19,6 @@
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
 #include "qemu/path.h"
-#include <sys/mman.h>
 #include <sys/syscall.h>
 #include <sys/param.h>
 #include <sys/sysctl.h>
contrib/ivshmem-server/ivshmem-server.c +0 -1
index bf4ee0b..e2f295b 100644
@@ -10,7 +10,6 @@
 #include "qemu/host-utils.h"
 #include "qemu/sockets.h"
 
-#include <sys/mman.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 
exec.c +0 -1
index f2c9e37..226a708 100644
@@ -19,7 +19,6 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #ifndef _WIN32
-#include <sys/mman.h>
 #endif
 
 #include "qemu/cutils.h"
hw/block/xen_disk.c +0 -1
index 064c116..ba7ce54 100644
@@ -21,7 +21,6 @@
 
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
-#include <sys/mman.h>
 #include <sys/uio.h>
 
 #include "hw/hw.h"
hw/char/xen_console.c +0 -1
index cbf1dcc..83108b0 100644
@@ -22,7 +22,6 @@
 #include "qemu/osdep.h"
 #include <sys/select.h>
 #include <termios.h>
-#include <sys/mman.h>
 
 #include "hw/hw.h"
 #include "sysemu/char.h"
hw/display/xenfb.c +0 -1
index 9866dfd..259bcac 100644
@@ -25,7 +25,6 @@
  */
 
 #include "qemu/osdep.h"
-#include <sys/mman.h>
 
 #include "hw/hw.h"
 #include "ui/console.h"
hw/i386/kvm/pci-assign.c +0 -1
index db2cbd2..dd9e73b 100644
@@ -22,7 +22,6 @@
  */
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include <sys/mman.h>
 #include "hw/hw.h"
 #include "hw/i386/pc.h"
 #include "qemu/error-report.h"
hw/misc/ivshmem.c +0 -2
index 90be9f7..c4dde3a 100644
@@ -36,8 +36,6 @@
 
 #include "hw/misc/ivshmem.h"
 
-#include <sys/mman.h>
-
 #define PCI_VENDOR_ID_IVSHMEM   PCI_VENDOR_ID_REDHAT_QUMRANET
 #define PCI_DEVICE_ID_IVSHMEM   0x1110
 
hw/misc/pc-testdev.c +0 -1
index 086893d..34bcebb 100644
@@ -37,7 +37,6 @@
 
 #include "qemu/osdep.h"
 #if defined(CONFIG_POSIX)
-#include <sys/mman.h>
 #endif
 #include "hw/hw.h"
 #include "hw/qdev.h"
hw/net/xen_nic.c +0 -1
index 7281730..0b4ddae 100644
@@ -22,7 +22,6 @@
 #include "qemu/osdep.h"
 #include <sys/socket.h>
 #include <sys/ioctl.h>
-#include <sys/mman.h>
 #include <sys/wait.h>
 
 #include "hw/hw.h"
hw/usb/xen-usb.c +0 -1
index 664df04..09e9656 100644
@@ -22,7 +22,6 @@
 #include <libusb.h>
 #include <stdio.h>
 #include <sys/types.h>
-#include <sys/mman.h>
 #include <sys/time.h>
 
 #include "qemu/osdep.h"
hw/vfio/common.c +0 -1
index e51ed3a..5ff5e92 100644
@@ -20,7 +20,6 @@
 
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
-#include <sys/mman.h>
 #include <linux/vfio.h>
 
 #include "hw/vfio/vfio-common.h"
hw/vfio/pci.c +0 -1
index deab0c6..53b87b7 100644
@@ -21,7 +21,6 @@
 #include "qemu/osdep.h"
 #include <linux/vfio.h>
 #include <sys/ioctl.h>
-#include <sys/mman.h>
 
 #include "hw/pci/msi.h"
 #include "hw/pci/msix.h"
hw/virtio/virtio-balloon.c +0 -4
index 8c15e09..557d3f9 100644
@@ -27,10 +27,6 @@
 #include "qapi-event.h"
 #include "trace.h"
 
-#if defined(__linux__)
-#include <sys/mman.h>
-#endif
-
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 
hw/xen/xen_backend.c +0 -1
index c63f9df..e7ce724 100644
@@ -23,7 +23,6 @@
  */
 
 #include "qemu/osdep.h"
-#include <sys/mman.h>
 #include <sys/signal.h>
 
 #include "hw/hw.h"
hw/xen/xen_pt_msi.c +0 -1
index 9a16f2b..62add06 100644
@@ -10,7 +10,6 @@
  */
 
 #include "qemu/osdep.h"
-#include <sys/mman.h>
 
 #include "hw/xen/xen_backend.h"
 #include "xen_pt.h"
include/qemu/osdep.h +0 -2
index 6937694..e63da28 100644
@@ -197,8 +197,6 @@ void qemu_anon_ram_free(void *ptr, size_t size);
 
 #if defined(CONFIG_MADVISE)
 
-#include <sys/mman.h>
-
 #define QEMU_MADV_WILLNEED  MADV_WILLNEED
 #define QEMU_MADV_DONTNEED  MADV_DONTNEED
 #ifdef MADV_DONTFORK
include/sysemu/os-posix.h +1 -0
index 07e3e5a..9c7dfdf 100644
@@ -26,6 +26,7 @@
 #ifndef QEMU_OS_POSIX_H
 #define QEMU_OS_POSIX_H
 
+#include <sys/mman.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
kvm-all.c +0 -1
index d317dcb..9447e08 100644
@@ -15,7 +15,6 @@
 
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
-#include <sys/mman.h>
 
 #include <linux/kvm.h>
 
linux-user/elfload.c +0 -1
index bb2558f..f807baf 100644
@@ -2,7 +2,6 @@
 #include "qemu/osdep.h"
 #include <sys/param.h>
 
-#include <sys/mman.h>
 #include <sys/resource.h>
 
 #include "qemu.h"
linux-user/flatload.c +0 -1
index f9139c3..48ad1c5 100644
@@ -34,7 +34,6 @@
 /****************************************************************************/
 
 #include "qemu/osdep.h"
-#include <sys/mman.h>
 
 #include "qemu.h"
 #include "flat.h"
linux-user/main.c +0 -1
index 8a11d02..42262a8 100644
@@ -18,7 +18,6 @@
  */
 #include "qemu/osdep.h"
 #include "qemu-version.h"
-#include <sys/mman.h>
 #include <sys/syscall.h>
 #include <sys/resource.h>
 
linux-user/mmap.c +0 -1
index 3519147..c4371d9 100644
@@ -17,7 +17,6 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
-#include <sys/mman.h>
 #include <linux/mman.h>
 #include <linux/unistd.h>
 
linux-user/strace.c +0 -1
index 0810c85..ec9bcff 100644
@@ -5,7 +5,6 @@
 #include <sys/shm.h>
 #include <sys/select.h>
 #include <sys/mount.h>
-#include <sys/mman.h>
 #include <sched.h>
 #include "qemu.h"
 
linux-user/syscall.c +0 -1
index df70255..d03731e 100644
@@ -32,7 +32,6 @@
 #include <sys/personality.h>
 #include <sys/prctl.h>
 #include <sys/resource.h>
-#include <sys/mman.h>
 #include <sys/swap.h>
 #include <linux/capability.h>
 #include <sched.h>
migration/postcopy-ram.c +0 -1
index cf7dcd2..1e422da 100644
@@ -52,7 +52,6 @@ struct PostcopyDiscardState {
 #if defined(__linux__)
 
 #include <poll.h>
-#include <sys/mman.h>
 #include <sys/ioctl.h>
 #include <sys/syscall.h>
 #include <asm/types.h> /* for __u64 */
net/netmap.c +0 -1
index 6cc0db5..64967b9 100644
@@ -26,7 +26,6 @@
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
 #include <net/if.h>
-#include <sys/mman.h>
 #define NETMAP_WITH_LIBS
 #include <net/netmap.h>
 #include <net/netmap_user.h>
os-posix.c +0 -1
index 107fde3..3755265 100644
@@ -26,7 +26,6 @@
 #include "qemu/osdep.h"
 #include <sys/wait.h>
 /*needed for MAP_POPULATE before including qemu-options.h */
-#include <sys/mman.h>
 #include <pwd.h>
 #include <grp.h>
 #include <libgen.h>
qemu-char.c +0 -1
index b13ecbb..c926e9a 100644
@@ -47,7 +47,6 @@
 #include <sys/times.h>
 #include <sys/wait.h>
 #include <termios.h>
-#include <sys/mman.h>
 #include <sys/ioctl.h>
 #include <sys/resource.h>
 #include <sys/socket.h>
scripts/clean-includes +3 -1
index 72b47f1..cdf070d 100755
@@ -104,6 +104,8 @@ for f in "$@"; do
       ;;
     *include/qemu/osdep.h | \
     *include/qemu/compiler.h | \
+    *include/sysemu/os-posix.h | \
+    *include/sysemu/os-win32.h | \
     *include/standard-headers/ )
       # Removing include lines from osdep.h itself would be counterproductive.
       echo "SKIPPING $f (special case header)"
@@ -143,7 +145,7 @@ for f in "$@"; do
            <setjmp.h> <stdarg.h> <stddef.h> <stdbool.h> <stdint.h> <sys/types.h>
            <stdlib.h> <stdio.h> <string.h> <strings.h> <inttypes.h>
            <limits.h> <unistd.h> <time.h> <ctype.h> <errno.h> <fcntl.h>
-           <sys/stat.h> <sys/time.h> <assert.h> <signal.h>
+           <sys/stat.h> <sys/time.h> <assert.h> <signal.h> <sys/mman.h>
            "sysemu/os-posix.h, sysemu/os-win32.h "glib-compat.h"
            "qemu/typedefs.h"
             ))' "$f"
target-arm/kvm.c +0 -1
index 83da447..5c2bd7a 100644
@@ -10,7 +10,6 @@
 
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
-#include <sys/mman.h>
 
 #include <linux/kvm.h>
 
target-arm/kvm32.c +0 -1
index c03e3e5..af3c0b5 100644
@@ -10,7 +10,6 @@
 
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
-#include <sys/mman.h>
 
 #include <linux/kvm.h>
 
target-arm/kvm64.c +0 -1
index e2a34f6..c84d4c7 100644
@@ -11,7 +11,6 @@
 
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
-#include <sys/mman.h>
 #include <sys/ptrace.h>
 
 #include <linux/elf.h>
target-i386/kvm.c +0 -1
index abf50e6..7b092ee 100644
@@ -15,7 +15,6 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include <sys/ioctl.h>
-#include <sys/mman.h>
 #include <sys/utsname.h>
 
 #include <linux/kvm.h>
target-mips/kvm.c +0 -1
index a854e4d..f3f832d 100644
@@ -11,7 +11,6 @@
 
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
-#include <sys/mman.h>
 
 #include <linux/kvm.h>
 
target-ppc/kvm.c +0 -1
index 24d6032..744a6ff 100644
@@ -17,7 +17,6 @@
 #include "qemu/osdep.h"
 #include <dirent.h>
 #include <sys/ioctl.h>
-#include <sys/mman.h>
 #include <sys/vfs.h>
 
 #include <linux/kvm.h>
target-s390x/kvm.c +0 -1
index 8f46fd0..8c5dcab 100644
@@ -23,7 +23,6 @@
 
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
-#include <sys/mman.h>
 
 #include <linux/kvm.h>
 #include <asm/ptrace.h>
tests/i440fx-test.c +0 -1
index 05029e9..59c93b9 100644
@@ -14,7 +14,6 @@
 
 #include "qemu/osdep.h"
 #include <glib.h>
-#include <sys/mman.h>
 
 #include "libqtest.h"
 #include "libqos/pci.h"
tests/ivshmem-test.c +0 -1
index c027ff1..e740c14 100644
@@ -11,7 +11,6 @@
 #include "qemu/osdep.h"
 #include <glib.h>
 #include <glib/gstdio.h>
-#include <sys/mman.h>
 #include "contrib/ivshmem-server/ivshmem-server.h"
 #include "libqos/pci-pc.h"
 #include "libqtest.h"
tests/vhost-user-bridge.c +0 -1
index 0779ba2..57c8f91 100644
@@ -33,7 +33,6 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/unistd.h>
-#include <sys/mman.h>
 #include <sys/eventfd.h>
 #include <arpa/inet.h>
 #include <netdb.h>
tests/vhost-user-test.c +0 -1
index 6961596..b826cbd 100644
@@ -18,7 +18,6 @@
 #include "sysemu/sysemu.h"
 
 #include <linux/vhost.h>
-#include <sys/mman.h>
 #include <sys/vfs.h>
 #include <qemu/sockets.h>
 
translate-all.c +0 -2
index c599dc4..7e9af4a 100644
@@ -18,8 +18,6 @@
  */
 #ifdef _WIN32
 #include <windows.h>
-#else
-#include <sys/mman.h>
 #endif
 #include "qemu/osdep.h"
 
util/memfd.c +0 -2
index 7c40691..8f0e7ce 100644
@@ -30,8 +30,6 @@
 #include <glib.h>
 #include <glib/gprintf.h>
 
-#include <sys/mman.h>
-
 #include "qemu/memfd.h"
 
 #ifdef CONFIG_MEMFD
util/mmap-alloc.c +0 -1
index 0b4cc7f..629d97a 100644
@@ -11,7 +11,6 @@
  */
 #include "qemu/osdep.h"
 #include <qemu/mmap-alloc.h>
-#include <sys/mman.h>
 
 #define HUGETLBFS_MAGIC       0x958458f6
 
util/osdep.c +0 -4
index 9a7a439..ff004e8 100644
@@ -25,10 +25,6 @@
 
 /* Needed early for CONFIG_BSD etc. */
 
-#if defined(CONFIG_MADVISE) || defined(CONFIG_POSIX_MADVISE)
-#include <sys/mman.h>
-#endif
-
 #ifdef CONFIG_SOLARIS
 #include <sys/statvfs.h>
 /* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for
util/oslib-posix.c +0 -1
index 4adde93..e2e1d4d 100644
@@ -36,7 +36,6 @@
 #include "trace.h"
 #include "qapi/error.h"
 #include "qemu/sockets.h"
-#include <sys/mman.h>
 #include <libgen.h>
 #include <sys/signal.h>
 #include "qemu/cutils.h"
xen-hvm.c +0 -1
index 01ee25d..a819b8d 100644
@@ -9,7 +9,6 @@
  */
 
 #include "qemu/osdep.h"
-#include <sys/mman.h>
 
 #include "cpu.h"
 #include "hw/pci/pci.h"
xen-mapcache.c +0 -1
index 49f394a..8f3a592 100644
@@ -17,7 +17,6 @@
 #include "qemu/bitmap.h"
 
 #include <xen/hvm/params.h>
-#include <sys/mman.h>
 
 #include "sysemu/xen-mapcache.h"
 #include "trace.h"
Signature · 1 line
2.5.5
Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Paolo Bonzini

qemu/osdep.h checks whether MAP_ANONYMOUS is defined, but this check is bogus without a previous inclusion of sys/mman.h. Include it in sysemu/os-posix.h and remove it from everywhere else.

block/qcow2-cache.c +0 -0
index 0fe8eda..4f4ce31 100644

block/qcow2-cache.c line 29

Quoted 5 lines
block/qcow2-cache.c +0 -1
@@ -26,7 +26,6 @@
 #include "qemu/osdep.h"
 
 #if defined(CONFIG_MADVISE) || defined(CONFIG_POSIX_MADVISE)
-#include <sys/mman.h>
 #endif

We end up with an empty #if..#endif block here.

hw/misc/pc-testdev.c line 42

Quoted 10 lines
hw/misc/pc-testdev.c +0 -1
@@ -37,7 +37,6 @@
 
 #include "qemu/osdep.h"
 #if defined(CONFIG_POSIX)
-#include <sys/mman.h>
 #endif
 #include "hw/hw.h"
 #include "hw/qdev.h"

...and here.

Otherwise

thanks
-- PMM