MySQL 9.1.0
Source Code Documentation
dynamic_loader_scheme_file_imp.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MYSQL_SERVER_DYNAMIC_LOADER_SCHEMA_FILE_H
25#define MYSQL_SERVER_DYNAMIC_LOADER_SCHEMA_FILE_H
26
32#include <map>
33#include <unordered_set>
34
35#if defined(_WIN32)
36#define dlsym(lib, name) (void *)GetProcAddress((HMODULE)lib, name)
37#define dlopen(libname, unused) LoadLibraryEx(libname, nullptr, 0)
38#define dlclose(lib) FreeLibrary((HMODULE)lib)
39#define RTLD_NOW 0x00002
40#define DLERROR_GENERATE(errmsg, error_number) \
41 char win_errormsg[2048]; \
42 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, error_number, 0, \
43 win_errormsg, 2048, nullptr)) { \
44 char *ptr; \
45 for (ptr = &win_errormsg[0] + strlen(win_errormsg) - 1; \
46 ptr >= &win_errormsg[0] && strchr("\r\n\t\0x20", *ptr); ptr--) \
47 *ptr = 0; \
48 errmsg = win_errormsg; \
49 } else \
50 errmsg = ""
51#define dlerror() ""
52#define dlopen_errno GetLastError()
53
54#else /* _WIN32 */
55
56#ifndef MYSQL_ABI_CHECK
57#include <dlfcn.h>
58#include <errno.h>
59#endif
60
61#define DLERROR_GENERATE(errmsg, error_number) errmsg = dlerror()
62#define dlopen_errno errno
63#endif
64
66 typedef std::map<std::string, void *> my_registry;
67 typedef mysql_component_t *(*list_components_func)();
68
70 static std::unordered_set<list_components_func> library_entry_set;
72
73 public:
74 /**
75 Initializes file:// scheme for dynamic loader for usage. Initializes
76 RW lock, all other structures should be empty. Shouldn't be called multiple
77 times.
78 */
79 static void init();
80 /**
81 De-initializes RW lock, all other structures doesn't require any action.
82 */
83 static void deinit();
84
85 public:
86 /**
87 Loads components that are located in executable file specified by URN.
88 We assume that URN starts with file://, but accept any. Will not success
89 when called multiple times on the same file.
90
91 @param urn URN to file to load components from.
92 @param [out] out_data Pointer to pointer to MySQL component data structures
93 to set result components data retrieved from specified file.
94 @return Status of performed operation
95 @retval false success
96 @retval true Failure, may be caused when name does not contain ://, cannot
97 be located, is not proper executable file or does not contain proper
98 initialization function.
99 */
101 (const char *urn, mysql_component_t **out_data));
102
103 /**
104 Unloads file that was previously loaded. The URN string must be exactly
105 the same as one used during call to load. Although you can call load() on
106 specified URN multiple times, subsequent calls unload() will always fail,
107 and all components from specified file will be invalid after first call to
108 unload().
109
110 @param urn URN to file to unload all components from.
111 @return Status of performed operation
112 @retval false success
113 @retval true failure
114 */
115 static DEFINE_BOOL_METHOD(unload, (const char *urn));
116};
117
118#endif /* MYSQL_SERVER_DYNAMIC_LOADER_SCHEMA_FILE_H */
Definition: dynamic_loader_scheme_file_imp.h:65
static mysql_rwlock_t LOCK_dynamic_loader_scheme_file
Definition: dynamic_loader_scheme_file_imp.h:71
static void deinit()
De-initializes RW lock, all other structures doesn't require any action.
Definition: dynamic_loader_scheme_file.cc:79
static mysql_service_status_t unload(const char *urn) noexcept
Unloads file that was previously loaded.
Definition: dynamic_loader_scheme_file.cc:204
static void init()
Initializes file:// scheme for dynamic loader for usage.
Definition: dynamic_loader_scheme_file.cc:70
std::map< std::string, void * > my_registry
Definition: dynamic_loader_scheme_file_imp.h:66
static my_registry object_files_list
Definition: dynamic_loader_scheme_file_imp.h:69
static std::unordered_set< list_components_func > library_entry_set
Definition: dynamic_loader_scheme_file_imp.h:70
static mysql_service_status_t load(const char *urn, mysql_component_t **out_data) noexcept
Loads components that are located in executable file specified by URN.
Definition: dynamic_loader_scheme_file.cc:99
Specifies macros to define Components.
Specifies macros to define Service Implementations.
#define DEFINE_BOOL_METHOD(name, args)
A short macro to define method that returns bool, which is the most common case.
Definition: service_implementation.h:88
Carries information on the specific Component, all Service Implementations it provides,...
Definition: dynamic_loader.h:263
An instrumented rwlock structure.
Definition: mysql_rwlock_bits.h:51