| 1 | /*------------------------------------------------------------------------- |
| 2 | * |
| 3 | * dsm_impl.h |
| 4 | * low-level dynamic shared memory primitives |
| 5 | * |
| 6 | * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
| 7 | * Portions Copyright (c) 1994, Regents of the University of California |
| 8 | * |
| 9 | * src/include/storage/dsm_impl.h |
| 10 | * |
| 11 | *------------------------------------------------------------------------- |
| 12 | */ |
| 13 | #ifndef DSM_IMPL_H |
| 14 | #define DSM_IMPL_H |
| 15 | |
| 16 | /* Dynamic shared memory implementations. */ |
| 17 | #define DSM_IMPL_POSIX 1 |
| 18 | #define DSM_IMPL_SYSV 2 |
| 19 | #define DSM_IMPL_WINDOWS 3 |
| 20 | #define DSM_IMPL_MMAP 4 |
| 21 | |
| 22 | /* |
| 23 | * Determine which dynamic shared memory implementations will be supported |
| 24 | * on this platform, and which one will be the default. |
| 25 | */ |
| 26 | #ifdef WIN32 |
| 27 | #define USE_DSM_WINDOWS |
| 28 | #define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_WINDOWS |
| 29 | #else |
| 30 | #ifdef HAVE_SHM_OPEN |
| 31 | #define USE_DSM_POSIX |
| 32 | #define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_POSIX |
| 33 | #endif |
| 34 | #define USE_DSM_SYSV |
| 35 | #ifndef DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE |
| 36 | #define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_SYSV |
| 37 | #endif |
| 38 | #define USE_DSM_MMAP |
| 39 | #endif |
| 40 | |
| 41 | /* GUC. */ |
| 42 | extern int dynamic_shared_memory_type; |
| 43 | |
| 44 | /* |
| 45 | * Directory for on-disk state. |
| 46 | * |
| 47 | * This is used by all implementations for crash recovery and by the mmap |
| 48 | * implementation for storage. |
| 49 | */ |
| 50 | #define PG_DYNSHMEM_DIR "pg_dynshmem" |
| 51 | #define PG_DYNSHMEM_MMAP_FILE_PREFIX "mmap." |
| 52 | |
| 53 | /* A "name" for a dynamic shared memory segment. */ |
| 54 | typedef uint32 dsm_handle; |
| 55 | |
| 56 | /* All the shared-memory operations we know about. */ |
| 57 | typedef enum |
| 58 | { |
| 59 | DSM_OP_CREATE, |
| 60 | DSM_OP_ATTACH, |
| 61 | DSM_OP_DETACH, |
| 62 | DSM_OP_DESTROY |
| 63 | } dsm_op; |
| 64 | |
| 65 | /* Create, attach to, detach from, resize, or destroy a segment. */ |
| 66 | extern bool dsm_impl_op(dsm_op op, dsm_handle handle, Size request_size, |
| 67 | void **impl_private, void **mapped_address, Size *mapped_size, |
| 68 | int elevel); |
| 69 | |
| 70 | /* Implementation-dependent actions required to keep segment until shutdown. */ |
| 71 | extern void dsm_impl_pin_segment(dsm_handle handle, void *impl_private, |
| 72 | void **impl_private_pm_handle); |
| 73 | extern void dsm_impl_unpin_segment(dsm_handle handle, void **impl_private); |
| 74 | |
| 75 | #endif /* DSM_IMPL_H */ |
| 76 | |