2
Licensed Materials - Property of IBM
3
DB2 Storage Engine Enablement
4
Copyright IBM Corporation 2007,2008
7
Redistribution and use in source and binary forms, with or without modification,
8
are permitted provided that the following conditions are met:
9
(a) Redistributions of source code must retain this list of conditions, the
10
copyright notice in section {d} below, and the disclaimer following this
12
(b) Redistributions in binary form must reproduce this list of conditions, the
13
copyright notice in section (d) below, and the disclaimer following this
14
list of conditions, in the documentation and/or other materials provided
15
with the distribution.
16
(c) The name of IBM may not be used to endorse or promote products derived from
17
this software without specific prior written permission.
18
(d) The text of the required copyright notice is:
19
Licensed Materials - Property of IBM
20
DB2 Storage Engine Enablement
21
Copyright IBM Corporation 2007,2008
24
THIS SOFTWARE IS PROVIDED BY IBM CORPORATION "AS IS" AND ANY EXPRESS OR IMPLIED
25
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27
SHALL IBM CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
37
#ifndef DB2I_BLOBCOLLECTION_H
38
#define DB2I_BLOBCOLLECTION_H
40
#include "db2i_global.h"
41
#include "db2i_file.h"
44
@class ProtectedBuffer
45
@brief Implements memory management for (optionally) protected buffers.
47
Buffers created with the protection option will have a guard page set on the
48
page following requested allocation size. The side effect is that the actual
49
allocation is up to 2*4096-1 bytes larger than the size requested by the
56
ProtectedBuffer() : protectBuf(false)
59
void Malloc(size_t size, bool protect = false)
62
bufptr.alloc(size + (protectBuf ? 0x1fff : 0x0));
63
if ((void*)bufptr != NULL)
67
mprotect(protectedPage(), 0x1000, PROT_NONE);
69
// Prevents a problem with DBUG_PRINT over-reading in recent versions of
71
*((char*)protectedPage()-1) = 0;
78
if ((void*)bufptr != NULL)
81
mprotect(protectedPage(), 0x1000, PROT_READ | PROT_WRITE);
91
ValidatedPointer<char>& ptr() {return bufptr;}
92
bool isProtected() const {return protectBuf;}
93
size_t allocLen() const {return len;}
97
return (void*)(((address64_t)(void*)bufptr + len + 0x1000) & ~0xfff);
100
ValidatedPointer<char> bufptr;
108
@class BlobCollection
109
@brief Manages memory allocation for reading blobs associated with a table.
111
Allocations are done on-demand and are protected with a guard page if less
112
than the max possible size is allocated.
117
BlobCollection(db2i_table* db2Table, uint32 defaultAllocSize) :
118
defaultAllocation(defaultAllocSize), table(db2Table)
120
buffers = new ProtectedBuffer[table->getBlobCount()];
128
ValidatedPointer<char>& getBufferPtr(int fieldIndex)
130
int blobIndex = table->getBlobIdFromField(fieldIndex);
131
if ((char*)buffers[blobIndex].ptr() == NULL)
132
generateBuffer(fieldIndex);
134
return buffers[blobIndex].ptr();
137
ValidatedPointer<char>& reallocBuffer(int fieldIndex, size_t size);
142
uint32 getSizeToAllocate(int fieldIndex, bool& shouldProtect);
143
void generateBuffer(int fieldIndex);
145
db2i_table* table; // The table being read
146
ProtectedBuffer* buffers; // The buffers
147
uint32 defaultAllocation;
148
/* The default size to use when first allocating a buffer */