runtime-loader.h revision 8fa59d6e8a7241b88e10a611d883318d157317cf
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * IPRT - runtime loader generation
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * Copyright (C) 2008 Sun Microsystems, Inc.
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * This file is part of VirtualBox Open Source Edition (OSE), as
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * available from http://www.virtualbox.org. This file is free software;
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * you can redistribute it and/or modify it under the terms of the GNU
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * General Public License (GPL) as published by the Free Software
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * Foundation, in version 2 as it comes in the "COPYING" file of the
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2e545ce2450a9953665f701bb05350f0d3f26275nd * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * The contents of this file may alternatively be used under the terms
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * of the Common Development and Distribution License Version 1.0
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * VirtualBox OSE distribution, in which case the provisions of the
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * CDDL are applicable instead of those of the GPL.
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * You may elect to license modified versions of this file under the
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * terms and conditions of either the GPL or the CDDL or both.
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * Clara, CA 95054 USA or visit http://www.sun.com if you need
befb6758d5618c60f29b19f9a7eb75ab993511dcjim * additional information or have any questions.
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen/* How to use this loader generator
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * This loader generator can be used to generate stub code for loading a shared
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * library and its functions at runtime, or for generating a header file with
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * the declaration of the loader function and optionally declarations for the
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * functions loaded. It should be included in a header file or a C source
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * file, after defining certain macros which it makes use of.
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * To generate the C source code for function proxy stubs and the library
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * loader function, you should define the following macros in your source file
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * before including this header:
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * RT_RUNTIME_LOADER_LIB_NAME - the file name of the library to load
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * RT_RUNTIME_LOADER_FUNCTION - the name of the loader function
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * RT_RUNTIME_LOADER_INSERT_SYMBOLS - a macro containing the names of the
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * functions to be loaded, defined in the
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * following pattern:
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * #define RT_RUNTIME_LOADER_INSERT_SYMBOLS \
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * RT_PROXY_STUB(func_name, ret_type, (long_param_list), (short_param_list)) \
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * RT_PROXY_STUB(func_name2, ret_type2, (long_param_list2), (short_param_list2)) \
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * where long_param_list is a paramter list for declaring the function of the
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * form (type1 arg1, type2 arg2, ...) and short_param_list for calling it, of
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * the form (arg1, arg2, ...).
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * To generate the header file, you should define RT_RUNTIME_LOADER_FUNCTION
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * and if you wish to generate declarations for the functions you should
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * additionally define RT_RUNTIME_LOADER_INSERT_SYMBOLS as above and
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * RT_RUNTIME_LOADER_GENERATE_DECLS (without a value) before including this
e1e8390280254f7f0580d701e583f670643d4f3fnilgun/** @todo this is far too complicated. A script for generating the files would
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * probably be preferable. */
e1e8390280254f7f0580d701e583f670643d4f3fnilgun/** The following are the symbols which we need from the library. */
e1e8390280254f7f0580d701e583f670643d4f3fnilgun# define RT_PROXY_STUB(function, rettype, signature, shortsig) \
e1e8390280254f7f0580d701e583f670643d4f3fnilgun { return ( (rettype (*) signature) function ## _fn ) shortsig; }
e1e8390280254f7f0580d701e583f670643d4f3fnilgun/* Now comes a table of functions to be loaded from the library */
e1e8390280254f7f0580d701e583f670643d4f3fnilguntypedef struct
e1e8390280254f7f0580d701e583f670643d4f3fnilgun const char *name;
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen void (**fn)(void);
205f749042ed530040a4f0080dbcb47ceae8a374rjung# define RT_PROXY_STUB(s, dummy1, dummy2, dummy3 ) { #s , & s ## _fn } ,
static int rtldrLoadOnce(void *, void *)
return rc;
return rc;
# ifdef RT_RUNTIME_LOADER_GENERATE_DECLS