lkml.org 
[lkml]   [2013]   [May]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4 7/9] liblockdep: Support using LD_PRELOAD
On Wed, May 15, 2013 at 11:15:39PM -0400, Sasha Levin wrote:
> +
> +/* pthread mutex API */
> +
> +#ifdef __GLIBC__
> +extern int __pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
> +extern int __pthread_mutex_lock(pthread_mutex_t *mutex);
> +extern int __pthread_mutex_trylock(pthread_mutex_t *mutex);
> +extern int __pthread_mutex_unlock(pthread_mutex_t *mutex);
> +extern int __pthread_mutex_destroy(pthread_mutex_t *mutex);
> +#else
> +#define __pthread_mutex_init NULL
> +#define __pthread_mutex_lock NULL
> +#define __pthread_mutex_trylock NULL
> +#define __pthread_mutex_unlock NULL
> +#define __pthread_mutex_destroy NULL
> +#endif
> +static int (*ll_pthread_mutex_init)(pthread_mutex_t *mutex,
> + const pthread_mutexattr_t *attr) = __pthread_mutex_init;
> +static int (*ll_pthread_mutex_lock)(pthread_mutex_t *mutex) = __pthread_mutex_lock;
> +static int (*ll_pthread_mutex_trylock)(pthread_mutex_t *mutex) = __pthread_mutex_trylock;
> +static int (*ll_pthread_mutex_unlock)(pthread_mutex_t *mutex) = __pthread_mutex_unlock;
> +static int (*ll_pthread_mutex_destroy)(pthread_mutex_t *mutex) = __pthread_mutex_destroy;
> +
> +/* pthread rwlock API */
> +
> +#ifdef __GLIBC__
> +extern int __pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr);
> +extern int __pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
> +extern int __pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
> +extern int __pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
> +extern int __pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
> +extern int __pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
> +extern int __pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
> +#else
> +#define __pthread_rwlock_init NULL
> +#define __pthread_rwlock_destroy NULL
> +#define __pthread_rwlock_wrlock NULL
> +#define __pthread_rwlock_trywrlock NULL
> +#define __pthread_rwlock_rdlock NULL
> +#define __pthread_rwlock_tryrdlock NULL
> +#define __pthread_rwlock_unlock NULL
> +#endif
> +
> +static int (*ll_pthread_rwlock_init)(pthread_rwlock_t *rwlock,
> + const pthread_rwlockattr_t *attr) = __pthread_rwlock_init;
> +static int (*ll_pthread_rwlock_destroy)(pthread_rwlock_t *rwlock) = __pthread_rwlock_destroy;
> +static int (*ll_pthread_rwlock_rdlock)(pthread_rwlock_t *rwlock) = __pthread_rwlock_rdlock;
> +static int (*ll_pthread_rwlock_tryrdlock)(pthread_rwlock_t *rwlock) = __pthread_rwlock_tryrdlock;
> +static int (*ll_pthread_rwlock_trywrlock)(pthread_rwlock_t *rwlock) = __pthread_rwlock_trywrlock;
> +static int (*ll_pthread_rwlock_wrlock)(pthread_rwlock_t *rwlock) = __pthread_rwlock_wrlock;
> +static int (*ll_pthread_rwlock_unlock)(pthread_rwlock_t *rwlock) = __pthread_rwlock_unlock;
> +

> +__attribute__((constructor)) static void init_preload(void)
> +{
> + if (__init_state != done)
> + return;
> +
> +#ifndef __GLIBC__
> + __init_state = prepare;
> +
> + ll_pthread_mutex_init = dlsym(RTLD_NEXT, "pthread_mutex_init");
> + ll_pthread_mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
> + ll_pthread_mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
> + ll_pthread_mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
> + ll_pthread_mutex_destroy = dlsym(RTLD_NEXT, "pthread_mutex_destroy");
> +
> + ll_pthread_rwlock_init = dlsym(RTLD_NEXT, "pthread_rwlock_init");
> + ll_pthread_rwlock_destroy = dlsym(RTLD_NEXT, "pthread_rwlock_destroy");
> + ll_pthread_rwlock_rdlock = dlsym(RTLD_NEXT, "pthread_rwlock_rdlock");
> + ll_pthread_rwlock_tryrdlock = dlsym(RTLD_NEXT, "pthread_rwlock_tryrdlock");
> + ll_pthread_rwlock_wrlock = dlsym(RTLD_NEXT, "pthread_rwlock_wrlock");
> + ll_pthread_rwlock_trywrlock = dlsym(RTLD_NEXT, "pthread_rwlock_trywrlock");
> + ll_pthread_rwlock_unlock = dlsym(RTLD_NEXT, "pthread_rwlock_unlock");
> +#endif
> +
> + printf("%p\n", ll_pthread_mutex_trylock);fflush(stdout);
> +
> + lockdep_init();
> +
> + __init_state = done;
> +}

I guess that begs the question do we really want to support !glibc?


\
 
 \ /
  Last update: 2013-05-22 12:41    [W:0.103 / U:0.352 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site