Skip to content
Snippets Groups Projects
Commit 294dc053 authored by Vladislav Shpilevoy's avatar Vladislav Shpilevoy
Browse files

sql: make BtCursor's memory aligned

Vdbe at runtime allocates VdbeCursor structure using
allocateCursor() function. Inside there is a pointer at BtCursor
structure. To make the allocation faster and improve cache
locality, both cursors are allocated in one memory block + some
extra memory for uint32_t array, where BtCursor followed
VdbeCursor and the array without any padding:

   VdbeCursor + uint32_t * N + BtCursor

The problem is that BtCursor needs 8 byte alignment. When it
followed VdbeCursor (aligned by 8) + some uint32_t values, its
actual alignment could become 4 bytes. That led to a crash when
alignment sanitizer is enabled in clang.

The patch makes BtCursor offset aligned by 8 bytes.

Part of #4609
parent abef6986
No related branches found
No related tags found
Loading
......@@ -234,10 +234,9 @@ allocateCursor(
*/
Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem;
int nByte;
VdbeCursor *pCx = 0;
nByte =
ROUND8(sizeof(VdbeCursor)) + sizeof(u32)*nField +
int bt_offset = ROUND8(sizeof(VdbeCursor) + sizeof(uint32_t) * nField);
int nByte = bt_offset +
(eCurType==CURTYPE_TARANTOOL ? ROUND8(sizeof(BtCursor)) : 0);
assert(iCur>=0 && iCur<p->nCursor);
......@@ -251,8 +250,7 @@ allocateCursor(
pCx->eCurType = eCurType;
pCx->nField = nField;
if (eCurType==CURTYPE_TARANTOOL) {
pCx->uc.pCursor = (BtCursor*)
&pMem->z[ROUND8(sizeof(VdbeCursor))+sizeof(u32)*nField];
pCx->uc.pCursor = (BtCursor*)&pMem->z[bt_offset];
sqlCursorZero(pCx->uc.pCursor);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment