mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-02-02 10:00:38 +01:00
Synch with FB1 changes.
This commit is contained in:
parent
0528cc5002
commit
eea9bdfe5a
@ -19,6 +19,7 @@
|
|||||||
*
|
*
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
* Contributor(s): ______________________________________.
|
* Contributor(s): ______________________________________.
|
||||||
|
* 02 Nov 2001: Mike Nordell - Synch with FB1 changes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -79,9 +80,9 @@ nested FOR loops are added.
|
|||||||
#include "../dsql/errd_proto.h"
|
#include "../dsql/errd_proto.h"
|
||||||
#include "../jrd/gds_proto.h"
|
#include "../jrd/gds_proto.h"
|
||||||
#include "../jrd/thd_proto.h"
|
#include "../jrd/thd_proto.h"
|
||||||
#include "../jrd/gdsassert.h"
|
|
||||||
|
|
||||||
ASSERT_FILENAME /* Define things dsql/assert needed */
|
ASSERT_FILENAME /* Define things dsql/assert needed */
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#define MIN_ALLOCATION 1024
|
#define MIN_ALLOCATION 1024
|
||||||
#if (defined PC_PLATFORM && !defined NETWARE_386)
|
#if (defined PC_PLATFORM && !defined NETWARE_386)
|
||||||
@ -157,7 +158,10 @@ BLK ALLD_alloc( PLB pool, UCHAR type, ULONG count)
|
|||||||
SLONG best_tail, tail;
|
SLONG best_tail, tail;
|
||||||
ULONG needed_blocks;
|
ULONG needed_blocks;
|
||||||
|
|
||||||
assert(pool != NULL);
|
if (!pool) {
|
||||||
|
BUGCHECK ("Bad pool, ALLD_alloc");
|
||||||
|
}
|
||||||
|
|
||||||
DEV_BLKCHK(pool, type_plb);
|
DEV_BLKCHK(pool, type_plb);
|
||||||
|
|
||||||
if (type <= (SCHAR) type_MIN || type >= (SCHAR) type_MAX)
|
if (type <= (SCHAR) type_MIN || type >= (SCHAR) type_MAX)
|
||||||
@ -167,45 +171,50 @@ BLK ALLD_alloc( PLB pool, UCHAR type, ULONG count)
|
|||||||
|
|
||||||
size = block_sizes[type].typ_root_length;
|
size = block_sizes[type].typ_root_length;
|
||||||
|
|
||||||
if ((tail = block_sizes[type].typ_tail_length) && count >= 1)
|
if ((tail = block_sizes[type].typ_tail_length) && count >= 1) {
|
||||||
size += (count - 1) * tail;
|
size += (count - 1) * tail;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEV_BUILD
|
if (size <= sizeof(struct blk) || size >= MAX_BLOCK) {
|
||||||
if (size <= sizeof(struct blk) || size >= MAX_BLOCK)
|
|
||||||
BUGCHECK("bad block size");
|
BUGCHECK("bad block size");
|
||||||
#endif
|
}
|
||||||
|
|
||||||
needed_blocks = SIZE_TO_BLOCKS(BLOCK_ROUNDUP(size));
|
needed_blocks = SIZE_TO_BLOCKS(BLOCK_ROUNDUP(size));
|
||||||
|
|
||||||
assert(BLOCKS_TO_SIZE(needed_blocks) >= size);
|
if (BLOCKS_TO_SIZE (needed_blocks) < size) {
|
||||||
|
BUGCHECK ("ALLD_alloc rounded down when it should round up");
|
||||||
|
}
|
||||||
|
|
||||||
/* Find best fit. Best fit is defined to be the free block of shortest
|
/* Find best fit. Best fit is defined to be the free block of shortest
|
||||||
tail. If there isn't a fit, extend the pool and try, try again. */
|
tail. If there isn't a fit, extend the pool and try, try again. */
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE)
|
||||||
|
{
|
||||||
best = NULL;
|
best = NULL;
|
||||||
best_tail = MAX_BLOCK;
|
best_tail = MAX_BLOCK;
|
||||||
for (ptr = &pool->plb_free; ((free = *ptr) != NULL);
|
for (ptr = &pool->plb_free; ((free = *ptr) != NULL); ptr = &free->frb_next)
|
||||||
ptr =
|
{
|
||||||
&free->frb_next) if ((SCHAR HUGE_PTR *) free ==
|
if ((SCHAR HUGE_PTR *) free == (SCHAR HUGE_PTR *) free->frb_next)
|
||||||
(SCHAR HUGE_PTR *) free->frb_next) {
|
{
|
||||||
BUGCHECK("corrupt pool");
|
BUGCHECK("corrupt pool");
|
||||||
}
|
}
|
||||||
/* Is this block big enough?
|
/* Is this block big enough?
|
||||||
* And have less leftover than the best one found? */
|
* And have less leftover than the best one found? */
|
||||||
else
|
else if (
|
||||||
if (
|
((tail =
|
||||||
((tail
|
|
||||||
=
|
|
||||||
((ULONG) free->frb_header.blk_length -
|
((ULONG) free->frb_header.blk_length -
|
||||||
needed_blocks)) >= 0) && (tail < best_tail)) {
|
needed_blocks)) >= 0) && (tail < best_tail))
|
||||||
|
{
|
||||||
best = ptr;
|
best = ptr;
|
||||||
best_tail = tail;
|
best_tail = tail;
|
||||||
if (tail == 0)
|
if (tail == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (best)
|
}
|
||||||
|
}
|
||||||
|
if (best) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
extend_pool(pool, size);
|
extend_pool(pool, size);
|
||||||
}
|
}
|
||||||
@ -215,17 +224,21 @@ BLK ALLD_alloc( PLB pool, UCHAR type, ULONG count)
|
|||||||
the entire free block as our block (a little extra won't hurt). */
|
the entire free block as our block (a little extra won't hurt). */
|
||||||
|
|
||||||
free = *best;
|
free = *best;
|
||||||
if (best_tail > SIZE_TO_BLOCKS(BLOCK_ROUNDUP(sizeof(struct frb)))) {
|
if (best_tail > SIZE_TO_BLOCKS(BLOCK_ROUNDUP(sizeof(struct frb))))
|
||||||
|
{
|
||||||
/* Carve off the needed size from the bottom of the free block */
|
/* Carve off the needed size from the bottom of the free block */
|
||||||
l = free->frb_header.blk_length - needed_blocks;
|
l = free->frb_header.blk_length - needed_blocks;
|
||||||
|
|
||||||
block = (BLK) ((UCHAR *) free + BLOCKS_TO_SIZE(l));
|
block = (BLK) ((UCHAR *) free + BLOCKS_TO_SIZE(l));
|
||||||
|
|
||||||
/* Reset the length of the free block */
|
/* Reset the length of the free block */
|
||||||
assert(l <= MAX_USHORT);
|
if (needed_blocks < 0) {
|
||||||
|
BUGCHECK ("ALLD_alloc: asking for less than nothing");
|
||||||
|
}
|
||||||
free->frb_header.blk_length = (USHORT) l;
|
free->frb_header.blk_length = (USHORT) l;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
/* There isn't left over in the free block to save in the free list */
|
/* There isn't left over in the free block to save in the free list */
|
||||||
/* So give the client the whole free block */
|
/* So give the client the whole free block */
|
||||||
|
|
||||||
@ -240,11 +253,17 @@ BLK ALLD_alloc( PLB pool, UCHAR type, ULONG count)
|
|||||||
/* Zero the whole allocated structure */
|
/* Zero the whole allocated structure */
|
||||||
memset(block, 0, BLOCKS_TO_SIZE(needed_blocks));
|
memset(block, 0, BLOCKS_TO_SIZE(needed_blocks));
|
||||||
|
|
||||||
/* Now set the block header (yeah, we just zero'ed it, sue me) */
|
/* Note that only the last 8 bits of the pool id are
|
||||||
|
stored in the block header. find_pool does the
|
||||||
|
necessary expansion */
|
||||||
|
|
||||||
block->blk_type = type;
|
block->blk_type = type;
|
||||||
assert(pool->plb_pool_id <= MAX_UCHAR);
|
|
||||||
block->blk_pool_id = (UCHAR)pool->plb_pool_id;
|
block->blk_pool_id = (UCHAR)pool->plb_pool_id;
|
||||||
assert(needed_blocks <= MAX_USHORT);
|
|
||||||
|
if (needed_blocks > (ULONG) MAX_USHORT) {
|
||||||
|
BUGCHECK ("ALLD_alloc: too greedy");
|
||||||
|
}
|
||||||
|
|
||||||
block->blk_length = (USHORT) needed_blocks;
|
block->blk_length = (USHORT) needed_blocks;
|
||||||
|
|
||||||
#ifdef SUPERSERVER
|
#ifdef SUPERSERVER
|
||||||
@ -276,8 +295,9 @@ BLK ALLD_extend(BLK * pointer, ULONG size)
|
|||||||
register SLONG *p1, *p2;
|
register SLONG *p1, *p2;
|
||||||
register SCHAR *c1, *c2;
|
register SCHAR *c1, *c2;
|
||||||
|
|
||||||
assert(pointer != NULL);
|
if (!pointer || !(*pointer)) {
|
||||||
assert(*pointer != NULL);
|
BUGCHECK ("bad pointer in ALLD_extend");
|
||||||
|
}
|
||||||
|
|
||||||
block = *pointer;
|
block = *pointer;
|
||||||
pool = find_pool(block);
|
pool = find_pool(block);
|
||||||
@ -289,25 +309,29 @@ BLK ALLD_extend(BLK * pointer, ULONG size)
|
|||||||
|
|
||||||
/* Copy the bytes a longword at a time */
|
/* Copy the bytes a longword at a time */
|
||||||
if ((l = length >> SHIFTLONG) != 0)
|
if ((l = length >> SHIFTLONG) != 0)
|
||||||
do
|
{
|
||||||
|
do {
|
||||||
*p1++ = *p2++;
|
*p1++ = *p2++;
|
||||||
while (--l);
|
} while (--l);
|
||||||
|
}
|
||||||
|
|
||||||
/* Copy any remaining bytes */
|
/* Copy any remaining bytes */
|
||||||
if (length &= 3) {
|
if (length &= 3)
|
||||||
|
{
|
||||||
c1 = (SCHAR *) p1;
|
c1 = (SCHAR *) p1;
|
||||||
c2 = (SCHAR *) p2;
|
c2 = (SCHAR *) p2;
|
||||||
do
|
do {
|
||||||
*c1++ = *c2++;
|
*c1++ = *c2++;
|
||||||
while (--length);
|
} while (--length);
|
||||||
}
|
}
|
||||||
|
|
||||||
release(reinterpret_cast<FRB>(block), pool);
|
release(reinterpret_cast<FRB>(block), pool);
|
||||||
|
|
||||||
if (new_->blk_type == (SCHAR) type_vec)
|
if (new_->blk_type == (SCHAR) type_vec) {
|
||||||
((VEC) new_)->vec_count = size;
|
((VEC) new_)->vec_count = size;
|
||||||
else if (new_->blk_type == (SCHAR) type_vcl)
|
} else if (new_->blk_type == (SCHAR) type_vcl) {
|
||||||
((VCL) new_)->vcl_count = size;
|
((VCL) new_)->vcl_count = size;
|
||||||
|
}
|
||||||
|
|
||||||
*pointer = new_;
|
*pointer = new_;
|
||||||
|
|
||||||
@ -330,7 +354,9 @@ void ALLD_fini(void)
|
|||||||
BLK *vector, *until;
|
BLK *vector, *until;
|
||||||
PLB pool;
|
PLB pool;
|
||||||
|
|
||||||
assert(init_flag); /* Must _init before _fini */
|
if (!init_flag) { // Must _init before _fini
|
||||||
|
BUGCHECK ("ALLD_fini - finishing before starting");
|
||||||
|
}
|
||||||
|
|
||||||
/* if there are no pools, we've already finished. */
|
/* if there are no pools, we've already finished. */
|
||||||
|
|
||||||
@ -341,10 +367,13 @@ void ALLD_fini(void)
|
|||||||
* objects in reverse order, and be careful not to refer to pools
|
* objects in reverse order, and be careful not to refer to pools
|
||||||
* during the process.
|
* during the process.
|
||||||
*/
|
*/
|
||||||
for (vector = pools->vec_object + pools->vec_count, until =
|
for (vector = pools->vec_object + pools->vec_count,
|
||||||
pools->vec_object; --vector >= until;)
|
until = pools->vec_object; --vector >= until;)
|
||||||
if ((pool = (PLB) * vector) != NULL)
|
{
|
||||||
|
if ((pool = (PLB) * vector) != NULL) {
|
||||||
ALLD_rlpool(pool);
|
ALLD_rlpool(pool);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pools = NULL;
|
pools = NULL;
|
||||||
init_flag = FALSE;
|
init_flag = FALSE;
|
||||||
@ -394,7 +423,8 @@ USHORT ALLD_init(void)
|
|||||||
tdsql = GET_THREAD_DATA;
|
tdsql = GET_THREAD_DATA;
|
||||||
|
|
||||||
init = (init_flag == FALSE);
|
init = (init_flag == FALSE);
|
||||||
if (!init_flag) {
|
if (!init_flag)
|
||||||
|
{
|
||||||
init_flag = TRUE;
|
init_flag = TRUE;
|
||||||
|
|
||||||
pools = (VEC) temp_vector;
|
pools = (VEC) temp_vector;
|
||||||
@ -451,7 +481,7 @@ void* ALLD_malloc(ULONG size)
|
|||||||
* promply depends on tdsql being non-NULL. Knock, knock, anyone home?
|
* promply depends on tdsql being non-NULL. Knock, knock, anyone home?
|
||||||
*/
|
*/
|
||||||
IBERROR(-1, "out of memory");
|
IBERROR(-1, "out of memory");
|
||||||
return ((UCHAR *) NULL); /* Added to remove warnings */
|
return 0; // Not reached
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -493,7 +523,7 @@ PLB ALLD_pool(void)
|
|||||||
if (trace_pools)
|
if (trace_pools)
|
||||||
{
|
{
|
||||||
temp_pool.plb_blk_type_count =
|
temp_pool.plb_blk_type_count =
|
||||||
reinterpret_cast <long*>(gds__alloc(sizeof(alld_block_type_count)));
|
reinterpret_cast <SLONG*>(gds__alloc(sizeof(alld_block_type_count)));
|
||||||
if (!temp_pool.plb_blk_type_count) {
|
if (!temp_pool.plb_blk_type_count) {
|
||||||
trace_pools = 0; /* No memory!! stop tracing pool info */
|
trace_pools = 0; /* No memory!! stop tracing pool info */
|
||||||
} else {
|
} else {
|
||||||
@ -502,8 +532,9 @@ PLB ALLD_pool(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (pool_id == 0)
|
if (pool_id == 0) {
|
||||||
DSQL_permanent_pool = &temp_pool;
|
DSQL_permanent_pool = &temp_pool;
|
||||||
|
}
|
||||||
|
|
||||||
pool = (PLB) ALLD_alloc(&temp_pool, type_plb, 0);
|
pool = (PLB) ALLD_alloc(&temp_pool, type_plb, 0);
|
||||||
pool->plb_pool_id = pool_id;
|
pool->plb_pool_id = pool_id;
|
||||||
@ -514,8 +545,9 @@ PLB ALLD_pool(void)
|
|||||||
#endif
|
#endif
|
||||||
pools->vec_object[pool_id] = (BLK) pool;
|
pools->vec_object[pool_id] = (BLK) pool;
|
||||||
|
|
||||||
if (pool_id == 0)
|
if (pool_id == 0) {
|
||||||
DSQL_permanent_pool = pool;
|
DSQL_permanent_pool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
@ -539,19 +571,24 @@ void ALLD_print_memory_pool_info( IB_FILE * fptr)
|
|||||||
HNK hnk;
|
HNK hnk;
|
||||||
int i, j, col;
|
int i, j, col;
|
||||||
|
|
||||||
if (!trace_pools)
|
if (!trace_pools) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ib_fprintf(fptr, "\n\tALLD_xx block types\n");
|
ib_fprintf(fptr, "\n\tALLD_xx block types\n");
|
||||||
ib_fprintf(fptr, "\t--------------------");
|
ib_fprintf(fptr, "\t--------------------");
|
||||||
for (i = 0, col = 0; i < type_MAX; i++)
|
for (i = 0, col = 0; i < type_MAX; i++)
|
||||||
if (alld_block_type_count[i]) {
|
{
|
||||||
if (col % 5 == 0)
|
if (alld_block_type_count[i])
|
||||||
|
{
|
||||||
|
if (col % 5 == 0) {
|
||||||
ib_fprintf(fptr, "\n\t");
|
ib_fprintf(fptr, "\n\t");
|
||||||
|
}
|
||||||
ib_fprintf(fptr, "%s = %d ", ALLD_types[i],
|
ib_fprintf(fptr, "%s = %d ", ALLD_types[i],
|
||||||
alld_block_type_count[i]);
|
alld_block_type_count[i]);
|
||||||
++col;
|
++col;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ib_fprintf(fptr, "\n");
|
ib_fprintf(fptr, "\n");
|
||||||
|
|
||||||
if (!pools) {
|
if (!pools) {
|
||||||
@ -559,31 +596,40 @@ void ALLD_print_memory_pool_info( IB_FILE * fptr)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vector = pools;
|
vector = pools;
|
||||||
for (j = 0, i = 0; i < (int) vector->vec_count; i++) {
|
for (j = 0, i = 0; i < (int) vector->vec_count; i++)
|
||||||
|
{
|
||||||
myPool = (PLB) vector->vec_object[i];
|
myPool = (PLB) vector->vec_object[i];
|
||||||
if (myPool)
|
if (myPool) {
|
||||||
++j;
|
++j;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ib_fprintf(fptr, "\t There are %d pools", j);
|
ib_fprintf(fptr, "\t There are %d pools", j);
|
||||||
for (i = 0; i < (int) vector->vec_count; i++) {
|
for (i = 0; i < (int) vector->vec_count; i++)
|
||||||
|
{
|
||||||
myPool = (PLB) vector->vec_object[i];
|
myPool = (PLB) vector->vec_object[i];
|
||||||
if (!myPool)
|
if (!myPool) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
ib_fprintf(fptr, "\n\t Pool %d", myPool->plb_pool_id);
|
ib_fprintf(fptr, "\n\t Pool %d", myPool->plb_pool_id);
|
||||||
for (j = 0, hnk = myPool->plb_hunks; hnk; hnk = hnk->hnk_next)
|
for (j = 0, hnk = myPool->plb_hunks; hnk; hnk = hnk->hnk_next) {
|
||||||
j++;
|
j++;
|
||||||
if (j)
|
}
|
||||||
|
if (j) {
|
||||||
ib_fprintf(fptr, " has %d hunks", j);
|
ib_fprintf(fptr, " has %d hunks", j);
|
||||||
|
}
|
||||||
for (j = 0, col = 0; j < type_MAX; j++)
|
for (j = 0, col = 0; j < type_MAX; j++)
|
||||||
|
{
|
||||||
if (myPool->plb_blk_type_count[j]) {
|
if (myPool->plb_blk_type_count[j]) {
|
||||||
if (col % 5 == 0)
|
if (col % 5 == 0) {
|
||||||
ib_fprintf(fptr, "\n\t ");
|
ib_fprintf(fptr, "\n\t ");
|
||||||
|
}
|
||||||
ib_fprintf(fptr, "%s = %d ", ALLD_types[j],
|
ib_fprintf(fptr, "%s = %d ", ALLD_types[j],
|
||||||
myPool->plb_blk_type_count[j]);
|
myPool->plb_blk_type_count[j]);
|
||||||
++col;
|
++col;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -750,14 +796,17 @@ static void extend_pool( PLB pool, ULONG size)
|
|||||||
|
|
||||||
DEV_BLKCHK(pool, type_plb);
|
DEV_BLKCHK(pool, type_plb);
|
||||||
|
|
||||||
size =
|
size = (size + sizeof(struct hnk) + MIN_ALLOCATION - 1)
|
||||||
(size + sizeof(struct hnk) + MIN_ALLOCATION -
|
& ~((ULONG) MIN_ALLOCATION - 1);
|
||||||
1) & ~((ULONG) MIN_ALLOCATION - 1);
|
|
||||||
block = (BLK) ALLD_malloc(size);
|
block = (BLK) ALLD_malloc(size);
|
||||||
assert(SIZE_TO_BLOCKS(size) <= MAX_USHORT);
|
|
||||||
|
if (SIZE_TO_BLOCKS (size) > MAX_USHORT) {
|
||||||
|
BUGCHECK ("too greedy in extend pool of alld.c");
|
||||||
|
}
|
||||||
|
|
||||||
block->blk_length = (USHORT) SIZE_TO_BLOCKS(size);
|
block->blk_length = (USHORT) SIZE_TO_BLOCKS(size);
|
||||||
block->blk_type = (SCHAR) type_frb;
|
block->blk_type = (SCHAR) type_frb;
|
||||||
assert(pool->plb_pool_id <= MAX_UCHAR);
|
|
||||||
block->blk_pool_id = (UCHAR) pool->plb_pool_id;
|
block->blk_pool_id = (UCHAR) pool->plb_pool_id;
|
||||||
#ifdef SUPERSERVER
|
#ifdef SUPERSERVER
|
||||||
if (trace_pools) {
|
if (trace_pools) {
|
||||||
@ -792,22 +841,34 @@ static PLB find_pool( BLK block)
|
|||||||
USHORT pool_id;
|
USHORT pool_id;
|
||||||
|
|
||||||
if (pools->vec_count < 256)
|
if (pools->vec_count < 256)
|
||||||
|
{
|
||||||
if ((pool_id = block->blk_pool_id) < pools->vec_count &&
|
if ((pool_id = block->blk_pool_id) < pools->vec_count &&
|
||||||
(pool = (PLB) pools->vec_object[pool_id]))
|
(pool = (PLB) pools->vec_object[pool_id]))
|
||||||
|
{
|
||||||
return pool;
|
return pool;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
BUGCHECK("bad pool id");
|
BUGCHECK("bad pool id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (pool_id = block->blk_pool_id; pool_id < pools->vec_count;
|
for (pool_id = block->blk_pool_id; pool_id < pools->vec_count; pool_id += 256)
|
||||||
pool_id += 256) if (pool = (PLB) pools->vec_object[pool_id]) {
|
{
|
||||||
|
if (pool = (PLB) pools->vec_object[pool_id])
|
||||||
|
{
|
||||||
hunk = pool->plb_hunks;
|
hunk = pool->plb_hunks;
|
||||||
for (; hunk; hunk = hunk->hnk_next)
|
for (; hunk; hunk = hunk->hnk_next)
|
||||||
if ((SCHAR HUGE_PTR *) block >=
|
{
|
||||||
(SCHAR HUGE_PTR *) hunk->hnk_address
|
if ((SCHAR HUGE_PTR *) block >= (SCHAR HUGE_PTR *) hunk->hnk_address
|
||||||
&& (SCHAR HUGE_PTR *) block <
|
&& (SCHAR HUGE_PTR *) block <
|
||||||
(SCHAR HUGE_PTR *) hunk->hnk_address + hunk->hnk_length)
|
(SCHAR HUGE_PTR *) hunk->hnk_address + hunk->hnk_length)
|
||||||
|
{
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BUGCHECK("bad pool id");
|
BUGCHECK("bad pool id");
|
||||||
return (PLB) NULL; /* Added to remove warnings */
|
return (PLB) NULL; /* Added to remove warnings */
|
||||||
}
|
}
|
||||||
@ -830,22 +891,23 @@ static void release( FRB block, PLB pool)
|
|||||||
**************************************/
|
**************************************/
|
||||||
register FRB prior, free;
|
register FRB prior, free;
|
||||||
FRB* ptr;
|
FRB* ptr;
|
||||||
#ifdef SUPERSERVER
|
|
||||||
UCHAR blk_header_type;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DEV_BLKCHK(pool, type_plb);
|
DEV_BLKCHK(pool, type_plb);
|
||||||
|
|
||||||
#ifdef SUPERSERVER
|
#ifdef SUPERSERVER
|
||||||
blk_header_type = block->frb_header.blk_type;
|
UCHAR blk_header_type = block->frb_header.blk_type;
|
||||||
#endif
|
#endif
|
||||||
block->frb_header.blk_type = (SCHAR) type_frb;
|
block->frb_header.blk_type = (SCHAR) type_frb;
|
||||||
prior = NULL;
|
prior = NULL;
|
||||||
|
|
||||||
for (ptr = &pool->plb_free; (free = *ptr) != NULL;
|
for (ptr = &pool->plb_free; (free = *ptr) != NULL;
|
||||||
prior = free, ptr =
|
prior = free, ptr = &free->frb_next)
|
||||||
&free->frb_next) if ((SCHAR HUGE_PTR *) block <=
|
{
|
||||||
(SCHAR HUGE_PTR *) free) break;
|
if ((SCHAR HUGE_PTR *) block <= (SCHAR HUGE_PTR *) free)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_GDS_ALLOC
|
#ifdef DEBUG_GDS_ALLOC
|
||||||
/* Debugging code to erase memory locations after a release -
|
/* Debugging code to erase memory locations after a release -
|
||||||
@ -859,11 +921,16 @@ static void release( FRB block, PLB pool)
|
|||||||
{
|
{
|
||||||
ULONG size;
|
ULONG size;
|
||||||
size = BLOCKS_TO_SIZE(block->frb_header.blk_length);
|
size = BLOCKS_TO_SIZE(block->frb_header.blk_length);
|
||||||
assert(size >= sizeof(struct blk));
|
if (size < sizeof (struct blk))
|
||||||
|
{
|
||||||
|
BUGCHECK ("Releasing less that 4 bytes: alld.c/release");
|
||||||
|
}
|
||||||
size -= sizeof(struct blk);
|
size -= sizeof(struct blk);
|
||||||
if (size)
|
if (size)
|
||||||
|
{
|
||||||
memset((SCHAR *) block + sizeof(struct blk),
|
memset((SCHAR *) block + sizeof(struct blk),
|
||||||
ALLD_RELEASED_PATTERN, size);
|
ALLD_RELEASED_PATTERN, size);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
#endif /* DEBUG_GDS_ALLOC */
|
#endif /* DEBUG_GDS_ALLOC */
|
||||||
|
|
||||||
@ -878,9 +945,11 @@ static void release( FRB block, PLB pool)
|
|||||||
|
|
||||||
/* Try to merge the free block with the next one down. */
|
/* Try to merge the free block with the next one down. */
|
||||||
|
|
||||||
if (free) {
|
if (free)
|
||||||
|
{
|
||||||
if ((SCHAR HUGE_PTR *) block + EXPAND_BLOCKSIZE(&block->frb_header) ==
|
if ((SCHAR HUGE_PTR *) block + EXPAND_BLOCKSIZE(&block->frb_header) ==
|
||||||
(SCHAR HUGE_PTR *) free) {
|
(SCHAR HUGE_PTR *) free)
|
||||||
|
{
|
||||||
block->frb_header.blk_length += free->frb_header.blk_length;
|
block->frb_header.blk_length += free->frb_header.blk_length;
|
||||||
block->frb_next = free->frb_next;
|
block->frb_next = free->frb_next;
|
||||||
#ifdef DEBUG_GDS_ALLOC
|
#ifdef DEBUG_GDS_ALLOC
|
||||||
@ -890,16 +959,19 @@ static void release( FRB block, PLB pool)
|
|||||||
}
|
}
|
||||||
else if ((SCHAR HUGE_PTR *) block +
|
else if ((SCHAR HUGE_PTR *) block +
|
||||||
EXPAND_BLOCKSIZE(&block->frb_header) >
|
EXPAND_BLOCKSIZE(&block->frb_header) >
|
||||||
(SCHAR HUGE_PTR *) free) {
|
(SCHAR HUGE_PTR *) free)
|
||||||
|
{
|
||||||
BUGCHECK("released block overlaps following free block");
|
BUGCHECK("released block overlaps following free block");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try and merge the block with the prior free block */
|
/* Try and merge the block with the prior free block */
|
||||||
|
|
||||||
if (prior) {
|
if (prior)
|
||||||
|
{
|
||||||
if ((SCHAR HUGE_PTR *) prior + EXPAND_BLOCKSIZE(&prior->frb_header) ==
|
if ((SCHAR HUGE_PTR *) prior + EXPAND_BLOCKSIZE(&prior->frb_header) ==
|
||||||
(SCHAR HUGE_PTR *) block) {
|
(SCHAR HUGE_PTR *) block)
|
||||||
|
{
|
||||||
prior->frb_header.blk_length += block->frb_header.blk_length;
|
prior->frb_header.blk_length += block->frb_header.blk_length;
|
||||||
prior->frb_next = block->frb_next;
|
prior->frb_next = block->frb_next;
|
||||||
#ifdef DEBUG_GDS_ALLOC
|
#ifdef DEBUG_GDS_ALLOC
|
||||||
@ -909,7 +981,8 @@ static void release( FRB block, PLB pool)
|
|||||||
}
|
}
|
||||||
else if ((SCHAR HUGE_PTR *) prior +
|
else if ((SCHAR HUGE_PTR *) prior +
|
||||||
EXPAND_BLOCKSIZE(&prior->frb_header) >
|
EXPAND_BLOCKSIZE(&prior->frb_header) >
|
||||||
(SCHAR HUGE_PTR *) block) {
|
(SCHAR HUGE_PTR *) block)
|
||||||
|
{
|
||||||
BUGCHECK("released block overlaps prior free block");
|
BUGCHECK("released block overlaps prior free block");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user