Date: Mon, 29 Oct 2001 00:58:21 -0600 From: Alfred Perlstein <bright@mu.org> To: Lamont Granquist <lamont@scriptkiddie.org> Cc: freebsd-hackers@freebsd.org Subject: Re: MT-Safe wrapper around memcpy()? Message-ID: <20011029005821.X15052@elvis.mu.org> In-Reply-To: <20011029005316.W15052@elvis.mu.org>; from bright@mu.org on Mon, Oct 29, 2001 at 12:53:16AM -0600 References: <20011028223152.K5909-100000@coredump.scriptkiddie.org> <20011029005316.W15052@elvis.mu.org>
index | next in thread | previous in thread | raw e-mail
* Alfred Perlstein <bright@mu.org> [011029 00:53] wrote:
> * Lamont Granquist <lamont@scriptkiddie.org> [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
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011029005821.X15052>
