ds@1952: /* ds@1952: ** 2004 May 22 ds@1952: ** ds@1952: ** The author disclaims copyright to this source code. In place of ds@1952: ** a legal notice, here is a blessing: ds@1952: ** ds@1952: ** May you do good and not evil. ds@1952: ** May you find forgiveness for yourself and forgive others. ds@1952: ** May you share freely, never taking more than you give. ds@1952: ** ds@1952: ****************************************************************************** ds@1952: ** ds@1952: ** This file contains macros and a little bit of code that is common to ds@1952: ** all of the platform-specific files (os_*.c) and is #included into those ds@1952: ** files. ds@1952: ** ds@1952: ** This file should be #included by the os_*.c files only. It is not a ds@1952: ** general purpose header file. ds@1952: */ ds@1952: ds@1952: /* ds@1952: ** At least two bugs have slipped in because we changed the MEMORY_DEBUG ds@1952: ** macro to SQLITE_DEBUG and some older makefiles have not yet made the ds@1952: ** switch. The following code should catch this problem at compile-time. ds@1952: */ ds@1952: #ifdef MEMORY_DEBUG ds@1952: # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." ds@1952: #endif ds@1952: ds@1952: ds@1952: /* ds@1952: * When testing, this global variable stores the location of the ds@1952: * pending-byte in the database file. ds@1952: */ ds@1952: #ifdef SQLITE_TEST ds@1952: unsigned int sqlite3_pending_byte = 0x40000000; ds@1952: #endif ds@1952: ds@1952: #ifdef SQLITE_DEBUG ds@1952: int sqlite3_os_trace = 0; ds@1952: #define OSTRACE1(X) if( sqlite3_os_trace ) sqlite3DebugPrintf(X) ds@1952: #define OSTRACE2(X,Y) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y) ds@1952: #define OSTRACE3(X,Y,Z) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z) ds@1952: #define OSTRACE4(X,Y,Z,A) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A) ds@1952: #define OSTRACE5(X,Y,Z,A,B) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A,B) ds@1952: #define OSTRACE6(X,Y,Z,A,B,C) \ ds@1952: if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C) ds@1952: #define OSTRACE7(X,Y,Z,A,B,C,D) \ ds@1952: if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C,D) ds@1952: #else ds@1952: #define OSTRACE1(X) ds@1952: #define OSTRACE2(X,Y) ds@1952: #define OSTRACE3(X,Y,Z) ds@1952: #define OSTRACE4(X,Y,Z,A) ds@1952: #define OSTRACE5(X,Y,Z,A,B) ds@1952: #define OSTRACE6(X,Y,Z,A,B,C) ds@1952: #define OSTRACE7(X,Y,Z,A,B,C,D) ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** Macros for performance tracing. Normally turned off. Only works ds@1952: ** on i486 hardware. ds@1952: */ ds@1952: #ifdef SQLITE_PERFORMANCE_TRACE ds@1952: __inline__ unsigned long long int hwtime(void){ ds@1952: unsigned long long int x; ds@1952: __asm__("rdtsc\n\t" ds@1952: "mov %%edx, %%ecx\n\t" ds@1952: :"=A" (x)); ds@1952: return x; ds@1952: } ds@1952: static unsigned long long int g_start; ds@1952: static unsigned int elapse; ds@1952: #define TIMER_START g_start=hwtime() ds@1952: #define TIMER_END elapse=hwtime()-g_start ds@1952: #define TIMER_ELAPSED elapse ds@1952: #else ds@1952: #define TIMER_START ds@1952: #define TIMER_END ds@1952: #define TIMER_ELAPSED 0 ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** If we compile with the SQLITE_TEST macro set, then the following block ds@1952: ** of code will give us the ability to simulate a disk I/O error. This ds@1952: ** is used for testing the I/O recovery logic. ds@1952: */ ds@1952: #ifdef SQLITE_TEST ds@1952: int sqlite3_io_error_hit = 0; ds@1952: int sqlite3_io_error_pending = 0; ds@1952: int sqlite3_io_error_persist = 0; ds@1952: int sqlite3_diskfull_pending = 0; ds@1952: int sqlite3_diskfull = 0; ds@1952: #define SimulateIOError(CODE) \ ds@1952: if( sqlite3_io_error_pending || sqlite3_io_error_hit ) \ ds@1952: if( sqlite3_io_error_pending-- == 1 \ ds@1952: || (sqlite3_io_error_persist && sqlite3_io_error_hit) ) \ ds@1952: { local_ioerr(); CODE; } ds@1952: static void local_ioerr(){ ds@1952: IOTRACE(("IOERR\n")); ds@1952: sqlite3_io_error_hit = 1; ds@1952: } ds@1952: #define SimulateDiskfullError(CODE) \ ds@1952: if( sqlite3_diskfull_pending ){ \ ds@1952: if( sqlite3_diskfull_pending == 1 ){ \ ds@1952: local_ioerr(); \ ds@1952: sqlite3_diskfull = 1; \ ds@1952: sqlite3_io_error_hit = 1; \ ds@1952: CODE; \ ds@1952: }else{ \ ds@1952: sqlite3_diskfull_pending--; \ ds@1952: } \ ds@1952: } ds@1952: #else ds@1952: #define SimulateIOError(A) ds@1952: #define SimulateDiskfullError(A) ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** When testing, keep a count of the number of open files. ds@1952: */ ds@1952: #ifdef SQLITE_TEST ds@1952: int sqlite3_open_file_count = 0; ds@1952: #define OpenCounter(X) sqlite3_open_file_count+=(X) ds@1952: #else ds@1952: #define OpenCounter(X) ds@1952: #endif