/src/mysql-server/mysys/my_static.cc
Line | Count | Source |
1 | | /* Copyright (c) 2000, 2025, Oracle and/or its affiliates. |
2 | | |
3 | | This program is free software; you can redistribute it and/or modify |
4 | | it under the terms of the GNU General Public License, version 2.0, |
5 | | as published by the Free Software Foundation. |
6 | | |
7 | | This program is designed to work with certain software (including |
8 | | but not limited to OpenSSL) that is licensed under separate terms, |
9 | | as designated in a particular file or component or in included license |
10 | | documentation. The authors of MySQL hereby grant you an additional |
11 | | permission to link the program and your derivative works with the |
12 | | separately licensed software that they have either included with |
13 | | the program or referenced in the documentation. |
14 | | |
15 | | Without limiting anything contained in the foregoing, this file, |
16 | | which is part of C Driver for MySQL (Connector/C), is also subject to the |
17 | | Universal FOSS Exception, version 1.0, a copy of which can be found at |
18 | | http://oss.oracle.com/licenses/universal-foss-exception. |
19 | | |
20 | | This program is distributed in the hope that it will be useful, |
21 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | | GNU General Public License, version 2.0, for more details. |
24 | | |
25 | | You should have received a copy of the GNU General Public License |
26 | | along with this program; if not, write to the Free Software |
27 | | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
28 | | |
29 | | /** |
30 | | @file mysys/my_static.cc |
31 | | Static variables for mysys library. All defined here for easy making of |
32 | | a shared library. |
33 | | */ |
34 | | |
35 | | #include "mysys/my_static.h" |
36 | | |
37 | | #include <sys/types.h> |
38 | | #include <atomic> |
39 | | #include <cassert> |
40 | | #include <cstdarg> |
41 | | |
42 | | #include "my_sys.h" |
43 | | #include "mysql/my_loglevel.h" |
44 | | #include "mysql/psi/mysql_mutex.h" |
45 | | #include "mysql/psi/psi_memory.h" |
46 | | #include "mysql/psi/psi_thread.h" |
47 | | #include "mysys/mysys_priv.h" // IWYU pragma: keep |
48 | | |
49 | | /* get memory in hunks */ |
50 | | constexpr uint ONCE_ALLOC_INIT = 4096 - MALLOC_OVERHEAD; |
51 | | |
52 | | PSI_memory_key key_memory_charset_loader; |
53 | | PSI_memory_key key_memory_lf_node; |
54 | | PSI_memory_key key_memory_lf_dynarray; |
55 | | PSI_memory_key key_memory_lf_slist; |
56 | | PSI_memory_key key_memory_LIST; |
57 | | PSI_memory_key key_memory_IO_CACHE; |
58 | | PSI_memory_key key_memory_KEY_CACHE; |
59 | | PSI_memory_key key_memory_SAFE_HASH_ENTRY; |
60 | | PSI_memory_key key_memory_MY_BITMAP_bitmap; |
61 | | PSI_memory_key key_memory_my_compress_alloc; |
62 | | PSI_memory_key key_memory_my_err_head; |
63 | | PSI_memory_key key_memory_my_file_info; |
64 | | PSI_memory_key key_memory_max_alloca; |
65 | | PSI_memory_key key_memory_MY_DIR; |
66 | | PSI_memory_key key_memory_MY_TMPDIR_full_list; |
67 | | PSI_memory_key key_memory_DYNAMIC_STRING; |
68 | | PSI_memory_key key_memory_TREE; |
69 | | |
70 | | PSI_thread_key key_thread_timer_notifier; |
71 | | |
72 | | #ifdef _WIN32 |
73 | | PSI_memory_key key_memory_win_SECURITY_ATTRIBUTES; |
74 | | PSI_memory_key key_memory_win_PACL; |
75 | | PSI_memory_key key_memory_win_IP_ADAPTER_ADDRESSES; |
76 | | PSI_memory_key key_memory_win_handle_info; |
77 | | #endif /* _WIN32 */ |
78 | | |
79 | | /* from my_init */ |
80 | | char *home_dir = nullptr; |
81 | | const char *my_progname = nullptr; |
82 | | char curr_dir[FN_REFLEN] = {0}, home_dir_buff[FN_REFLEN] = {0}; |
83 | | |
84 | | ulong my_tmp_file_created = 0; |
85 | | |
86 | | ulong my_stream_opened = 0; |
87 | | ulong my_file_opened = 0; |
88 | | ulong my_file_total_opened = 0; |
89 | | |
90 | | namespace file_info { |
91 | | /** |
92 | | Increment status variables. |
93 | | @relates file_info::CountFileOpen |
94 | | |
95 | | @param pt previous file_type (only relevant when assigning an fd to a stream |
96 | | in my_fdopen): |
97 | | @param ct current file type (to differentiate between streams and files). |
98 | | */ |
99 | 0 | void CountFileOpen(OpenType pt, OpenType ct) { |
100 | 0 | mysql_mutex_assert_owner(&THR_LOCK_open); |
101 | 0 | assert(my_file_opened + my_stream_opened == my_file_total_opened); |
102 | 0 | assert(pt == OpenType::UNOPEN || ct == OpenType::STREAM_BY_FDOPEN); |
103 | 0 | switch (ct) { |
104 | 0 | case OpenType::UNOPEN: |
105 | 0 | assert(false); |
106 | 0 | return; |
107 | | |
108 | 0 | case OpenType::STREAM_BY_FDOPEN: |
109 | 0 | if (pt != OpenType::UNOPEN) { |
110 | | // If fd was opened through mysys, we have already counted |
111 | | // it in my_file_opened_. Since we will now increment |
112 | | // my_file_stream_opened_ for it, we decrement my_file_opened_ |
113 | | // so that it is not counted twice. |
114 | 0 | assert(pt != OpenType::STREAM_BY_FOPEN && |
115 | 0 | pt != OpenType::STREAM_BY_FDOPEN); |
116 | 0 | --my_file_opened; |
117 | 0 | ++my_stream_opened; |
118 | 0 | assert(my_file_opened + my_stream_opened == my_file_total_opened); |
119 | 0 | return; |
120 | 0 | } |
121 | 0 | [[fallthrough]]; |
122 | 0 | case OpenType::STREAM_BY_FOPEN: |
123 | 0 | ++my_stream_opened; |
124 | 0 | break; |
125 | | |
126 | 0 | default: |
127 | 0 | ++my_file_opened; |
128 | 0 | } |
129 | 0 | ++my_file_total_opened; |
130 | 0 | assert(my_file_opened + my_stream_opened == my_file_total_opened); |
131 | 0 | } |
132 | | |
133 | | /** |
134 | | Decrement status variables. |
135 | | @relates file_info::CountFileClose |
136 | | |
137 | | @param ft file type (to differentiate between streams and files). |
138 | | */ |
139 | 0 | void CountFileClose(OpenType ft) { |
140 | 0 | mysql_mutex_assert_owner(&THR_LOCK_open); |
141 | 0 | assert(my_file_opened + my_stream_opened == my_file_total_opened); |
142 | 0 | switch (ft) { |
143 | 0 | case OpenType::UNOPEN: |
144 | 0 | return; |
145 | 0 | case OpenType::STREAM_BY_FOPEN: |
146 | 0 | case OpenType::STREAM_BY_FDOPEN: |
147 | 0 | --my_stream_opened; |
148 | 0 | break; |
149 | 0 | default: |
150 | 0 | --my_file_opened; |
151 | 0 | }; |
152 | 0 | --my_file_total_opened; |
153 | 0 | assert(my_file_opened + my_stream_opened == my_file_total_opened); |
154 | 0 | } |
155 | | } // namespace file_info |
156 | | |
157 | | int my_umask = 0664, my_umask_dir = 0777; |
158 | | |
159 | | /* from mf_reccache.c */ |
160 | | ulong my_default_record_cache_size = RECORD_CACHE_SIZE; |
161 | | |
162 | | /* from my_malloc */ |
163 | | USED_MEM *my_once_root_block = nullptr; /* pointer to first block */ |
164 | | unsigned int my_once_extra = ONCE_ALLOC_INIT; /* Memory to alloc / block */ |
165 | | |
166 | | std::atomic<ErrorHandlerFunctionPointer> error_handler_hook{my_message_stderr}; |
167 | | |
168 | | void (*local_message_hook)(enum loglevel ll, uint ecode, |
169 | | va_list args) = my_message_local_stderr; |
170 | | |
171 | | static void enter_cond_dummy( |
172 | | void *a [[maybe_unused]], mysql_cond_t *b [[maybe_unused]], |
173 | | mysql_mutex_t *c [[maybe_unused]], const PSI_stage_info *d [[maybe_unused]], |
174 | | PSI_stage_info *e [[maybe_unused]], const char *f [[maybe_unused]], |
175 | 0 | const char *g [[maybe_unused]], int h [[maybe_unused]]) {} |
176 | | |
177 | | static void exit_cond_dummy(void *a [[maybe_unused]], |
178 | | const PSI_stage_info *b [[maybe_unused]], |
179 | | const char *c [[maybe_unused]], |
180 | | const char *d [[maybe_unused]], |
181 | 0 | int e [[maybe_unused]]) {} |
182 | | |
183 | | static void enter_stage_dummy(void *a [[maybe_unused]], |
184 | | const PSI_stage_info *b [[maybe_unused]], |
185 | | PSI_stage_info *c [[maybe_unused]], |
186 | | const char *d [[maybe_unused]], |
187 | | const char *e [[maybe_unused]], |
188 | 0 | int f [[maybe_unused]]) {} |
189 | | |
190 | | static void set_waiting_for_disk_space_dummy(void *a [[maybe_unused]], |
191 | 0 | bool b [[maybe_unused]]) {} |
192 | | |
193 | 0 | static int is_killed_dummy(const void *a [[maybe_unused]]) { return 0; } |
194 | | |
195 | | /* |
196 | | Initialize these hooks to dummy implementations. The real server |
197 | | implementations will be set during server startup by |
198 | | init_server_components(). |
199 | | */ |
200 | | void (*enter_cond_hook)(void *, mysql_cond_t *, mysql_mutex_t *, |
201 | | const PSI_stage_info *, PSI_stage_info *, const char *, |
202 | | const char *, int) = enter_cond_dummy; |
203 | | |
204 | | void (*exit_cond_hook)(void *, const PSI_stage_info *, const char *, |
205 | | const char *, int) = exit_cond_dummy; |
206 | | |
207 | | void (*enter_stage_hook)(void *, const PSI_stage_info *, PSI_stage_info *, |
208 | | const char *, const char *, int) = enter_stage_dummy; |
209 | | |
210 | | void (*set_waiting_for_disk_space_hook)(void *, bool) = |
211 | | set_waiting_for_disk_space_dummy; |
212 | | |
213 | | int (*is_killed_hook)(const void *) = is_killed_dummy; |
214 | | |
215 | | #if defined(ENABLED_DEBUG_SYNC) |
216 | | /** |
217 | | Global pointer to be set if callback function is defined |
218 | | (e.g. in mysqld). See sql/debug_sync.cc. |
219 | | */ |
220 | | DebugSyncCallbackFp debug_sync_C_callback_ptr; |
221 | | #endif /* defined(ENABLED_DEBUG_SYNC) */ |
222 | | |
223 | | /* How to disable options */ |
224 | | bool my_disable_locking = false; |
225 | | bool my_enable_symlinks = false; |