codekingpro/portable-devtools
114k
1/*-------------------------------------------------------------------------2 *3 * pg_shmem.h4 * Platform-independent API for shared memory support.5 *6 * Every port is expected to support shared memory with approximately7 * SysV-ish semantics; in particular, a memory block is not anonymous8 * but has an ID, and we must be able to tell whether there are any9 * remaining processes attached to a block of a specified ID.10 *11 * To simplify life for the SysV implementation, the ID is assumed to12 * consist of two unsigned long values (these are key and ID in SysV13 * terms). Other platforms may ignore the second value if they need14 * only one ID number.15 *16 *17 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group18 * Portions Copyright (c) 1994, Regents of the University of California19 *20 * src/include/storage/pg_shmem.h21 *22 *-------------------------------------------------------------------------23 */24#ifndef PG_SHMEM_H25#define PG_SHMEM_H26 27#include "storage/dsm_impl.h"28 29typedef struct PGShmemHeader /* standard header for all Postgres shmem */30{31 int32 magic; /* magic # to identify Postgres segments */32#define PGShmemMagic 67983489433 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#endif42} PGShmemHeader;43 44/* GUC variables */45extern PGDLLIMPORT int shared_memory_type;46extern PGDLLIMPORT int huge_pages;47extern PGDLLIMPORT int huge_page_size;48 49/* Possible values for huge_pages */50typedef enum51{52 HUGE_PAGES_OFF,53 HUGE_PAGES_ON,54 HUGE_PAGES_TRY55} HugePagesType;56 57/* Possible values for shared_memory_type */58typedef enum59{60 SHMEM_TYPE_WINDOWS,61 SHMEM_TYPE_SYSV,62 SHMEM_TYPE_MMAP63} PGShmemType;64 65#ifndef WIN3266extern PGDLLIMPORT unsigned long UsedShmemSegID;67#else68extern PGDLLIMPORT HANDLE UsedShmemSegID;69extern PGDLLIMPORT void *ShmemProtectiveRegion;70#endif71extern PGDLLIMPORT void *UsedShmemSegAddr;72 73#if !defined(WIN32) && !defined(EXEC_BACKEND)74#define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_MMAP75#elif !defined(WIN32)76#define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_SYSV77#else78#define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_WINDOWS79#endif80 81#ifdef EXEC_BACKEND82extern void PGSharedMemoryReAttach(void);83extern void PGSharedMemoryNoReAttach(void);84#endif85 86extern PGShmemHeader *PGSharedMemoryCreate(Size size,87 PGShmemHeader **shim);88extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2);89extern void PGSharedMemoryDetach(void);90extern void GetHugePageSize(Size *hugepagesize, int *mmap_flags);91 92#endif /* PG_SHMEM_H */93 