Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Dec 2020 13:02:46 +0100
From:      Paul Floyd <pjfloyd@wanadoo.fr>
To:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   pthread_self() problem in DRD
Message-ID:  <61236c3a-05b8-7986-e95d-a9369eaf522b@wanadoo.fr>

next in thread | raw e-mail | index | archive | help
Hi

I'm trying to debug an issue in DRD (a thread hazard detection tool, 
part of Valgrind). There is an issue when using shared libraries.

A detailed description is here

https://github.com/paulfloyd/freebsd_valgrind/issues/57

In short, the flow of events is

 1. [guest] The DRD init function gets called (as it is marked
    __attribute__((constructor))
 2. [guest] DRD init sets the current thread id, calling pthread_self()
    and using a client request.
 3. [host] DRD_(thread_set_pthreadid)() gets called, and it is passed
    the DRD tid and the value obtained from pthread_self().
 4. [guest] The testcase does a dlopen() and then calls a function in
    the shared library
 5. [guest] the shard lib function calls pthread_create
 6. [host] pthread_create gets intercepted and performs another call to
    DRD_(set_pthread_id)()


I've marked thinks as guest/host, in reality there is only one process 
executing.


The problem is that the thread id obtained in step 3 is not the same as 
the one obtained in step 6. The result is an assert.


Two questions

 1. Is there any reason why pthread_self() should return different
    values when executed from a constructor and then from a dlopen()'d
    function?
 2. Is there any initialization code that affects the value returned by
    pthread_self()? It's possible that something is missing.


A+

Paul





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?61236c3a-05b8-7986-e95d-a9369eaf522b>