Move some kernel constants to the right place.

Also reinstated SF_DEVICE, which is used to ensure we don't try and
leakcheck a page that is mapped from a device.  This got lost in the
2.x-to-3.x transition, or some time after.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4538 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c
index 5b1abba..46a8a64 100644
--- a/coregrind/m_aspacemgr/aspacemgr.c
+++ b/coregrind/m_aspacemgr/aspacemgr.c
@@ -851,8 +851,13 @@
    if (fd != -1 && (flags & SF_FILE)) {
       vg_assert((off & (VKI_PAGE_SIZE-1)) == 0);
 
-      if (VG_(fstat)(fd, &st) < 0)
+      if (VG_(fstat)(fd, &st) < 0) {
 	 flags &= ~SF_FILE;
+      } else {
+         // Note unusual mapping types
+         if (VKI_S_ISCHR(st.st_mode) || VKI_S_ISBLK(st.st_mode))
+            flags |= SF_DEVICE;
+      }
    }
 
    if ((flags & SF_FILE) && filename == NULL && fd != -1)
@@ -1180,7 +1185,8 @@
 
    for (i = 0; i < segments_used; i++) {
       s = &segments[i];
-      flags = s->flags & (SF_SHARED|SF_MMAP|SF_VALGRIND|SF_CORE|SF_STACK);
+      // Note that, for example, we don't want to touch a device page.
+      flags = s->flags & (SF_SHARED|SF_MMAP|SF_VALGRIND|SF_CORE|SF_STACK|SF_DEVICE);
       if (flags != SF_MMAP && flags != SF_STACK && flags != (SF_MMAP|SF_STACK))
          continue;
       if ((s->prot & (VKI_PROT_READ|VKI_PROT_WRITE)) 
diff --git a/coregrind/m_signals.c b/coregrind/m_signals.c
index 0aa4417..9ea1591 100644
--- a/coregrind/m_signals.c
+++ b/coregrind/m_signals.c
@@ -928,7 +928,7 @@
 /* If true, then this Segment may be mentioned in the core */
 static Bool may_dump(const Segment *seg)
 {
-   return (seg->flags & SF_VALGRIND) == 0 && VG_(is_client_addr)(seg->addr);
+   return (seg->flags & (SF_DEVICE|SF_VALGRIND)) == 0 && VG_(is_client_addr)(seg->addr);
 }
 
 /* If true, then this Segment's contents will be in the core */
diff --git a/coregrind/pub_core_aspacemgr.h b/coregrind/pub_core_aspacemgr.h
index 6d2e99f..e3bd9a5 100644
--- a/coregrind/pub_core_aspacemgr.h
+++ b/coregrind/pub_core_aspacemgr.h
@@ -80,6 +80,7 @@
 #define SF_CORE     (1 <<  7) // allocated by core on behalf of the client
 #define SF_VALGRIND (1 <<  8) // a valgrind-internal mapping - not in client
 #define SF_CODE     (1 <<  9) // segment contains cached code
+#define SF_DEVICE   (1 << 10) // device mapping;  avoid careless touching
 
 typedef struct _Segment Segment;
 
diff --git a/include/vki-linux.h b/include/vki-linux.h
index a7010f8..6868e3b 100644
--- a/include/vki-linux.h
+++ b/include/vki-linux.h
@@ -1073,6 +1073,26 @@
 // From linux-2.6.8.1/include/linux/stat.h
 //----------------------------------------------------------------------
 
+#define VKI_S_IFMT  00170000
+#define VKI_S_IFSOCK 0140000
+#define VKI_S_IFLNK  0120000
+#define VKI_S_IFREG  0100000
+#define VKI_S_IFBLK  0060000
+#define VKI_S_IFDIR  0040000
+#define VKI_S_IFCHR  0020000
+#define VKI_S_IFIFO  0010000
+#define VKI_S_ISUID  0004000
+#define VKI_S_ISGID  0002000
+#define VKI_S_ISVTX  0001000
+
+#define VKI_S_ISLNK(m)	(((m) & VKI_S_IFMT) == VKI_S_IFLNK)
+#define VKI_S_ISREG(m)	(((m) & VKI_S_IFMT) == VKI_S_IFREG)
+#define VKI_S_ISDIR(m)	(((m) & VKI_S_IFMT) == VKI_S_IFDIR)
+#define VKI_S_ISCHR(m)	(((m) & VKI_S_IFMT) == VKI_S_IFCHR)
+#define VKI_S_ISBLK(m)	(((m) & VKI_S_IFMT) == VKI_S_IFBLK)
+#define VKI_S_ISFIFO(m)	(((m) & VKI_S_IFMT) == VKI_S_IFIFO)
+#define VKI_S_ISSOCK(m)	(((m) & VKI_S_IFMT) == VKI_S_IFSOCK)
+
 #define VKI_S_IRUSR 00400
 #define VKI_S_IWUSR 00200
 
diff --git a/include/vki-x86-linux.h b/include/vki-x86-linux.h
index 550402a..f713fb3 100644
--- a/include/vki-x86-linux.h
+++ b/include/vki-x86-linux.h
@@ -318,26 +318,6 @@
 // From linux-2.6.8.1/include/asm-i386/stat.h
 //----------------------------------------------------------------------
 
-#define VKI_S_IFMT  00170000
-#define VKI_S_IFSOCK 0140000
-#define VKI_S_IFLNK	 0120000
-#define VKI_S_IFREG  0100000
-#define VKI_S_IFBLK  0060000
-#define VKI_S_IFDIR  0040000
-#define VKI_S_IFCHR  0020000
-#define VKI_S_IFIFO  0010000
-#define VKI_S_ISUID  0004000
-#define VKI_S_ISGID  0002000
-#define VKI_S_ISVTX  0001000
-
-#define VKI_S_ISLNK(m)	(((m) & VKI_S_IFMT) == VKI_S_IFLNK)
-#define VKI_S_ISREG(m)	(((m) & VKI_S_IFMT) == VKI_S_IFREG)
-#define VKI_S_ISDIR(m)	(((m) & VKI_S_IFMT) == VKI_S_IFDIR)
-#define VKI_S_ISCHR(m)	(((m) & VKI_S_IFMT) == VKI_S_IFCHR)
-#define VKI_S_ISBLK(m)	(((m) & VKI_S_IFMT) == VKI_S_IFBLK)
-#define VKI_S_ISFIFO(m)	(((m) & VKI_S_IFMT) == VKI_S_IFIFO)
-#define VKI_S_ISSOCK(m)	(((m) & VKI_S_IFMT) == VKI_S_IFSOCK)
-
 struct vki_stat {
 	unsigned long  st_dev;
 	unsigned long  st_ino;