From owner-freebsd-hackers Sun Oct 28 22:58:23 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from elvis.mu.org (elvis.mu.org [216.33.66.196]) by hub.freebsd.org (Postfix) with ESMTP id 02D1A37B401 for ; Sun, 28 Oct 2001 22:58:21 -0800 (PST) Received: by elvis.mu.org (Postfix, from userid 1192) id 1A5F681D08; Mon, 29 Oct 2001 00:58:21 -0600 (CST) Date: Mon, 29 Oct 2001 00:58:21 -0600 From: Alfred Perlstein To: Lamont Granquist Cc: freebsd-hackers@freebsd.org Subject: Re: MT-Safe wrapper around memcpy()? Message-ID: <20011029005821.X15052@elvis.mu.org> References: <20011028223152.K5909-100000@coredump.scriptkiddie.org> <20011029005316.W15052@elvis.mu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20011029005316.W15052@elvis.mu.org>; from bright@mu.org on Mon, Oct 29, 2001 at 12:53:16AM -0600 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 * 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. best of luck, -- -Alfred Perlstein [alfred@freebsd.org] 'Instead of asking why a piece of software is using "1970s technology," start asking why software is ignoring 30 years of accumulated wisdom.' http://www.morons.org/rants/gpl-harmful.php3 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message