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