diff options
Diffstat (limited to 'src/include/storage/shmem.h')
-rw-r--r-- | src/include/storage/shmem.h | 56 |
1 files changed, 14 insertions, 42 deletions
diff --git a/src/include/storage/shmem.h b/src/include/storage/shmem.h index 4bee544fb63..cbfca69e674 100644 --- a/src/include/storage/shmem.h +++ b/src/include/storage/shmem.h @@ -3,11 +3,18 @@ * shmem.h * shared memory management structures * + * Historical note: + * A long time ago, Postgres' shared memory region was allowed to be mapped + * at a different address in each process, and shared memory "pointers" were + * passed around as offsets relative to the start of the shared memory region. + * That is no longer the case: each process must map the shared memory region + * at the same address. This means shared memory pointers can be passed + * around directly between different processes. * * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/storage/shmem.h,v 1.53 2008/01/01 19:45:59 momjian Exp $ + * $PostgreSQL: pgsql/src/include/storage/shmem.h,v 1.54 2008/11/02 21:24:52 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -17,53 +24,18 @@ #include "utils/hsearch.h" -/* - * The shared memory region can start at a different address - * in every process. Shared memory "pointers" are actually - * offsets relative to the start of the shared memory region(s). - * - * In current usage, this is not actually a problem, but we keep - * the code that used to handle it... - */ -typedef unsigned long SHMEM_OFFSET; - -#define INVALID_OFFSET (-1) - -/* - * Start of the primary shared memory region, in this process' address space. - * The macros in this header file can only cope with offsets into this - * shared memory region! - */ -extern PGDLLIMPORT SHMEM_OFFSET ShmemBase; - - -/* coerce an offset into a pointer in this process's address space */ -#define MAKE_PTR(xx_offs)\ - (ShmemBase+((unsigned long)(xx_offs))) - -/* coerce a pointer into a shmem offset */ -#define MAKE_OFFSET(xx_ptr)\ - ((SHMEM_OFFSET) (((unsigned long)(xx_ptr))-ShmemBase)) - -#define SHM_PTR_VALID(xx_ptr)\ - (((unsigned long)(xx_ptr)) > ShmemBase) - -/* cannot have an offset to ShmemFreeStart (offset 0) */ -#define SHM_OFFSET_VALID(xx_offs)\ - (((xx_offs) != 0) && ((xx_offs) != INVALID_OFFSET)) - /* shmqueue.c */ typedef struct SHM_QUEUE { - SHMEM_OFFSET prev; - SHMEM_OFFSET next; + struct SHM_QUEUE *prev; + struct SHM_QUEUE *next; } SHM_QUEUE; /* shmem.c */ extern void InitShmemAccess(void *seghdr); extern void InitShmemAllocation(void); extern void *ShmemAlloc(Size size); -extern bool ShmemIsValid(unsigned long addr); +extern bool ShmemAddrIsValid(void *addr); extern void InitShmemIndex(void); extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags); @@ -77,15 +49,15 @@ extern void RequestAddinShmemSpace(Size size); /* size constants for the shmem index table */ /* max size of data structure string name */ #define SHMEM_INDEX_KEYSIZE (48) - /* max size of the shmem index table (not a hard limit) */ + /* estimated size of the shmem index table (not a hard limit) */ #define SHMEM_INDEX_SIZE (32) /* this is a hash bucket in the shmem index table */ typedef struct { char key[SHMEM_INDEX_KEYSIZE]; /* string name */ - unsigned long location; /* location in shared mem */ - unsigned long size; /* numbytes allocated for the structure */ + void *location; /* location in shared mem */ + Size size; /* # bytes allocated for the structure */ } ShmemIndexEnt; /* |