From owner-freebsd-hackers Mon Oct 29 4: 5:35 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from warez.scriptkiddie.org (uswest-dsl-142-38.cortland.com [209.162.142.38]) by hub.freebsd.org (Postfix) with ESMTP id 95C9737B403 for ; Mon, 29 Oct 2001 04:05:29 -0800 (PST) Received: from [192.168.69.11] (unknown [192.168.69.11]) by warez.scriptkiddie.org (Postfix) with ESMTP id 4B51962D01 for ; Mon, 29 Oct 2001 04:05:28 -0800 (PST) Date: Mon, 29 Oct 2001 04:05:37 -0800 (PST) From: Lamont Granquist To: Subject: Re: MT-Safe wrapper around memcpy()? In-Reply-To: <20011029005821.X15052@elvis.mu.org> Message-ID: <20011029040255.D27876-100000@coredump.scriptkiddie.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Mon, 29 Oct 2001, Alfred Perlstein wrote: > * Alfred Perlstein [011029 00:53] wrote: > > * Lamont Granquist [011029 00:43] wrote: > > > > > > I'm trying to figure out the best way to write a wrapper around memcpy() > > > which can call fprintf() without winding up getting into a recursive > > > loop. The problem is that fprintf() will call memcpy() and around and > > > around we go. > > > > > > I can use a global variable to prevent this, but that usage isn't thread > > > safe. I can make it thread safe by using pthread keys, but then i have to > > > link in libc_r, and for non-pthreaded programs i don't want to do that. > > > > > > Anyone have any suggestions? Right now I'm almost thinking that I just > > > need to directly patch libc and libc_r. It might be an ugly patch though, > > > and I'd rather not have this patch mandate recompiling all of libc. > > > > Where do you see mem* calling printf? > > Uh, nevermind. :) > > Ok, what you want to do is use a nested flag in memcpy so you > don't recurse, there's some code in libc that's conditionally > compiled when compiling libc_r, _THREAD_SAFE or something is > defined, once you find that then just simply use the global > for non threaded programs and keys for threaded ones. you mean like localtime.c: #ifdef _THREAD_SAFE pthread_mutex_lock(&lcl_mutex); #endif and such? problem is that i could do that if i was dropping it into libc itself, but as a single .so that i want to LD_PRELOAD, i need a run-time conditional rather than a precompiler conditional. i think i may be asking for a lot... To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message