From 767bb87ee25dc6319cf582aa20e19e94c7fc599a Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sun, 22 May 2011 14:26:08 +0100 Subject: [PATCH] Fix for pr3301924. If a relative path name is passed to the Windows LoadModule function, it is applied in turn to each path in the DLL search path. For the ivl_dlopen function, we actually want to mimic the Unix behaviour, where a relative path is relative to the current working directory. On systems where the KB2264107 security fix has been applied, the CWD is excluded from the DLL search path, so we no longer get the required behaviour. This patch reworks the ivl_dlopen function to give the correct behaviour under Windows. This patch also adds a flush of the stderr stream after reporting VPI call errors. This fixes a race between the stdout and stderr streams when running the regression tests in a MinGW shell. --- vvp/ivl_dlfcn.h | 12 ++++++++++-- vvp/vpi_tasks.cc | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/vvp/ivl_dlfcn.h b/vvp/ivl_dlfcn.h index ef68d9bb0..1406482d7 100644 --- a/vvp/ivl_dlfcn.h +++ b/vvp/ivl_dlfcn.h @@ -1,7 +1,7 @@ #ifndef __ivl_dlfcn_H #define __ivl_dlfcn_H /* - * Copyright (c) 2001-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2011 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -33,7 +33,15 @@ typedef shl_t ivl_dll_t; #if defined(__MINGW32__) inline ivl_dll_t ivl_dlopen(const char *name, bool global_flag) -{ return (void *)LoadLibrary(name); } +{ + static char full_name[4096]; + unsigned long length = GetFullPathName(name, sizeof(full_name), + full_name, NULL); + if ((length == 0) || (length > sizeof(full_name))) + return 0; + + return (void *)LoadLibrary(full_name); +} inline void *ivl_dlsym(ivl_dll_t dll, const char *nm) { return (void *)GetProcAddress((HINSTANCE)dll,nm);} diff --git a/vvp/vpi_tasks.cc b/vvp/vpi_tasks.cc index e76789f7a..7eee8f9c7 100644 --- a/vvp/vpi_tasks.cc +++ b/vvp/vpi_tasks.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2011 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -742,6 +742,7 @@ void print_vpi_call_errors() free(vpi_call_error_lst[idx].name); } free(vpi_call_error_lst); + fflush(stderr); } #ifdef CHECK_WITH_VALGRIND