From owner-freebsd-hackers Tue Nov 17 05:48:43 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id FAA13772 for freebsd-hackers-outgoing; Tue, 17 Nov 1998 05:48:43 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from elvis.vnet.net (elvis.vnet.net [166.82.1.5]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id FAA13767 for ; Tue, 17 Nov 1998 05:48:42 -0800 (PST) (envelope-from rivers@dignus.com) Received: from dignus.com (ponds.vnet.net [166.82.177.48]) by elvis.vnet.net (8.8.8/8.8.4) with ESMTP id IAA27181; Tue, 17 Nov 1998 08:48:09 -0500 (EST) Received: from lakes.dignus.com (lakes [10.0.0.3]) by dignus.com (8.8.8/8.8.5) with ESMTP id JAA13852; Tue, 17 Nov 1998 09:30:02 -0500 (EST) Received: (from rivers@localhost) by lakes.dignus.com (8.8.8/8.6.9) id IAA11670; Tue, 17 Nov 1998 08:48:40 -0500 (EST) Date: Tue, 17 Nov 1998 08:48:40 -0500 (EST) From: Thomas David Rivers Message-Id: <199811171348.IAA11670@lakes.dignus.com> To: hackers@FreeBSD.ORG, nate@mt.sri.com Subject: Re: Wrapping a function In-Reply-To: <199811170517.WAA22627@mt.sri.com> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > Does anyone have an easy way of 'wrapping' an already existing library > function so that any programs linked against your .o will call your > function, but so your function can call the 'real' library function? > > Example: > > my_malloc.c: > > void *malloc(size_t size) > { > void *ret; > > printf("Calling malloc\n"); > ret = REALMALLOC(size); > printf("Leaving malloc\n"); > return ret; > } > > Ignoring all of the functions where there is loss of errno and such, are > they any good ideas? Note, the use of the dl* functions is explicitly > not allowed since those happen to be the functions I want to wrap in > this case. > > I'm at a loss here how to do this in C, so any good hacks are welcomed. > > > Nate > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message > I don't know about our linker (gnu-ld) - but many UNIX linkers (and other systems as well) have a way to re-name identifiers. The standard trick would be to pre-link the malloc code from the library; renaming the malloc entry there - to say, MALLOC. (ld -r is how you prelink.) Then, you can link your code with that. - Dave Rivers - To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message