Home | History | Annotate | Line # | Download | only in isc
lib.c revision 1.9
      1 /*	$NetBSD: lib.c,v 1.9 2022/09/23 12:15:33 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/lib.h>
     20 #include <isc/mem.h>
     21 #include <isc/util.h>
     22 
     23 #include "config.h"
     24 #include "mem_p.h"
     25 #include "tls_p.h"
     26 #include "trampoline_p.h"
     27 
     28 #ifndef ISC_CONSTRUCTOR
     29 #error Either __attribute__((constructor|destructor))__ or DllMain support needed to compile BIND 9.
     30 #endif
     31 
     32 /***
     33  *** Functions
     34  ***/
     35 
     36 void
     37 isc_lib_register(void) {
     38 	isc_bind9 = false;
     39 }
     40 
     41 #ifdef WIN32
     42 int
     43 isc_lib_ntservice(int(WINAPI *mainfunc)(int argc, char *argv[]), int argc,
     44 		  char *argv[]) {
     45 	isc__trampoline_t *trampoline = isc__trampoline_get(NULL, NULL);
     46 	int r;
     47 
     48 	isc__trampoline_attach(trampoline);
     49 
     50 	r = mainfunc(argc, argv);
     51 
     52 	isc__trampoline_detach(trampoline);
     53 
     54 	return (r);
     55 }
     56 #endif /* ifdef WIN32 */
     57 
     58 void
     59 isc__initialize(void) ISC_CONSTRUCTOR;
     60 void
     61 isc__shutdown(void) ISC_DESTRUCTOR;
     62 
     63 void
     64 isc__initialize(void) {
     65 	isc__mem_initialize();
     66 	isc__tls_initialize();
     67 	isc__trampoline_initialize();
     68 }
     69 
     70 void
     71 isc__shutdown(void) {
     72 	isc__trampoline_shutdown();
     73 	isc__tls_shutdown();
     74 	isc__mem_shutdown();
     75 }
     76 
     77 /*
     78  * This is a workaround for situation when libisc is statically linked.  Under
     79  * normal situation, the linker throws out all symbols from compilation unit
     80  * when no symbols are used in the final binary.  This empty function must be
     81  * called at least once from different compilation unit (mem.c in this case).
     82  */
     83 void
     84 isc_enable_constructors() {
     85 	/* do nothing */
     86 }
     87