PERFORCE change 152762 for review

Peter Wemm peter at FreeBSD.org
Mon Nov 10 12:51:23 PST 2008


http://perforce.freebsd.org/chv.cgi?CH=152762

Change 152762 by peter at peter_hammer on 2008/11/10 20:50:38

	Hack! Hack!  Oh the shame..

Affected files ...

.. //depot/projects/valgrind/coregrind/m_aspacemgr/aspacemgr-freebsd.c#12 edit
.. //depot/projects/valgrind/include/vki/vki-freebsd.h#13 edit

Differences ...

==== //depot/projects/valgrind/coregrind/m_aspacemgr/aspacemgr-freebsd.c#12 (text+ko) ====

@@ -2919,6 +2919,62 @@
 /* static ... to keep it out of the stack frame. */
 static Char procmap_buf[M_PROCMAP_BUF];
 
+#if defined(VGP_x86_freebsd)
+static Bool is32on64(void)
+{
+   Int oid[2];
+   vki_size_t len;
+   char machbuf[32];
+   static Int is32on64 = -1;
+   SysRes sres;
+
+   if (is32on64 == -1) {
+      oid[0] = VKI_CTL_HW;
+      oid[1] = VKI_HW_MACHINE;
+      len = sizeof(machbuf);
+      sres =  VG_(do_syscall6)(__NR___sysctl, (UWord)oid, 2, (UWord)machbuf, (UWord)&len, 0, 0);
+      if (!sres.isError) {
+         machbuf[31] = '\0';
+         if (VG_(strcmp)(machbuf, "amd64") == 0)
+            is32on64 = 1;
+         else
+            is32on64 = 0;
+      } else {
+         is32on64 = -2;
+      }
+   }
+   if (is32on64 == 1) {
+      return True;
+   } else {
+      return False;
+   }
+}
+
+static void fix_32on64(vki_size_t *len)
+{
+   struct vki_kinfo_vmentry_32on64 *kve64, t;
+   struct vki_kinfo_vmentry *kve32;
+
+   aspacem_assert(sizeof(vki_kinfo_vmentry) < sizeof(vki_kinfo_vmentry_32on64));
+   kve64 = (struct vki_kinfo_vmentry_32on64 *)procmap_buf;
+   kve32 = (struct vki_kinfo_vmentry *)procmap_buf;
+   for (i = 0; i < *len / sizeof(vki_kinfo_vmentry_32on64); i++, kve32++, kve64++) {
+      t = *kve64;
+      aspacem_assert(t.kve_start < 0x100000000ul);
+      aspacem_assert(t.kve_end < 0x100000000ul);
+      kve32->kve_structsize = t.kve_structsize;
+      kve32->kve_start = t.kve_start;
+      kve32->kve_end = t.kve_end;
+      kve32->kve_protection = t.kve_protection;
+      kve32->kve_path = t.kve_path;
+      kve32->kve_offset = t.kve_offset;
+      kve32->kve_fsid = t.kve_fsid;
+      kve32->kve_fileid = t.kve_fileid;
+   }
+   *len = *len * sizeof(vki_kinfo_vmentry) / sizeof(vki_kinfo_vmentry_32on64);
+}
+#endif
+
 static void parse_procselfmaps (
       void (*record_mapping)( Addr addr, SizeT len, UInt prot,
                               ULong dev, ULong ino, ULong offset, 
@@ -2950,6 +3006,10 @@
       VG_(debugLog)(0, "procselfmaps", "sysctl %ld\n", sres.err);
       ML_(am_exit)(1);
    }
+#if defined(VGP_x86_freebsd)
+   if (is32on64())
+      fix_32on64(&len);
+#endif
 
    gapStart = Addr_MIN;
    i = 0;

==== //depot/projects/valgrind/include/vki/vki-freebsd.h#13 (text+ko) ====

@@ -1810,6 +1810,28 @@
 	int	kve_ispare[3];
 };
 
+#if defined(VGP_x86_freebsd)
+/* Special case.. adapt to what the 64 bit kernel gives us */
+struct vki_kinfo_vmentry_32on64 {
+	int	kve_structsize;
+	int	kve_type;
+	ULong	kve_start;
+	ULong	kve_end;
+	int	kve_flags;
+	int	kve_resident;
+	int	kve_private_resident;
+	int	kve_protection;
+	int	kve_ref_count;
+	int	kve_shadow_count;
+	char	kve_path[VKI_PATH_MAX];
+	ULong	kve_pspare[8];
+	Off64T	kve_offset;
+	ULong   kve_fileid;
+	UInt    kve_fsid;
+	int	kve_ispare[3];
+};
+#endif
+
 //----------------------------------------------------------------------
 // From sys/sysctl.h (and related)
 //----------------------------------------------------------------------


More information about the p4-projects mailing list