Changeset 9828 for trunk/src


Ignore:
Timestamp:
Feb 20, 2003, 10:47:01 AM (23 years ago)
Author:
sandervl
Message:

Added custombuild API for registering a callback for LX Dll loading thru LoadLibrary*()

Location:
trunk/src/kernel32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/windlllx.cpp

    r9411 r9828  
    1 /* $Id: windlllx.cpp,v 1.26 2002-11-18 13:53:54 sandervl Exp $ */
     1/* $Id: windlllx.cpp,v 1.27 2003-02-20 09:47:01 sandervl Exp $ */
    22
    33/*
     
    3434#include <wprocess.h>
    3535#include "oslibmisc.h"
     36#include <custombuild.h>
    3637
    3738#include <exe386.h>
     
    4041#include "dbglocal.h"
    4142
     43/*******************************************************************************
     44*   Global Variables                                                           *
     45*******************************************************************************/
    4246char *lpszCustomDllName      = NULL;
    4347char *lpszCustomExportPrefix = NULL;
    4448ULONG dwOrdinalBase          = 0;
    4549
     50/**
     51 * FreeLibrary callback for LX Dlls, it's call only when the library is actually
     52 * being unloaded.
     53 * Maintained by ODIN_SetLxDllUnLoadCallback().
     54 */
     55PFNLXDLLUNLOAD pfnLxDllUnLoadCallback = NULL;
     56
    4657//******************************************************************************
    4758//******************************************************************************
    4859void WIN32API SetCustomBuildName(char *lpszName, DWORD ordinalbase,
    49                                  char *lpszExportPrefix) 
     60                                 char *lpszExportPrefix)
    5061{
    5162    lpszCustomDllName      = lpszName;
     
    261272ULONG Win32LxDll::Release()
    262273{
    263  HINSTANCE     hinst;
     274 HINSTANCE     hinst                = hinstanceOS2;
     275 HINSTANCE     hinstOdin            = hinstance;
    264276 WIN32DLLENTRY EntryPointTmp        = dllEntryPoint;
    265277 PVOID         pResDataTmp          = (PVOID)pResRootDir;
     
    267279 DWORD         MinorImageVersionTmp = MinorImageVersion;
    268280 DWORD         SubsystemTmp         = Subsystem;
     281 BOOL          fNoUnload            = fDisableUnload; //only set for kernel32.dll
     282 BOOL          fDynLoaded           = isDynamicLib();
    269283 ULONG         ret;
    270284 APIRET        rc;
    271  BOOL          fNoUnload = fDisableUnload; //only set for kernel32.dll
    272  Win32LxDll   *pModule;
    273 
    274   hinst = hinstanceOS2;
     285
    275286  ret = Win32DllBase::Release();
    276   if(ret == 0 && !fNoUnload) {//only set for kernel32.dll (fDisableUnload)
     287
     288  /** @sketch
     289   * If this module is not unreference and it was loaded using LoadLibrary() then
     290   *    call the custombuild callback if present.
     291   *    The callback should call UnRegisterLxDll().
     292   * Endif
     293   *
     294   * @remark
     295   * #ifdef HACK_NEVER_UNLOAD_LX_DLLS
     296   * This will never be called!
     297   * #endif
     298   *
     299   * @todo: call pfnLxDllLoadCallback if DosFreeModule failes.
     300   *        It's not implemented because it's complex and at the moment we will
     301   *        never actually get here.
     302   *        So, this callback is here just as a reminder eventhough it's working..
     303   */
     304  if (!ret && fDynLoaded && pfnLxDllUnLoadCallback)
     305  {
     306    pfnLxDllUnLoadCallback(hinstanceOS2, hinstance);
     307  }
     308
     309  if (ret == 0 && !fNoUnload) {//only set for kernel32.dll (fDisableUnload)
    277310    //DosFreeModule sends a termination message to the dll.
    278311    //The LX dll informs us when it's removed (UnregisterDll call)
     
    280313    if(rc) {
    281314            dprintf(("Win32LxDll::Release: DosFreeModule %x returned %d", hinst, rc));
    282             if(rc == ERROR_INVALID_ACCESS && !fExitProcess) 
     315            if(rc == ERROR_INVALID_ACCESS && !fExitProcess)
    283316            {
     317                #ifndef HACK_NEVER_UNLOAD_LX_DLLS
     318                #error  @todo: call pfnLxDllLoadCallback and let it do the registering if it did that on the initial load..
     319                #endif
    284320                //Dll refused to unload because it has an active exitlist handler
    285321                //or depends on a dll that registered an exitlist handler
     
    295331
    296332                /* OS/2 dll, system dll, converted dll or win32k took care of it. */
    297                 pModule = Win32LxDll::findModuleByOS2Handle(hinst);
     333                Win32LxDll *pModule = Win32LxDll::findModuleByOS2Handle(hinst);
    298334                if(pModule)
    299335                {
     
    365401//******************************************************************************
    366402//******************************************************************************
     403
     404/**
     405 * Custombuild API for registering a callback for LX Dll loading thru LoadLibrary*().
     406 * @returns Success indicator.
     407 * @param   pfn     Pointer to callback.
     408 *                  NULL if callback is deregistered.
     409 */
     410BOOL WIN32API ODIN_SetLxDllUnLoadCallback(PFNLXDLLUNLOAD pfn)
     411{
     412    pfnLxDllUnLoadCallback = pfn;
     413    return TRUE;
     414}
     415
  • trunk/src/kernel32/wprocess.cpp

    r9802 r9828  
    1 /* $Id: wprocess.cpp,v 1.180 2003-02-13 17:16:50 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.181 2003-02-20 09:47:01 sandervl Exp $ */
    22
    33/*
     
    5151#include <win\ntddk.h>
    5252
     53#include <custombuild.h>
     54
    5355#define DBG_LOCALLOG    DBG_wprocess
    5456#include "dbglocal.h"
     
    8890static TEB      *threadList = 0;
    8991static VMutex    threadListMutex;
     92
     93/**
     94 * LoadLibraryExA callback for LX Dlls, it's call only on the initial load.
     95 * Maintained by ODIN_SetLxDllLoadCallback().
     96 * Note! Because of some hacks it may also be called from Win32LxDll::Release().
     97 */
     98PFNLXDLLLOAD pfnLxDllLoadCallback = NULL;
    9099
    91100
     
    451460//******************************************************************************
    452461// ODIN_SetTIBSwitch: override TIB switching
    453 // 
     462//
    454463// Parameters:
    455464//      BOOL fSwitchTIB
     
    743752    fDisableLXDllLoading = TRUE;
    744753}
     754
     755
     756/**
     757 * Custombuild API for registering a callback for LX Dll loading thru LoadLibrary*().
     758 * @returns Success indicator.
     759 * @param   pfn     Pointer to callback.
     760 *                  NULL if callback is deregistered.
     761 */
     762BOOL WIN32API ODIN_SetLxDllLoadCallback(PFNLXDLLLOAD pfn)
     763{
     764    pfnLxDllLoadCallback = pfn;
     765    return TRUE;
     766}
     767
    745768
    746769/**
     
    942965     *      Try load the executable using LoadLibrary
    943966     *      IF successfully loaded THEN
    944      *          IF LX dll and is using the PE Loader THEN
    945      *              Set Load library.
    946      *              Inc reference count.
     967     *          Try find registered/pe2lx object.
     968     *          IF callback Then
     969     *              If callback give green light Then
     970     *                  Find registered lx object.
     971     *              Else
     972     *                  Unload it if loaded.
     973     *              Endif
    947974     *          Endif
    948      *          Inc dynamic reference count.
    949      *          RETURN successfully.
     975     *          IF module object found Then
     976     *              IF LX dll and is using the PE Loader THEN
     977     *                  Set Load library.
     978     *                  Inc reference count.
     979     *              Endif
     980     *              Inc dynamic reference count.
     981     *              RETURN successfully.
     982     *          Else
     983     *              fail.
     984     *          Endif
    950985     *      Endif
    951986     *  Endif
     
    959994            /* OS/2 dll, system dll, converted dll or win32k took care of it. */
    960995            pModule = Win32DllBase::findModuleByOS2Handle(hDll);
     996            /* Custombuild customizing may take care of it too. */
     997            if (pfnLxDllLoadCallback)
     998            {
     999                /* If callback says yes, continue load it, else fail. */
     1000                if (pfnLxDllLoadCallback(hDll, pModule ? pModule->getInstanceHandle() : NULL))
     1001                    pModule = Win32DllBase::findModuleByOS2Handle(hDll);
     1002                else if (pModule)
     1003                {
     1004                    pModule->Release();
     1005                    pModule = NULL;
     1006                }
     1007            }
    9611008            if (pModule)
    9621009            {
     
    18351882#endif
    18361883
    1837     if(bInheritHandles && lpStartupInfo->dwFlags & STARTF_USESTDHANDLES) 
     1884    if(bInheritHandles && lpStartupInfo->dwFlags & STARTF_USESTDHANDLES)
    18381885    {
    18391886        //Translate standard handles if the child needs to inherit them
     
    18451892        retcode |= HMHandleTranslateToOS2(lpStartupInfo->hStdError, &startinfo.hStdError);
    18461893
    1847         if(retcode) { 
     1894        if(retcode) {
    18481895            SetLastError(ERROR_INVALID_HANDLE);
    18491896            return FALSE;
     
    23212368//******************************************************************************
    23222369// ODIN_SetProcAddress: Override a dll export
    2323 // 
     2370//
    23242371// Parameters:
    23252372//      HMODULE hModule         Module handle
     
    23312378//
    23322379//******************************************************************************
    2333 FARPROC WIN32API ODIN_SetProcAddress(HMODULE hModule, LPCSTR lpszProc, 
     2380FARPROC WIN32API ODIN_SetProcAddress(HMODULE hModule, LPCSTR lpszProc,
    23342381                                     FARPROC pfnNewProc)
    23352382{
Note: See TracChangeset for help on using the changeset viewer.