1 /* $NetBSD: lib.c,v 1.10 2023/06/26 22:03:01 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 /*! \file */ 17 18 #include <isc/bind9.h> 19 #include <isc/iterated_hash.h> 20 #include <isc/lib.h> 21 #include <isc/mem.h> 22 #include <isc/util.h> 23 24 #include "config.h" 25 #include "mem_p.h" 26 #include "tls_p.h" 27 #include "trampoline_p.h" 28 29 #ifndef ISC_CONSTRUCTOR 30 #error Either __attribute__((constructor|destructor))__ or DllMain support needed to compile BIND 9. 31 #endif 32 33 /*** 34 *** Functions 35 ***/ 36 37 void 38 isc_lib_register(void) { 39 isc_bind9 = false; 40 } 41 42 #ifdef WIN32 43 int 44 isc_lib_ntservice(int(WINAPI *mainfunc)(int argc, char *argv[]), int argc, 45 char *argv[]) { 46 isc__trampoline_t *trampoline = isc__trampoline_get(NULL, NULL); 47 int r; 48 49 isc__trampoline_attach(trampoline); 50 51 r = mainfunc(argc, argv); 52 53 isc__trampoline_detach(trampoline); 54 55 return (r); 56 } 57 #endif /* ifdef WIN32 */ 58 59 void 60 isc__initialize(void) ISC_CONSTRUCTOR; 61 void 62 isc__shutdown(void) ISC_DESTRUCTOR; 63 64 void 65 isc__initialize(void) { 66 isc__mem_initialize(); 67 isc__tls_initialize(); 68 isc__trampoline_initialize(); 69 } 70 71 void 72 isc__shutdown(void) { 73 isc__trampoline_shutdown(); 74 isc__tls_shutdown(); 75 isc__mem_shutdown(); 76 } 77 78 /* 79 * This is a workaround for situation when libisc is statically linked. Under 80 * normal situation, the linker throws out all symbols from compilation unit 81 * when no symbols are used in the final binary. This empty function must be 82 * called at least once from different compilation unit (mem.c in this case). 83 */ 84 void 85 isc_enable_constructors() { 86 /* do nothing */ 87 } 88