Changeset 21733 for branches


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.

Location:
branches/gcc-kmk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/gcc-kmk/Config.kmk

    r21695 r21733  
    1515#------------------------------------------------------------------------------
    1616
    17 TEMPLATE_OdinCxx            = Odin C++ sources
     17TEMPLATE_OdinCxx            = Odin C/C++ sources
    1818TEMPLATE_OdinCxx_TOOL       = GXX3OMF
    1919TEMPLATE_OdinCxx_INCS       = $(PATH_ROOT)/include/win $(PATH_ROOT)/include
     
    2929TEMPLATE_OdinCRT_EXTENDS_BY     = overriding
    3030TEMPLATE_OdinCRT_DEFS       = __WIN32OS2__ __i386__
     31
     32TEMPLATE_OdinCxxDLL             = Odin C/C++ DLL
     33TEMPLATE_OdinCxxDLL_EXTENDS     = OdinCxx
     34TEMPLATE_OdinCxxDLL_EXTENDS_BY  = overriding
     35TEMPLATE_OdinCxxDLL_LIBS        = $(TEMPLATE_OdinCxx_LIBS) $(INSTTARGET_initdll)
    3136
    3237#------------------------------------------------------------------------------
  • branches/gcc-kmk/include/custombuild.h

    r21720 r21733  
    3434typedef BOOL (WIN32API *PFN_ENDCUSTOMIZE)();
    3535typedef BOOL (WIN32API *PFN_ISPESTUBLOADER)(char *pszProgram);
     36
     37typedef ULONG (APIENTRY *PFN_INITDLL)(ULONG hModule, ULONG ulFlag);
     38typedef void  (APIENTRY *PFN_CLEANUPDLL)(ULONG ulReason);
    3639
    3740typedef struct {
  • 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
  • branches/gcc-kmk/src/Makefile.kmk

    r21697 r21733  
    99# Include sub-makefiles.
    1010#
     11include $(PATH_SUB_CURRENT)/initdll/Makefile.kmk
    1112include $(PATH_SUB_CURRENT)/guidlib/Makefile.kmk
    1213include $(PATH_SUB_CURRENT)/kernel32/Makefile.kmk
  • branches/gcc-kmk/src/custombuild/initterm.cpp

    r21727 r21733  
    77 *
    88 * Project Odin Software License can be found in LICENSE.TXT
    9  *
    109 */
    1110
    12 /*-------------------------------------------------------------*/
    13 /* INITERM.C -- Source for a custom dynamic link library       */
    14 /*              initialization and termination (_DLL_InitTerm) */
    15 /*              function.                                      */
    16 /*                                                             */
    17 /* When called to perform initialization, this sample function */
    18 /* gets storage for an array of integers, and initializes its  */
    19 /* elements with random integers.  At termination time, it     */
    20 /* frees the array.  Substitute your own special processing.   */
    21 /*-------------------------------------------------------------*/
    22 
    23 
    24 /* Include files */
     11//
     12// @todo Custom Build is broken ATM:
     13//
     14// 1. inittermXXX()/cleanupXXX() are now DLL_InitXXX/DLL_TermXXX
     15//    (see the respective initterm.cpp files for more info).
     16// 2. There is no inittermXXX.cpp files any longer (all initialization functions
     17//    are in XXX/initterm.cpp) so a define (e.g. CUSTOMBUILD) is necessary to
     18//    disable compilation multiple versions of DLL_Init()/DLL_Term().
     19// N. ...
     20//
     21
    2522#define  INCL_DOSMODULEMGR
    2623#define  INCL_DOSMISC
     
    5350extern "C" {
    5451
     52ULONG APIENTRY inittermKernel32(ULONG hModule);
     53void  APIENTRY cleanupKernel32(ULONG hModule);
     54
     55ULONG APIENTRY inittermUser32(ULONG hModule, ULONG ulFlag);
     56void  APIENTRY cleanupUser32(ULONG ulReason);
     57ULONG APIENTRY inittermOdinCtrl(ULONG hModule, ULONG ulFlag);
     58
     59ULONG APIENTRY inittermWinmm(ULONG hModule, ULONG ulFlag);
     60ULONG APIENTRY inittermShell32(ULONG hModule, ULONG ulFlag);
     61ULONG APIENTRY inittermOle32(ULONG hModule, ULONG ulFlag);
     62ULONG APIENTRY inittermComdlg32(ULONG hModule, ULONG ulFlag);
     63ULONG APIENTRY inittermComctl32(ULONG hModule, ULONG ulFlag);
     64ULONG APIENTRY inittermGdi32(ULONG hModule, ULONG ulFlag);
     65ULONG APIENTRY inittermNTDLL(ULONG hModule, ULONG ulFlag);
     66ULONG APIENTRY inittermWsock32(ULONG hModule, ULONG ulFlag);
     67ULONG APIENTRY inittermWininet(ULONG hModule, ULONG ulFlag);
     68ULONG APIENTRY inittermRpcrt4(ULONG hModule, ULONG ulFlag);
     69ULONG APIENTRY inittermAvifil32(ULONG hModule, ULONG ulFlag);
     70ULONG APIENTRY inittermQuartz(ULONG hModule, ULONG ulFlag);
     71ULONG APIENTRY inittermRiched32(ULONG hModule, ULONG ulFlag);
     72ULONG APIENTRY inittermWnaspi32(ULONG hModule, ULONG ulFlag);
     73ULONG APIENTRY inittermUxTheme(ULONG hModule, ULONG ulFlag);
     74ULONG APIENTRY inittermDInput(ULONG hModule, ULONG ulFlag);
     75ULONG APIENTRY inittermDSound(ULONG hModule, ULONG ulFlag);
     76ULONG APIENTRY inittermWinSpool(ULONG hModule, ULONG ulFlag);
     77ULONG APIENTRY inittermDDraw(ULONG hModule, ULONG ulFlag);
     78ULONG APIENTRY inittermNTDLL(ULONG hModule, ULONG ulFlag);
     79ULONG APIENTRY inittermMSVCRT(ULONG hModule, ULONG ulFlag);
     80ULONG APIENTRY inittermImm32(ULONG hModule, ULONG ulFlag);
     81ULONG APIENTRY inittermCrypt32(ULONG hModule, ULONG ulFlag);
     82ULONG APIENTRY inittermOleacc(ULONG hModule, ULONG ulFlag);
     83ULONG APIENTRY inittermmscms(ULONG hModule, ULONG ulFlag);
     84ULONG APIENTRY inittermRsaenh(ULONG hModule, ULONG ulFlag);
     85ULONG APIENTRY inittermSecur32(ULONG hModule, ULONG ulFlag);
     86
    5587/*-------------------------------------------------------------------*/
    5688/* A clean up routine registered with DosExitList must be used if    */
     
    140172         SetCustomBuildName("KERNEL32.DLL", ORDINALBASE_KERNEL32);
    141173         rc = inittermKernel32(hModule, ulFlag);
    142          if(rc == 0) 
     174         if(rc == 0)
    143175             return 0UL;
    144176
    145177         SetCustomBuildName("USER32.DLL", ORDINALBASE_USER32);
    146178         rc = inittermUser32(hModule, ulFlag);
    147          if(rc == 0) 
     179         if(rc == 0)
    148180                return 0UL;
    149181
     
    156188            return 0UL;
    157189
    158          SetCustomBuildName("VERSION.DLL", 0);       
     190         SetCustomBuildName("VERSION.DLL", 0);
    159191         if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
    160192            return 0UL;
     
    162194         SetCustomBuildName("WSOCK32.DLL", ORDINALBASE_WSOCK32);
    163195         rc = inittermWsock32(hModule, ulFlag);
    164          if(rc == 0) 
     196         if(rc == 0)
    165197                return 0UL;
    166198
    167199         SetCustomBuildName("WINMM.DLL", 0);
    168200         rc = inittermWinmm(hModule, ulFlag);
    169          if(rc == 0) 
     201         if(rc == 0)
    170202                return 0UL;
    171203
    172204         SetCustomBuildName("RPCRT4.DLL", 0);
    173205         rc = inittermRpcrt4(hModule, ulFlag);
    174          if(rc == 0) 
     206         if(rc == 0)
    175207                return 0UL;
    176208
    177209         SetCustomBuildName("OLE32.DLL", ORDINALBASE_OLE32);
    178210         rc = inittermOle32(hModule, ulFlag);
    179          if(rc == 0) 
     211         if(rc == 0)
    180212                return 0UL;
    181213
    182214         SetCustomBuildName("COMCTL32.DLL", ORDINALBASE_COMCTL32);
    183215         rc = inittermComctl32(hModule, ulFlag);
    184          if(rc == 0) 
     216         if(rc == 0)
    185217                return 0UL;
    186218
     
    191223         SetCustomBuildName("SHELL32.DLL", ORDINALBASE_SHELL32);
    192224         rc = inittermShell32(hModule, ulFlag);
    193          if(rc == 0) 
     225         if(rc == 0)
    194226                return 0UL;
    195227
    196228         SetCustomBuildName("COMDLG32.DLL", 0);
    197229         rc = inittermComdlg32(hModule, ulFlag);
    198          if(rc == 0) 
     230         if(rc == 0)
    199231                return 0UL;
    200232
    201233         SetCustomBuildName("RICHED32.DLL", 0);
    202234         rc = inittermRiched32(hModule, ulFlag);
    203          if(rc == 0) 
    204                 return 0UL;
    205          
     235         if(rc == 0)
     236                return 0UL;
     237
    206238         SetCustomBuildName(NULL, 0);
    207239         break;
     
    246278ULONG APIENTRY O32__DLL_InitTerm(ULONG handle, ULONG flag);
    247279//******************************************************************************
    248 ULONG APIENTRY InitializeKernel32()
     280BOOL APIENTRY InitializeKernel32()
    249281{
    250282    HMODULE hModule;
    251283
    252284    DosQueryModuleHandleStrict("WGSS50", &hModule);
    253     return O32__DLL_InitTerm(hModule, 0);
     285    return O32__DLL_InitTerm(hModule, 0) != 0;
    254286}
    255287//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.