From: Matthew E. <ma...@gs...> - 2003-04-22 00:56:37
|
Hi all, There has been increasing interest in using Valgrind on the FreeBSD platform and I have been working off and on to make this a reality since the 1.0.0 days. My code base is now a hacked up version of 1.9.5 with very limited functionality. (No pthreads or LDT support.) One of the largest stumbling blocks has been the various Linux-isms that are present in the code, which are expected given the code's history. The two most major problems which can be addressed by architecture are the use of hard-coded syscall names and hard-coded pthread internal variable names. What follows are a couple of proposals that will assist porting valgrind to non-Linux platforms. I appreciate any feedback that you may have. 1) Introduce a mapping layer for syscall #defines. As near as I can tell, all the syscalls referred to outside of vg_syscalls.c are generic, POSIX-mandated syscalls (exit, execve, getpid, gettimeofday, etc), and should be present on all UNIX platforms, thus no platform-specific code outside of vg_syscalls.c. I propose introducing a vg_syscall.h file that maps the platform's syscall #defines to valgrind-specific #defines. This would limit the scope of the syscall-related changes required on non-Linux platforms to vg_syscalls.[ch], rather than <n> files (<n> currently 7 on FreeBSD) just to patch up the __NR syscall symbols. Although this means another file to keep updated, it provides an easy place to document various kernel API changes, with the corresponding implementations in vg_syscalls.c. For example, on Linux, we'd have something like this: vg_syscall.h: #define VKI_SC_exit __NR_exit #define VKI_SC_getpid __NR_getpid And on FreeBSD, we'd have something like this: #define VKI_SC_exit SYS_exit #define VKI_SC_getpid SYS_getpid 2) Introduce a mapping layer for pthread structures Currently the vg_libpthread.c code assumes the names of pthread_mutex structure elements. As expected, these are not the same on FreeBSD and are likely different on the other *BSDs as well. I propose that we introduce some mapping #defines in vg_kerneliface.h to handle such differences. For example, on Linux: #define VKI_PTHREAD_OWNER __m_owner #define VKI_PTHREAD_COUNT __m_count #define VKI_PTHREAD_KIND __m_kind And on FreeBSD: #define VKI_PTHREAD_OWNER m_owner #define VKI_PTHREAD_COUNT m_data.m_count #define VKI_PTHREAD_KIND m_type Then we can do things like this instead, which should be more portable: int __pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr) { mutex->VKI_PTHREAD_COUNT = 0; mutex->VKI_PTHREAD_OWNER = (_pthread_descr)VG_INVALID_THREADID; mutex->VKI_PTHREAD_KIND = PTHREAD_MUTEX_ERRORCHECK_NP; if (mutexattr) mutex->VKI_PTHREAD_KIND = mutexattr->__mutexkind; return 0; } Thanks, -- Matt Emmerton |
From: Tom H. <th...@cy...> - 2003-04-22 08:05:08
|
In message <00f201c30869$f2414d20$120...@gs...> Matthew Emmerton <ma...@gs...> wrote: > I propose introducing a vg_syscall.h file that maps the platform's syscall > #defines to valgrind-specific #defines. This would limit the scope of the > syscall-related changes required on non-Linux platforms to vg_syscalls.[ch], > rather than <n> files (<n> currently 7 on FreeBSD) just to patch up the __NR > syscall symbols. > > Although this means another file to keep updated, it provides an easy place > to document various kernel API changes, with the corresponding > implementations in vg_syscalls.c. > > For example, on Linux, we'd have something like this: > > vg_syscall.h: > #define VKI_SC_exit __NR_exit > #define VKI_SC_getpid __NR_getpid > > And on FreeBSD, we'd have something like this: > > #define VKI_SC_exit SYS_exit > #define VKI_SC_getpid SYS_getpid Linux does already have defines for the SYS_xxx names and including sys/syscall.h should get you those defines, which are defined to the appropriate __NR_xxx name. Tom -- Tom Hughes (th...@cy...) Software Engineer, Cyberscience Corporation http://www.cyberscience.com/ |
From: Nicholas N. <nj...@ca...> - 2003-04-22 08:28:48
|
On Mon, 21 Apr 2003, Matthew Emmerton wrote: > There has been increasing interest in using Valgrind on the FreeBSD platform > > 1) Introduce a mapping layer for syscall #defines. > > For example, on Linux we'd have something like this: > > vg_syscall.h: > #define VKI_SC_exit __NR_exit > #define VKI_SC_getpid __NR_getpid > > And on FreeBSD, we'd have something like this: > > #define VKI_SC_exit SYS_exit > #define VKI_SC_getpid SYS_getpid Do the *BSD and Linux system calls match as easily as this? Ie. none of the "equivalent" ones have different arguments or similar? > 2) Introduce a mapping layer for pthread structures > > For example, on Linux: > > #define VKI_PTHREAD_OWNER __m_owner > #define VKI_PTHREAD_COUNT __m_count > #define VKI_PTHREAD_KIND __m_kind > > And on FreeBSD: > > #define VKI_PTHREAD_OWNER m_owner > #define VKI_PTHREAD_COUNT m_data.m_count > #define VKI_PTHREAD_KIND m_type Similarly, is there a nice one-to-one mapping between the relevant structures, such that this simple approach will work? Have you tried implementing these layers? It's a nice, simple proposal you've given, I'd like to know whether it suffices in practice :) Eg. I imagine many of the syscalls, particularly the common ones, overlap in *BSD and Linux, but what about the less common ones? Also, you say you have 1.9.5 working with only limited functionality... what are the other stumbling blocks (you mentioned LDTs)? Thanks. N |
From: Matthew E. <ma...@gs...> - 2003-04-22 12:12:59
|
> On Mon, 21 Apr 2003, Matthew Emmerton wrote: > > > There has been increasing interest in using Valgrind on the FreeBSD platform > > > > 1) Introduce a mapping layer for syscall #defines. > > > > For example, on Linux we'd have something like this: > > > > vg_syscall.h: > > #define VKI_SC_exit __NR_exit > > #define VKI_SC_getpid __NR_getpid > > > > And on FreeBSD, we'd have something like this: > > > > #define VKI_SC_exit SYS_exit > > #define VKI_SC_getpid SYS_getpid > > Do the *BSD and Linux system calls match as easily as this? Ie. none of > the "equivalent" ones have different arguments or similar? Most of the standard syscalls have matching names and matching data structures. So far, the only syscalls that have really caused me grief are the ones that simply don't exist on FreeBSD, and an #ifdef/#endif pair handles that nicely. Tom Hughes had mentioned including <sys/syscall.h> on Linux which will get SYS_xxx names rather than the __NR_xxx names. I'm curious as to whether this header implements is some sort of SUSv3 or POSIX standard for syscall naming? If so, it would be nice if we could take advantage of it since it would make this particular issue a moot point. > > 2) Introduce a mapping layer for pthread structures > > > > For example, on Linux: > > > > #define VKI_PTHREAD_OWNER __m_owner > > #define VKI_PTHREAD_COUNT __m_count > > #define VKI_PTHREAD_KIND __m_kind > > > > And on FreeBSD: > > > > #define VKI_PTHREAD_OWNER m_owner > > #define VKI_PTHREAD_COUNT m_data.m_count > > #define VKI_PTHREAD_KIND m_type > > Similarly, is there a nice one-to-one mapping between the relevant > structures, such that this simple approach will work? From what I've tried so far, this seems to work just fine -- especially since there are POSIX standards mandating the typing of internal pthread variables. (This is where FreeBSD isn't up to snuff, at least from what I've read.) > Have you tried implementing these layers? It's a nice, simple proposal > you've given, I'd like to know whether it suffices in practice :) Eg. I > imagine many of the syscalls, particularly the common ones, overlap in > *BSD and Linux, but what about the less common ones? Most of what I've done so far in the code is s/Linuxism/BSDism/ and that has been enough to get most of the code to compile and execute properly. There are pieces of code which are definitely OS-specified (most of the assembler stuff, for example) which I have adjusted by hand, and a couple of header (ie, vg_unsafe.h) which I have just rewritten. > Also, you say you have 1.9.5 working with only limited functionality... > what are the other stumbling blocks (you mentioned LDTs)? The biggest is the pthread stuff, which is intertwined with the LDT code, and because of some wierdness in our pthread code, I haven't got it working correctly yet. I will work away at getting more things working and get back to the list with my findings -- this was just a ping to see what the interest level was. Thanks, -- Matt |
From: Matt E. <ma...@gs...> - 2004-03-06 04:30:29
|
I just downloaded and installed the development version of valgrind (2.1.0) on RH9. It builds successfully, but running "tests/vg_regtest --all" fails with 4 failures. == 108 tests, 4 stderr failures, 0 stdout failures ================= corecheck/tests/pth_cancel2 (stderr) helgrind/tests/inherit (stderr) memcheck/tests/new_override (stderr) none/tests/fork (stderr) The fork check looks like a non-issue (an extra newline on stderr), but the other 3 look like problems. I'm going to grab the latest from CVS and see if anything is different. *** pth_cancel2.stderr.exp 2002-11-18 06:33:37.000000000 -0500 --- pth_cancel2.stderr.out 2004-03-05 23:02:36.000000000 -0500 *************** *** 1 **** --- 2 ---- + read: Interrupted system call *** inherit.stderr.exp 2003-10-18 18:27:10.000000000 -0400 --- inherit.stderr.out 2004-03-05 23:02:59.000000000 -0500 *************** *** 1 **** ! XXX We expect an error on inherit.c:48 --- 1,2 ---- ! ! *** new_override.stderr.exp 2003-06-01 16:04:10.000000000 -0400 --- new_override.stderr.out 2004-03-05 23:04:10.000000000 -0500 *************** *** 1 **** --- 2,3 ---- + Conditional jump or move depends on uninitialised value(s) + at 0x........: main (new_override.cpp:25) *************** *** 3 **** ! ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) --- 5 ---- ! ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 0 from 0) *** fork.stderr.exp 2003-10-14 17:11:29.000000000 -0400 --- fork.stderr.out 2004-03-05 23:05:01.000000000 -0500 *************** *** 2 **** --- 3 ---- + -- Matt Emmerton |