- first step for DLL plugin support with MSVC. Now the BOCHS.EXE with plugin

support compiles and links fine and the main object files for the plugin DLLs
  are created. Since the gui and iodev makefiles are not ready yet, the link
  stage must be done manually. Support for the search path defined in
  LTDL_LIBRARY_PATH should be added when the DLL plugins compile and work.
This commit is contained in:
Volker Ruppert 2011-06-15 17:24:32 +00:00
parent 48f5c3b794
commit 6a42228075
5 changed files with 65 additions and 4 deletions

View File

@ -431,7 +431,7 @@ typedef struct {
void* record_io;
} bx_debug_t;
void CDECL bx_signal_handler(int signum);
BOCHSAPI_MSVCONLY void CDECL bx_signal_handler(int signum);
int bx_atexit(void);
BOCHSAPI extern bx_debug_t bx_dbg;

View File

@ -2255,7 +2255,22 @@ AC_SUBST(ENH_DBG_OBJS)
DIALOG_OBJS=""
EXPORT_DYNAMIC="-export-dynamic"
case $target in
*-pc-windows* | *-pc-winnt* | *-cygwin* | *-mingw*)
*-pc-windows* | *-pc-winnt*)
if test "$bx_plugins" = 1; then
# set variables for building DLL plugins
PLUGIN_VAR=""
PLUGIN_LIBNAME_TRANSFORMATION='%.o=bx_%.dll'
INSTALL_PLUGINS_VAR=install_dll_plugins
LIBS="$LIBS advapi32.lib comctl32.lib comdlg32.lib gdi32.lib shell32.lib user32.lib"
else
if test "$with_win32" != yes; then
LIBS="$LIBS -lcomctl32"
fi
fi
DIALOG_OBJS="win32dialog.o win32paramdlg.o"
EXPORT_DYNAMIC=""
;;
*-cygwin* | *-mingw*)
if test "$bx_plugins" = 1; then
AC_CHECK_LIB(mingwex, opendir, LIBS="$LIBS -lmingwex")
# set variables for building DLL plugins

View File

@ -20,7 +20,7 @@
#if BX_PLUGINS
#if BX_HAVE_LTDL
#include <ltdl.h>
#else
#elif !defined(_MSC_VER)
#include "ltdl.h"
#endif
#endif
@ -39,7 +39,11 @@ typedef struct _plugin_t
plugintype_t type;
int initialized;
#if BX_PLUGINS
#if defined(_MSC_VER)
HINSTANCE handle;
#else
lt_dlhandle handle;
#endif
#endif
int argc;
char *name, *args, *argv[MAX_ARGC];

View File

@ -342,7 +342,11 @@ plugin_t *plugin_unload(plugin_t *plugin)
if (plugin->initialized)
plugin->plugin_fini();
#if defined(_MSC_VER)
FreeLibrary(plugin->handle);
#else
lt_dlclose(plugin->handle);
#endif
delete [] plugin->name;
dead_plug = plugin;
@ -395,21 +399,42 @@ void plugin_load(char *name, char *args, plugintype_t type)
// be called from either dlopen (global constructors) or plugin_init.
BX_ASSERT(current_plugin_context == NULL);
current_plugin_context = plugin;
#if defined(_MSC_VER)
plugin->handle = LoadLibrary(plugin_filename);
BX_INFO(("DLL handle is %p", plugin->handle));
if (!plugin->handle)
{
current_plugin_context = NULL;
BX_PANIC(("LoadLibrary failed for module '%s': error=%d", name, GetLastError()));
free(plugin);
return;
}
#else
plugin->handle = lt_dlopen (plugin_filename);
BX_INFO(("lt_dlhandle is %p", plugin->handle));
if (!plugin->handle)
{
current_plugin_context = NULL;
BX_PANIC(("dlopen failed for module '%s': %s", name, lt_dlerror ()));
free (plugin);
free(plugin);
return;
}
#endif
if (type != PLUGTYPE_USER) {
sprintf(buf, PLUGIN_INIT_FMT_STRING, name);
} else {
sprintf(buf, PLUGIN_INIT_FMT_STRING, "user");
}
#if defined(_MSC_VER)
plugin->plugin_init =
(int (*)(struct _plugin_t *, enum plugintype_t, int, char *[])) /* monster typecast */
GetProcAddress(plugin->handle, buf);
if (plugin->plugin_init == NULL) {
pluginlog->panic("could not find plugin_init: error=%d", GetLastError());
plugin_abort ();
}
#else
plugin->plugin_init =
(int (*)(struct _plugin_t *, enum plugintype_t, int, char *[])) /* monster typecast */
lt_dlsym (plugin->handle, buf);
@ -417,17 +442,26 @@ void plugin_load(char *name, char *args, plugintype_t type)
pluginlog->panic("could not find plugin_init: %s", lt_dlerror ());
plugin_abort ();
}
#endif
if (type != PLUGTYPE_USER) {
sprintf(buf, PLUGIN_FINI_FMT_STRING, name);
} else {
sprintf(buf, PLUGIN_FINI_FMT_STRING, "user");
}
#if defined(_MSC_VER)
plugin->plugin_fini = (void (*)(void)) GetProcAddress(plugin->handle, buf);
if (plugin->plugin_fini == NULL) {
pluginlog->panic("could not find plugin_fini: error=%d", GetLastError());
plugin_abort ();
}
#else
plugin->plugin_fini = (void (*)(void)) lt_dlsym (plugin->handle, buf);
if (plugin->plugin_fini == NULL) {
pluginlog->panic("could not find plugin_fini: %s", lt_dlerror ());
plugin_abort();
}
#endif
pluginlog->info("loaded plugin %s",plugin_filename);
/* Insert plugin at the _end_ of the plugin linked list. */
@ -498,12 +532,14 @@ plugin_startup(void)
#if BX_PLUGINS
pluginlog = new logfunctions();
pluginlog->put("PLGIN");
#if !defined(_MSC_VER)
int status = lt_dlinit ();
if (status != 0) {
BX_ERROR (("initialization error in ltdl library (for loading plugins)"));
BX_PANIC (("error message was: %s", lt_dlerror ()));
}
#endif
#endif
}

View File

@ -372,9 +372,15 @@ void plugin_fini(void);
int plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[]);
// still in extern "C"
#if BX_PLUGINS && defined(_MSC_VER)
#define DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(mod) \
extern "C" __declspec(dllexport) int __cdecl lib##mod##_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[]); \
extern "C" __declspec(dllexport) void __cdecl lib##mod##_LTX_plugin_fini(void);
#else
#define DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(mod) \
int lib##mod##_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[]); \
void lib##mod##_LTX_plugin_fini(void);
#endif
DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(harddrv)
DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(hdimage)