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