diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-08-20 23:26:37 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-08-20 23:26:37 +0000 |
commit | 0007490e0964d194a606ba79bb11ae1642da3372 (patch) | |
tree | 91db8ec49d812ba2c4307fcf858dfb7fd3890819 /src/backend/storage/ipc/shmem.c | |
parent | 2299ceab1cc5e141431f19eaf70c30f0d84eb28b (diff) |
Convert the arithmetic for shared memory size calculation from 'int'
to 'Size' (that is, size_t), and install overflow detection checks in it.
This allows us to remove the former arbitrary restrictions on NBuffers
etc. It won't make any difference in a 32-bit machine, but in a 64-bit
machine you could theoretically have terabytes of shared buffers.
(How efficiently we could manage 'em remains to be seen.) Similarly,
num_temp_buffers, work_mem, and maintenance_work_mem can be set above
2Gb on a 64-bit machine. Original patch from Koichi Suzuki, additional
work by moi.
Diffstat (limited to 'src/backend/storage/ipc/shmem.c')
-rw-r--r-- | src/backend/storage/ipc/shmem.c | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index 9af059139e7..76b3ef26cc4 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.84 2005/05/29 04:23:04 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.85 2005/08/20 23:26:20 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -141,8 +141,8 @@ InitShmemAllocation(void *seghdr, bool init) void * ShmemAlloc(Size size) { - uint32 newStart; - uint32 newFree; + Size newStart; + Size newFree; void *newSpace; /* use volatile pointer to prevent code rearrangement */ @@ -415,3 +415,40 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr) SpinLockRelease(ShmemIndexLock); return structPtr; } + + +/* + * Add two Size values, checking for overflow + */ +Size +add_size(Size s1, Size s2) +{ + Size result; + + result = s1 + s2; + /* We are assuming Size is an unsigned type here... */ + if (result < s1 || result < s2) + ereport(ERROR, + (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("requested shared memory size overflows size_t"))); + return result; +} + +/* + * Multiply two Size values, checking for overflow + */ +Size +mul_size(Size s1, Size s2) +{ + Size result; + + if (s1 == 0 || s2 == 0) + return 0; + result = s1 * s2; + /* We are assuming Size is an unsigned type here... */ + if (result / s2 != s1) + ereport(ERROR, + (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("requested shared memory size overflows size_t"))); + return result; +} |