VirtualBox

source: vbox/trunk/include/iprt/ldrlazy.h@ 47791

Last change on this file since 47791 was 45928, checked in by vboxsync, 12 years ago

ldrlazy.h + win/lazy-dbghelp.h: New lazy loader that works on windows.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1/** @file
2 * IPRT - Lazy share library linking (2nd try).
3 */
4
5/*
6 * Copyright (C) 2013 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_ldrlazy_h
27#define ___iprt_ldrlazy_h
28
29#include <iprt/ldr.h>
30
31/** @defgroup grp_rt_ldrlazy Lazy shared library linking.
32 * @ingroup grp_rt
33 *
34 *
35 * @{
36 */
37
38
39/**
40 * Defines a module for use in lazy resolving.
41 *
42 * @param a_Mod The module name (C name).
43 * @param a_pszFile The file to tell RTLdrLoad to load.
44 */
45#define RTLDRLAZY_MODULE(a_Mod, a_pszFile) \
46 RTLDRLAZY_MODULE_EX(a_Mod, a_pszFile, RTLdrLoad)
47
48/**
49 * Defines a module for use in lazy resolving.
50 *
51 * @param a_Mod The module name (C name).
52 * @param a_pszFile The file to tell RTLdrLoad to load.
53 * @param a_pfnLoadIt Function to call for loading the DLL, replacing
54 * RTLdrLoad.
55 */
56#define RTLDRLAZY_MODULE_EX(a_Mod, a_pszFile, a_pfnLoadIt) \
57 static bool rtLdrLazy_##a_Mod##_Resolve(const char *pszName, void **ppvSymbol) \
58 { \
59 static RTLDRMOD volatile s_hMod = NIL_RTLDRMOD; \
60 static bool volatile s_fLoaded = false; \
61 RTLDRMOD hMod; \
62 int rc; \
63 if (!s_fLoaded) \
64 { \
65 rc = a_pfnLoadIt(a_pszFile, &hMod); \
66 s_hMod = RT_SUCCESS(rc) ? hMod : NIL_RTLDRMOD; \
67 s_fLoaded = true; \
68 if (RT_FAILURE(rc)) \
69 return false; \
70 } \
71 hMod = s_hMod; \
72 if (hMod == NIL_RTLDRMOD) \
73 return false; \
74 rc = RTLdrGetSymbol(hMod, pszName, ppvSymbol); \
75 return RT_SUCCESS(rc); \
76 }
77
78
79
80/** Function name mangler for preventing collision with system prototypes. */
81#define RTLDRLAZY_FUNC_NAME(a_Mod, a_Name) a_Mod##__##a_Name
82
83/**
84 * Defines a function that should be lazily resolved.
85 */
86#define RTLDRLAZY_FUNC(a_Mod, a_RetType, a_CallConv, a_Name, a_ParamDecl, a_ParamNames, a_ErrRet) \
87 DECLINLINE(a_RetType) RTLDRLAZY_FUNC_NAME(a_Mod, a_Name) a_ParamDecl \
88 { \
89 static a_RetType (a_CallConv * s_pfn) a_ParamDecl; \
90 if (!s_pfn) \
91 { \
92 if (!rtLdrLazy_##a_Mod##_Resolve(#a_Name, (void **)&s_pfn)) \
93 return a_ErrRet; \
94 } \
95 return s_pfn a_ParamNames; \
96 }
97
98
99/** @} */
100
101#endif
102
Note: See TracBrowser for help on using the repository browser.

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