Ignore:
Timestamp:
Oct 24, 2011, 7:58:02 PM (14 years ago)
Author:
dmik
Message:

Create lnitdll.lib to hold common DLL init/term code.

This simplifies creating init/term functions for individual DLLs
a lot and keeps common parts in a single place instead of duplicating
them a zillion times.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gcc-kmk/include/initdll.h

    r21728 r21733  
     1/** @file
     2 *
     3 * INITDLL library interface.
     4 *
     5 * Project Odin Software License can be found in LICENSE.TXT
     6 */
     7
    18#ifndef __INITDLL_H__
    29#define __INITDLL_H__
    310
    4 #if (defined(__IBMCPP__) || defined(__IBMC__) || defined(__INNOTEK_LIBC__))
     11#include <odin.h>
     12
     13/**
     14 * Called to initialize resources of the DLL module when it is loaded.
     15 *
     16 * This callback function is implemented by modules that link to initldll.lib
     17 * and want to override the default DLL initialization procedure called when the
     18 * DLL is loaded by the system (according to the INIT/TERM policy specified in
     19 * the LIBRARY statement in the .DEF file). See DLL_InitDefault() for more
     20 * information about the default initialization procedure.
     21 *
     22 * On success, the returned value must be the DosExitList() order code (high
     23 * byte of the low word) that defines the order in which DLL_Term() will be
     24 * called WRT other uninitialization routines and exit list handlers. Returning
     25 * 0 will cause DLL_Term() to be called first. Note that if several handlers
     26 * use the same order code they are called in LIFO order. For DLLs, this means
     27 * that DLL_Term() will be called in the order opposite to DLL_Init().
     28 *
     29 * @param hModule DLL module handle.
     30 * @return Exit list order on success or -1 to indicate a failure.
     31 */
     32ULONG SYSTEM DLL_Init(ULONG hModule);
     33
     34/**
     35 * Called to free resources of the DLL module when it is unloaded.
     36 *
     37 * This callback function is implemented by modules that link to initldll.lib
     38 * and want to override the default DLL uninitialization procedure called when
     39 * the DLL is unloaded by the system (according to the INIT/TERM policy
     40 * specified in the LIBRARY statement in the .DEF file). See DLL_TermDefault()
     41 * for more information about the default uninitialization procedure.
     42 *
     43 * @param hModule DLL module handle.
     44 */
     45void SYSTEM DLL_Term(ULONG hModule);
     46
     47/**
     48 * Default DLL initialization procedure.
     49 *
     50 * This procedure is called if your module does not implement the DLL_Init()
     51 * callback function. It performs steps necessary to initializes the C/C++
     52 * runtime.
     53 *
     54 * You may call this procedure from your DLL_Init() implementation to perform
     55 * the standard initialization steps described above.
     56 *
     57 * @param hModule DLL module handle.
     58 * @return 0 on success or -1 to indicate a failure.
     59 */
     60ULONG SYSTEM DLL_InitDefault(ULONG hModule);
     61
     62/**
     63 * Default DLL uninitialization procedure.
     64 *
     65 * This procedure is called if your module does not implement the DLL_Term()
     66 * callback function. It performs steps necessary to terminate the C/C++
     67 * runtime.
     68 *
     69 * You may call this procedure from your DLL_Uniit() implementation to perform
     70 * the standard initialization steps described above.
     71 *
     72 * @param hModule DLL module handle.
     73 */
     74void SYSTEM DLL_TermDefault(ULONG hModule);
    575
    676#ifdef __cplusplus
     
    878#endif
    979
     80#if defined(__IBMCPP__) || defined(__IBMC__)
     81
     82/**
     83 * C run-time environment initialization function.
     84 * Returns 0 to indicate success and -1 to indicate failure.
     85 */
     86int  _Optlink _CRT_init(void);
     87
     88/**
     89 * C run-time environment termination function.
     90 * It only needs to be called when the C run-time functions are statically
     91 * linked.
     92 */
     93void _Optlink _CRT_term(void);
     94
    1095#if (__IBMCPP__ == 300) || (__IBMC__ == 300)
    11 void _Optlink __ctordtorInit( void );
    12 #define ctordtorInit()  __ctordtorInit()
    1396
    14 void _Optlink __ctordtorTerm( void );
    15 #define ctordtorTerm()  __ctordtorTerm()
     97void _Optlink __ctordtorInit(void);
     98void _Optlink __ctordtorTerm(void);
    1699
    17100#elif (__IBMCPP__ == 360) || (__IBMC__ == 360) || (__IBMC__ == 430)
    18 void _Optlink __ctordtorInit( int flag );
    19 #define ctordtorInit()  __ctordtorInit(0)
    20101
    21 void _Optlink __ctordtorTerm( int flag );
    22 #define ctordtorTerm()  __ctordtorTerm(0)
     102void _Optlink __ctordtorInit(int flag);
     103#define __ctordtorInit()  __ctordtorInit(0)
    23104
    24 #elif defined(__INNOTEK_LIBC__)
     105void _Optlink __ctordtorTerm(int flag);
     106#define __ctordtorTerm()  __ctordtorTerm(0)
    25107
    26 extern void __ctordtorInit(void);
    27 extern void __ctordtorTerm(void);
     108#else
     109#error "Unknown VAC compiler version!"
     110#endif
    28111
    29 #define ctordtorInit() __ctordtorInit()
    30 #define ctordtorTerm() __ctordtorTerm()
     112#elif defined(__EMX__)
     113
     114int  _CRT_init(void);
     115void _CRT_term(void);
     116
     117void __ctordtorInit(void);
     118void __ctordtorTerm(void);
     119
     120#elif defined(__WATCOMC__)
     121
     122#define _DLL_InitTerm LibMain
     123
     124int  _Optlink _CRT_init(void);
     125void _Optlink _CRT_term(void);
     126
     127#define __ctordtorInit()
     128#define __ctordtorTerm()
     129
     130//prevent Watcom from mucking with this name
     131extern DWORD _Resource_PEResTab;
     132#pragma aux _Resource_PEResTab "*";
    31133
    32134#else
     
    34136#endif
    35137
    36 #ifndef __INNOTEK_LIBC__
    37 
    38 /*-------------------------------------------------------------------*/
    39 /* _CRT_init is the C run-time environment initialization function.  */
    40 /* It will return 0 to indicate success and -1 to indicate failure.  */
    41 /*-------------------------------------------------------------------*/
    42 int  _Optlink _CRT_init(void);
    43 
    44 /*-------------------------------------------------------------------*/
    45 /* _CRT_term is the C run-time environment termination function.     */
    46 /* It only needs to be called when the C run-time functions are      */
    47 /* statically linked.                                                */
    48 /*-------------------------------------------------------------------*/
    49 void _Optlink _CRT_term(void);
    50 #endif // __INNOTEK_LIBC__
    51 
    52 
    53 #ifdef __cplusplus
    54 }
    55 #endif
    56 
    57 #elif defined(__WATCOMC__)
    58 
    59 #define _DLL_InitTerm LibMain
    60 
    61 #define ctordtorInit()
    62 #define ctordtorTerm()
    63 
    64 #ifdef __cplusplus
    65 extern "C" {
    66 //prevent Watcom from mucking with this name
    67 extern DWORD _Resource_PEResTab;
    68 #pragma aux _Resource_PEResTab "*";
    69 }
    70 #endif
    71 
    72 #endif  /* IBM CPP Compiler */
    73 
    74 #ifdef __cplusplus
    75 extern "C" {
    76 #endif
    77 
    78 typedef ULONG (APIENTRY *PFN_INITDLL)(ULONG hModule, ULONG ulFlag);
    79 typedef void  (APIENTRY *PFN_CLEANUPDLL)(ULONG ulReason);
    80 
    81 ULONG APIENTRY inittermKernel32(ULONG hModule, ULONG ulFlag);
    82 void  APIENTRY cleanupKernel32(ULONG ulReason);
    83 
    84 ULONG APIENTRY inittermUser32(ULONG hModule, ULONG ulFlag);
    85 void  APIENTRY cleanupUser32(ULONG ulReason);
    86 ULONG APIENTRY inittermOdinCtrl(ULONG hModule, ULONG ulFlag);
    87 
    88 //NOTE!!!!!!!!!!!!!!!!!
    89 //if this list is extended, then update our custombuild code!!!!
    90 //NOTE!!!!!!!!!!!!!!!!!
    91 ULONG APIENTRY inittermWinmm(ULONG hModule, ULONG ulFlag);
    92 ULONG APIENTRY inittermShell32(ULONG hModule, ULONG ulFlag);
    93 ULONG APIENTRY inittermOle32(ULONG hModule, ULONG ulFlag);
    94 ULONG APIENTRY inittermComdlg32(ULONG hModule, ULONG ulFlag);
    95 ULONG APIENTRY inittermComctl32(ULONG hModule, ULONG ulFlag);
    96 ULONG APIENTRY inittermGdi32(ULONG hModule, ULONG ulFlag);
    97 ULONG APIENTRY inittermNTDLL(ULONG hModule, ULONG ulFlag);
    98 ULONG APIENTRY inittermWsock32(ULONG hModule, ULONG ulFlag);
    99 ULONG APIENTRY inittermWininet(ULONG hModule, ULONG ulFlag);
    100 ULONG APIENTRY inittermRpcrt4(ULONG hModule, ULONG ulFlag);
    101 ULONG APIENTRY inittermAvifil32(ULONG hModule, ULONG ulFlag);
    102 ULONG APIENTRY inittermQuartz(ULONG hModule, ULONG ulFlag);
    103 ULONG APIENTRY inittermRiched32(ULONG hModule, ULONG ulFlag);
    104 ULONG APIENTRY inittermWnaspi32(ULONG hModule, ULONG ulFlag);
    105 ULONG APIENTRY inittermUxTheme(ULONG hModule, ULONG ulFlag);
    106 ULONG APIENTRY inittermDInput(ULONG hModule, ULONG ulFlag);
    107 ULONG APIENTRY inittermDSound(ULONG hModule, ULONG ulFlag);
    108 ULONG APIENTRY inittermWinSpool(ULONG hModule, ULONG ulFlag);
    109 ULONG APIENTRY inittermDDraw(ULONG hModule, ULONG ulFlag);
    110 ULONG APIENTRY inittermNTDLL(ULONG hModule, ULONG ulFlag);
    111 ULONG APIENTRY inittermMSVCRT(ULONG hModule, ULONG ulFlag);
    112 ULONG APIENTRY inittermImm32(ULONG hModule, ULONG ulFlag);
    113 ULONG APIENTRY inittermCrypt32(ULONG hModule, ULONG ulFlag);
    114 ULONG APIENTRY inittermOleacc(ULONG hModule, ULONG ulFlag);
    115 ULONG APIENTRY inittermmscms(ULONG hModule, ULONG ulFlag);
    116 ULONG APIENTRY inittermRsaenh(ULONG hModule, ULONG ulFlag);
    117 ULONG APIENTRY inittermSecur32(ULONG hModule, ULONG ulFlag);
    118 
    119 ULONG APIENTRY InitializeKernel32();
    120 
     138BOOL APIENTRY InitializeKernel32();
    121139VOID APIENTRY ReportFatalDllInitError(PCSZ pszModName);
    122140
    123141#ifdef __cplusplus
    124 }
     142} // extern "C"
    125143#endif
    126144
Note: See TracChangeset for help on using the changeset viewer.