1 | /***************************************************************************** |
2 | |
3 | Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved. |
4 | Copyright (c) 2013, 2018, MariaDB Corporation. |
5 | Copyright (c) 2008, Google Inc. |
6 | |
7 | Portions of this file contain modifications contributed and copyrighted by |
8 | Google, Inc. Those modifications are gratefully acknowledged and are described |
9 | briefly in the InnoDB documentation. The contributions by Google are |
10 | incorporated with their permission, and subject to the conditions contained in |
11 | the file COPYING.Google. |
12 | |
13 | This program is free software; you can redistribute it and/or modify it under |
14 | the terms of the GNU General Public License as published by the Free Software |
15 | Foundation; version 2 of the License. |
16 | |
17 | This program is distributed in the hope that it will be useful, but WITHOUT |
18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
19 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
20 | |
21 | You should have received a copy of the GNU General Public License along with |
22 | this program; if not, write to the Free Software Foundation, Inc., |
23 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
24 | |
25 | *****************************************************************************/ |
26 | |
27 | /***********************************************************************//** |
28 | @file include/univ.i |
29 | Version control for database, common definitions, and include files |
30 | |
31 | Created 1/20/1994 Heikki Tuuri |
32 | ****************************************************************************/ |
33 | |
34 | #ifndef univ_i |
35 | #define univ_i |
36 | |
37 | /* aux macros to convert M into "123" (string) if M is defined like |
38 | #define M 123 */ |
39 | #define _IB_TO_STR(s) #s |
40 | #define IB_TO_STR(s) _IB_TO_STR(s) |
41 | |
42 | #define INNODB_VERSION_MAJOR 5 |
43 | #define INNODB_VERSION_MINOR 7 |
44 | #define INNODB_VERSION_BUGFIX 22 |
45 | |
46 | /* The following is the InnoDB version as shown in |
47 | SELECT plugin_version FROM information_schema.plugins; |
48 | calculated in make_version_string() in sql/sql_show.cc like this: |
49 | "version >> 8" . "version & 0xff" |
50 | because the version is shown with only one dot, we skip the last |
51 | component, i.e. we show M.N.P as M.N */ |
52 | #define INNODB_VERSION_SHORT \ |
53 | (MYSQL_VERSION_MAJOR << 8 | MYSQL_VERSION_MINOR) |
54 | |
55 | #define INNODB_VERSION_STR \ |
56 | IB_TO_STR(MYSQL_VERSION_MAJOR) "." \ |
57 | IB_TO_STR(MYSQL_VERSION_MINOR) "." \ |
58 | IB_TO_STR(MYSQL_VERSION_PATCH) |
59 | |
60 | #define REFMAN "http://dev.mysql.com/doc/refman/5.7/en/" |
61 | |
62 | /** How far ahead should we tell the service manager the timeout |
63 | (time in seconds) */ |
64 | #define INNODB_EXTEND_TIMEOUT_INTERVAL 30 |
65 | |
66 | #ifdef MYSQL_DYNAMIC_PLUGIN |
67 | /* In the dynamic plugin, redefine some externally visible symbols |
68 | in order not to conflict with the symbols of a builtin InnoDB. */ |
69 | |
70 | /* Rename all C++ classes that contain virtual functions, because we |
71 | have not figured out how to apply the visibility=hidden attribute to |
72 | the virtual method table (vtable) in GCC 3. */ |
73 | # define ha_innobase ha_innodb |
74 | #endif /* MYSQL_DYNAMIC_PLUGIN */ |
75 | |
76 | #if defined(_WIN32) |
77 | # include <windows.h> |
78 | #endif /* _WIN32 */ |
79 | |
80 | /* Include a minimum number of SQL header files so that few changes |
81 | made in SQL code cause a complete InnoDB rebuild. These headers are |
82 | used throughout InnoDB but do not include too much themselves. They |
83 | support cross-platform development and expose comonly used SQL names. */ |
84 | |
85 | #include <my_global.h> |
86 | |
87 | /* JAN: TODO: missing 5.7 header */ |
88 | #ifdef HAVE_MY_THREAD_H |
89 | //# include <my_thread.h> |
90 | #endif |
91 | |
92 | #ifndef UNIV_INNOCHECKSUM |
93 | # include <m_string.h> |
94 | # include <mysqld_error.h> |
95 | #endif /* !UNIV_INNOCHECKSUM */ |
96 | |
97 | /* Include <sys/stat.h> to get S_I... macros defined for os0file.cc */ |
98 | #include <sys/stat.h> |
99 | |
100 | #ifndef _WIN32 |
101 | # include <sys/mman.h> /* mmap() for os0proc.cc */ |
102 | # include <sched.h> |
103 | # include "my_config.h" |
104 | #endif |
105 | |
106 | #include <stdint.h> |
107 | #define __STDC_FORMAT_MACROS /* Enable C99 printf format macros */ |
108 | #include <inttypes.h> |
109 | #ifdef HAVE_UNISTD_H |
110 | #include <unistd.h> |
111 | #endif |
112 | |
113 | #include "my_pthread.h" |
114 | |
115 | /* Following defines are to enable performance schema |
116 | instrumentation in each of five InnoDB modules if |
117 | HAVE_PSI_INTERFACE is defined. */ |
118 | #ifdef HAVE_PSI_INTERFACE |
119 | # define UNIV_PFS_MUTEX |
120 | # define UNIV_PFS_RWLOCK |
121 | # define UNIV_PFS_IO |
122 | # define UNIV_PFS_THREAD |
123 | |
124 | // JAN: TODO: MySQL 5.7 PSI |
125 | // # include "mysql/psi/psi.h" /* HAVE_PSI_MEMORY_INTERFACE */ |
126 | # ifdef HAVE_PSI_MEMORY_INTERFACE |
127 | # define UNIV_PFS_MEMORY |
128 | # endif /* HAVE_PSI_MEMORY_INTERFACE */ |
129 | |
130 | /* There are mutexes/rwlocks that we want to exclude from |
131 | instrumentation even if their corresponding performance schema |
132 | define is set. And this PFS_NOT_INSTRUMENTED is used |
133 | as the key value to identify those objects that would |
134 | be excluded from instrumentation. */ |
135 | # define PFS_NOT_INSTRUMENTED ULINT32_UNDEFINED |
136 | |
137 | # define PFS_IS_INSTRUMENTED(key) ((key) != PFS_NOT_INSTRUMENTED) |
138 | |
139 | /* JAN: TODO: missing 5.7 header */ |
140 | #ifdef HAVE_PFS_THREAD_PROVIDER_H |
141 | /* For PSI_MUTEX_CALL() and similar. */ |
142 | #include "pfs_thread_provider.h" |
143 | #endif |
144 | |
145 | #include "mysql/psi/mysql_thread.h" |
146 | /* For PSI_FILE_CALL(). */ |
147 | /* JAN: TODO: missing 5.7 header */ |
148 | #ifdef HAVE_PFS_FILE_PROVIDER_H |
149 | #include "pfs_file_provider.h" |
150 | #endif |
151 | |
152 | #include "mysql/psi/mysql_file.h" |
153 | |
154 | #endif /* HAVE_PSI_INTERFACE */ |
155 | |
156 | #ifdef _WIN32 |
157 | # define YY_NO_UNISTD_H 1 |
158 | /* VC++ tries to optimise for size by default, from V8+. The size of |
159 | the pointer to member depends on whether the type is defined before the |
160 | compiler sees the type in the translation unit. This default behaviour |
161 | can cause the pointer to be a different size in different translation |
162 | units, depending on the above rule. We force optimise for size behaviour |
163 | for all cases. This is used by ut0lst.h related code. */ |
164 | # pragma pointers_to_members(full_generality, multiple_inheritance) |
165 | #endif /* _WIN32 */ |
166 | |
167 | /* DEBUG VERSION CONTROL |
168 | ===================== */ |
169 | |
170 | /* When this macro is defined then additional test functions will be |
171 | compiled. These functions live at the end of each relevant source file |
172 | and have "test_" prefix. These functions can be called from the end of |
173 | innodb_init() or they can be called from gdb after srv_start() has executed |
174 | using the call command. */ |
175 | /* |
176 | #define UNIV_COMPILE_TEST_FUNCS |
177 | #define UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR |
178 | #define UNIV_ENABLE_UNIT_TEST_MAKE_FILEPATH |
179 | #define UNIV_ENABLE_UNIT_TEST_DICT_STATS |
180 | #define UNIV_ENABLE_UNIT_TEST_ROW_RAW_FORMAT_INT |
181 | */ |
182 | |
183 | #if defined HAVE_valgrind && defined HAVE_VALGRIND_MEMCHECK_H |
184 | # define UNIV_DEBUG_VALGRIND |
185 | #endif |
186 | |
187 | #ifdef DBUG_OFF |
188 | # undef UNIV_DEBUG |
189 | #elif !defined UNIV_DEBUG |
190 | # define UNIV_DEBUG |
191 | #endif |
192 | |
193 | #if 0 |
194 | #define UNIV_DEBUG_VALGRIND /* Enable extra |
195 | Valgrind instrumentation */ |
196 | #define UNIV_DEBUG_PRINT /* Enable the compilation of |
197 | some debug print functions */ |
198 | #define UNIV_AHI_DEBUG /* Enable adaptive hash index |
199 | debugging without UNIV_DEBUG */ |
200 | #define UNIV_BUF_DEBUG /* Enable buffer pool |
201 | debugging without UNIV_DEBUG */ |
202 | #define UNIV_BLOB_LIGHT_DEBUG /* Enable off-page column |
203 | debugging without UNIV_DEBUG */ |
204 | #define UNIV_DEBUG_LOCK_VALIDATE /* Enable |
205 | ut_ad(lock_rec_validate_page()) |
206 | assertions. */ |
207 | #define UNIV_LRU_DEBUG /* debug the buffer pool LRU */ |
208 | #define UNIV_HASH_DEBUG /* debug HASH_ macros */ |
209 | #define UNIV_LOG_LSN_DEBUG /* write LSN to the redo log; |
210 | this will break redo log file compatibility, but it may be useful when |
211 | debugging redo log application problems. */ |
212 | #define UNIV_IBUF_DEBUG /* debug the insert buffer */ |
213 | #define UNIV_IBUF_COUNT_DEBUG /* debug the insert buffer; |
214 | this limits the database to IBUF_COUNT_N_SPACES and IBUF_COUNT_N_PAGES, |
215 | and the insert buffer must be empty when the database is started */ |
216 | #define UNIV_PERF_DEBUG /* debug flag that enables |
217 | light weight performance |
218 | related stuff. */ |
219 | #define UNIV_SEARCH_PERF_STAT /* statistics for the |
220 | adaptive hash index */ |
221 | #define UNIV_SRV_PRINT_LATCH_WAITS /* enable diagnostic output |
222 | in sync0sync.cc */ |
223 | #define UNIV_BTR_PRINT /* enable functions for |
224 | printing B-trees */ |
225 | #define UNIV_ZIP_DEBUG /* extensive consistency checks |
226 | for compressed pages */ |
227 | #define UNIV_ZIP_COPY /* call page_zip_copy_recs() |
228 | more often */ |
229 | #define UNIV_AIO_DEBUG /* prints info about |
230 | submitted and reaped AIO |
231 | requests to the log. */ |
232 | #define UNIV_STATS_DEBUG /* prints various stats |
233 | related debug info from |
234 | dict0stats.c */ |
235 | #define FTS_INTERNAL_DIAG_PRINT /* FTS internal debugging |
236 | info output */ |
237 | #endif |
238 | |
239 | #define UNIV_BTR_DEBUG /* check B-tree links */ |
240 | #define UNIV_LIGHT_MEM_DEBUG /* light memory debugging */ |
241 | |
242 | // #define UNIV_SQL_DEBUG |
243 | |
244 | /* Linkage specifier for non-static InnoDB symbols (variables and functions) |
245 | that are only referenced from within InnoDB, not from MySQL. We disable the |
246 | GCC visibility directive on all Sun operating systems because there is no |
247 | easy way to get it to work. See http://bugs.mysql.com/bug.php?id=52263. */ |
248 | #if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(sun) || defined(__INTEL_COMPILER) |
249 | # define UNIV_INTERN __attribute__((visibility ("hidden"))) |
250 | #else |
251 | # define UNIV_INTERN |
252 | #endif |
253 | |
254 | #ifndef MY_ATTRIBUTE |
255 | #if defined(__GNUC__) |
256 | # define MY_ATTRIBUTE(A) __attribute__(A) |
257 | #else |
258 | # define MY_ATTRIBUTE(A) |
259 | #endif |
260 | #endif |
261 | |
262 | #define UNIV_INLINE static inline |
263 | |
264 | #define UNIV_WORD_SIZE SIZEOF_SIZE_T |
265 | |
266 | /** The following alignment is used in memory allocations in memory heap |
267 | management to ensure correct alignment for doubles etc. */ |
268 | #define UNIV_MEM_ALIGNMENT 8U |
269 | |
270 | /* |
271 | DATABASE VERSION CONTROL |
272 | ======================== |
273 | */ |
274 | |
275 | #ifdef HAVE_LZO |
276 | #define IF_LZO(A,B) A |
277 | #else |
278 | #define IF_LZO(A,B) B |
279 | #endif |
280 | |
281 | #ifdef HAVE_LZ4 |
282 | #define IF_LZ4(A,B) A |
283 | #else |
284 | #define IF_LZ4(A,B) B |
285 | #endif |
286 | |
287 | #ifdef HAVE_LZMA |
288 | #define IF_LZMA(A,B) A |
289 | #else |
290 | #define IF_LZMA(A,B) B |
291 | #endif |
292 | |
293 | #ifdef HAVE_BZIP2 |
294 | #define IF_BZIP2(A,B) A |
295 | #else |
296 | #define IF_BZIP2(A,B) B |
297 | #endif |
298 | |
299 | #ifdef HAVE_SNAPPY |
300 | #define IF_SNAPPY(A,B) A |
301 | #else |
302 | #define IF_SNAPPY(A,B) B |
303 | #endif |
304 | |
305 | #if defined (HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE) || defined(_WIN32) |
306 | #define IF_PUNCH_HOLE(A,B) A |
307 | #else |
308 | #define IF_PUNCH_HOLE(A,B) B |
309 | #endif |
310 | |
311 | /** log2 of smallest compressed page size (1<<10 == 1024 bytes) |
312 | Note: This must never change! */ |
313 | #define UNIV_ZIP_SIZE_SHIFT_MIN 10U |
314 | |
315 | /** log2 of largest compressed page size (1<<14 == 16384 bytes). |
316 | A compressed page directory entry reserves 14 bits for the start offset |
317 | and 2 bits for flags. This limits the uncompressed page size to 16k. |
318 | */ |
319 | #define UNIV_ZIP_SIZE_SHIFT_MAX 14U |
320 | |
321 | /* Define the Min, Max, Default page sizes. */ |
322 | /** Minimum Page Size Shift (power of 2) */ |
323 | #define UNIV_PAGE_SIZE_SHIFT_MIN 12U |
324 | /** log2 of largest page size (1<<16 == 64436 bytes). */ |
325 | /** Maximum Page Size Shift (power of 2) */ |
326 | #define UNIV_PAGE_SIZE_SHIFT_MAX 16U |
327 | /** log2 of default page size (1<<14 == 16384 bytes). */ |
328 | /** Default Page Size Shift (power of 2) */ |
329 | #define UNIV_PAGE_SIZE_SHIFT_DEF 14U |
330 | /** Original 16k InnoDB Page Size Shift, in case the default changes */ |
331 | #define UNIV_PAGE_SIZE_SHIFT_ORIG 14U |
332 | /** Original 16k InnoDB Page Size as an ssize (log2 - 9) */ |
333 | #define UNIV_PAGE_SSIZE_ORIG (UNIV_PAGE_SIZE_SHIFT_ORIG - 9U) |
334 | |
335 | /** Minimum page size InnoDB currently supports. */ |
336 | #define UNIV_PAGE_SIZE_MIN (1U << UNIV_PAGE_SIZE_SHIFT_MIN) |
337 | /** Maximum page size InnoDB currently supports. */ |
338 | #define UNIV_PAGE_SIZE_MAX (1U << UNIV_PAGE_SIZE_SHIFT_MAX) |
339 | /** Default page size for InnoDB tablespaces. */ |
340 | #define UNIV_PAGE_SIZE_DEF (1U << UNIV_PAGE_SIZE_SHIFT_DEF) |
341 | /** Original 16k page size for InnoDB tablespaces. */ |
342 | #define UNIV_PAGE_SIZE_ORIG (1U << UNIV_PAGE_SIZE_SHIFT_ORIG) |
343 | |
344 | /** Smallest compressed page size */ |
345 | #define UNIV_ZIP_SIZE_MIN (1U << UNIV_ZIP_SIZE_SHIFT_MIN) |
346 | |
347 | /** Largest compressed page size */ |
348 | #define UNIV_ZIP_SIZE_MAX (1U << UNIV_ZIP_SIZE_SHIFT_MAX) |
349 | |
350 | /** Largest possible ssize for an uncompressed page. |
351 | (The convention 'ssize' is used for 'log2 minus 9' or the number of |
352 | shifts starting with 512.) |
353 | This max number varies depending on srv_page_size. */ |
354 | #define UNIV_PAGE_SSIZE_MAX \ |
355 | ulint(srv_page_size_shift - UNIV_ZIP_SIZE_SHIFT_MIN + 1U) |
356 | |
357 | /** Smallest possible ssize for an uncompressed page. */ |
358 | #define UNIV_PAGE_SSIZE_MIN \ |
359 | ulint(UNIV_PAGE_SIZE_SHIFT_MIN - UNIV_ZIP_SIZE_SHIFT_MIN + 1U) |
360 | |
361 | /** Maximum number of parallel threads in a parallelized operation */ |
362 | #define UNIV_MAX_PARALLELISM 32 |
363 | |
364 | /** This is the "mbmaxlen" for my_charset_filename (defined in |
365 | strings/ctype-utf8.c), which is used to encode File and Database names. */ |
366 | #define FILENAME_CHARSET_MAXNAMLEN 5 |
367 | |
368 | /** The maximum length of an encode table name in bytes. The max |
369 | table and database names are NAME_CHAR_LEN (64) characters. After the |
370 | encoding, the max length would be NAME_CHAR_LEN (64) * |
371 | FILENAME_CHARSET_MAXNAMLEN (5) = 320 bytes. The number does not include a |
372 | terminating '\0'. InnoDB can handle longer names internally */ |
373 | #define MAX_TABLE_NAME_LEN 320 |
374 | |
375 | /** The maximum length of a database name. Like MAX_TABLE_NAME_LEN this is |
376 | the MySQL's NAME_LEN, see check_and_convert_db_name(). */ |
377 | #define MAX_DATABASE_NAME_LEN MAX_TABLE_NAME_LEN |
378 | |
379 | /** MAX_FULL_NAME_LEN defines the full name path including the |
380 | database name and table name. In addition, 14 bytes is added for: |
381 | 2 for surrounding quotes around table name |
382 | 1 for the separating dot (.) |
383 | 9 for the #mysql50# prefix */ |
384 | #define MAX_FULL_NAME_LEN \ |
385 | (MAX_TABLE_NAME_LEN + MAX_DATABASE_NAME_LEN + 14) |
386 | |
387 | /** Maximum length of the compression alogrithm string. Currently we support |
388 | only (NONE | ZLIB | LZ4). */ |
389 | #define MAX_COMPRESSION_LEN 4 |
390 | |
391 | /** The maximum length in bytes that a database name can occupy when stored in |
392 | UTF8, including the terminating '\0', see dict_fs2utf8(). You must include |
393 | mysql_com.h if you are to use this macro. */ |
394 | #define MAX_DB_UTF8_LEN (NAME_LEN + 1) |
395 | |
396 | /** The maximum length in bytes that a table name can occupy when stored in |
397 | UTF8, including the terminating '\0', see dict_fs2utf8(). You must include |
398 | mysql_com.h if you are to use this macro. */ |
399 | #define MAX_TABLE_UTF8_LEN (NAME_LEN + sizeof(srv_mysql50_table_name_prefix)) |
400 | |
401 | /* |
402 | UNIVERSAL TYPE DEFINITIONS |
403 | ========================== |
404 | */ |
405 | |
406 | /** Unsigned octet of bits */ |
407 | typedef unsigned char byte; |
408 | /** Machine-word-width unsigned integer */ |
409 | typedef size_t ulint; |
410 | /** Machine-word-width signed integer */ |
411 | typedef ssize_t lint; |
412 | |
413 | /** ulint format for the printf() family of functions */ |
414 | #define ULINTPF "%zu" |
415 | /** ulint hexadecimal format for the printf() family of functions */ |
416 | #define ULINTPFx "%zx" |
417 | |
418 | #ifdef _WIN32 |
419 | /* Use the integer types and formatting strings defined in Visual Studio. */ |
420 | # define UINT32PF "%u" |
421 | # define INT64PF "%lld" |
422 | # define UINT64scan "llu" |
423 | # define UINT64PFx "%016llx" |
424 | #elif defined __APPLE__ |
425 | /* Apple prefers to call the 64-bit types 'long long' |
426 | in both 32-bit and 64-bit environments. */ |
427 | # define UINT32PF "%" PRIu32 |
428 | # define INT64PF "%lld" |
429 | # define UINT64scan "llu" |
430 | # define UINT64PFx "%016llx" |
431 | #else |
432 | /* Use the integer types and formatting strings defined in the C99 standard. */ |
433 | # define UINT32PF "%" PRIu32 |
434 | # define INT64PF "%" PRId64 |
435 | # define UINT64scan PRIu64 |
436 | # define UINT64PFx "%016" PRIx64 |
437 | #endif |
438 | |
439 | #ifdef UNIV_INNOCHECKSUM |
440 | extern bool strict_verify; |
441 | extern FILE* log_file; |
442 | extern unsigned long long cur_page_num; |
443 | #endif /* UNIV_INNOCHECKSUM */ |
444 | |
445 | typedef int64_t ib_int64_t; |
446 | typedef uint64_t ib_uint64_t; |
447 | typedef uint32_t ib_uint32_t; |
448 | |
449 | #define UINT64PF "%" UINT64scan |
450 | #define IB_ID_FMT UINT64PF |
451 | |
452 | /** Log sequence number (also used for redo log byte arithmetics) */ |
453 | typedef ib_uint64_t lsn_t; |
454 | |
455 | /** The 'undefined' value for a ulint */ |
456 | #define ULINT_UNDEFINED ((ulint)(-1)) |
457 | |
458 | #define ULONG_UNDEFINED ((ulong)(-1)) |
459 | |
460 | /** The 'undefined' value for a ib_uint64_t */ |
461 | #define UINT64_UNDEFINED ((ib_uint64_t)(-1)) |
462 | |
463 | /** The bitmask of 32-bit unsigned integer */ |
464 | #define ULINT32_MASK 0xFFFFFFFFU |
465 | /** The undefined 32-bit unsigned integer */ |
466 | #define ULINT32_UNDEFINED ULINT32_MASK |
467 | |
468 | /** Maximum value for a ulint */ |
469 | #define ULINT_MAX ((ulint)(-2)) |
470 | |
471 | /** Maximum value for ib_uint64_t */ |
472 | #define IB_UINT64_MAX ((ib_uint64_t) (~0ULL)) |
473 | |
474 | /** The generic InnoDB system object identifier data type */ |
475 | typedef ib_uint64_t ib_id_t; |
476 | #define IB_ID_MAX (~(ib_id_t) 0) |
477 | #define IB_ID_FMT UINT64PF |
478 | |
479 | #ifndef UINTMAX_MAX |
480 | #define UINTMAX_MAX IB_UINT64_MAX |
481 | #endif |
482 | /** This 'ibool' type is used within Innobase. Remember that different included |
483 | headers may define 'bool' differently. Do not assume that 'bool' is a ulint! */ |
484 | #define ibool ulint |
485 | |
486 | #ifndef TRUE |
487 | |
488 | #define TRUE 1 |
489 | #define FALSE 0 |
490 | |
491 | #endif |
492 | |
493 | #define UNIV_NOTHROW |
494 | |
495 | /** The following number as the length of a logical field means that the field |
496 | has the SQL NULL as its value. NOTE that because we assume that the length |
497 | of a field is a 32-bit integer when we store it, for example, to an undo log |
498 | on disk, we must have also this number fit in 32 bits, also in 64-bit |
499 | computers! */ |
500 | |
501 | #define UNIV_SQL_NULL ULINT32_UNDEFINED |
502 | |
503 | /** Lengths which are not UNIV_SQL_NULL, but bigger than the following |
504 | number indicate that a field contains a reference to an externally |
505 | stored part of the field in the tablespace. The length field then |
506 | contains the sum of the following flag and the locally stored len. */ |
507 | |
508 | #define UNIV_EXTERN_STORAGE_FIELD (UNIV_SQL_NULL - UNIV_PAGE_SIZE_DEF) |
509 | |
510 | #if defined(__GNUC__) |
511 | /* Tell the compiler that variable/function is unused. */ |
512 | # define UNIV_UNUSED MY_ATTRIBUTE ((unused)) |
513 | #else |
514 | # define UNIV_UNUSED |
515 | #endif /* CHECK FOR GCC VER_GT_2 */ |
516 | |
517 | /* Some macros to improve branch prediction and reduce cache misses */ |
518 | #if defined(COMPILER_HINTS) && defined(__GNUC__) |
519 | /* Tell the compiler that 'expr' probably evaluates to 'constant'. */ |
520 | # define UNIV_EXPECT(expr,constant) __builtin_expect(expr, constant) |
521 | /* Tell the compiler that a pointer is likely to be NULL */ |
522 | # define UNIV_LIKELY_NULL(ptr) __builtin_expect((ptr) != 0, 0) |
523 | /* Minimize cache-miss latency by moving data at addr into a cache before |
524 | it is read. */ |
525 | # define UNIV_PREFETCH_R(addr) __builtin_prefetch(addr, 0, 3) |
526 | /* Minimize cache-miss latency by moving data at addr into a cache before |
527 | it is read or written. */ |
528 | # define UNIV_PREFETCH_RW(addr) __builtin_prefetch(addr, 1, 3) |
529 | |
530 | /* Sun Studio includes sun_prefetch.h as of version 5.9 */ |
531 | #elif (defined(__SUNPRO_C) || defined(__SUNPRO_CC)) |
532 | |
533 | # include <sun_prefetch.h> |
534 | |
535 | # define UNIV_EXPECT(expr,value) (expr) |
536 | # define UNIV_LIKELY_NULL(expr) (expr) |
537 | |
538 | # if defined(COMPILER_HINTS) |
539 | //# define UNIV_PREFETCH_R(addr) sun_prefetch_read_many((void*) addr) |
540 | # define UNIV_PREFETCH_R(addr) ((void) 0) |
541 | # define UNIV_PREFETCH_RW(addr) sun_prefetch_write_many(addr) |
542 | # else |
543 | # define UNIV_PREFETCH_R(addr) ((void) 0) |
544 | # define UNIV_PREFETCH_RW(addr) ((void) 0) |
545 | # endif /* COMPILER_HINTS */ |
546 | |
547 | # elif defined __WIN__ && defined COMPILER_HINTS |
548 | # include <xmmintrin.h> |
549 | # define UNIV_EXPECT(expr,value) (expr) |
550 | # define UNIV_LIKELY_NULL(expr) (expr) |
551 | // __MM_HINT_T0 - (temporal data) |
552 | // prefetch data into all levels of the cache hierarchy. |
553 | # define UNIV_PREFETCH_R(addr) _mm_prefetch((char *) addr, _MM_HINT_T0) |
554 | # define UNIV_PREFETCH_RW(addr) _mm_prefetch((char *) addr, _MM_HINT_T0) |
555 | #else |
556 | /* Dummy versions of the macros */ |
557 | # define UNIV_EXPECT(expr,value) (expr) |
558 | # define UNIV_LIKELY_NULL(expr) (expr) |
559 | # define UNIV_PREFETCH_R(addr) ((void) 0) |
560 | # define UNIV_PREFETCH_RW(addr) ((void) 0) |
561 | #endif |
562 | |
563 | /* Tell the compiler that cond is likely to hold */ |
564 | #define UNIV_LIKELY(cond) UNIV_EXPECT(cond, TRUE) |
565 | /* Tell the compiler that cond is unlikely to hold */ |
566 | #define UNIV_UNLIKELY(cond) UNIV_EXPECT(cond, FALSE) |
567 | |
568 | /* Compile-time constant of the given array's size. */ |
569 | #define UT_ARR_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
570 | |
571 | /* The return type from a thread's start function differs between Unix and |
572 | Windows, so define a typedef for it and a macro to use at the end of such |
573 | functions. */ |
574 | |
575 | #ifdef _WIN32 |
576 | typedef DWORD os_thread_ret_t; |
577 | # define OS_THREAD_DUMMY_RETURN return(0) |
578 | # define OS_PATH_SEPARATOR '\\' |
579 | # define OS_PATH_SEPARATOR_ALT '/' |
580 | #else |
581 | typedef void* os_thread_ret_t; |
582 | # define OS_THREAD_DUMMY_RETURN return(NULL) |
583 | # define OS_PATH_SEPARATOR '/' |
584 | # define OS_PATH_SEPARATOR_ALT '\\' |
585 | #endif |
586 | |
587 | #include <stdio.h> |
588 | #include "db0err.h" |
589 | #include "ut0dbg.h" |
590 | #include "ut0lst.h" |
591 | #include "ut0ut.h" |
592 | #include "sync0types.h" |
593 | |
594 | #ifdef UNIV_DEBUG_VALGRIND |
595 | # include <valgrind/memcheck.h> |
596 | # define UNIV_MEM_VALID(addr, size) VALGRIND_MAKE_MEM_DEFINED(addr, size) |
597 | # define UNIV_MEM_INVALID(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size) |
598 | # define UNIV_MEM_FREE(addr, size) VALGRIND_MAKE_MEM_NOACCESS(addr, size) |
599 | # define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size) |
600 | # define UNIV_MEM_DESC(addr, size) VALGRIND_CREATE_BLOCK(addr, size, #addr) |
601 | # define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b) |
602 | # define UNIV_MEM_ASSERT_RW_LOW(addr, size, should_abort) do { \ |
603 | const void* _p = (const void*) (ulint) \ |
604 | VALGRIND_CHECK_MEM_IS_DEFINED(addr, size); \ |
605 | if (UNIV_LIKELY_NULL(_p)) { \ |
606 | fprintf(stderr, "%s:%d: %p[%u] undefined at %ld\n", \ |
607 | __FILE__, __LINE__, \ |
608 | (const void*) (addr), (unsigned) (size), (long) \ |
609 | (((const char*) _p) - ((const char*) (addr)))); \ |
610 | if (should_abort) { \ |
611 | ut_error; \ |
612 | } \ |
613 | } \ |
614 | } while (0) |
615 | # define UNIV_MEM_ASSERT_RW(addr, size) \ |
616 | UNIV_MEM_ASSERT_RW_LOW(addr, size, false) |
617 | # define UNIV_MEM_ASSERT_RW_ABORT(addr, size) \ |
618 | UNIV_MEM_ASSERT_RW_LOW(addr, size, true) |
619 | # define UNIV_MEM_ASSERT_W(addr, size) do { \ |
620 | const void* _p = (const void*) (ulint) \ |
621 | VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size); \ |
622 | if (UNIV_LIKELY_NULL(_p)) \ |
623 | fprintf(stderr, "%s:%d: %p[%u] unwritable at %ld\n", \ |
624 | __FILE__, __LINE__, \ |
625 | (const void*) (addr), (unsigned) (size), (long) \ |
626 | (((const char*) _p) - ((const char*) (addr)))); \ |
627 | } while (0) |
628 | # define UNIV_MEM_TRASH(addr, c, size) do { \ |
629 | ut_d(memset(addr, c, size)); \ |
630 | UNIV_MEM_INVALID(addr, size); \ |
631 | } while (0) |
632 | #else |
633 | # define UNIV_MEM_VALID(addr, size) do {} while(0) |
634 | # define UNIV_MEM_INVALID(addr, size) do {} while(0) |
635 | # define UNIV_MEM_FREE(addr, size) do {} while(0) |
636 | # define UNIV_MEM_ALLOC(addr, size) do {} while(0) |
637 | # define UNIV_MEM_DESC(addr, size) do {} while(0) |
638 | # define UNIV_MEM_UNDESC(b) do {} while(0) |
639 | # define UNIV_MEM_ASSERT_RW_LOW(addr, size, should_abort) do {} while(0) |
640 | # define UNIV_MEM_ASSERT_RW(addr, size) do {} while(0) |
641 | # define UNIV_MEM_ASSERT_RW_ABORT(addr, size) do {} while(0) |
642 | # define UNIV_MEM_ASSERT_W(addr, size) do {} while(0) |
643 | # define UNIV_MEM_TRASH(addr, c, size) do {} while(0) |
644 | #endif |
645 | |
646 | extern ulong srv_page_size_shift; |
647 | extern ulong srv_page_size; |
648 | |
649 | static const size_t UNIV_SECTOR_SIZE = 512; |
650 | |
651 | /* Dimension of spatial object we support so far. It has its root in |
652 | myisam/sp_defs.h. We only support 2 dimension data */ |
653 | #define SPDIMS 2 |
654 | |
655 | #endif |
656 | |