mirror of
https://github.com/postgres/postgres.git
synced 2025-11-13 16:22:44 +03:00
Add more critical-section calls: all code sections that hold spinlocks
are now critical sections, so as to ensure die() won't interrupt us while we are munging shared-memory data structures. Avoid insecure intermediate states in some code that proc_exit will call, like palloc/pfree. Rename START/END_CRIT_CODE to START/END_CRIT_SECTION, since that seems to be what people tend to call them anyway, and make them be called with () like a function call, in hopes of not confusing pg_indent. I doubt that this is sufficient to make SIGTERM safe anywhere; there's just too much code that could get invoked during proc_exit().
This commit is contained in:
5
src/backend/utils/cache/temprel.c
vendored
5
src/backend/utils/cache/temprel.c
vendored
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.32 2000/12/22 23:12:07 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.33 2001/01/12 21:54:00 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -263,8 +263,6 @@ AtEOXact_temp_relations(bool isCommit)
|
||||
temp_rel->created_in_cur_xact)
|
||||
{
|
||||
/* This entry must be removed */
|
||||
pfree(temp_rel);
|
||||
/* remove from linked list */
|
||||
if (prev != NIL)
|
||||
{
|
||||
lnext(prev) = lnext(l);
|
||||
@@ -277,6 +275,7 @@ AtEOXact_temp_relations(bool isCommit)
|
||||
pfree(l);
|
||||
l = temp_rels;
|
||||
}
|
||||
pfree(temp_rel);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.76 2000/12/18 00:44:48 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.77 2001/01/12 21:54:00 tgl Exp $
|
||||
*
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
@@ -395,11 +395,12 @@ ShutdownPostgres(void)
|
||||
* We don't want to do any inessential cleanup, since that just raises
|
||||
* the odds of failure --- but there's some stuff we need to do.
|
||||
*
|
||||
* Release any spinlocks that we may hold. This is a kluge to improve
|
||||
* the odds that we won't get into a self-made stuck spinlock scenario
|
||||
* while trying to shut down.
|
||||
* Release any spinlocks or buffer context locks we might be holding.
|
||||
* This is a kluge to improve the odds that we won't get into a self-made
|
||||
* stuck-spinlock scenario while trying to shut down.
|
||||
*/
|
||||
ProcReleaseSpins(NULL);
|
||||
UnlockBuffers();
|
||||
/*
|
||||
* In case a transaction is open, delete any files it created. This
|
||||
* has to happen before bufmgr shutdown, so having smgr register a
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.36 2001/01/06 21:59:39 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.37 2001/01/12 21:54:01 tgl Exp $
|
||||
*
|
||||
* NOTE:
|
||||
* This is a new (Feb. 05, 1999) implementation of the allocation set
|
||||
@@ -384,6 +384,11 @@ AllocSetReset(MemoryContext context)
|
||||
AllocSetCheck(context);
|
||||
#endif
|
||||
|
||||
/* Clear chunk freelists */
|
||||
MemSet(set->freelist, 0, sizeof(set->freelist));
|
||||
/* New blocks list is either empty or just the keeper block */
|
||||
set->blocks = set->keeper;
|
||||
|
||||
while (block != NULL)
|
||||
{
|
||||
AllocBlock next = block->next;
|
||||
@@ -411,11 +416,6 @@ AllocSetReset(MemoryContext context)
|
||||
}
|
||||
block = next;
|
||||
}
|
||||
|
||||
/* Now blocks list is either empty or just the keeper block */
|
||||
set->blocks = set->keeper;
|
||||
/* Clear chunk freelists in any case */
|
||||
MemSet(set->freelist, 0, sizeof(set->freelist));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -439,6 +439,11 @@ AllocSetDelete(MemoryContext context)
|
||||
AllocSetCheck(context);
|
||||
#endif
|
||||
|
||||
/* Make it look empty, just in case... */
|
||||
MemSet(set->freelist, 0, sizeof(set->freelist));
|
||||
set->blocks = NULL;
|
||||
set->keeper = NULL;
|
||||
|
||||
while (block != NULL)
|
||||
{
|
||||
AllocBlock next = block->next;
|
||||
@@ -450,11 +455,6 @@ AllocSetDelete(MemoryContext context)
|
||||
free(block);
|
||||
block = next;
|
||||
}
|
||||
|
||||
/* Make it look empty, just in case... */
|
||||
set->blocks = NULL;
|
||||
MemSet(set->freelist, 0, sizeof(set->freelist));
|
||||
set->keeper = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -605,15 +605,16 @@ AllocSetAlloc(MemoryContext context, Size size)
|
||||
}
|
||||
|
||||
chunk = (AllocChunk) (block->freeptr);
|
||||
|
||||
block->freeptr += (availchunk + ALLOC_CHUNKHDRSZ);
|
||||
availspace -= (availchunk + ALLOC_CHUNKHDRSZ);
|
||||
|
||||
chunk->size = availchunk;
|
||||
#ifdef MEMORY_CONTEXT_CHECKING
|
||||
chunk->requested_size = 0; /* mark it free */
|
||||
#endif
|
||||
chunk->aset = (void *) set->freelist[a_fidx];
|
||||
set->freelist[a_fidx] = chunk;
|
||||
|
||||
block->freeptr += (availchunk + ALLOC_CHUNKHDRSZ);
|
||||
availspace -= (availchunk + ALLOC_CHUNKHDRSZ);
|
||||
}
|
||||
|
||||
/* Mark that we need to create a new block */
|
||||
@@ -696,6 +697,10 @@ AllocSetAlloc(MemoryContext context, Size size)
|
||||
* OK, do the allocation
|
||||
*/
|
||||
chunk = (AllocChunk) (block->freeptr);
|
||||
|
||||
block->freeptr += (chunk_size + ALLOC_CHUNKHDRSZ);
|
||||
Assert(block->freeptr <= block->endptr);
|
||||
|
||||
chunk->aset = (void *) set;
|
||||
chunk->size = chunk_size;
|
||||
#ifdef MEMORY_CONTEXT_CHECKING
|
||||
@@ -705,9 +710,6 @@ AllocSetAlloc(MemoryContext context, Size size)
|
||||
((char *) AllocChunkGetPointer(chunk))[size] = 0x7E;
|
||||
#endif
|
||||
|
||||
block->freeptr += (chunk_size + ALLOC_CHUNKHDRSZ);
|
||||
Assert(block->freeptr <= block->endptr);
|
||||
|
||||
AllocAllocInfo(set, chunk);
|
||||
return AllocChunkGetPointer(chunk);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user