1 /***************************************************************************** 2 3 Copyright (c) 1994, 2021, Oracle and/or its affiliates. 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 /* The following is the InnoDB version as shown in 58 SELECT plugin_version FROM information_schema.plugins; 59 calculated in make_version_string() in sql/sql_show.cc like this: 60 "version >> 8" . "version & 0xff" 61 because the version is shown with only one dot, we skip the last 62 component, i.e. we show M.N.P as M.N */ 63 #define INNODB_VERSION_SHORT \ 64 (INNODB_VERSION_MAJOR << 8 | INNODB_VERSION_MINOR) 65 66 #define INNODB_VERSION_STR \ 67 IB_TO_STR(INNODB_VERSION_MAJOR) "." \ 68 IB_TO_STR(INNODB_VERSION_MINOR) "." \ 69 IB_TO_STR(INNODB_VERSION_BUGFIX) 70 71 #define REFMAN "http://dev.mysql.com/doc/refman/" \ 72 IB_TO_STR(MYSQL_VERSION_MAJOR) "." \ 73 IB_TO_STR(MYSQL_VERSION_MINOR) "/en/" 74 75 #ifdef MYSQL_DYNAMIC_PLUGIN 76 /* In the dynamic plugin, redefine some externally visible symbols 77 in order not to conflict with the symbols of a builtin InnoDB. */ 78 79 /* Rename all C++ classes that contain virtual functions, because we 80 have not figured out how to apply the visibility=hidden attribute to 81 the virtual method table (vtable) in GCC 3. */ 82 # define ha_innobase ha_innodb 83 #endif /* MYSQL_DYNAMIC_PLUGIN */ 84 85 #if defined(_WIN32) 86 # include <windows.h> 87 #endif /* _WIN32 */ 88 89 /* The defines used with MySQL */ 90 91 #ifndef UNIV_HOTBACKUP 92 93 /* Include a minimum number of SQL header files so that few changes 94 made in SQL code cause a complete InnoDB rebuild. These headers are 95 used throughout InnoDB but do not include too much themselves. They 96 support cross-platform development and expose comonly used SQL names. */ 97 98 # include <my_global.h> 99 # include <my_thread.h> 100 101 # ifndef UNIV_INNOCHECKSUM 102 # include <m_string.h> 103 # include <mysqld_error.h> 104 # endif /* !UNIV_INNOCHECKSUM */ 105 #endif /* !UNIV_HOTBACKUP */ 106 107 /* Include <sys/stat.h> to get S_I... macros defined for os0file.cc */ 108 #include <sys/stat.h> 109 110 #ifndef _WIN32 111 # include <sys/mman.h> /* mmap() for os0proc.cc */ 112 # include <sched.h> 113 #endif /* !_WIN32 */ 114 115 /* Include the header file generated by CMake */ 116 #ifndef _WIN32 117 # ifndef UNIV_HOTBACKUP 118 # include "my_config.h" 119 # endif /* UNIV_HOTBACKUP */ 120 #endif 121 122 #include <stdint.h> 123 #include <inttypes.h> 124 #ifdef HAVE_UNISTD_H 125 #include <unistd.h> 126 #endif 127 128 /* Following defines are to enable performance schema 129 instrumentation in each of five InnoDB modules if 130 HAVE_PSI_INTERFACE is defined. */ 131 #if defined(HAVE_PSI_INTERFACE) && !defined(UNIV_HOTBACKUP) 132 # define UNIV_PFS_MUTEX 133 134 #ifdef UNIV_PFS_MUTEX 135 /* For the rwlocks to be tracked UNIV_PFS_MUTEX has to be defined. If not 136 defined, the rwlocks are simply not tracked. */ 137 # define UNIV_PFS_RWLOCK 138 #endif /* UNIV_PFS_MUTEX */ 139 140 # define UNIV_PFS_IO 141 # define UNIV_PFS_THREAD 142 143 # include "mysql/psi/psi.h" /* HAVE_PSI_MEMORY_INTERFACE */ 144 # ifdef HAVE_PSI_MEMORY_INTERFACE 145 # define UNIV_PFS_MEMORY 146 # endif /* HAVE_PSI_MEMORY_INTERFACE */ 147 148 /* For PSI_MUTEX_CALL() and similar. */ 149 #include "pfs_thread_provider.h" 150 #include "mysql/psi/mysql_thread.h" 151 /* For PSI_FILE_CALL(). */ 152 #include "pfs_file_provider.h" 153 #include "mysql/psi/mysql_file.h" 154 155 #endif /* HAVE_PSI_INTERFACE */ 156 157 #ifdef _WIN32 158 # define YY_NO_UNISTD_H 1 159 /* VC++ tries to optimise for size by default, from V8+. The size of 160 the pointer to member depends on whether the type is defined before the 161 compiler sees the type in the translation unit. This default behaviour 162 can cause the pointer to be a different size in different translation 163 units, depending on the above rule. We force optimise for size behaviour 164 for all cases. This is used by ut0lst.h related code. */ 165 # pragma pointers_to_members(full_generality, single_inheritance) 166 #endif /* _WIN32 */ 167 168 /* DEBUG VERSION CONTROL 169 ===================== */ 170 171 /* When this macro is defined then additional test functions will be 172 compiled. These functions live at the end of each relevant source file 173 and have "test_" prefix. These functions can be called from the end of 174 innobase_init() or they can be called from gdb after 175 innobase_start_or_create_for_mysql() has executed using the call 176 command. */ 177 /* 178 #define UNIV_COMPILE_TEST_FUNCS 179 #define UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR 180 #define UNIV_ENABLE_UNIT_TEST_MAKE_FILEPATH 181 #define UNIV_ENABLE_UNIT_TEST_DICT_STATS 182 #define UNIV_ENABLE_UNIT_TEST_ROW_RAW_FORMAT_INT 183 */ 184 185 #if defined HAVE_VALGRIND 186 # define UNIV_DEBUG_VALGRIND 187 #endif /* HAVE_VALGRIND */ 188 #if 0 189 #define UNIV_DEBUG_VALGRIND /* Enable extra 190 Valgrind instrumentation */ 191 #define UNIV_DEBUG_PRINT /* Enable the compilation of 192 some debug print functions */ 193 #define UNIV_AHI_DEBUG /* Enable adaptive hash index 194 debugging without UNIV_DEBUG */ 195 #define UNIV_BUF_DEBUG /* Enable buffer pool 196 debugging without UNIV_DEBUG */ 197 #define UNIV_BLOB_LIGHT_DEBUG /* Enable off-page column 198 debugging without UNIV_DEBUG */ 199 #define UNIV_DEBUG /* Enable ut_ad() assertions 200 and disable UNIV_INLINE */ 201 #define UNIV_DEBUG_LOCK_VALIDATE /* Enable 202 ut_ad(lock_rec_validate_page()) 203 assertions. */ 204 #define UNIV_LRU_DEBUG /* debug the buffer pool LRU */ 205 #define UNIV_HASH_DEBUG /* debug HASH_ macros */ 206 #define UNIV_LOG_LSN_DEBUG /* write LSN to the redo log; 207 this will break redo log file compatibility, but it may be useful when 208 debugging redo log application problems. */ 209 #define UNIV_IBUF_DEBUG /* debug the insert buffer */ 210 #define UNIV_IBUF_COUNT_DEBUG /* debug the insert buffer; 211 this limits the database to IBUF_COUNT_N_SPACES and IBUF_COUNT_N_PAGES, 212 and the insert buffer must be empty when the database is started */ 213 #define UNIV_PERF_DEBUG /* debug flag that enables 214 light weight performance 215 related stuff. */ 216 #define UNIV_SEARCH_PERF_STAT /* statistics for the 217 adaptive hash index */ 218 #define UNIV_SRV_PRINT_LATCH_WAITS /* enable diagnostic output 219 in sync0sync.cc */ 220 #define UNIV_BTR_PRINT /* enable functions for 221 printing B-trees */ 222 #define UNIV_ZIP_DEBUG /* extensive consistency checks 223 for compressed pages */ 224 #define UNIV_ZIP_COPY /* call page_zip_copy_recs() 225 more often */ 226 #define UNIV_AIO_DEBUG /* prints info about 227 submitted and reaped AIO 228 requests to the log. */ 229 #define UNIV_STATS_DEBUG /* prints various stats 230 related debug info from 231 dict0stats.c */ 232 #define FTS_INTERNAL_DIAG_PRINT /* FTS internal debugging 233 info output */ 234 #endif 235 236 #define UNIV_BTR_DEBUG /* check B-tree links */ 237 #define UNIV_LIGHT_MEM_DEBUG /* light memory debugging */ 238 239 // #define UNIV_SQL_DEBUG 240 241 #if defined(COMPILER_HINTS) \ 242 && defined __GNUC__ \ 243 && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 3) 244 245 /** Starting with GCC 4.3, the "cold" attribute is used to inform the 246 compiler that a function is unlikely executed. The function is 247 optimized for size rather than speed and on many targets it is placed 248 into special subsection of the text section so all cold functions 249 appears close together improving code locality of non-cold parts of 250 program. The paths leading to call of cold functions within code are 251 marked as unlikely by the branch prediction mechanism. optimize a 252 rarely invoked function for size instead for speed. */ 253 # define UNIV_COLD MY_ATTRIBUTE((cold)) 254 #else 255 # define UNIV_COLD /* empty */ 256 #endif 257 258 #ifndef UNIV_MUST_NOT_INLINE 259 /* Definition for inline version */ 260 261 #define UNIV_INLINE static inline 262 263 #else /* !UNIV_MUST_NOT_INLINE */ 264 /* If we want to compile a noninlined version we use the following macro 265 definitions: */ 266 267 #define UNIV_NONINL 268 #define UNIV_INLINE 269 270 #endif /* !UNIV_MUST_NOT_INLINE */ 271 272 #ifdef _WIN32 273 # ifdef _WIN64 274 # define UNIV_WORD_SIZE 8 275 # else 276 # define UNIV_WORD_SIZE 4 277 # endif 278 #else /* !_WIN32 */ 279 /** MySQL config.h generated by CMake will define SIZEOF_LONG in Posix */ 280 #define UNIV_WORD_SIZE SIZEOF_LONG 281 #endif /* _WIN32 */ 282 283 /** The following alignment is used in memory allocations in memory heap 284 management to ensure correct alignment for doubles etc. */ 285 #define UNIV_MEM_ALIGNMENT 8 286 287 /* 288 DATABASE VERSION CONTROL 289 ======================== 290 */ 291 292 /** There are currently two InnoDB file formats which are used to group 293 features with similar restrictions and dependencies. Using an enum allows 294 switch statements to give a compiler warning when a new one is introduced. */ 295 enum innodb_file_formats_enum { 296 /** Antelope File Format: InnoDB/MySQL up to 5.1. 297 This format includes REDUNDANT and COMPACT row formats */ 298 UNIV_FORMAT_A = 0, 299 300 /** Barracuda File Format: Introduced in InnoDB plugin for 5.1: 301 This format includes COMPRESSED and DYNAMIC row formats. It 302 includes the ability to create secondary indexes from data that 303 is not on the clustered index page and the ability to store more 304 data off the clustered index page. */ 305 UNIV_FORMAT_B = 1 306 }; 307 308 typedef enum innodb_file_formats_enum innodb_file_formats_t; 309 310 /** Minimum supported file format */ 311 #define UNIV_FORMAT_MIN UNIV_FORMAT_A 312 313 /** Maximum supported file format */ 314 #define UNIV_FORMAT_MAX UNIV_FORMAT_B 315 316 /** The 2-logarithm of UNIV_PAGE_SIZE: */ 317 #define UNIV_PAGE_SIZE_SHIFT srv_page_size_shift 318 319 /** The universal page size of the database */ 320 #define UNIV_PAGE_SIZE ((ulint) srv_page_size) 321 322 /** log2 of smallest compressed page size (1<<10 == 1024 bytes) 323 Note: This must never change! */ 324 #define UNIV_ZIP_SIZE_SHIFT_MIN 10 325 326 /** log2 of largest compressed page size (1<<14 == 16384 bytes). 327 A compressed page directory entry reserves 14 bits for the start offset 328 and 2 bits for flags. This limits the uncompressed page size to 16k. 329 Even though a 16k uncompressed page can theoretically be compressed 330 into a larger compressed page, it is not a useful feature so we will 331 limit both with this same constant. */ 332 #define UNIV_ZIP_SIZE_SHIFT_MAX 14 333 334 /* Define the Min, Max, Default page sizes. */ 335 /** Minimum Page Size Shift (power of 2) */ 336 #define UNIV_PAGE_SIZE_SHIFT_MIN 12 337 /** Maximum Page Size Shift (power of 2) */ 338 #define UNIV_PAGE_SIZE_SHIFT_MAX 16 339 /** Default Page Size Shift (power of 2) */ 340 #define UNIV_PAGE_SIZE_SHIFT_DEF 14 341 /** Original 16k InnoDB Page Size Shift, in case the default changes */ 342 #define UNIV_PAGE_SIZE_SHIFT_ORIG 14 343 /** Original 16k InnoDB Page Size as an ssize (log2 - 9) */ 344 #define UNIV_PAGE_SSIZE_ORIG (UNIV_PAGE_SIZE_SHIFT_ORIG - 9) 345 346 /** Minimum page size InnoDB currently supports. */ 347 #define UNIV_PAGE_SIZE_MIN (1 << UNIV_PAGE_SIZE_SHIFT_MIN) 348 /** Maximum page size InnoDB currently supports. */ 349 #define UNIV_PAGE_SIZE_MAX (1 << UNIV_PAGE_SIZE_SHIFT_MAX) 350 /** Default page size for InnoDB tablespaces. */ 351 #define UNIV_PAGE_SIZE_DEF (1 << UNIV_PAGE_SIZE_SHIFT_DEF) 352 /** Original 16k page size for InnoDB tablespaces. */ 353 #define UNIV_PAGE_SIZE_ORIG (1 << UNIV_PAGE_SIZE_SHIFT_ORIG) 354 355 /** Smallest compressed page size */ 356 #define UNIV_ZIP_SIZE_MIN (1 << UNIV_ZIP_SIZE_SHIFT_MIN) 357 358 /** Largest compressed page size */ 359 #define UNIV_ZIP_SIZE_MAX (1 << UNIV_ZIP_SIZE_SHIFT_MAX) 360 361 /** Largest possible ssize for an uncompressed page. 362 (The convention 'ssize' is used for 'log2 minus 9' or the number of 363 shifts starting with 512.) 364 This max number varies depending on UNIV_PAGE_SIZE. */ 365 #define UNIV_PAGE_SSIZE_MAX \ 366 static_cast<ulint>(UNIV_PAGE_SIZE_SHIFT - UNIV_ZIP_SIZE_SHIFT_MIN + 1) 367 368 /** Smallest possible ssize for an uncompressed page. */ 369 #define UNIV_PAGE_SSIZE_MIN \ 370 static_cast<ulint>(UNIV_PAGE_SIZE_SHIFT_MIN - UNIV_ZIP_SIZE_SHIFT_MIN + 1) 371 372 /** Maximum number of parallel threads in a parallelized operation */ 373 #define UNIV_MAX_PARALLELISM 32 374 375 /** This is the "mbmaxlen" for my_charset_filename (defined in 376 strings/ctype-utf8.c), which is used to encode File and Database names. */ 377 #define FILENAME_CHARSET_MAXNAMLEN 5 378 379 /** The maximum length of an encode table name in bytes. The max 380 table and database names are NAME_CHAR_LEN (64) characters. After the 381 encoding, the max length would be NAME_CHAR_LEN (64) * 382 FILENAME_CHARSET_MAXNAMLEN (5) = 320 bytes. The number does not include a 383 terminating '\0'. InnoDB can handle longer names internally */ 384 #define MAX_TABLE_NAME_LEN 320 385 386 /** The maximum length of a database name. Like MAX_TABLE_NAME_LEN this is 387 the MySQL's NAME_LEN, see check_and_convert_db_name(). */ 388 #define MAX_DATABASE_NAME_LEN MAX_TABLE_NAME_LEN 389 390 /** MAX_FULL_NAME_LEN defines the full name path including the 391 database name and table name. In addition, 14 bytes is added for: 392 2 for surrounding quotes around table name 393 1 for the separating dot (.) 394 9 for the #mysql50# prefix */ 395 #define MAX_FULL_NAME_LEN \ 396 (MAX_TABLE_NAME_LEN + MAX_DATABASE_NAME_LEN + 14) 397 398 /** Maximum length of the compression alogrithm string. Currently we support 399 only (NONE | ZLIB | LZ4). */ 400 #define MAX_COMPRESSION_LEN 4 401 402 /** The maximum length in bytes that a database name can occupy when stored in 403 UTF8, including the terminating '\0', see dict_fs2utf8(). You must include 404 mysql_com.h if you are to use this macro. */ 405 #define MAX_DB_UTF8_LEN (NAME_LEN + 1) 406 407 /** The maximum length in bytes that a table name can occupy when stored in 408 UTF8, including the terminating '\0', see dict_fs2utf8(). You must include 409 mysql_com.h if you are to use this macro. */ 410 #define MAX_TABLE_UTF8_LEN (NAME_LEN + sizeof(srv_mysql50_table_name_prefix)) 411 412 /* 413 UNIVERSAL TYPE DEFINITIONS 414 ========================== 415 */ 416 417 /* Note that inside MySQL 'byte' is defined as char on Linux! */ 418 #define byte unsigned char 419 420 /* Another basic type we use is unsigned long integer which should be equal to 421 the word size of the machine, that is on a 32-bit platform 32 bits, and on a 422 64-bit platform 64 bits. We also give the printf format for the type as a 423 macro ULINTPF. */ 424 425 #ifdef _WIN32 426 /* Use the integer types and formatting strings defined in Visual Studio. */ 427 # define UINT32PF "%lu" 428 # define UINT64PF "%llu" 429 # define UINT64PFx "%016llx" 430 typedef unsigned __int64 ib_uint64_t; 431 typedef unsigned __int32 ib_uint32_t; 432 #else 433 /* Use the integer types and formatting strings defined in the C99 standard. */ 434 # define UINT32PF "%" PRIu32 435 # define UINT64PF "%" PRIu64 436 # define UINT64PFx "%016" PRIx64 437 typedef uint64_t ib_uint64_t; 438 typedef uint32_t ib_uint32_t; 439 #endif /* _WIN32 */ 440 441 #define IB_ID_FMT UINT64PF 442 443 #ifdef _WIN64 444 typedef unsigned __int64 ulint; 445 typedef __int64 lint; 446 # define ULINTPF UINT64PF 447 #else 448 typedef unsigned long int ulint; 449 typedef long int lint; 450 # define ULINTPF "%lu" 451 #endif /* _WIN64 */ 452 453 #ifndef _WIN32 454 #if SIZEOF_LONG != SIZEOF_VOIDP 455 #error "Error: InnoDB's ulint must be of the same size as void*" 456 #endif 457 #endif 458 459 /** The 'undefined' value for a ulint */ 460 #define ULINT_UNDEFINED ((ulint)(-1)) 461 462 #define ULONG_UNDEFINED ((ulong)(-1)) 463 464 /** The 'undefined' value for a ib_uint64_t */ 465 #define UINT64_UNDEFINED ((ib_uint64_t)(-1)) 466 467 /** The bitmask of 32-bit unsigned integer */ 468 #define ULINT32_MASK 0xFFFFFFFF 469 /** The undefined 32-bit unsigned integer */ 470 #define ULINT32_UNDEFINED ULINT32_MASK 471 472 /** Maximum value for a ulint */ 473 #define ULINT_MAX ((ulint)(-2)) 474 475 /** Maximum value for ib_uint64_t */ 476 #define IB_UINT64_MAX ((ib_uint64_t) (~0ULL)) 477 478 /** The generic InnoDB system object identifier data type */ 479 typedef ib_uint64_t ib_id_t; 480 #define IB_ID_MAX IB_UINT64_MAX 481 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((ulint) ptr, 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 ulint 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 #define UNIV_MEM_ASSERT_AND_FREE(addr, size) do { \ 646 UNIV_MEM_ASSERT_W(addr, size); \ 647 UNIV_MEM_FREE(addr, size); \ 648 } while (0) 649 #define UNIV_MEM_ASSERT_AND_ALLOC(addr, size) do { \ 650 UNIV_MEM_ASSERT_W(addr, size); \ 651 UNIV_MEM_ALLOC(addr, size); \ 652 } while (0) 653 654 extern ulong srv_page_size_shift; 655 extern ulong srv_page_size; 656 657 static const size_t UNIV_SECTOR_SIZE = 512; 658 659 /* Dimension of spatial object we support so far. It has its root in 660 myisam/sp_defs.h. We only support 2 dimension data */ 661 #define SPDIMS 2 662 663 #endif 664