Skip to content

Commit

Permalink
Bug 1389967 In MinGW, work around a pointer to a function thunk disap…
Browse files Browse the repository at this point in the history
…pearing when we unload nssckbi r=franziskus,dmajor

--HG--
extra : amend_source : 685830be6c93acd820c2af29204e19ac51775a9d
  • Loading branch information
tomrittervg committed May 21, 2018
1 parent 83607c3 commit a2e0739
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/base/error.c
Expand Up @@ -15,6 +15,10 @@
#include <limits.h> /* for UINT_MAX */
#include <string.h> /* for memmove */

#if defined(__MINGW32__)
#include <windows.h>
#endif

#define NSS_MAX_ERROR_STACK_COUNT 16 /* error codes */

/*
Expand Down Expand Up @@ -65,7 +69,32 @@ static const PRCallOnceType error_call_again;
static PRStatus
error_once_function(void)
{

/*
* This #ifdef function is redundant. It performs the same thing as the
* else case.
*
* However, the MinGW version looks up the function from nss3's export
* table, and on MinGW _that_ behaves differently than passing a
* function pointer in a different module because MinGW has
* -mnop-fun-dllimport specified, which generates function thunks for
* cross-module calls. And when a module (like nssckbi) gets unloaded,
* and you try to call into that thunk (which is now missing) you'll
* crash. So we do this bit of ugly to avoid that crash. Fortunately
* this is the only place we've had to do this.
*/
#if defined(__MINGW32__)
HMODULE nss3 = GetModuleHandleW(L"nss3");
if (nss3) {
FARPROC freePtr = GetProcAddress(nss3, "PR_Free");
if (freePtr) {
return PR_NewThreadPrivateIndex(&error_stack_index, freePtr);
}
}
return PR_NewThreadPrivateIndex(&error_stack_index, PR_Free);
#else
return PR_NewThreadPrivateIndex(&error_stack_index, PR_Free);
#endif
}

/*
Expand Down

0 comments on commit a2e0739

Please sign in to comment.