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 |