Home | History | Annotate | Line # | Download | only in librumphijack
hijackdlsym.c revision 1.2.2.2
      1  1.2.2.2  bouyer /*      $NetBSD: hijackdlsym.c,v 1.2.2.2 2011/03/05 15:09:23 bouyer Exp $	*/
      2  1.2.2.2  bouyer 
      3  1.2.2.2  bouyer /*-
      4  1.2.2.2  bouyer  * Copyright (c) 2011 Antti Kantee.  All Rights Reserved.
      5  1.2.2.2  bouyer  *
      6  1.2.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
      7  1.2.2.2  bouyer  * modification, are permitted provided that the following conditions
      8  1.2.2.2  bouyer  * are met:
      9  1.2.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     10  1.2.2.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     11  1.2.2.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.2.2.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     13  1.2.2.2  bouyer  *    documentation and/or other materials provided with the distribution.
     14  1.2.2.2  bouyer  *
     15  1.2.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     16  1.2.2.2  bouyer  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  1.2.2.2  bouyer  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18  1.2.2.2  bouyer  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  1.2.2.2  bouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.2.2.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21  1.2.2.2  bouyer  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.2.2.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.2.2.2  bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.2.2.2  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.2.2.2  bouyer  * SUCH DAMAGE.
     26  1.2.2.2  bouyer  */
     27  1.2.2.2  bouyer 
     28  1.2.2.2  bouyer #include <sys/cdefs.h>
     29  1.2.2.2  bouyer __RCSID("$NetBSD: hijackdlsym.c,v 1.2.2.2 2011/03/05 15:09:23 bouyer Exp $");
     30  1.2.2.2  bouyer 
     31  1.2.2.2  bouyer #include <dlfcn.h>
     32  1.2.2.2  bouyer 
     33  1.2.2.2  bouyer #include "hijack.h"
     34  1.2.2.2  bouyer 
     35  1.2.2.2  bouyer /*
     36  1.2.2.2  bouyer  * This is called from librumpclient in case of LD_PRELOAD.
     37  1.2.2.2  bouyer  * It ensures correct RTLD_NEXT.
     38  1.2.2.2  bouyer  *
     39  1.2.2.2  bouyer  * (note, this module is compiled with -O0 to make sure this
     40  1.2.2.2  bouyer  * function is not treated as a tailcall or other optimizations
     41  1.2.2.2  bouyer  * applied)
     42  1.2.2.2  bouyer  */
     43  1.2.2.2  bouyer 
     44  1.2.2.2  bouyer /* why is this indirection required for powerpc ???? */
     45  1.2.2.2  bouyer static void * __noinline
     46  1.2.2.2  bouyer bouncer(void *handle, const char *symbol)
     47  1.2.2.2  bouyer {
     48  1.2.2.2  bouyer 
     49  1.2.2.2  bouyer 	return dlsym(handle, symbol);
     50  1.2.2.2  bouyer }
     51  1.2.2.2  bouyer 
     52  1.2.2.2  bouyer void *
     53  1.2.2.2  bouyer rumphijack_dlsym(void *handle, const char *symbol)
     54  1.2.2.2  bouyer {
     55  1.2.2.2  bouyer 
     56  1.2.2.2  bouyer 	return bouncer(handle, symbol);
     57  1.2.2.2  bouyer }
     58