2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-05 09:05:40 +00:00
Files
bind/lib/isc/win32/DLLMain.c
Ondřej Surý c5887c4312 Disable safe-guard assertion in DLL_THREAD_ATTACH/DLL_THREAD_DETACH
The BIND 9 libraries on Windows define DllMain() optional entry point
into a dynamic-link library (DLL).  When the system starts or terminates
a process or thread, it calls the entry-point function for each loaded
DLL using the first thread of the process.

When the DLL is being loaded into the virtual address space of the
current process as a result of the process starting up, we make a call
to DisableThreadLibraryCalls() which should disable the
DLL_THREAD_ATTACH and DLL_THREAD_DETACH notifications for the specified
dynamic-link library (DLL).

This seems not be the case because we never check the return value of
the DisableThreadLibraryCalls() call, and it could in fact fail.  The
DisableThreadLibraryCalls() function fails if the DLL specified by
hModule has active static thread local storage, or if hModule is an
invalid module handle.

In this commit, we remove the safe-guard assertion put in place for the
DLL_THREAD_ATTACH and DLL_THREAD_DETACH events and we just ignore them.
BIND 9 doesn't create/destroy enough threads for it actually to make any
difference, and in fact we do use static thread local storage in the
code.
2021-02-24 08:31:42 +01:00

55 lines
1.1 KiB
C

/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#include <stdio.h>
#include <windows.h>
#include <isc/mem.h>
#include <isc/tls.h>
#include <isc/util.h>
#include "mem_p.h"
#include "tls_p.h"
/*
* Called when we enter the DLL
*/
__declspec(dllexport) BOOL WINAPI
DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
switch (fdwReason) {
/*
* The DLL is loading due to process initialization or a call to
* LoadLibrary.
*/
case DLL_PROCESS_ATTACH:
isc__mem_initialize();
isc__tls_initialize();
break;
/*
* The DLL is unloading from a process due to process
* termination or a call to FreeLibrary.
*/
case DLL_PROCESS_DETACH:
isc__tls_shutdown();
isc__mem_shutdown();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
default:
break;
}
return (TRUE);
}