VirtualBox

Changeset 28363 in vbox


Ignore:
Timestamp:
Apr 15, 2010 2:08:05 PM (15 years ago)
Author:
vboxsync
Message:

iprt/runtime-loader.h: doxygen, hunarian.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/runtime-loader.h

    r28361 r28363  
    11/** @file
    2  * IPRT - runtime loader generation
     2 * IPRT - Runtime Loader Generation.
    33 */
    44
    55/*
    6  * Copyright (C) 2008 Sun Microsystems, Inc.
     6 * Copyright (C) 2008-2010 Sun Microsystems, Inc.
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2828 */
    2929
    30 /* How to use this loader generator
     30#include <iprt/types.h>
     31#ifdef RT_RUNTIME_LOADER_GENERATE_BODY_STUBS
     32# include <iprt/ldr.h>
     33# include <iprt/log.h>
     34# include <iprt/once.h>
     35#endif
     36
     37/** @defgroup grp_rt_runtime_loader     Runtime Loader Generation
     38 *
     39 * How to use this loader generator
    3140 *
    3241 * This loader generator can be used to generate stub code for loading a shared
     
    4554 *                                     functions to be loaded, defined in the
    4655 *                                     following pattern:
    47  *
     56 * @code
    4857 * #define RT_RUNTIME_LOADER_INSERT_SYMBOLS \
    4958 *  RT_PROXY_STUB(func_name, ret_type, (long_param_list), (short_param_list)) \
    5059 *  RT_PROXY_STUB(func_name2, ret_type2, (long_param_list2), (short_param_list2)) \
    5160 *  ...
     61 * @endcode
    5262 *
    5363 * where long_param_list is a paramter list for declaring the function of the
     
    6070 * RT_RUNTIME_LOADER_GENERATE_DECLS (without a value) before including this
    6171 * file.
     72 *
     73 * @{
    6274 */
    6375/** @todo this is far too complicated.  A script for generating the files would
    64  * probably be preferable. */
    65 
    66 #include <iprt/ldr.h>
    67 #include <iprt/log.h>
    68 #include <iprt/once.h>
     76 * probably be preferable.
     77 *
     78 * bird> An alternative is to generate assembly jump wrappers, this only
     79 * requires the symbol names and prefix.  I've done this ages ago when we forked
     80 * the EMX/GCC toolchain on OS/2...  It's a wee bit more annoying in x86 PIC/PIE
     81 * mode, but nothing that cannot be dealt with.
     82 */
     83/** @todo r=bird: The use of RTR3DECL here is an unresolved issue. */
     84/** @todo r=bird: The lack of RT_C_DECLS_BEGIN/END is an unresolved issue.  Here
     85 *        we'll get into trouble if we use the same symbol names as the
     86 *        original! */
     87/** @todo r=bird: The prefix usage here is very confused: RT_RUNTIME_LOADER_XXX,
     88 *        RT_PROXY_STUB, etc. */
    6989
    7090#ifdef RT_RUNTIME_LOADER_GENERATE_BODY_STUBS
    71 /** The following are the symbols which we need from the library. */
     91
     92/* The following are the symbols which we need from the library. */
    7293# define RT_PROXY_STUB(function, rettype, signature, shortsig) \
    73  void (*function ## _fn)(void); \
    74  RTR3DECL(rettype) function signature \
    75  { return ( (rettype (*) signature) function ## _fn ) shortsig; }
     94    void (*function ## _fn)(void); \
     95    RTR3DECL(rettype) function signature \
     96    { return ( (rettype (*) signature) function ## _fn ) shortsig; }
    7697
    7798RT_RUNTIME_LOADER_INSERT_SYMBOLS
     
    79100# undef RT_PROXY_STUB
    80101
    81 /* Now comes a table of functions to be loaded from the library */
     102/* Now comes a table of functions to be loaded from the library. */
    82103typedef struct
    83104{
    84     const char *name;
    85     void (**fn)(void);
    86 } SHARED_FUNC;
     105    const char *pszName;
     106    void (**ppfn)(void);
     107} RTLDRSHAREDFUNC;
    87108
    88109# define RT_PROXY_STUB(s, dummy1, dummy2, dummy3 ) { #s , & s ## _fn } ,
    89 static SHARED_FUNC SharedFuncs[] =
     110static RTLDRSHAREDFUNC g_aSharedFuncs[] =
    90111{
    91 RT_RUNTIME_LOADER_INSERT_SYMBOLS
     112    RT_RUNTIME_LOADER_INSERT_SYMBOLS
    92113    { NULL, NULL }
    93114};
    94115# undef RT_PROXY_STUB
    95116
    96 /* The function which does the actual work for RT_RUNTIME_LOADER_FUNCTION,
    97  * serialised for thread safety. */
    98 static int rtldrLoadOnce(void *, void *)
     117/**
     118 * The function which does the actual work for RT_RUNTIME_LOADER_FUNCTION,
     119 * serialised for thread safety.
     120 */
     121static DECLCALLBACK(int) rtldrLoadOnce(void *, void *)
    99122{
    100     RTLDRMOD hLib;
     123    RTLDRMOD    hLib;
     124    int         rc;
    101125
    102126    LogFlowFunc(("\n"));
    103     int rc = RTLdrLoad(RT_RUNTIME_LOADER_LIB_NAME, &hLib);
    104     for (unsigned i = 0; RT_SUCCESS(rc) && SharedFuncs[i].name != NULL; ++i)
    105         rc = RTLdrGetSymbol(hLib, SharedFuncs[i].name, (void**)SharedFuncs[i].fn);
     127    rc = RTLdrLoad(RT_RUNTIME_LOADER_LIB_NAME, &hLib);
     128    for (unsigned i = 0; RT_SUCCESS(rc) && g_aSharedFuncs[i].pszName != NULL; ++i)
     129        rc = RTLdrGetSymbol(hLib, g_aSharedFuncs[i].pszName, (void **)g_aSharedFuncs[i].ppfn);
    106130    LogFlowFunc(("rc = %Rrc\n", rc));
     131
    107132    return rc;
    108133}
    109134
    110 /** Load the shared library RT_RUNTIME_LOADER_LIB_NAME and resolve the symbols
    111  * pointed to by RT_RUNTIME_LOADER_INSERT_SYMBOLS.  May safely be called from
    112  * multiple threads and will not return until the library is loaded or has
    113  * failed to load. */
     135/**
     136 * Load the shared library RT_RUNTIME_LOADER_LIB_NAME and resolve the symbols
     137 * pointed to by RT_RUNTIME_LOADER_INSERT_SYMBOLS.
     138 *
     139 * May safely be called from multiple threads and will not return until the
     140 * library is loaded or has failed to load.
     141 *
     142 * @returns IPRT status code.
     143 */
    114144RTR3DECL(int) RT_RUNTIME_LOADER_FUNCTION(void)
    115145{
    116     static RTONCE sOnce = RTONCE_INITIALIZER;
     146    static RTONCE   s_Once = RTONCE_INITIALIZER;
     147    int             rc;
    117148
    118149    LogFlowFunc(("\n"));
    119     int rc = RTOnce (&sOnce, rtldrLoadOnce, NULL, NULL);
     150    rc = RTOnce(&s_Once, rtldrLoadOnce, NULL, NULL);
    120151    LogFlowFunc(("rc = %Rrc\n", rc));
     152
    121153    return rc;
    122154}
     
    142174 */
    143175RTR3DECL(int) RT_RUNTIME_LOADER_FUNCTION(void);
     176
    144177#else
    145 # error One of RT_RUNTIME_LOADER_GENERATE_HEADER or \
    146 RT_RUNTIME_LOADER_GENERATE_BODY_STUBS must be defined when including this file
     178# error "One of RT_RUNTIME_LOADER_GENERATE_HEADER or RT_RUNTIME_LOADER_GENERATE_BODY_STUBS must be defined when including this file"
    147179#endif
     180
     181/** @} */
     182
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette