1 /***************************************************************************** 2 3 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved. 4 Copyright (c) 2008, Google Inc. 5 6 Portions of this file contain modifications contributed and copyrighted by 7 Google, Inc. Those modifications are gratefully acknowledged and are described 8 briefly in the InnoDB documentation. The contributions by Google are 9 incorporated with their permission, and subject to the conditions contained in 10 the file COPYING.Google. 11 12 This program is free software; you can redistribute it and/or modify 13 it under the terms of the GNU General Public License, version 2.0, 14 as published by the Free Software Foundation. 15 16 This program is also distributed with certain software (including 17 but not limited to OpenSSL) that is licensed under separate terms, 18 as designated in a particular file or component or in included license 19 documentation. The authors of MySQL hereby grant you an additional 20 permission to link the program and your derivative works with the 21 separately licensed software that they have included with MySQL. 22 23 This program is distributed in the hope that it will be useful, 24 but WITHOUT ANY WARRANTY; without even the implied warranty of 25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 GNU General Public License, version 2.0, for more details. 27 28 You should have received a copy of the GNU General Public License along with 29 this program; if not, write to the Free Software Foundation, Inc., 30 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA 31 32 *****************************************************************************/ 33 34 /***********************************************************************//** 35 @file include/univ.i 36 Version control for database, common definitions, and include files 37 38 Created 1/20/1994 Heikki Tuuri 39 ****************************************************************************/ 40 41 #ifndef univ_i 42 #define univ_i 43 44 #ifdef UNIV_HOTBACKUP 45 #include "hb_univ.i" 46 #endif /* UNIV_HOTBACKUP */ 47 48 /* aux macros to convert M into "123" (string) if M is defined like 49 #define M 123 */ 50 #define _IB_TO_STR(s) #s 51 #define IB_TO_STR(s) _IB_TO_STR(s) 52 53 #define INNODB_VERSION_MAJOR MYSQL_VERSION_MAJOR 54 #define INNODB_VERSION_MINOR MYSQL_VERSION_MINOR 55 #define INNODB_VERSION_BUGFIX MYSQL_VERSION_PATCH 56 57 #ifndef PERCONA_INNODB_VERSION 58 #define PERCONA_INNODB_VERSION 91.0 59 #endif 60 61 /* Enable UNIV_LOG_ARCHIVE in XtraDB */ 62 #define UNIV_LOG_ARCHIVE 1 63 64 /* The following is the InnoDB version as shown in 65 SELECT plugin_version FROM information_schema.plugins; 66 calculated in make_version_string() in sql/sql_show.cc like this: 67 "version >> 8" . "version & 0xff" 68 because the version is shown with only one dot, we skip the last 69 component, i.e. we show M.N.P as M.N */ 70 #define INNODB_VERSION_SHORT \ 71 (INNODB_VERSION_MAJOR << 8 | INNODB_VERSION_MINOR) 72 73 #define INNODB_VERSION_STR \ 74 IB_TO_STR(INNODB_VERSION_MAJOR) "." \ 75 IB_TO_STR(INNODB_VERSION_MINOR) "." \ 76 IB_TO_STR(INNODB_VERSION_BUGFIX) "-" \ 77 IB_TO_STR(PERCONA_INNODB_VERSION) 78 79 #define REFMAN "http://dev.mysql.com/doc/refman/" \ 80 IB_TO_STR(MYSQL_VERSION_MAJOR) "." \ 81 IB_TO_STR(MYSQL_VERSION_MINOR) "/en/" 82 83 #ifdef MYSQL_DYNAMIC_PLUGIN 84 /* In the dynamic plugin, redefine some externally visible symbols 85 in order not to conflict with the symbols of a builtin InnoDB. */ 86 87 /* Rename all C++ classes that contain virtual functions, because we 88 have not figured out how to apply the visibility=hidden attribute to 89 the virtual method table (vtable) in GCC 3. */ 90 # define ha_innobase ha_innodb 91 #endif /* MYSQL_DYNAMIC_PLUGIN */ 92 93 #if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)) && !defined(MYSQL_SERVER) && !defined(__WIN__) 94 # undef __WIN__ 95 # define __WIN__ 96 97 # include <windows.h> 98 99 # ifdef _NT_ 100 # define __NT__ 101 # endif 102 103 #else 104 /* The defines used with MySQL */ 105 106 /* Include two header files from MySQL to make the Unix flavor used 107 in compiling more Posix-compatible. These headers also define __WIN__ 108 if we are compiling on Windows. */ 109 110 #ifndef UNIV_HOTBACKUP 111 # include <my_global.h> 112 # include <my_pthread.h> 113 #endif /* UNIV_HOTBACKUP */ 114 115 /* Include <sys/stat.h> to get S_I... macros defined for os0file.cc */ 116 # include <sys/stat.h> 117 # if !defined(__WIN__) 118 # include <sys/mman.h> /* mmap() for os0proc.cc */ 119 # endif 120 121 /* Include the header file generated by GNU autoconf */ 122 # ifndef __WIN__ 123 # ifndef UNIV_HOTBACKUP 124 # include "config.h" 125 # endif /* UNIV_HOTBACKUP */ 126 # endif 127 128 # ifdef HAVE_SCHED_H 129 # include <sched.h> 130 # endif 131 132 # ifdef HAVE_MALLOC_H 133 # include <malloc.h> 134 # endif 135 136 /* We only try to do explicit inlining of functions with gcc and 137 Sun Studio */ 138 139 # ifdef HAVE_PREAD 140 # define HAVE_PWRITE 141 # endif 142 143 #endif /* #if (defined(WIN32) || ... */ 144 145 #ifndef __WIN__ 146 #define __STDC_FORMAT_MACROS /* Enable C99 printf format macros */ 147 #include <inttypes.h> 148 #endif /* !__WIN__ */ 149 150 /* Following defines are to enable performance schema 151 instrumentation in each of four InnoDB modules if 152 HAVE_PSI_INTERFACE is defined. */ 153 #if defined HAVE_PSI_INTERFACE && !defined UNIV_HOTBACKUP 154 # define UNIV_PFS_MUTEX 155 # define UNIV_PFS_RWLOCK 156 157 # define UNIV_PFS_IO 158 # define UNIV_PFS_THREAD 159 160 /* There are mutexes/rwlocks that we want to exclude from 161 instrumentation even if their corresponding performance schema 162 define is set. And this PFS_NOT_INSTRUMENTED is used 163 as the key value to identify those objects that would 164 be excluded from instrumentation. */ 165 # define PFS_NOT_INSTRUMENTED ULINT32_UNDEFINED 166 167 # define PFS_IS_INSTRUMENTED(key) ((key) != PFS_NOT_INSTRUMENTED) 168 169 #endif /* HAVE_PSI_INTERFACE */ 170 171 #ifdef __WIN__ 172 # define YY_NO_UNISTD_H 1 173 #endif /* __WIN__ */ 174 175 /* DEBUG VERSION CONTROL 176 ===================== */ 177 178 /* When this macro is defined then additional test functions will be 179 compiled. These functions live at the end of each relevant source file 180 and have "test_" prefix. These functions are not called from anywhere in 181 the code, they can be called from gdb after 182 innobase_start_or_create_for_mysql() has executed using the call 183 command. Not tested on Windows. */ 184 /* 185 #define UNIV_COMPILE_TEST_FUNCS 186 */ 187 188 #if defined HAVE_VALGRIND 189 # define UNIV_DEBUG_VALGRIND 190 #endif /* HAVE_VALGRIND */ 191 #if 0 192 #define UNIV_DEBUG_VALGRIND /* Enable extra 193 Valgrind instrumentation */ 194 #define UNIV_DEBUG_PRINT /* Enable the compilation of 195 some debug print functions */ 196 #define UNIV_AHI_DEBUG /* Enable adaptive hash index 197 debugging without UNIV_DEBUG */ 198 #define UNIV_BUF_DEBUG /* Enable buffer pool 199 debugging without UNIV_DEBUG */ 200 #define UNIV_BLOB_LIGHT_DEBUG /* Enable off-page column 201 debugging without UNIV_DEBUG */ 202 #define UNIV_DEBUG /* Enable ut_ad() assertions 203 and disable UNIV_INLINE */ 204 #define UNIV_DEBUG_LOCK_VALIDATE /* Enable 205 ut_ad(lock_rec_validate_page()) 206 assertions. */ 207 #define UNIV_DEBUG_FILE_ACCESSES /* Enable freed block access 208 debugging without UNIV_DEBUG */ 209 #define UNIV_LRU_DEBUG /* debug the buffer pool LRU */ 210 #define UNIV_HASH_DEBUG /* debug HASH_ macros */ 211 #define UNIV_LIST_DEBUG /* debug UT_LIST_ macros */ 212 #define UNIV_LOG_LSN_DEBUG /* write LSN to the redo log; 213 this will break redo log file compatibility, but it may be useful when 214 debugging redo log application problems. */ 215 #define UNIV_MEM_DEBUG /* detect memory leaks etc */ 216 #define UNIV_IBUF_DEBUG /* debug the insert buffer */ 217 #define UNIV_BLOB_DEBUG /* track BLOB ownership; 218 assumes that no BLOBs survive server restart */ 219 #define UNIV_IBUF_COUNT_DEBUG /* debug the insert buffer; 220 this limits the database to IBUF_COUNT_N_SPACES and IBUF_COUNT_N_PAGES, 221 and the insert buffer must be empty when the database is started */ 222 #define UNIV_PERF_DEBUG /* debug flag that enables 223 light weight performance 224 related stuff. */ 225 #define UNIV_SYNC_DEBUG /* debug mutex and latch 226 operations (very slow); also UNIV_DEBUG must be defined */ 227 #define UNIV_SEARCH_DEBUG /* debug B-tree comparisons */ 228 #define UNIV_SYNC_PERF_STAT /* operation counts for 229 rw-locks and mutexes */ 230 #define UNIV_SEARCH_PERF_STAT /* statistics for the 231 adaptive hash index */ 232 #define UNIV_SRV_PRINT_LATCH_WAITS /* enable diagnostic output 233 in sync0sync.cc */ 234 #define UNIV_BTR_PRINT /* enable functions for 235 printing B-trees */ 236 #define UNIV_ZIP_DEBUG /* extensive consistency checks 237 for compressed pages */ 238 #define UNIV_ZIP_COPY /* call page_zip_copy_recs() 239 more often */ 240 #define UNIV_AIO_DEBUG /* prints info about 241 submitted and reaped AIO 242 requests to the log. */ 243 #define UNIV_STATS_DEBUG /* prints various stats 244 related debug info from 245 dict0stats.c */ 246 #define FTS_INTERNAL_DIAG_PRINT /* FTS internal debugging 247 info output */ 248 #endif 249 250 #define UNIV_BTR_DEBUG /* check B-tree links */ 251 #define UNIV_LIGHT_MEM_DEBUG /* light memory debugging */ 252 253 /* 254 #define UNIV_SQL_DEBUG 255 #define UNIV_LOG_DEBUG 256 */ 257 /* the above option prevents forcing of log to disk 258 at a buffer page write: it should be tested with this 259 option off; also some ibuf tests are suppressed */ 260 261 /* Linkage specifier for non-static InnoDB symbols (variables and functions) 262 that are only referenced from within InnoDB, not from MySQL. We disable the 263 GCC visibility directive on all Sun operating systems because there is no 264 easy way to get it to work. See http://bugs.mysql.com/bug.php?id=52263. */ 265 #if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(sun) || defined(__INTEL_COMPILER) 266 # define UNIV_INTERN MY_ATTRIBUTE((visibility ("hidden"))) 267 #else 268 # define UNIV_INTERN 269 #endif 270 #if defined(INNODB_COMPILER_HINTS) \ 271 && defined __GNUC__ \ 272 && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 3) 273 /** Starting with GCC 4.3, the "cold" attribute is used to inform the 274 compiler that a function is unlikely executed. The function is 275 optimized for size rather than speed and on many targets it is placed 276 into special subsection of the text section so all cold functions 277 appears close together improving code locality of non-cold parts of 278 program. The paths leading to call of cold functions within code are 279 marked as unlikely by the branch prediction mechanism. optimize a 280 rarely invoked function for size instead for speed. */ 281 # define UNIV_COLD MY_ATTRIBUTE((cold)) 282 #else 283 # define UNIV_COLD /* empty */ 284 #endif 285 286 #ifdef UNIV_LINUX 287 # define UNIV_THREAD_LOCAL __thread 288 #else 289 /* FIXME: the TLS variables are silently broken on other platforms for now */ 290 # define UNIV_THREAD_LOCAL 291 #endif 292 293 #ifndef UNIV_MUST_NOT_INLINE 294 /* Definition for inline version */ 295 296 #define UNIV_INLINE static inline 297 298 #else /* !UNIV_MUST_NOT_INLINE */ 299 /* If we want to compile a noninlined version we use the following macro 300 definitions: */ 301 302 #define UNIV_NONINL 303 #define UNIV_INLINE UNIV_INTERN 304 305 #endif /* !UNIV_MUST_NOT_INLINE */ 306 307 #ifdef _WIN32 308 #define UNIV_WORD_SIZE 4 309 #elif defined(_WIN64) 310 #define UNIV_WORD_SIZE 8 311 #else 312 /** MySQL config.h generated by GNU autoconf will define SIZEOF_LONG in Posix */ 313 #define UNIV_WORD_SIZE SIZEOF_LONG 314 #endif 315 316 /** The following alignment is used in memory allocations in memory heap 317 management to ensure correct alignment for doubles etc. */ 318 #define UNIV_MEM_ALIGNMENT 8 319 320 /** The following alignment is used in aligning lints etc. */ 321 #define UNIV_WORD_ALIGNMENT UNIV_WORD_SIZE 322 323 /* 324 DATABASE VERSION CONTROL 325 ======================== 326 */ 327 328 /** There are currently two InnoDB file formats which are used to group 329 features with similar restrictions and dependencies. Using an enum allows 330 switch statements to give a compiler warning when a new one is introduced. */ 331 enum innodb_file_formats_enum { 332 /** Antelope File Format: InnoDB/MySQL up to 5.1. 333 This format includes REDUNDANT and COMPACT row formats */ 334 UNIV_FORMAT_A = 0, 335 336 /** Barracuda File Format: Introduced in InnoDB plugin for 5.1: 337 This format includes COMPRESSED and DYNAMIC row formats. It 338 includes the ability to create secondary indexes from data that 339 is not on the clustered index page and the ability to store more 340 data off the clustered index page. */ 341 UNIV_FORMAT_B = 1 342 }; 343 344 typedef enum innodb_file_formats_enum innodb_file_formats_t; 345 346 /** Minimum supported file format */ 347 #define UNIV_FORMAT_MIN UNIV_FORMAT_A 348 349 /** Maximum supported file format */ 350 #define UNIV_FORMAT_MAX UNIV_FORMAT_B 351 352 /** The 2-logarithm of UNIV_PAGE_SIZE: */ 353 #define UNIV_PAGE_SIZE_SHIFT srv_page_size_shift 354 355 /** The universal page size of the database */ 356 #define UNIV_PAGE_SIZE ((ulint) srv_page_size) 357 358 /** log2 of smallest compressed page size (1<<10 == 1024 bytes) 359 Note: This must never change! */ 360 #define UNIV_ZIP_SIZE_SHIFT_MIN 10 361 362 /** log2 of largest compressed page size (1<<14 == 16384 bytes). 363 A compressed page directory entry reserves 14 bits for the start offset 364 and 2 bits for flags. This limits the uncompressed page size to 16k. 365 Even though a 16k uncompressed page can theoretically be compressed 366 into a larger compressed page, it is not a useful feature so we will 367 limit both with this same constant. */ 368 #define UNIV_ZIP_SIZE_SHIFT_MAX 14 369 370 /* Define the Min, Max, Default page sizes. */ 371 /** Minimum Page Size Shift (power of 2) */ 372 #define UNIV_PAGE_SIZE_SHIFT_MIN 12 373 /** Maximum Page Size Shift (power of 2) */ 374 #define UNIV_PAGE_SIZE_SHIFT_MAX 14 375 /** Default Page Size Shift (power of 2) */ 376 #define UNIV_PAGE_SIZE_SHIFT_DEF 14 377 /** Original 16k InnoDB Page Size Shift, in case the default changes */ 378 #define UNIV_PAGE_SIZE_SHIFT_ORIG 14 379 380 /** Minimum page size InnoDB currently supports. */ 381 #define UNIV_PAGE_SIZE_MIN (1 << UNIV_PAGE_SIZE_SHIFT_MIN) 382 /** Maximum page size InnoDB currently supports. */ 383 #define UNIV_PAGE_SIZE_MAX (1 << UNIV_PAGE_SIZE_SHIFT_MAX) 384 /** Default page size for InnoDB tablespaces. */ 385 #define UNIV_PAGE_SIZE_DEF (1 << UNIV_PAGE_SIZE_SHIFT_DEF) 386 /** Original 16k page size for InnoDB tablespaces. */ 387 #define UNIV_PAGE_SIZE_ORIG (1 << UNIV_PAGE_SIZE_SHIFT_ORIG) 388 389 /** Smallest compressed page size */ 390 #define UNIV_ZIP_SIZE_MIN (1 << UNIV_ZIP_SIZE_SHIFT_MIN) 391 392 /** Largest compressed page size */ 393 #define UNIV_ZIP_SIZE_MAX (1 << UNIV_ZIP_SIZE_SHIFT_MAX) 394 395 /** Number of supported page sizes (The convention 'ssize' is used 396 for 'log2 minus 9' or the number of shifts starting with 512.) 397 This number varies depending on UNIV_PAGE_SIZE. */ 398 #define UNIV_PAGE_SSIZE_MAX \ 399 (UNIV_PAGE_SIZE_SHIFT - UNIV_ZIP_SIZE_SHIFT_MIN + 1) 400 401 /** Maximum number of parallel threads in a parallelized operation */ 402 #define UNIV_MAX_PARALLELISM 32 403 404 /** This is the "mbmaxlen" for my_charset_filename (defined in 405 strings/ctype-utf8.c), which is used to encode File and Database names. */ 406 #define FILENAME_CHARSET_MAXNAMLEN 5 407 408 /** The maximum length of an encode table name in bytes. The max 409 table and database names are NAME_CHAR_LEN (64) characters. After the 410 encoding, the max length would be NAME_CHAR_LEN (64) * 411 FILENAME_CHARSET_MAXNAMLEN (5) = 320 bytes. The number does not include a 412 terminating '\0'. InnoDB can handle longer names internally */ 413 #define MAX_TABLE_NAME_LEN 320 414 415 /** The maximum length of a database name. Like MAX_TABLE_NAME_LEN this is 416 the MySQL's NAME_LEN, see check_and_convert_db_name(). */ 417 #define MAX_DATABASE_NAME_LEN MAX_TABLE_NAME_LEN 418 419 /** MAX_FULL_NAME_LEN defines the full name path including the 420 database name and table name. In addition, 14 bytes is added for: 421 2 for surrounding quotes around table name 422 1 for the separating dot (.) 423 9 for the #mysql50# prefix */ 424 #define MAX_FULL_NAME_LEN \ 425 (MAX_TABLE_NAME_LEN + MAX_DATABASE_NAME_LEN + 14) 426 427 /** The maximum length in bytes that a database name can occupy when stored in 428 UTF8, including the terminating '\0', see dict_fs2utf8(). You must include 429 mysql_com.h if you are to use this macro. */ 430 #define MAX_DB_UTF8_LEN (NAME_LEN + 1) 431 432 /** The maximum length in bytes that a table name can occupy when stored in 433 UTF8, including the terminating '\0', see dict_fs2utf8(). You must include 434 mysql_com.h if you are to use this macro. */ 435 #define MAX_TABLE_UTF8_LEN (NAME_LEN + sizeof(srv_mysql50_table_name_prefix)) 436 437 /* 438 UNIVERSAL TYPE DEFINITIONS 439 ========================== 440 */ 441 442 /* Note that inside MySQL 'byte' is defined as char on Linux! */ 443 #define byte unsigned char 444 445 /* Another basic type we use is unsigned long integer which should be equal to 446 the word size of the machine, that is on a 32-bit platform 32 bits, and on a 447 64-bit platform 64 bits. We also give the printf format for the type as a 448 macro ULINTPF. */ 449 450 451 #ifdef __WIN__ 452 /* Use the integer types and formatting strings defined in Visual Studio. */ 453 # define UINT32PF "%I32u" 454 # define INT64PF "%I64d" 455 # define UINT64PF "%I64u" 456 # define UINT64PFx "%016I64x" 457 # define DBUG_LSN_PF "%llu" 458 typedef __int64 ib_int64_t; 459 typedef unsigned __int64 ib_uint64_t; 460 typedef unsigned __int32 ib_uint32_t; 461 #else 462 /* Use the integer types and formatting strings defined in the C99 standard. */ 463 # define UINT32PF "%" PRIu32 464 # define INT64PF "%" PRId64 465 # define UINT64PF "%" PRIu64 466 # define UINT64PFx "%016" PRIx64 467 # define DBUG_LSN_PF UINT64PF 468 typedef int64_t ib_int64_t; 469 typedef uint64_t ib_uint64_t; 470 typedef uint32_t ib_uint32_t; 471 # endif /* __WIN__ */ 472 473 # define IB_ID_FMT UINT64PF 474 475 #ifdef _WIN64 476 typedef unsigned __int64 ulint; 477 typedef __int64 lint; 478 # define ULINTPF UINT64PF 479 #else 480 typedef unsigned long int ulint; 481 typedef long int lint; 482 # define ULINTPF "%lu" 483 #endif /* _WIN64 */ 484 485 #ifndef UNIV_HOTBACKUP 486 typedef unsigned long long int ullint; 487 #endif /* UNIV_HOTBACKUP */ 488 489 #ifndef __WIN__ 490 #if SIZEOF_LONG != SIZEOF_VOIDP 491 #error "Error: InnoDB's ulint must be of the same size as void*" 492 #endif 493 #endif 494 495 /** The 'undefined' value for a ulint */ 496 #define ULINT_UNDEFINED ((ulint)(-1)) 497 498 #define ULONG_UNDEFINED ((ulong)(-1)) 499 500 /** The 'undefined' value for a ib_uint64_t */ 501 #define UINT64_UNDEFINED ((ib_uint64_t)(-1)) 502 503 /** The bitmask of 32-bit unsigned integer */ 504 #define ULINT32_MASK 0xFFFFFFFF 505 /** The undefined 32-bit unsigned integer */ 506 #define ULINT32_UNDEFINED ULINT32_MASK 507 508 /** Maximum value for a ulint */ 509 #define ULINT_MAX ((ulint)(-2)) 510 511 /** Maximum value for ib_uint64_t */ 512 #define IB_UINT64_MAX ((ib_uint64_t) (~0ULL)) 513 514 /** The generic InnoDB system object identifier data type */ 515 typedef ib_uint64_t ib_id_t; 516 #define IB_ID_MAX IB_UINT64_MAX 517 518 /** The 'undefined' value for a ullint */ 519 #define ULLINT_UNDEFINED ((ullint)(-1)) 520 521 /** This 'ibool' type is used within Innobase. Remember that different included 522 headers may define 'bool' differently. Do not assume that 'bool' is a ulint! */ 523 #define ibool ulint 524 525 #ifndef TRUE 526 527 #define TRUE 1 528 #define FALSE 0 529 530 #endif 531 532 #define UNIV_NOTHROW 533 534 /** The following number as the length of a logical field means that the field 535 has the SQL NULL as its value. NOTE that because we assume that the length 536 of a field is a 32-bit integer when we store it, for example, to an undo log 537 on disk, we must have also this number fit in 32 bits, also in 64-bit 538 computers! */ 539 540 #define UNIV_SQL_NULL ULINT32_UNDEFINED 541 542 /** Lengths which are not UNIV_SQL_NULL, but bigger than the following 543 number indicate that a field contains a reference to an externally 544 stored part of the field in the tablespace. The length field then 545 contains the sum of the following flag and the locally stored len. */ 546 547 #define UNIV_EXTERN_STORAGE_FIELD (UNIV_SQL_NULL - UNIV_PAGE_SIZE_MAX) 548 549 #if defined(__GNUC__) && (__GNUC__ > 2) && ! defined(__INTEL_COMPILER) 550 #define HAVE_GCC_GT_2 551 /* Tell the compiler that variable/function is unused. */ 552 # define UNIV_UNUSED MY_ATTRIBUTE ((unused)) 553 #else 554 # define UNIV_UNUSED 555 #endif /* CHECK FOR GCC VER_GT_2 */ 556 557 /* Some macros to improve branch prediction and reduce cache misses */ 558 #if defined(INNODB_COMPILER_HINTS) && defined(HAVE_GCC_GT_2) 559 /* Tell the compiler that 'expr' probably evaluates to 'constant'. */ 560 # define UNIV_EXPECT(expr,constant) __builtin_expect(expr, constant) 561 /* Tell the compiler that a pointer is likely to be NULL */ 562 # define UNIV_LIKELY_NULL(ptr) __builtin_expect((ulint) ptr, 0) 563 /* Minimize cache-miss latency by moving data at addr into a cache before 564 it is read. */ 565 # define UNIV_PREFETCH_R(addr) __builtin_prefetch(addr, 0, 3) 566 /* Minimize cache-miss latency by moving data at addr into a cache before 567 it is read or written. */ 568 # define UNIV_PREFETCH_RW(addr) __builtin_prefetch(addr, 1, 3) 569 570 /* Sun Studio includes sun_prefetch.h as of version 5.9 */ 571 #elif (defined(__SUNPRO_C) && __SUNPRO_C >= 0x590) \ 572 || (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590) 573 574 # include <sun_prefetch.h> 575 576 #if __SUNPRO_C >= 0x550 577 # undef UNIV_INTERN 578 # define UNIV_INTERN __hidden 579 #endif /* __SUNPRO_C >= 0x550 */ 580 581 # define UNIV_EXPECT(expr,value) (expr) 582 # define UNIV_LIKELY_NULL(expr) (expr) 583 584 # if defined(INNODB_COMPILER_HINTS) 585 //# define UNIV_PREFETCH_R(addr) sun_prefetch_read_many((void*) addr) 586 # define UNIV_PREFETCH_R(addr) ((void) 0) 587 # define UNIV_PREFETCH_RW(addr) sun_prefetch_write_many(addr) 588 # else 589 # define UNIV_PREFETCH_R(addr) ((void) 0) 590 # define UNIV_PREFETCH_RW(addr) ((void) 0) 591 # endif /* INNODB_COMPILER_HINTS */ 592 593 #else 594 /* Dummy versions of the macros */ 595 # define UNIV_EXPECT(expr,value) (expr) 596 # define UNIV_LIKELY_NULL(expr) (expr) 597 # define UNIV_PREFETCH_R(addr) ((void) 0) 598 # define UNIV_PREFETCH_RW(addr) ((void) 0) 599 #endif 600 601 /* Tell the compiler that cond is likely to hold */ 602 #define UNIV_LIKELY(cond) UNIV_EXPECT(cond, TRUE) 603 /* Tell the compiler that cond is unlikely to hold */ 604 #define UNIV_UNLIKELY(cond) UNIV_EXPECT(cond, FALSE) 605 606 /* Compile-time constant of the given array's size. */ 607 #define UT_ARR_SIZE(a) (sizeof(a) / sizeof((a)[0])) 608 609 /* The return type from a thread's start function differs between Unix and 610 Windows, so define a typedef for it and a macro to use at the end of such 611 functions. */ 612 613 #ifdef __WIN__ 614 typedef ulint os_thread_ret_t; 615 #define OS_THREAD_DUMMY_RETURN return(0) 616 #else 617 typedef void* os_thread_ret_t; 618 #define OS_THREAD_DUMMY_RETURN return(NULL) 619 #endif 620 621 #include <stdio.h> 622 #include "ut0dbg.h" 623 #include "ut0ut.h" 624 #include "db0err.h" 625 #ifdef UNIV_DEBUG_VALGRIND 626 # include <valgrind/memcheck.h> 627 # define UNIV_MEM_VALID(addr, size) VALGRIND_MAKE_MEM_DEFINED(addr, size) 628 # define UNIV_MEM_INVALID(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size) 629 # define UNIV_MEM_FREE(addr, size) VALGRIND_MAKE_MEM_NOACCESS(addr, size) 630 # define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size) 631 # define UNIV_MEM_DESC(addr, size) VALGRIND_CREATE_BLOCK(addr, size, #addr) 632 # define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b) 633 # define UNIV_MEM_ASSERT_RW_LOW(addr, size, should_abort) do { \ 634 const void* _p = (const void*) (ulint) \ 635 VALGRIND_CHECK_MEM_IS_DEFINED(addr, size); \ 636 if (UNIV_LIKELY_NULL(_p)) { \ 637 fprintf(stderr, "%s:%d: %p[%u] undefined at %ld\n", \ 638 __FILE__, __LINE__, \ 639 (const void*) (addr), (unsigned) (size), (long) \ 640 (((const char*) _p) - ((const char*) (addr)))); \ 641 if (should_abort) { \ 642 ut_error; \ 643 } \ 644 } \ 645 } while (0) 646 # define UNIV_MEM_ASSERT_RW(addr, size) \ 647 UNIV_MEM_ASSERT_RW_LOW(addr, size, false) 648 # define UNIV_MEM_ASSERT_RW_ABORT(addr, size) \ 649 UNIV_MEM_ASSERT_RW_LOW(addr, size, true) 650 # define UNIV_MEM_ASSERT_W(addr, size) do { \ 651 const void* _p = (const void*) (ulint) \ 652 VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size); \ 653 if (UNIV_LIKELY_NULL(_p)) \ 654 fprintf(stderr, "%s:%d: %p[%u] unwritable at %ld\n", \ 655 __FILE__, __LINE__, \ 656 (const void*) (addr), (unsigned) (size), (long) \ 657 (((const char*) _p) - ((const char*) (addr)))); \ 658 } while (0) 659 # define UNIV_MEM_TRASH(addr, c, size) do { \ 660 ut_d(memset(addr, c, size)); \ 661 UNIV_MEM_INVALID(addr, size); \ 662 } while (0) 663 #else 664 # define UNIV_MEM_VALID(addr, size) do {} while(0) 665 # define UNIV_MEM_INVALID(addr, size) do {} while(0) 666 # define UNIV_MEM_FREE(addr, size) do {} while(0) 667 # define UNIV_MEM_ALLOC(addr, size) do {} while(0) 668 # define UNIV_MEM_DESC(addr, size) do {} while(0) 669 # define UNIV_MEM_UNDESC(b) do {} while(0) 670 # define UNIV_MEM_ASSERT_RW_LOW(addr, size, should_abort) do {} while(0) 671 # define UNIV_MEM_ASSERT_RW(addr, size) do {} while(0) 672 # define UNIV_MEM_ASSERT_RW_ABORT(addr, size) do {} while(0) 673 # define UNIV_MEM_ASSERT_W(addr, size) do {} while(0) 674 # define UNIV_MEM_TRASH(addr, c, size) do {} while(0) 675 #endif 676 #define UNIV_MEM_ASSERT_AND_FREE(addr, size) do { \ 677 UNIV_MEM_ASSERT_W(addr, size); \ 678 UNIV_MEM_FREE(addr, size); \ 679 } while (0) 680 #define UNIV_MEM_ASSERT_AND_ALLOC(addr, size) do { \ 681 UNIV_MEM_ASSERT_W(addr, size); \ 682 UNIV_MEM_ALLOC(addr, size); \ 683 } while (0) 684 685 extern ulong srv_page_size_shift; 686 extern ulong srv_page_size; 687 688 #endif 689