From owner-freebsd-hackers Mon Nov 16 21:18:14 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id VAA16233 for freebsd-hackers-outgoing; Mon, 16 Nov 1998 21:18:14 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from ns.mt.sri.com (sri-gw.MT.net [206.127.105.141]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id VAA16225 for ; Mon, 16 Nov 1998 21:18:13 -0800 (PST) (envelope-from nate@mt.sri.com) Received: from mt.sri.com (rocky.mt.sri.com [206.127.76.100]) by ns.mt.sri.com (8.8.8/8.8.8) with SMTP id WAA18286 for ; Mon, 16 Nov 1998 22:17:47 -0700 (MST) (envelope-from nate@rocky.mt.sri.com) Received: by mt.sri.com (SMI-8.6/SMI-SVR4) id WAA22627; Mon, 16 Nov 1998 22:17:47 -0700 Date: Mon, 16 Nov 1998 22:17:47 -0700 Message-Id: <199811170517.WAA22627@mt.sri.com> From: Nate Williams MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: hackers@FreeBSD.ORG Subject: Wrapping a function X-Mailer: VM 6.34 under 19.16 "Lille" XEmacs Lucid 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