Unmark gen_random_uuid() function leakproof.
[pgsql.git] / src / include / storage / pg_shmem.h
blob3065ff5be71c1637d8fc35d405e54e0d0bebcb5b
1 /*-------------------------------------------------------------------------
3 * pg_shmem.h
4 * Platform-independent API for shared memory support.
6 * Every port is expected to support shared memory with approximately
7 * SysV-ish semantics; in particular, a memory block is not anonymous
8 * but has an ID, and we must be able to tell whether there are any
9 * remaining processes attached to a block of a specified ID.
11 * To simplify life for the SysV implementation, the ID is assumed to
12 * consist of two unsigned long values (these are key and ID in SysV
13 * terms). Other platforms may ignore the second value if they need
14 * only one ID number.
17 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
18 * Portions Copyright (c) 1994, Regents of the University of California
20 * src/include/storage/pg_shmem.h
22 *-------------------------------------------------------------------------
24 #ifndef PG_SHMEM_H
25 #define PG_SHMEM_H
27 #include "storage/dsm_impl.h"
29 typedef struct PGShmemHeader /* standard header for all Postgres shmem */
31 int32 magic; /* magic # to identify Postgres segments */
32 #define PGShmemMagic 679834894
33 pid_t creatorPID; /* PID of creating process (set but unread) */
34 Size totalsize; /* total size of segment */
35 Size freeoffset; /* offset to first free space */
36 dsm_handle dsm_control; /* ID of dynamic shared memory control seg */
37 void *index; /* pointer to ShmemIndex table */
38 #ifndef WIN32 /* Windows doesn't have useful inode#s */
39 dev_t device; /* device data directory is on */
40 ino_t inode; /* inode number of data directory */
41 #endif
42 } PGShmemHeader;
44 /* GUC variables */
45 extern PGDLLIMPORT int shared_memory_type;
46 extern PGDLLIMPORT int huge_pages;
47 extern PGDLLIMPORT int huge_page_size;
49 /* Possible values for huge_pages and huge_pages_status */
50 typedef enum
52 HUGE_PAGES_OFF,
53 HUGE_PAGES_ON,
54 HUGE_PAGES_TRY, /* only for huge_pages */
55 HUGE_PAGES_UNKNOWN, /* only for huge_pages_status */
56 } HugePagesType;
58 /* Possible values for shared_memory_type */
59 typedef enum
61 SHMEM_TYPE_WINDOWS,
62 SHMEM_TYPE_SYSV,
63 SHMEM_TYPE_MMAP,
64 } PGShmemType;
66 #ifndef WIN32
67 extern PGDLLIMPORT unsigned long UsedShmemSegID;
68 #else
69 extern PGDLLIMPORT HANDLE UsedShmemSegID;
70 extern PGDLLIMPORT void *ShmemProtectiveRegion;
71 #endif
72 extern PGDLLIMPORT void *UsedShmemSegAddr;
74 #if !defined(WIN32) && !defined(EXEC_BACKEND)
75 #define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_MMAP
76 #elif !defined(WIN32)
77 #define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_SYSV
78 #else
79 #define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_WINDOWS
80 #endif
82 #ifdef EXEC_BACKEND
83 extern void PGSharedMemoryReAttach(void);
84 extern void PGSharedMemoryNoReAttach(void);
85 #endif
87 extern PGShmemHeader *PGSharedMemoryCreate(Size size,
88 PGShmemHeader **shim);
89 extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2);
90 extern void PGSharedMemoryDetach(void);
91 extern void GetHugePageSize(Size *hugepagesize, int *mmap_flags);
93 #endif /* PG_SHMEM_H */