Date: Thu, 23 Oct 2008 05:24:24 GMT From: Peter Wemm <peter@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 151775 for review Message-ID: <200810230524.m9N5OOiQ051666@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=151775 Change 151775 by peter@peter_cheese on 2008/10/23 05:24:08 merge freebsd changes into new MD files before re-shuffling. Affected files ... .. //depot/projects/valgrind/coregrind/launcher-linux.c#2 integrate .. //depot/projects/valgrind/coregrind/m_aspacemgr/aspacemgr-common.c#2 edit .. //depot/projects/valgrind/coregrind/m_aspacemgr/aspacemgr-linux.c#2 integrate Differences ... ==== //depot/projects/valgrind/coregrind/launcher-linux.c#2 (text+ko) ==== @@ -42,7 +42,7 @@ #include <stdlib.h> #include <string.h> #include <sys/mman.h> -#include <sys/user.h> +/* #include <sys/user.h> */ #include <unistd.h> #include "pub_core_debuglog.h" @@ -241,6 +241,10 @@ mode. */ if (0==strcmp(VG_PLATFORM,"x86-linux")) default_platform = "x86-linux"; + else if (0==strcmp(VG_PLATFORM,"x86-freebsd")) + default_platform = "x86-freebsd"; + else if (0==strcmp(VG_PLATFORM,"amd64-freebsd")) + default_platform = "amd64-freebsd"; else if (0==strcmp(VG_PLATFORM,"amd64-linux")) default_platform = "amd64-linux"; else if (0==strcmp(VG_PLATFORM,"ppc32-linux")) @@ -270,14 +274,27 @@ we can tell stage2. stage2 will use the name for recursive invokations of valgrind on child processes. */ memset(launcher_name, 0, PATH_MAX+1); +#if defined(VGO_linux) r = readlink("/proc/self/exe", launcher_name, PATH_MAX); +#elif defined(VGO_freebsd) + r = readlink("/proc/curproc/file", launcher_name, PATH_MAX); +#else +#error "unknown OS" +#endif if (r == -1) { /* If /proc/self/exe can't be followed, don't give up. Instead continue with an empty string for VALGRIND_LAUNCHER. In the sys_execve wrapper, this is tested, and if found to be empty, fail the execve. */ +#if defined(VGO_linux) fprintf(stderr, "valgrind: warning (non-fatal): " "readlink(\"/proc/self/exe\") failed.\n"); +#elif defined(VGO_freebsd) + fprintf(stderr, "valgrind: warning (non-fatal): " + "readlink(\"/proc/curproc/file\") failed.\n"); +#else +#error "unknown OS" +#endif fprintf(stderr, "valgrind: continuing, however --trace-children=yes " "will not work.\n"); } ==== //depot/projects/valgrind/coregrind/m_aspacemgr/aspacemgr-common.c#2 (text+ko) ==== @@ -159,6 +159,13 @@ || defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5) res = VG_(do_syscall6)(__NR_mmap, (UWord)start, length, prot, flags, fd, offset); +# elif defined(VGO_freebsd) + if (flags & VKI_MAP_ANONYMOUS && fd == 0) + fd = -1; + // AAA: fix 64 bit start + // QQQ: truncates to 32 bit offset!! + res = VG_(do_syscall7)(__NR_mmap, (UWord)start, length, + prot, flags, fd, 0, offset); # else # error Unknown platform # endif @@ -196,6 +203,10 @@ ML_(am_barf)("ML_(am_do_extend_mapping_NO_NOTIFY) on AIX5"); /* NOTREACHED, but gcc doesn't understand that */ return VG_(mk_SysRes_Error)(0); +# elif defined(VGO_freebsd) + ML_(am_barf)("ML_(am_do_extend_mapping_NO_NOTIFY) on FreeBSD"); + /* NOTREACHED, but gcc doesn't understand that */ + return VG_(mk_SysRes_Error)(0); # else # error Unknown OS # endif @@ -221,6 +232,10 @@ ML_(am_barf)("ML_(am_do_relocate_nooverlap_mapping_NO_NOTIFY) on AIX5"); /* NOTREACHED, but gcc doesn't understand that */ return VG_(mk_SysRes_Error)(0); +# elif defined(VGO_freebsd) + ML_(am_barf)("ML_(am_do_relocate_nooverlap_mapping_NO_NOTIFY) on FreeBSD"); + /* NOTREACHED, but gcc doesn't understand that */ + return VG_(mk_SysRes_Error)(0); # else # error Unknown OS # endif ==== //depot/projects/valgrind/coregrind/m_aspacemgr/aspacemgr-linux.c#2 (text+ko) ==== @@ -352,6 +352,7 @@ /* Given a file descriptor, attempt to deduce its filename. To do this, we use /proc/self/fd/<FD>. If this doesn't point to a file, or if it doesn't exist, we return False. */ +#if defined(VGO_linux) static Bool get_name_for_fd ( Int fd, /*OUT*/HChar* buf, Int nbuf ) { @@ -366,6 +367,49 @@ else return False; } +#elif defined(VGO_freebsd) +static +Bool get_name_for_fd ( Int fd, HChar* buf, Int nbuf ) +{ + static int nr_fromfd = -1; + SysRes res; + Int i; + + for (i = 0; i < nbuf; i++) buf[i] = 0; + if (nr_fromfd == -1) { + int oid[2]; + int real_oid[10]; + vki_size_t oidlen; + char *name = "machdep.getpath_fromfd_num"; + vki_size_t len; + int sc; + + oid[0] = 0; /* magic */ + oid[1] = 3; /* undocumented */ + oidlen = sizeof(real_oid); + res = VG_(do_syscall6)(__NR___sysctl, (UWord)oid, 2, (UWord)real_oid, (UWord)&oidlen, (UWord)name, strlen(name)); + oidlen /= sizeof(int); + if (!res.isError && oidlen > 0) { + len = sizeof(sc); + res = VG_(do_syscall6)(__NR___sysctl, (UWord)real_oid, oidlen, (UWord)&sc, (UWord)&len, 0, 0); + if (!res.isError && sc > 0) + nr_fromfd = sc; + } + if (nr_fromfd == -1) + nr_fromfd = -2; + } + if (nr_fromfd < 0) + return False; + + res = VG_(do_syscall3)(nr_fromfd, fd, (UWord)buf, nbuf); + if (!res.isError && buf[0] == '/') + return True; + else + return False; +} +#else +#error undefined os +#endif /*-----------------------------------------------------------------*/ @@ -963,12 +1007,15 @@ same = same && seg_prot == prot +#ifndef VGO_freebsd && (cmp_devino ? (nsegments[i].dev == dev && nsegments[i].ino == ino) : True) && (cmp_offsets ? nsegments[i].start-nsegments[i].offset == addr-offset - : True); + : True) +#endif + ; if (!same) { sync_check_ok = False; VG_(debugLog)( @@ -1491,8 +1538,12 @@ seg.kind = SkAnonV; if (dev != 0 && ino != 0) seg.kind = SkFileV; - if (filename) + if (filename) { +#if defined(VGO_freebsd) + seg.kind = SkFileV; +#endif seg.fnIdx = allocate_segname( filename ); + } if (0) show_nsegment( 2,0, &seg ); add_segment( &seg ); @@ -1539,7 +1590,11 @@ " sp_at_startup = 0x%010llx (supplied)\n", (ULong)sp_at_startup ); +#ifdef VGP_x86_freebsd + aspacem_minAddr = (Addr) 0x00010000; // 64K +#else aspacem_minAddr = (Addr) 0x04000000; // 64M +#endif # if VG_WORDSIZE == 8 aspacem_maxAddr = (Addr)0x800000000 - 1; // 32G @@ -1603,10 +1658,18 @@ VG_(am_show_nsegments)(2, "Initial layout"); +#ifdef VGO_freebsd + VG_(debugLog)(2, "aspacem", "Reading /proc/curproc/map\n"); +#else VG_(debugLog)(2, "aspacem", "Reading /proc/self/maps\n"); +#endif parse_procselfmaps( read_maps_callback, NULL ); +#ifdef VGO_freebsd + VG_(am_show_nsegments)(2, "With contents of /proc/curproc/map"); +#else VG_(am_show_nsegments)(2, "With contents of /proc/self/maps"); +#endif AM_SANITY_CHECK; return suggested_clstack_top; @@ -2159,7 +2222,7 @@ sres = VG_(am_do_mmap_NO_NOTIFY)( start, length, prot, VKI_MAP_FIXED|VKI_MAP_PRIVATE|VKI_MAP_ANONYMOUS, - 0, 0 + 0, 0 ); if (sres.isError) return sres; @@ -2575,6 +2638,7 @@ Addr start2 = start1; Addr end2 = end1; +//VG_(printf)("am_create_reservation start=%p, len=%p\n", start, length); if (extra < 0) start2 += extra; // this moves it down :-) if (extra > 0) end2 += extra; @@ -2590,11 +2654,15 @@ segment, we're hosed. This does rely on the assumption that all mergeable adjacent segments can be merged, but add_segment() should ensure that. */ - if (startI != endI) + if (startI != endI) { +//VG_(printf)("startI %p != endI %p\n", startI, endI); return False; + } - if (nsegments[startI].kind != SkFree) + if (nsegments[startI].kind != SkFree) { +//VG_(printf)("nsegments[startI].kind %d != SkFree %d\n", nsegments[startI].kind, SkFree); return False; + } /* Looks good - make the reservation. */ aspacem_assert(nsegments[startI].start <= start2); @@ -2914,6 +2982,12 @@ { /* Read a word-sized hex number. */ Int n = 0; + if (*buf == '0') { + n++; buf++; + if (*buf == 'x') { + n++; buf++; + } + } *val = 0; while (hexdigit(*buf) >= 0) { *val = (*val << 4) + hexdigit(*buf); @@ -2956,9 +3030,9 @@ SysRes fd; /* Read the initial memory mapping from the /proc filesystem. */ - fd = ML_(am_open)( "/proc/self/maps", VKI_O_RDONLY, 0 ); + fd = ML_(am_open)( "/proc/curproc/map", VKI_O_RDONLY, 0 ); if (fd.isError) - ML_(am_barf)("can't open /proc/self/maps"); + ML_(am_barf)("can't open /proc/curproc/map"); buf_n_tot = 0; do { @@ -2973,7 +3047,7 @@ if (buf_n_tot >= M_PROCMAP_BUF-5) ML_(am_barf_toolow)("M_PROCMAP_BUF"); if (buf_n_tot == 0) - ML_(am_barf)("I/O error on /proc/self/maps"); + ML_(am_barf)("I/O error on /proc/curproc/map"); procmap_buf[buf_n_tot] = 0; } @@ -3014,6 +3088,9 @@ UInt prot; UWord maj, min; ULong foffset, dev, ino; +#ifdef VGO_freebsd + UInt junk; +#endif foffset = ino = 0; /* keep gcc-4.1.0 happy */ @@ -3030,6 +3107,7 @@ while (True) { if (i >= buf_n_tot) break; +#if defined(VGO_linux) /* Read (without fscanf :) the pattern %16x-%16x %c%c%c%c %16x %2x:%2x %d */ j = readhex(&procmap_buf[i], &start); if (j > 0) i += j; else goto syntaxerror; @@ -3073,12 +3151,121 @@ j = readdec64(&procmap_buf[i], &ino); if (j > 0) i += j; else goto syntaxerror; +#elif defined(VGO_freebsd) + /* Read (without fscanf :) the pattern %8x %8x %d %d %8x %c%c%c%c %d %d %8x .* .* .* */ + /* 0x38000000 0x38119000 281 748 0xd76df8a0 r-x 2 1 0x0 COW NC vnode */ + j = readhex(&procmap_buf[i], &start); + if (j > 0) i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == ' ') i += j; else goto syntaxerror; + j = readhex(&procmap_buf[i], &endPlusOne); + if (j > 0) i += j; else goto syntaxerror; + + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == ' ') i += j; else goto syntaxerror; + + j = readdec(&procmap_buf[i], &junk); + if (j > 0) i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == ' ') i += j; else goto syntaxerror; + j = readdec(&procmap_buf[i], &junk); + if (j > 0) i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == ' ') i += j; else goto syntaxerror; + j = readhex(&procmap_buf[i], &junk); + if (j > 0) i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == ' ') i += j; else goto syntaxerror; + + j = readchar(&procmap_buf[i], &rr); + if (j == 1 && (rr == 'r' || rr == '-')) i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ww); + if (j == 1 && (ww == 'w' || ww == '-')) i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &xx); + if (j == 1 && (xx == 'x' || xx == '-')) i += j; else goto syntaxerror; + + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == ' ') i += j; else goto syntaxerror; + + j = readdec(&procmap_buf[i], &junk); + if (j > 0) i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == ' ') i += j; else goto syntaxerror; + j = readdec(&procmap_buf[i], &junk); + if (j > 0) i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == ' ') i += j; else goto syntaxerror; + + j = readhex(&procmap_buf[i], &junk); + if (j > 0) i += j; else goto syntaxerror; + + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == ' ') i += j; else goto syntaxerror; + + /* COW or NCOW */ + j = readchar(&procmap_buf[i], &ch); + if (j != 1) goto syntaxerror; + if (ch == 'N') { + i += j; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == 'C') i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == 'O') i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == 'W') i += j; else goto syntaxerror; + } else if (ch == 'C') { + i += j; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == 'O') i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == 'W') i += j; else goto syntaxerror; + } else { + goto syntaxerror; + } + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == ' ') i += j; else goto syntaxerror; + + /* NC or NNC */ + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == 'N') i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && (ch == 'N' || ch == 'C')) i += j; else goto syntaxerror; + if (ch == 'N') { + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == 'C') i += j; else goto syntaxerror; + } + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == ' ') i += j; else goto syntaxerror; + + /* map type (vnode, swap, default) */ + j = readchar(&procmap_buf[i], &ch); + if (j != 1) goto syntaxerror; + if (ch == 'v') { + i += j; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == 'n') i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == 'o') i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == 'd') i += j; else goto syntaxerror; + j = readchar(&procmap_buf[i], &ch); + if (j == 1 && ch == 'e') i += j; else goto syntaxerror; + } + foffset = 0; +#else +#error "Unknown OS" +#endif goto read_line_ok; syntaxerror: +#ifdef VGO_freebsd + VG_(debugLog)(0, "Valgrind:", + "FATAL: syntax error reading /proc/curproc/map\n"); +#else VG_(debugLog)(0, "Valgrind:", "FATAL: syntax error reading /proc/self/maps\n"); +#endif { Int k, m; HChar buf50[51]; m = 0; @@ -3120,11 +3307,19 @@ foffset = 0; } +#if 0 +#ifdef VGO_freebsd + if (!filename) + filename = find_path(start); +#endif +#endif + prot = 0; if (rr == 'r') prot |= VKI_PROT_READ; if (ww == 'w') prot |= VKI_PROT_WRITE; if (xx == 'x') prot |= VKI_PROT_EXEC; +#if defined(VGO_linux) /* Linux has two ways to encode a device number when it is exposed to user space (via fstat etc). The old way is the traditional unix scheme that produces a 16 bit @@ -3145,7 +3340,9 @@ should always have a new style device number and everything should match. */ dev = (min & 0xff) | (maj << 8) | ((min & ~0xff) << 12); - +#else + dev = 0; +#endif if (record_gap && gapStart < start) (*record_gap) ( gapStart, start-gapStart );
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200810230524.m9N5OOiQ051666>