/src/server/mysys/mysys_priv.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. |
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 as published by |
5 | | the Free Software Foundation; version 2 of the License. |
6 | | |
7 | | This program is distributed in the hope that it will be useful, |
8 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | | GNU General Public License for more details. |
11 | | |
12 | | You should have received a copy of the GNU General Public License |
13 | | along with this program; if not, write to the Free Software |
14 | | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ |
15 | | |
16 | | #ifndef MYSYS_PRIV_INCLUDED |
17 | | #define MYSYS_PRIV_INCLUDED |
18 | | |
19 | | #include <my_global.h> |
20 | | #include <my_sys.h> |
21 | | #include <my_crypt.h> |
22 | | |
23 | | C_MODE_START |
24 | | |
25 | | #ifdef USE_SYSTEM_WRAPPERS |
26 | | #include "system_wrappers.h" |
27 | | #endif |
28 | | |
29 | | #ifdef HAVE_GETRUSAGE |
30 | | #include <sys/resource.h> |
31 | | #endif |
32 | | |
33 | | #include <my_pthread.h> |
34 | | |
35 | | #ifdef HAVE_PSI_INTERFACE |
36 | | |
37 | | #if !defined(HAVE_PREAD) && !defined(_WIN32) |
38 | | extern PSI_mutex_key key_my_file_info_mutex; |
39 | | #endif /* !defined(HAVE_PREAD) && !defined(_WIN32) */ |
40 | | |
41 | | #if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) |
42 | | extern PSI_mutex_key key_LOCK_localtime_r; |
43 | | #endif /* !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) */ |
44 | | |
45 | | extern PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock, |
46 | | key_IO_CACHE_SHARE_mutex, key_KEY_CACHE_cache_lock, |
47 | | key_my_thread_var_mutex, key_THR_LOCK_charset, key_THR_LOCK_heap, |
48 | | key_THR_LOCK_lock, key_THR_LOCK_malloc, |
49 | | key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net, |
50 | | key_THR_LOCK_open, key_THR_LOCK_threads, key_LOCK_uuid_generator, |
51 | | key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap, key_LOCK_timer; |
52 | | |
53 | | extern PSI_cond_key key_COND_timer, key_IO_CACHE_SHARE_cond, |
54 | | key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend, |
55 | | key_THR_COND_threads; |
56 | | |
57 | | extern PSI_thread_key key_thread_timer; |
58 | | extern PSI_rwlock_key key_SAFEHASH_mutex; |
59 | | |
60 | | #endif /* HAVE_PSI_INTERFACE */ |
61 | | |
62 | | extern PSI_stage_info stage_waiting_for_table_level_lock; |
63 | | |
64 | | /* These keys are always defined. */ |
65 | | |
66 | | extern PSI_memory_key key_memory_DYNAMIC_STRING; |
67 | | extern PSI_memory_key key_memory_IO_CACHE; |
68 | | extern PSI_memory_key key_memory_KEY_CACHE; |
69 | | extern PSI_memory_key key_memory_LIST; |
70 | | extern PSI_memory_key key_memory_MY_BITMAP_bitmap; |
71 | | extern PSI_memory_key key_memory_MY_DIR; |
72 | | extern PSI_memory_key key_memory_MY_STAT; |
73 | | extern PSI_memory_key key_memory_MY_TMPDIR_full_list; |
74 | | extern PSI_memory_key key_memory_QUEUE; |
75 | | extern PSI_memory_key key_memory_SAFE_HASH_ENTRY; |
76 | | extern PSI_memory_key key_memory_TREE; |
77 | | extern PSI_memory_key key_memory_charset_file; |
78 | | extern PSI_memory_key key_memory_charset_loader; |
79 | | extern PSI_memory_key key_memory_defaults; |
80 | | extern PSI_memory_key key_memory_lf_dynarray; |
81 | | extern PSI_memory_key key_memory_lf_node; |
82 | | extern PSI_memory_key key_memory_lf_slist; |
83 | | extern PSI_memory_key key_memory_my_compress_alloc; |
84 | | extern PSI_memory_key key_memory_my_err_head; |
85 | | extern PSI_memory_key key_memory_my_file_info; |
86 | | extern PSI_memory_key key_memory_pack_frm; |
87 | | extern PSI_memory_key key_memory_charsets; |
88 | | extern PSI_memory_key key_memory_new; |
89 | | |
90 | | #ifdef _WIN32 |
91 | | extern PSI_memory_key key_memory_win_SECURITY_ATTRIBUTES; |
92 | | extern PSI_memory_key key_memory_win_PACL; |
93 | | extern PSI_memory_key key_memory_win_IP_ADAPTER_ADDRESSES; |
94 | | #endif |
95 | | |
96 | | extern mysql_mutex_t THR_LOCK_malloc, THR_LOCK_open, THR_LOCK_keycache; |
97 | | extern mysql_mutex_t THR_LOCK_lock, THR_LOCK_net; |
98 | | extern mysql_mutex_t THR_LOCK_charset; |
99 | | |
100 | | #include <mysql/psi/mysql_file.h> |
101 | | |
102 | | #ifdef HAVE_PSI_INTERFACE |
103 | | extern PSI_file_key key_file_charset, key_file_cnf; |
104 | | #endif /* HAVE_PSI_INTERFACE */ |
105 | | |
106 | | typedef struct { |
107 | | ulonglong counter; |
108 | | uint block_length, last_block_length; |
109 | | uchar key[MY_AES_BLOCK_SIZE]; |
110 | | ulonglong inbuf_counter; |
111 | | } IO_CACHE_CRYPT; |
112 | | |
113 | | extern int (*_my_b_encr_read)(IO_CACHE *info,uchar *Buffer,size_t Count); |
114 | | extern int (*_my_b_encr_write)(IO_CACHE *info,const uchar *Buffer,size_t Count); |
115 | | |
116 | | #ifdef SAFEMALLOC |
117 | | void *sf_malloc(size_t size, myf my_flags); |
118 | | void *sf_realloc(void *ptr, size_t size, myf my_flags); |
119 | | void sf_free(void *ptr); |
120 | | size_t sf_malloc_usable_size(void *ptr, my_bool *is_thread_specific); |
121 | | #else |
122 | 0 | #define sf_malloc(X,Y) malloc(X) |
123 | 0 | #define sf_realloc(X,Y,Z) realloc(X,Y) |
124 | 0 | #define sf_free(X) free(X) |
125 | | #endif |
126 | | |
127 | | /* |
128 | | EDQUOT is used only in 3 C files only in mysys/. If it does not exist on |
129 | | system, we set it to some value which can never happen. |
130 | | */ |
131 | | #ifndef EDQUOT |
132 | | #define EDQUOT (-1) |
133 | | #endif |
134 | | |
135 | | void my_error_unregister_all(void); |
136 | | |
137 | | #ifndef O_PATH /* not Linux */ |
138 | | #if defined(O_SEARCH) /* Illumos */ |
139 | | #define O_PATH O_SEARCH |
140 | | #elif defined(O_EXEC) /* FreeBSD */ |
141 | | #define O_PATH O_EXEC |
142 | | #endif |
143 | | #endif |
144 | | |
145 | | #ifdef O_PATH |
146 | | #define HAVE_OPEN_PARENT_DIR_NOSYMLINKS |
147 | | const char *my_open_parent_dir_nosymlinks(const char *pathname, int *pdfd); |
148 | | #define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ |
149 | 0 | int dfd, res; \ |
150 | 0 | const char *filename= my_open_parent_dir_nosymlinks(pathname, &dfd); \ |
151 | 0 | if (filename == NULL) return -1; \ |
152 | 0 | res= AT; \ |
153 | 0 | if (dfd >= 0) close(dfd); \ |
154 | 0 | return res; |
155 | | #elif defined(HAVE_REALPATH) && defined(PATH_MAX) |
156 | | #define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ |
157 | | char buf[PATH_MAX+1]; \ |
158 | | if (realpath(pathname, buf) == NULL) return -1; \ |
159 | | if (strcmp(pathname, buf)) { errno= ENOTDIR; return -1; } \ |
160 | | return NOAT; |
161 | | #elif defined(HAVE_REALPATH) |
162 | | #define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ |
163 | | char *buf= realpath(pathname, NULL); \ |
164 | | int res; \ |
165 | | if (buf == NULL) return -1; \ |
166 | | if (strcmp(pathname, buf)) { errno= ENOTDIR; res= -1; } \ |
167 | | else res= NOAT; \ |
168 | | free(buf); \ |
169 | | return res; |
170 | | #else |
171 | | #define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ |
172 | | return NOAT; |
173 | | #endif |
174 | | |
175 | | #ifndef _WIN32 |
176 | | #define CREATE_NOSYMLINK_FUNCTION(PROTO,AT,NOAT) \ |
177 | 0 | static int PROTO { NOSYMLINK_FUNCTION_BODY(AT,NOAT) } |
178 | | #else |
179 | | #define CREATE_NOSYMLINK_FUNCTION(PROTO,AT,NOAT) |
180 | | #endif |
181 | | |
182 | | #ifdef _WIN32 |
183 | | #include <sys/stat.h> |
184 | | /* my_winfile.c exports, should not be used outside mysys */ |
185 | | extern File my_win_open(const char *path, int oflag); |
186 | | extern int my_win_close(File fd); |
187 | | extern size_t my_win_read(File fd, uchar *buffer, size_t count); |
188 | | extern size_t my_win_write(File fd, const uchar *buffer, size_t count); |
189 | | extern size_t my_win_pread(File fd, uchar *buffer, size_t count, |
190 | | my_off_t offset); |
191 | | extern size_t my_win_pwrite(File fd, const uchar *buffer, size_t count, |
192 | | my_off_t offset); |
193 | | extern my_off_t my_win_lseek(File fd, my_off_t pos, int whence); |
194 | | extern int my_win_chsize(File fd, my_off_t newlength); |
195 | | extern FILE* my_win_fopen(const char *filename, const char *type); |
196 | | extern File my_win_fclose(FILE *file); |
197 | | extern File my_win_fileno(FILE *file); |
198 | | extern FILE* my_win_fdopen(File Filedes, const char *type); |
199 | | extern int my_win_stat(const char *path, struct _stati64 *buf); |
200 | | extern int my_win_fstat(File fd, struct _stati64 *buf); |
201 | | extern int my_win_fsync(File fd); |
202 | | extern File my_win_dup(File fd); |
203 | | extern File my_win_sopen(const char *path, int oflag, int shflag, int perm); |
204 | | extern File my_open_osfhandle(HANDLE handle, int oflag); |
205 | | |
206 | | |
207 | | /* |
208 | | The following constants are related to retries when file operation fails with |
209 | | ERROR_FILE_SHARING_VIOLATION |
210 | | */ |
211 | | #define FILE_SHARING_VIOLATION_RETRIES 50 |
212 | | #define FILE_SHARING_VIOLATION_DELAY_MS 10 |
213 | | |
214 | | |
215 | | /* DBUG injecting of ERROR_FILE_SHARING_VIOLATION */ |
216 | | #ifndef DBUG_OFF |
217 | | /* Open file, without sharing. if specific DBUG keyword is set */ |
218 | | #define DBUG_INJECT_FILE_SHARING_VIOLATION(filename) \ |
219 | | FILE *fp= NULL; \ |
220 | | do \ |
221 | | { \ |
222 | | DBUG_EXECUTE_IF("file_sharing_violation", \ |
223 | | fp= _fsopen(filename, "r", _SH_DENYRW);); \ |
224 | | } while (0) |
225 | | |
226 | | /* Close the file that causes ERROR_FILE_SHARING_VIOLATION.*/ |
227 | | #define DBUG_CLEAR_FILE_SHARING_VIOLATION() \ |
228 | | do \ |
229 | | { \ |
230 | | if (fp) \ |
231 | | { \ |
232 | | DWORD tmp_err= GetLastError(); \ |
233 | | fclose(fp); \ |
234 | | SetLastError(tmp_err); \ |
235 | | fp= NULL; \ |
236 | | } \ |
237 | | } while (0) |
238 | | |
239 | | #else |
240 | | #define DBUG_INJECT_FILE_SHARING_VIOLATION(filename) do {} while (0) |
241 | | #define DBUG_CLEAR_FILE_SHARING_VIOLATION() do {} while (0) |
242 | | #endif |
243 | | |
244 | | #endif |
245 | | |
246 | | C_MODE_END |
247 | | |
248 | | #endif |