[PATCH 2/2] perf tools: Fix mman macros using mman-fix.h

From: Wang Nan
Date: Tue Sep 06 2016 - 01:49:26 EST


Use mman-fix.h to fix potential undefined macros in mman.h for
building perf in old systems.

Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
Cc: Nilay Vaish <nilayvaish@xxxxxxxxx>
Cc: Hou Pengyang <houpengyang@xxxxxxxxxx>
Cc: He Kuang <hekuang@xxxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/trace/beauty/mmap.c | 63 +-----------------------------------------
tools/perf/util/event.c | 5 +---
tools/perf/util/map.c | 3 +-
3 files changed, 3 insertions(+), 68 deletions(-)

diff --git a/tools/perf/trace/beauty/mmap.c b/tools/perf/trace/beauty/mmap.c
index d0a3a8e..c96b3e2 100644
--- a/tools/perf/trace/beauty/mmap.c
+++ b/tools/perf/trace/beauty/mmap.c
@@ -1,8 +1,5 @@
#include <sys/mman.h>
-
-#ifndef PROT_SEM
-#define PROT_SEM 0x8
-#endif
+#include <asm/mman-fix.h>

static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size,
struct syscall_arg *arg)
@@ -33,31 +30,6 @@ static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size,

#define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot

-#ifndef MAP_FIXED
-#define MAP_FIXED 0x10
-#endif
-
-#ifndef MAP_ANONYMOUS
-#define MAP_ANONYMOUS 0x20
-#endif
-
-#ifndef MAP_32BIT
-#define MAP_32BIT 0x40
-#endif
-
-#ifndef MAP_STACK
-#define MAP_STACK 0x20000
-#endif
-
-#ifndef MAP_HUGETLB
-#define MAP_HUGETLB 0x40000
-#endif
-
-#ifndef MAP_UNINITIALIZED
-#define MAP_UNINITIALIZED 0x4000000
-#endif
-
-
static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size,
struct syscall_arg *arg)
{
@@ -125,39 +97,6 @@ static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size,

#define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags

-#ifndef MADV_HWPOISON
-#define MADV_HWPOISON 100
-#endif
-
-#ifndef MADV_SOFT_OFFLINE
-#define MADV_SOFT_OFFLINE 101
-#endif
-
-#ifndef MADV_MERGEABLE
-#define MADV_MERGEABLE 12
-#endif
-
-#ifndef MADV_UNMERGEABLE
-#define MADV_UNMERGEABLE 13
-#endif
-
-#ifndef MADV_HUGEPAGE
-#define MADV_HUGEPAGE 14
-#endif
-
-#ifndef MADV_NOHUGEPAGE
-#define MADV_NOHUGEPAGE 15
-#endif
-
-#ifndef MADV_DONTDUMP
-#define MADV_DONTDUMP 16
-#endif
-
-#ifndef MADV_DODUMP
-#define MADV_DODUMP 17
-#endif
-
-
static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size,
struct syscall_arg *arg)
{
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 23c3ebd..df85931 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1,5 +1,6 @@
#include <linux/types.h>
#include <sys/mman.h>
+#include <asm/mman-fix.h>
#include <api/fs/fs.h>
#include "event.h"
#include "debug.h"
@@ -249,10 +250,8 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
bool truncation = false;
unsigned long long timeout = proc_map_timeout * 1000000ULL;
int rc = 0;
-#ifdef MAP_HUGETLB
const char *hugetlbfs_mnt = hugetlbfs__mountpoint();
int hugetlbfs_mnt_len = hugetlbfs_mnt ? strlen(hugetlbfs_mnt) : 0;
-#endif

if (machine__is_default_guest(machine))
return 0;
@@ -347,12 +346,10 @@ out:

if (!strcmp(execname, ""))
strcpy(execname, anonstr);
-#ifdef MAP_HUGETLB
if (!strncmp(execname, hugetlbfs_mnt, hugetlbfs_mnt_len)) {
strcpy(execname, anonstr);
event->mmap2.flags |= MAP_HUGETLB;
}
-#endif

size = strlen(execname) + 1;
memcpy(event->mmap2.filename, execname, size);
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index f52d460..76c68853 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -7,6 +7,7 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
+#include <asm/mman-fix.h>
#include "map.h"
#include "thread.h"
#include "strlist.h"
@@ -29,9 +30,7 @@ static inline int is_anon_memory(const char *filename, u32 flags)
{
u32 anon_flags = 0;

-#ifdef MAP_HUGETLB
anon_flags |= MAP_HUGETLB;
-#endif
return flags & anon_flags ||
!strcmp(filename, "//anon") ||
!strncmp(filename, "/dev/zero", sizeof("/dev/zero") - 1) ||
--
1.8.3.4