Additional code to make sure and to assert that memory allocations have
8-byte alignment. Ticket #3777. (CVS 6450) FossilOrigin-Name: 208382e032134d9c78fe1cfcb98ce9defb4e3e26
This commit is contained in:
parent
3c71364643
commit
ea598cbd8d
22
manifest
22
manifest
@ -1,5 +1,5 @@
|
||||
C Allow\sthe\sjournal_size_limit\sto\sbe\slarger\sthan\s2147483647\sbytes.\s(CVS\s6449)
|
||||
D 2009-04-04T16:02:32
|
||||
C Additional\scode\sto\smake\ssure\sand\sto\sassert\sthat\smemory\sallocations\shave\n8-byte\salignment.\s\sTicket\s#3777.\s(CVS\s6450)
|
||||
D 2009-04-05T12:22:09
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@ -103,7 +103,7 @@ F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
|
||||
F src/backup.c 0082d0e5a63f04e88faee0dff0a7d63d3e92a78d
|
||||
F src/bitvec.c ef370407e03440b0852d05024fb016b14a471d3d
|
||||
F src/btmutex.c 341502bc496dc0840dcb00cde65680fb0e85c3ab
|
||||
F src/btree.c f4fdf5359f910dd9ac8d7bd92a67dae072b75f81
|
||||
F src/btree.c 457a71a1ebf490d5079ebe36d0213a8025d621a8
|
||||
F src/btree.h 8007018c1753944790c39610280894ab280210b8
|
||||
F src/btreeInt.h df64030d632f8c8ac217ed52e8b6b3eacacb33a5
|
||||
F src/build.c 72357fd75ef036d0afbf1756edab6d62c56fcf4b
|
||||
@ -129,7 +129,7 @@ F src/mem1.c e6d5c23941288df8191b8a98c28e3f57771e2270
|
||||
F src/mem2.c d02bd6a5b34f2d59012a852615621939d9c09548
|
||||
F src/mem3.c 67153ec933e08b70714055e872efb58a6b287939
|
||||
F src/mem5.c 838309b521c96a2a34507f74a5a739d28de4aac6
|
||||
F src/memjournal.c d6f5cc35cdba795fc3d39812c5669cc012b5ed6f
|
||||
F src/memjournal.c 1a987d078e7446a44417a1a6a01f80b48cf65b93
|
||||
F src/mutex.c 5e2ea0e0490a3567dc08a014bcee748c0cea727f
|
||||
F src/mutex.h 9e686e83a88838dac8b9c51271c651e833060f1e
|
||||
F src/mutex_noop.c f5a07671f25a1a9bd7c10ad7107bc2585446200f
|
||||
@ -143,7 +143,7 @@ F src/os_common.h 8c61457df58f1a4bd5f5adc3e90e01b37bf7afbc
|
||||
F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5
|
||||
F src/os_unix.c 5d667f24615043c937a138faaed5f3e93b8619b0
|
||||
F src/os_win.c 524fe4c31c469531191857e8036ef59bfb52d684
|
||||
F src/pager.c a8b53f7e4a821d5bc2e01477a5f10c9348ce1d7b
|
||||
F src/pager.c 1df277b7c78f780df119c9e2ddea6690979489c5
|
||||
F src/pager.h 0c9f3520c00d8a3b8e792ca56c9a11b6b02b4b0f
|
||||
F src/parse.y 070215cf461ab917c23253a9cbf0903f2b0d8f19
|
||||
F src/pcache.c 395f752a13574120bd7513a400ba02a265aaa76d
|
||||
@ -159,7 +159,7 @@ F src/select.c 462d9671e91accd983110fa38674be0d2a3daa66
|
||||
F src/shell.c 0a11f831603f17fea20ca97133c0f64e716af4a7
|
||||
F src/sqlite.h.in 59905c98fd40b3eb3c9a939a113858c75009b7b6
|
||||
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
|
||||
F src/sqliteInt.h 22114af78e17ab06b4ccd3b3f7db8ab14b5f2bb9
|
||||
F src/sqliteInt.h d1239060599bc45ed9e4668cb7759e6c433dd5ab
|
||||
F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d
|
||||
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
|
||||
F src/table.c 332ab0ea691e63862e2a8bdfe2c0617ee61062a3
|
||||
@ -204,9 +204,9 @@ F src/vdbe.c bddddefc5c7ec1c9cd3e4f9220eb813b43668605
|
||||
F src/vdbe.h d70a68bee196ab228914a3902c79dbd24342a0f2
|
||||
F src/vdbeInt.h 53a2f4696871712646c77351904576cca6ad9752
|
||||
F src/vdbeapi.c 950986b0f765b5b91aab1acb2b405d9450b749d1
|
||||
F src/vdbeaux.c 521187e184f642b3978c0ec00a0e165a45518ea6
|
||||
F src/vdbeaux.c d335ae5da63cd3b3a0f122e63d0e79e34a4e4fb1
|
||||
F src/vdbeblob.c e67757450ae8581a8b354d9d7e467e41502dfe38
|
||||
F src/vdbemem.c 53ab1c07800340d2ae100cb99537775a25b2efff
|
||||
F src/vdbemem.c 9798905787baae83d0b53b62030e32ecf7a0586f
|
||||
F src/vtab.c f1aba5a6dc1f83b97a39fbbc58ff8cbc76311347
|
||||
F src/walker.c 42bd3f00ca2ef5ae842304ec0d59903ef051412d
|
||||
F src/where.c 5a421d7265c79dc21c010e3218fd3abd448ec297
|
||||
@ -715,7 +715,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
P 11c77f4c2c2beee5267ea6e2f1a4bb845531b42c
|
||||
R 6fa763bbfd08cb93ca1062548d8a5a81
|
||||
P 81931259611ef10de731ea0e38cee92eb8629733
|
||||
R d1ec9689e8427e115f63f6ba1a6ce699
|
||||
U drh
|
||||
Z 3ec086d0c80add1adc32688c8dbd85a1
|
||||
Z d2872fc10d5a41a2536ecb51dcae9785
|
||||
|
@ -1 +1 @@
|
||||
81931259611ef10de731ea0e38cee92eb8629733
|
||||
208382e032134d9c78fe1cfcb98ce9defb4e3e26
|
@ -9,7 +9,7 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** $Id: btree.c,v 1.589 2009/04/02 20:16:59 drh Exp $
|
||||
** $Id: btree.c,v 1.590 2009/04/05 12:22:09 drh Exp $
|
||||
**
|
||||
** This file implements a external (disk-based) database using BTrees.
|
||||
** See the header comment on "btreeInt.h" for additional information.
|
||||
@ -5357,13 +5357,13 @@ static int balance_nonroot(BtCursor *pCur){
|
||||
}
|
||||
szCell = (u16*)&apCell[nMaxCells];
|
||||
aCopy[0] = (u8*)&szCell[nMaxCells];
|
||||
assert( ((aCopy[0] - (u8*)0) & 7)==0 ); /* 8-byte alignment required */
|
||||
assert( EIGHT_BYTE_ALIGNMENT(aCopy[0]) );
|
||||
for(i=1; i<NB; i++){
|
||||
aCopy[i] = &aCopy[i-1][pBt->pageSize+ROUND8(sizeof(MemPage))];
|
||||
assert( ((aCopy[i] - (u8*)0) & 7)==0 ); /* 8-byte alignment required */
|
||||
}
|
||||
aSpace1 = &aCopy[NB-1][pBt->pageSize+ROUND8(sizeof(MemPage))];
|
||||
assert( ((aSpace1 - (u8*)0) & 7)==0 ); /* 8-byte alignment required */
|
||||
assert( EIGHT_BYTE_ALIGNMENT(aSpace1) );
|
||||
if( ISAUTOVACUUM ){
|
||||
aFrom = &aSpace1[pBt->pageSize];
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
** The in-memory rollback journal is used to journal transactions for
|
||||
** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
|
||||
**
|
||||
** @(#) $Id: memjournal.c,v 1.10 2009/04/02 17:22:42 drh Exp $
|
||||
** @(#) $Id: memjournal.c,v 1.11 2009/04/05 12:22:09 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@ -237,6 +237,7 @@ static struct sqlite3_io_methods MemJournalMethods = {
|
||||
*/
|
||||
void sqlite3MemJournalOpen(sqlite3_file *pJfd){
|
||||
MemJournal *p = (MemJournal *)pJfd;
|
||||
assert( EIGHT_BYTE_ALIGNMENT(p) );
|
||||
memset(p, 0, sqlite3MemJournalSize());
|
||||
p->pMethod = &MemJournalMethods;
|
||||
}
|
||||
|
26
src/pager.c
26
src/pager.c
@ -18,7 +18,7 @@
|
||||
** file simultaneously, or one process from reading the database while
|
||||
** another is writing.
|
||||
**
|
||||
** @(#) $Id: pager.c,v 1.577 2009/04/04 15:53:48 drh Exp $
|
||||
** @(#) $Id: pager.c,v 1.578 2009/04/05 12:22:09 drh Exp $
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_DISKIO
|
||||
#include "sqliteInt.h"
|
||||
@ -3114,9 +3114,9 @@ int sqlite3PagerOpen(
|
||||
** source file journal.c).
|
||||
*/
|
||||
if( sqlite3JournalSize(pVfs)>sqlite3MemJournalSize() ){
|
||||
journalFileSize = sqlite3JournalSize(pVfs);
|
||||
journalFileSize = ROUND8(sqlite3JournalSize(pVfs));
|
||||
}else{
|
||||
journalFileSize = sqlite3MemJournalSize();
|
||||
journalFileSize = ROUND8(sqlite3MemJournalSize());
|
||||
}
|
||||
|
||||
/* Set the output variable to NULL in case an error occurs. */
|
||||
@ -3172,23 +3172,25 @@ int sqlite3PagerOpen(
|
||||
** Journal file name (nPathname+8+1 bytes)
|
||||
*/
|
||||
pPtr = (u8 *)sqlite3MallocZero(
|
||||
sizeof(*pPager) + /* Pager structure */
|
||||
pcacheSize + /* PCache object */
|
||||
pVfs->szOsFile + /* The main db file */
|
||||
journalFileSize * 2 + /* The two journal files */
|
||||
nPathname + 1 + /* zFilename */
|
||||
nPathname + 8 + 1 /* zJournal */
|
||||
ROUND8(sizeof(*pPager)) + /* Pager structure */
|
||||
ROUND8(pcacheSize) + /* PCache object */
|
||||
ROUND8(pVfs->szOsFile) + /* The main db file */
|
||||
journalFileSize * 2 + /* The two journal files */
|
||||
nPathname + 1 + /* zFilename */
|
||||
nPathname + 8 + 1 /* zJournal */
|
||||
);
|
||||
assert( EIGHT_BYTE_ALIGNMENT(journalFileSize) );
|
||||
if( !pPtr ){
|
||||
sqlite3_free(zPathname);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pPager = (Pager*)(pPtr);
|
||||
pPager->pPCache = (PCache*)(pPtr += sizeof(*pPager));
|
||||
pPager->fd = (sqlite3_file*)(pPtr += pcacheSize);
|
||||
pPager->sjfd = (sqlite3_file*)(pPtr += pVfs->szOsFile);
|
||||
pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager)));
|
||||
pPager->fd = (sqlite3_file*)(pPtr += ROUND8(pcacheSize));
|
||||
pPager->sjfd = (sqlite3_file*)(pPtr += ROUND8(pVfs->szOsFile));
|
||||
pPager->jfd = (sqlite3_file*)(pPtr += journalFileSize);
|
||||
pPager->zFilename = (char*)(pPtr += journalFileSize);
|
||||
assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
|
||||
|
||||
/* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
|
||||
if( zPathname ){
|
||||
|
@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** Internal interface definitions for SQLite.
|
||||
**
|
||||
** @(#) $Id: sqliteInt.h,v 1.850 2009/04/01 18:03:01 danielk1977 Exp $
|
||||
** @(#) $Id: sqliteInt.h,v 1.851 2009/04/05 12:22:09 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITEINT_H_
|
||||
#define _SQLITEINT_H_
|
||||
@ -455,6 +455,11 @@ extern const int sqlite3one;
|
||||
*/
|
||||
#define ROUNDDOWN8(x) ((x)&~7)
|
||||
|
||||
/*
|
||||
** Assert that the pointer X is aligned to an 8-byte boundary.
|
||||
*/
|
||||
#define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&7)==0)
|
||||
|
||||
/*
|
||||
** An instance of the following structure is used to store the busy-handler
|
||||
** callback for a given sqlite handle.
|
||||
|
@ -14,7 +14,7 @@
|
||||
** to version 2.8.7, all this code was combined into the vdbe.c source file.
|
||||
** But that file was getting too big so this subroutines were split out.
|
||||
**
|
||||
** $Id: vdbeaux.c,v 1.446 2009/03/25 15:43:09 danielk1977 Exp $
|
||||
** $Id: vdbeaux.c,v 1.447 2009/04/05 12:22:09 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
@ -1023,6 +1023,7 @@ static void allocSpace(
|
||||
u8 *pEnd, /* Pointer to 1 byte past the end of *ppFrom buffer */
|
||||
int *pnByte /* If allocation cannot be made, increment *pnByte */
|
||||
){
|
||||
assert( EIGHT_BYTE_ALIGNMENT(*ppFrom) );
|
||||
if( (*(void**)pp)==0 ){
|
||||
nByte = ROUND8(nByte);
|
||||
if( (pEnd - *ppFrom)>=nByte ){
|
||||
@ -1096,6 +1097,8 @@ void sqlite3VdbeMakeReady(
|
||||
if( isExplain && nMem<10 ){
|
||||
nMem = 10;
|
||||
}
|
||||
zCsr += (zCsr - (u8*)0)&7;
|
||||
assert( EIGHT_BYTE_ALIGNMENT(zCsr) );
|
||||
|
||||
do {
|
||||
memset(zCsr, 0, zEnd-zCsr);
|
||||
|
@ -15,7 +15,7 @@
|
||||
** only within the VDBE. Interface routines refer to a Mem using the
|
||||
** name sqlite_value
|
||||
**
|
||||
** $Id: vdbemem.c,v 1.139 2009/03/29 15:12:10 drh Exp $
|
||||
** $Id: vdbemem.c,v 1.140 2009/04/05 12:22:09 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
@ -209,6 +209,7 @@ int sqlite3VdbeMemStringify(Mem *pMem, int enc){
|
||||
assert( !(fg&(MEM_Str|MEM_Blob)) );
|
||||
assert( fg&(MEM_Int|MEM_Real) );
|
||||
assert( (pMem->flags&MEM_RowSet)==0 );
|
||||
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
|
||||
|
||||
|
||||
if( sqlite3VdbeMemGrow(pMem, nByte, 0) ){
|
||||
@ -345,6 +346,7 @@ static i64 doubleToInt64(double r){
|
||||
i64 sqlite3VdbeIntValue(Mem *pMem){
|
||||
int flags;
|
||||
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
|
||||
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
|
||||
flags = pMem->flags;
|
||||
if( flags & MEM_Int ){
|
||||
return pMem->u.i;
|
||||
@ -373,6 +375,7 @@ i64 sqlite3VdbeIntValue(Mem *pMem){
|
||||
*/
|
||||
double sqlite3VdbeRealValue(Mem *pMem){
|
||||
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
|
||||
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
|
||||
if( pMem->flags & MEM_Real ){
|
||||
return pMem->r;
|
||||
}else if( pMem->flags & MEM_Int ){
|
||||
@ -403,6 +406,7 @@ void sqlite3VdbeIntegerAffinity(Mem *pMem){
|
||||
assert( pMem->flags & MEM_Real );
|
||||
assert( (pMem->flags & MEM_RowSet)==0 );
|
||||
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
|
||||
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
|
||||
|
||||
pMem->u.i = doubleToInt64(pMem->r);
|
||||
if( pMem->r==(double)pMem->u.i ){
|
||||
@ -416,6 +420,8 @@ void sqlite3VdbeIntegerAffinity(Mem *pMem){
|
||||
int sqlite3VdbeMemIntegerify(Mem *pMem){
|
||||
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
|
||||
assert( (pMem->flags & MEM_RowSet)==0 );
|
||||
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
|
||||
|
||||
pMem->u.i = sqlite3VdbeIntValue(pMem);
|
||||
MemSetTypeFlag(pMem, MEM_Int);
|
||||
return SQLITE_OK;
|
||||
@ -427,6 +433,8 @@ int sqlite3VdbeMemIntegerify(Mem *pMem){
|
||||
*/
|
||||
int sqlite3VdbeMemRealify(Mem *pMem){
|
||||
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
|
||||
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
|
||||
|
||||
pMem->r = sqlite3VdbeRealValue(pMem);
|
||||
MemSetTypeFlag(pMem, MEM_Real);
|
||||
return SQLITE_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user