1 /*-------------------------------------------------------------------------
2  *
3  * shmem.h
4  *	  shared memory management structures
5  *
6  * Historical note:
7  * A long time ago, Postgres' shared memory region was allowed to be mapped
8  * at a different address in each process, and shared memory "pointers" were
9  * passed around as offsets relative to the start of the shared memory region.
10  * That is no longer the case: each process must map the shared memory region
11  * at the same address.  This means shared memory pointers can be passed
12  * around directly between different processes.
13  *
14  * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
15  * Portions Copyright (c) 1994, Regents of the University of California
16  *
17  * src/include/storage/shmem.h
18  *
19  *-------------------------------------------------------------------------
20  */
21 #ifndef SHMEM_H
22 #define SHMEM_H
23 
24 #include "utils/hsearch.h"
25 
26 
27 /* shmqueue.c */
28 typedef struct SHM_QUEUE
29 {
30 	struct SHM_QUEUE *prev;
31 	struct SHM_QUEUE *next;
32 } SHM_QUEUE;
33 
34 /* shmem.c */
35 extern void InitShmemAccess(void *seghdr);
36 extern void InitShmemAllocation(void);
37 extern void *ShmemAlloc(Size size);
38 extern bool ShmemAddrIsValid(const void *addr);
39 extern void InitShmemIndex(void);
40 extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size,
41 			  HASHCTL *infoP, int hash_flags);
42 extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
43 extern Size add_size(Size s1, Size s2);
44 extern Size mul_size(Size s1, Size s2);
45 
46 /* ipci.c */
47 extern void RequestAddinShmemSpace(Size size);
48 
49 /* size constants for the shmem index table */
50  /* max size of data structure string name */
51 #define SHMEM_INDEX_KEYSIZE		 (48)
52  /* estimated size of the shmem index table (not a hard limit) */
53 #define SHMEM_INDEX_SIZE		 (64)
54 
55 /* this is a hash bucket in the shmem index table */
56 typedef struct
57 {
58 	char		key[SHMEM_INDEX_KEYSIZE];		/* string name */
59 	void	   *location;		/* location in shared mem */
60 	Size		size;			/* # bytes allocated for the structure */
61 } ShmemIndexEnt;
62 
63 /*
64  * prototypes for functions in shmqueue.c
65  */
66 extern void SHMQueueInit(SHM_QUEUE *queue);
67 extern void SHMQueueElemInit(SHM_QUEUE *queue);
68 extern void SHMQueueDelete(SHM_QUEUE *queue);
69 extern void SHMQueueInsertBefore(SHM_QUEUE *queue, SHM_QUEUE *elem);
70 extern void SHMQueueInsertAfter(SHM_QUEUE *queue, SHM_QUEUE *elem);
71 extern Pointer SHMQueueNext(const SHM_QUEUE *queue, const SHM_QUEUE *curElem,
72 			 Size linkOffset);
73 extern Pointer SHMQueuePrev(const SHM_QUEUE *queue, const SHM_QUEUE *curElem,
74 			 Size linkOffset);
75 extern bool SHMQueueEmpty(const SHM_QUEUE *queue);
76 extern bool SHMQueueIsDetached(const SHM_QUEUE *queue);
77 
78 #endif   /* SHMEM_H */
79