From 9254bfded9fda79b2091ad22786c93285b3f61aa Mon Sep 17 00:00:00 2001 From: Jiri Malak Date: Fri, 1 Nov 2024 14:54:09 +0100 Subject: [PATCH] mstools: fix bug in DLL interface replace hand writen DLL interface by standard IDE driver code fix print function mismatch --- bld/mstools/c/dlltool.c | 246 -------------------------------------- bld/mstools/c/fuzzy.c | 83 ++++++++----- bld/mstools/h/dlltool.h | 69 ----------- bld/mstools/lib/lib.mif | 4 +- bld/mstools/link/link.mif | 4 +- 5 files changed, 58 insertions(+), 348 deletions(-) delete mode 100644 bld/mstools/c/dlltool.c delete mode 100644 bld/mstools/h/dlltool.h diff --git a/bld/mstools/c/dlltool.c b/bld/mstools/c/dlltool.c deleted file mode 100644 index b1a7ee2904..0000000000 --- a/bld/mstools/c/dlltool.c +++ /dev/null @@ -1,246 +0,0 @@ -/**************************************************************************** -* -* Open Watcom Project -* -* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. -* -* ======================================================================== -* -* This file contains Original Code and/or Modifications of Original -* Code as defined in and that are subject to the Sybase Open Watcom -* Public License version 1.0 (the 'License'). You may not use this file -* except in compliance with the License. BY USING THIS FILE YOU AGREE TO -* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is -* provided with the Original Code and Modifications, and is also -* available at www.sybase.com/developer/opensource. -* -* The Original Code and all software distributed under the License are -* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER -* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM -* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR -* NON-INFRINGEMENT. Please see the License for the specific language -* governing rights and limitations under the License. -* -* ======================================================================== -* -* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE -* DESCRIBE IT HERE! -* -****************************************************************************/ - - -#include -#include "bool.h" -#include "dlltool.h" -#include "error.h" -#include "memory.h" - -#define WLIB_DLL_FILENAME "wlibd.dll" -#if defined( __NT__ ) && defined( __386__ ) -#define DLL_GETVER "_IDEGetVersion@0" -#define DLL_INITDLL "_IDEInitDLL@12" -#define DLL_RUNSELF "_IDERunYourSelf@12" -#define DLL_FINIDLL "_IDEFiniDLL@4" -#define DLL_STOPRUN "_IDEStopRunning@0" -#define DLL_INITINFO "_IDEPassInitInfo@8" -#else -#define DLL_GETVER "IDEGetVersion" -#define DLL_INITDLL "IDEInitDLL" -#define DLL_RUNSELF "IDERunYourSelf" -#define DLL_FINIDLL "IDEFiniDLL" -#define DLL_STOPRUN "IDEStopRunning" -#define DLL_INITINFO "IDEPassInitInfo" -#endif - - -/* - * Types. - */ -typedef char WBool; /* really a C++ 'bool' */ -typedef unsigned IDEAPI (*GetVerFn)( void ); -typedef WBool IDEAPI (*InitDllFn)( IDECBHdl cbhdl, IDECallBacks *cb, IDEDllHdl *hdl ); -typedef WBool IDEAPI (*InitInfoFn)( IDEDllHdl hdl, IDEInitInfo *info ); -typedef WBool IDEAPI (*RunSelfFn)( IDEDllHdl hdl, const char *opts, WBool *fatalerr ); -typedef void IDEAPI (*FiniDllFn)( IDEDllHdl hdl ); -typedef void IDEAPI (*StopRunFn)( void ); - -typedef struct { - HINSTANCE dllhandle; - GetVerFn getversion; - InitDllFn initdll; - InitInfoFn initinfo; - RunSelfFn runyourself; - FiniDllFn finidll; - StopRunFn stoprunning; - IDECallBacks1 callbacks_ver1; - IDECallBacks callbacks; - IDEDllHdl dllHdl; - IDEInitInfo initdata; -} DllTool; - - -/* - * If a callback function isn't given to InitDllTool, the appropriate one - * of these do-nothing functions will be used. - */ -static IDEBool __stdcall print_message( IDECBHdl idehdl, const char *text ) -{ - /* unused parameters */ (void)idehdl; (void)text; - - return( 1 ); -} -static IDEBool __stdcall print_message_crlf( IDECBHdl idehdl, const char *text ) -{ - /* unused parameters */ (void)idehdl; (void)text; - - return( 1 ); -} -static IDEBool __stdcall print_with_info2( IDECBHdl idehdl, IDEMsgInfo2 *info ) -{ - /* unused parameters */ (void)idehdl; (void)info; - - return( 1 ); -} -static IDEBool __stdcall print_with_info( IDECBHdl idehdl, IDEMsgInfo *info ) -{ - /* unused parameters */ (void)idehdl; (void)info; - - return( 1 ); -} - - -/* - * Load a DLL. Returns NULL on failure. - */ -void *InitDllTool( int whichtool, const DllToolCallbacks *callbacks ) -/*******************************************************************/ -{ - DllTool * tool = AllocMem( sizeof( DllTool ) ); - unsigned dllversion; - IDECallBacks * dllcallbacks; - - /*** Load the DLL ***/ - switch( whichtool ) { - case DLLTOOL_WLIB: - tool->dllhandle = LoadLibrary( WLIB_DLL_FILENAME ); - break; - default: - Zoinks(); - }; - if( tool->dllhandle == NULL ) { - return( NULL ); - } - - /*** Grab the entry points ***/ - tool->getversion = (GetVerFn)GetProcAddress( tool->dllhandle, DLL_GETVER ); - tool->initdll = (InitDllFn)GetProcAddress( tool->dllhandle, DLL_INITDLL ); - tool->initinfo = (InitInfoFn)GetProcAddress( tool->dllhandle, DLL_INITINFO ); - tool->runyourself = (RunSelfFn)GetProcAddress( tool->dllhandle, DLL_RUNSELF ); - tool->finidll = (FiniDllFn)GetProcAddress( tool->dllhandle, DLL_FINIDLL ); - tool->stoprunning = (StopRunFn)GetProcAddress( tool->dllhandle, DLL_STOPRUN ); - if( tool->getversion == NULL || tool->initdll == NULL || - tool->runyourself == NULL || tool->finidll == NULL || - tool->stoprunning == NULL ) { - FreeLibrary( tool->dllhandle ); - return( NULL ); - } - - /*** Set up the callbacks ***/ - dllversion = tool->getversion(); - if( dllversion == 1 ) { - memset( &tool->callbacks_ver1, 0, sizeof( IDECallBacks1 ) ); - if( callbacks->printmessage != NULL ) { - tool->callbacks_ver1.PrintMessage = callbacks->printmessage; - } else { - tool->callbacks_ver1.PrintMessage = print_message; - } - if( callbacks->printmessageCRLF != NULL ) { - tool->callbacks_ver1.PrintWithCRLF = callbacks->printmessageCRLF; - } else { - tool->callbacks_ver1.PrintWithCRLF = print_message_crlf; - } - tool->callbacks_ver1.GetInfo = NULL; - tool->callbacks_ver1.RunBatch = NULL; - dllcallbacks = (IDECallBacks*) &tool->callbacks_ver1; - } else if( dllversion > 1 ) { - memset( &tool->callbacks, 0, sizeof( IDECallBacks ) ); - if( callbacks->printmessage != NULL ) { - tool->callbacks.PrintMessage = callbacks->printmessage; - } else { - tool->callbacks.PrintMessage = print_message; - } - if( callbacks->printmessageCRLF != NULL ) { - tool->callbacks.PrintWithCRLF = callbacks->printmessageCRLF; - } else { - tool->callbacks.PrintWithCRLF = print_message_crlf; - } - if( dllversion == 2 ) { - if( callbacks->printwithinfo != NULL ) { - tool->callbacks.PrintWithInfo = (IDEMsgInfoFn)callbacks->printwithinfo2; - } else { - tool->callbacks.PrintWithInfo = (IDEMsgInfoFn)print_with_info2; - } - } else { /* dllversion >= 3 */ - if( callbacks->printwithinfo != NULL ) { - tool->callbacks.PrintWithInfo = callbacks->printwithinfo; - } else { - tool->callbacks.PrintWithInfo = print_with_info; - } - } - tool->callbacks.GetInfo = NULL; - tool->callbacks.RunBatch = NULL; - tool->callbacks.ProgressMessage = NULL; - dllcallbacks = &tool->callbacks; - } else { - FreeLibrary( tool->dllhandle ); - return( NULL ); - } - - /*** Tell the DLL to initialize itself ***/ - if( tool->initdll( (IDECBHdl)callbacks->cookie, dllcallbacks, &tool->dllHdl ) ) { - FreeLibrary( tool->dllhandle ); - return( NULL ); - } - if( tool->initinfo != NULL ) { - memset( &tool->initdata, 0, sizeof( tool->initdata ) ); - tool->initdata.ver = IDE_CUR_INFO_VER; - tool->initdata.ignore_env = 1; - tool->initdata.cmd_line_has_files = 1; - tool->initinfo( tool->dllHdl, &tool->initdata ); - } - - return( (void*)tool ); -} - - -/* - * Unload a DLL. - */ -void FiniDllTool( void *_tool ) -/*****************************/ -{ - DllTool *tool = (DllTool*)_tool; - - tool->finidll( tool->dllHdl ); - FreeLibrary( tool->dllhandle ); -} - - -/* - * Run a DLL. Returns 0 on failure. - */ -int RunDllTool( void *_tool, const char *cmdline ) -/************************************************/ -{ - DllTool * tool = (DllTool*)_tool; - WBool fatal = 0; - WBool rc; - - rc = tool->runyourself( tool->dllHdl, cmdline, &fatal ); - if( rc || fatal ) { - return( 0 ); - } else { - return( 1 ); - } -} diff --git a/bld/mstools/c/fuzzy.c b/bld/mstools/c/fuzzy.c index e167279362..9d16a2e1cd 100644 --- a/bld/mstools/c/fuzzy.c +++ b/bld/mstools/c/fuzzy.c @@ -2,6 +2,7 @@ * * Open Watcom Project * +* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -37,16 +38,19 @@ #include "wio.h" #include "bool.h" #include "demangle.h" /* from lib_misc project */ -#include "dlltool.h" +#include "idedll.h" #include "error.h" #include "fuzzy.h" #include "hash.h" #include "memory.h" #include "orl.h" /* from riscdev project */ +#include "idedrv.h" #include "clibext.h" +#define WLIB_DLL_FILENAME "wlibd.dll" + #define HASH_TABLE_SIZE 2111 #define MAX_SYMBOL_LEN 512 @@ -76,7 +80,6 @@ typedef struct _MatchingInfo { */ static HashTable hashtable = NULL; static ListElem * bufflist = NULL; -static void * dllhandle = NULL; /* @@ -355,8 +358,8 @@ static char *find_file( const char *filename, const char *libpaths[] ) /* * Collect all external symbols from a library file. Returns 0 on error. */ -static int handle_lib_file( const char *filename, const char *libpaths[] ) -/************************************************************************/ +static int handle_lib_file( IDEDRV *info, const char *filename, const char *libpaths[] ) +/**************************************************************************************/ { char * realpath; size_t len; @@ -374,13 +377,12 @@ static int handle_lib_file( const char *filename, const char *libpaths[] ) len = strlen( realpath ); options = AllocMem( leeway + len + 1 ); sprintf( options, "-tl %s", realpath ); - rc = RunDllTool( dllhandle, options ); + rc = IdeDrvExecDLL( info, options ); FreeMem( options ); - if( rc ) { - return( 1 ); - } else { - return( 0 ); + if( rc == IDEDRV_ERR_LOAD ) { + Warning( "Cannot load WLIB DLL -- fuzzy name matching may not work" ); } + return( rc == IDEDRV_SUCCESS ? 1 : 0 ); } @@ -411,19 +413,36 @@ static int wlib_output( const char *text ) /* * WLIB DLL output callback functions. */ -static IDEBool __stdcall print_message_crlf( IDECBHdl hdl, const char *text ) +void IdeMsgFormat // FORMAT A MESSAGE + ( IDECBHdl handle // - handle for requestor + , IDEMsgInfo const * info // - message information + , char * buffer // - buffer + , size_t bsize // - buffer size + , IDEMsgInfoFn displayer ) // - display function +{ + /* unused parameters */ + (void)handle; + (void)info; + (void)buffer; + (void)bsize; + (void)displayer; +} + +static IDEBool IDEAPI print_message( IDECBHdl hdl, const char *text ) { /* unused parameters */ (void)hdl; return( (IDEBool)wlib_output( text ) ); } -static IDEBool __stdcall print_with_info2( IDECBHdl hdl, IDEMsgInfo2 *info ) + +static IDEBool IDEAPI print_message_crlf( IDECBHdl hdl, const char *text ) { /* unused parameters */ (void)hdl; - return( (IDEBool)wlib_output( info->msg ) ); + return( (IDEBool)wlib_output( text ) ); } -static IDEBool __stdcall print_with_info( IDECBHdl hdl, IDEMsgInfo *info ) + +static IDEBool IDEAPI print_with_info( IDECBHdl hdl, IDEMsgInfo *info ) { /* unused parameters */ (void)hdl; @@ -443,7 +462,6 @@ void InitFuzzy( const char *objs[], const char *libs[], unsigned count; orl_handle o_hnd; int rc = 1; - DllToolCallbacks dllcallbacks; ORLSetFuncs( orl_cli_funcs, obj_read, obj_seek, AllocMem, FreeMem ); /*** Create a hash table ***/ @@ -475,25 +493,32 @@ void InitFuzzy( const char *objs[], const char *libs[], /*** Collect all external symbols from the specified library files ***/ if( libs != NULL ) { + IDEDRV info; + IDECallBacks *cb; + + IdeDrvInit( &info, WLIB_DLL_FILENAME, NULL ); /*** Load the WLIB DLL ***/ - dllcallbacks.printmessage = NULL; - dllcallbacks.printmessageCRLF = print_message_crlf; - dllcallbacks.printwithinfo2 = print_with_info2; - dllcallbacks.printwithinfo = print_with_info; - dllcallbacks.cookie = NULL; - dllhandle = InitDllTool( DLLTOOL_WLIB, &dllcallbacks ); - if( dllhandle == NULL ) { - Warning( "Cannot load WLIB DLL -- fuzzy name matching may not work" ); - } else { - /*** Scan the file(s) ***/ - for( count = 0; libs[count] != NULL; count++ ) { - if( !handle_lib_file( libs[count], libpaths ) ) { - rc = (*callback)( libs[count] ); - if( !rc ) break; + cb = IdeDrvGetCallbacks(); + if( cb != NULL ) { + cb->PrintMessage = print_message; + cb->PrintWithCRLF = print_message_crlf; + cb->PrintWithInfo = print_with_info; + } + /*** Scan the file(s) ***/ + for( count = 0; libs[count] != NULL; count++ ) { + rc = handle_lib_file( &info, libs[count], libpaths ); + if( rc == IDEDRV_ERR_LOAD ) { + Warning( "Cannot load WLIB DLL -- fuzzy name matching may not work" ); + break; + } + if( rc != 0 ) { + rc = (*callback)( libs[count] ); + if( rc == 0 ) { + break; } } - FiniDllTool( dllhandle ); } + IdeDrvUnloadDLL( &info ); } } diff --git a/bld/mstools/h/dlltool.h b/bld/mstools/h/dlltool.h deleted file mode 100644 index 0f265f7dd7..0000000000 --- a/bld/mstools/h/dlltool.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -* -* Open Watcom Project -* -* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. -* -* ======================================================================== -* -* This file contains Original Code and/or Modifications of Original -* Code as defined in and that are subject to the Sybase Open Watcom -* Public License version 1.0 (the 'License'). You may not use this file -* except in compliance with the License. BY USING THIS FILE YOU AGREE TO -* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is -* provided with the Original Code and Modifications, and is also -* available at www.sybase.com/developer/opensource. -* -* The Original Code and all software distributed under the License are -* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER -* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM -* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR -* NON-INFRINGEMENT. Please see the License for the specific language -* governing rights and limitations under the License. -* -* ======================================================================== -* -* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE -* DESCRIBE IT HERE! -* -****************************************************************************/ - - -#ifndef _DLLTOOL_H -#define _DLLTOOL_H - -#include -#include "idedll.h" - - -/* - * Defines for specifying which tool to use. - */ -#define DLLTOOL_WLIB 0 - - -/* - * Define some types. - */ -typedef IDEBool (IDEAPI *IDEMsgInfo2Fn)( IDECBHdl hdl, IDEMsgInfo2 *info ); - -typedef struct { - IDEPrintMsgFn printmessage; - IDEPrintMsgFn printmessageCRLF; - IDEMsgInfo2Fn printwithinfo2; - IDEMsgInfoFn printwithinfo; - void * cookie; /* passed to callback routines */ -} DllToolCallbacks; - - -/* - * Function prototypes. - */ -extern void * InitDllTool( int whichtool, - const DllToolCallbacks *callbacks ); -extern void FiniDllTool( void *tool ); -extern int RunDllTool( void *tool, const char *cmdline ); - - -#endif diff --git a/bld/mstools/lib/lib.mif b/bld/mstools/lib/lib.mif index b38e743fc2..fe11a21195 100644 --- a/bld/mstools/lib/lib.mif +++ b/bld/mstools/lib/lib.mif @@ -2,13 +2,13 @@ tree_depth = 5 !include $(orl_dir)/client.mif -.c : $(lib_misc_dir)/c +.c : $(lib_misc_dir)/c;$(watcom_dir)/c extra_inc_dirs = -I"$(lib_misc_dir)/h" $(cli_orl_inc_dirs) !ifdef target_cpu exetarg_prebuild_objs = cmdlnprs.gc -exetarg_objs = deffile.obj lib.obj message.obj translat.obj demangle.obj dlltool.obj fuzzy.obj hash.obj parse.obj $(mstools_objs) +exetarg_objs = deffile.obj lib.obj message.obj translat.obj demangle.obj idedrv.obj fuzzy.obj hash.obj parse.obj $(mstools_objs) exetarg_libs = $(cli_orl_libs) !else exetarg_objs = libstub.obj $(mstools_stub_obj) $(mstools_objs) diff --git a/bld/mstools/link/link.mif b/bld/mstools/link/link.mif index 01c8bebe9e..5d949b56f0 100644 --- a/bld/mstools/link/link.mif +++ b/bld/mstools/link/link.mif @@ -6,13 +6,13 @@ tree_depth = 5 !include $(orl_dir)/client.mif -.c : $(lib_misc_dir)/c +.c : $(lib_misc_dir)/c;$(watcom_dir)/c extra_inc_dirs = -I"$(lib_misc_dir)/h" $(cli_orl_inc_dirs) !ifdef target_cpu exetarg_prebuild_objs = cmdlnprs.gc -exetarg_objs = deffile.obj link.obj message.obj translat.obj demangle.obj dlltool.obj fuzzy.obj hash.obj parse.obj $(mstools_objs) +exetarg_objs = deffile.obj link.obj message.obj translat.obj demangle.obj idedrv.obj fuzzy.obj hash.obj parse.obj $(mstools_objs) exetarg_libs = $(cli_orl_libs) !else exetarg_objs = linkstub.obj $(mstools_stub_obj) $(mstools_objs)