PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
dsm_impl.c File Reference
#include "postgres.h"
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include "portability/mem.h"
#include "storage/dsm_impl.h"
#include "storage/fd.h"
#include "utils/guc.h"
#include "utils/memutils.h"
#include "postmaster/postmaster.h"
Include dependency graph for dsm_impl.c:

Go to the source code of this file.

Macros

#define ZBUFFER_SIZE   8192
 
#define SEGMENT_NAME_PREFIX   "Global/PostgreSQL"
 

Functions

static bool dsm_impl_sysv (dsm_op op, dsm_handle handle, Size request_size, void **impl_private, void **mapped_address, Size *mapped_size, int elevel)
 
static bool dsm_impl_mmap (dsm_op op, dsm_handle handle, Size request_size, void **impl_private, void **mapped_address, Size *mapped_size, int elevel)
 
static int errcode_for_dynamic_shared_memory (void)
 
bool dsm_impl_op (dsm_op op, dsm_handle handle, Size request_size, void **impl_private, void **mapped_address, Size *mapped_size, int elevel)
 
bool dsm_impl_can_resize (void)
 
void dsm_impl_pin_segment (dsm_handle handle, void *impl_private, void **impl_private_pm_handle)
 
void dsm_impl_unpin_segment (dsm_handle handle, void **impl_private)
 

Variables

const struct config_enum_entry dynamic_shared_memory_options []
 
int dynamic_shared_memory_type
 

Macro Definition Documentation

#define SEGMENT_NAME_PREFIX   "Global/PostgreSQL"

Definition at line 116 of file dsm_impl.c.

Referenced by dsm_impl_pin_segment(), and dsm_impl_unpin_segment().

#define ZBUFFER_SIZE   8192

Definition at line 114 of file dsm_impl.c.

Referenced by dsm_impl_mmap().

Function Documentation

bool dsm_impl_can_resize ( void  )

Definition at line 206 of file dsm_impl.c.

References DSM_IMPL_MMAP, DSM_IMPL_NONE, DSM_IMPL_POSIX, DSM_IMPL_SYSV, DSM_IMPL_WINDOWS, and dynamic_shared_memory_type.

207 {
209  {
210  case DSM_IMPL_NONE:
211  return false;
212  case DSM_IMPL_POSIX:
213  return true;
214  case DSM_IMPL_SYSV:
215  return false;
216  case DSM_IMPL_WINDOWS:
217  return false;
218  case DSM_IMPL_MMAP:
219  return true;
220  default:
221  return false; /* should not happen */
222  }
223 }
#define DSM_IMPL_MMAP
Definition: dsm_impl.h:21
#define DSM_IMPL_SYSV
Definition: dsm_impl.h:19
#define DSM_IMPL_WINDOWS
Definition: dsm_impl.h:20
#define DSM_IMPL_POSIX
Definition: dsm_impl.h:18
int dynamic_shared_memory_type
Definition: dsm_impl.c:111
#define DSM_IMPL_NONE
Definition: dsm_impl.h:17
static bool dsm_impl_mmap ( dsm_op  op,
dsm_handle  handle,
Size  request_size,
void **  impl_private,
void **  mapped_address,
Size mapped_size,
int  elevel 
)
static

Definition at line 798 of file dsm_impl.c.

References close, CloseTransientFile(), DSM_OP_ATTACH, DSM_OP_CREATE, DSM_OP_DESTROY, DSM_OP_DETACH, ereport, errcode_for_dynamic_shared_memory(), errmsg(), fd(), ftruncate, MAP_FAILED, MAP_HASSEMAPHORE, MAP_NOSYNC, NULL, OpenTransientFile(), palloc0(), PG_DYNSHMEM_DIR, PG_DYNSHMEM_MMAP_FILE_PREFIX, remaining, snprintf(), success, unlink(), write, and ZBUFFER_SIZE.

Referenced by dsm_impl_op().

801 {
802  char name[64];
803  int flags;
804  int fd;
805  char *address;
806 
808  handle);
809 
810  /* Handle teardown cases. */
811  if (op == DSM_OP_DETACH || op == DSM_OP_DESTROY)
812  {
813  if (*mapped_address != NULL
814  && munmap(*mapped_address, *mapped_size) != 0)
815  {
816  ereport(elevel,
818  errmsg("could not unmap shared memory segment \"%s\": %m",
819  name)));
820  return false;
821  }
822  *mapped_address = NULL;
823  *mapped_size = 0;
824  if (op == DSM_OP_DESTROY && unlink(name) != 0)
825  {
826  ereport(elevel,
828  errmsg("could not remove shared memory segment \"%s\": %m",
829  name)));
830  return false;
831  }
832  return true;
833  }
834 
835  /* Create new segment or open an existing one for attach or resize. */
836  flags = O_RDWR | (op == DSM_OP_CREATE ? O_CREAT | O_EXCL : 0);
837  if ((fd = OpenTransientFile(name, flags, 0600)) == -1)
838  {
839  if (errno != EEXIST)
840  ereport(elevel,
842  errmsg("could not open shared memory segment \"%s\": %m",
843  name)));
844  return false;
845  }
846 
847  /*
848  * If we're attaching the segment, determine the current size; if we are
849  * creating or resizing the segment, set the size to the requested value.
850  */
851  if (op == DSM_OP_ATTACH)
852  {
853  struct stat st;
854 
855  if (fstat(fd, &st) != 0)
856  {
857  int save_errno;
858 
859  /* Back out what's already been done. */
860  save_errno = errno;
861  CloseTransientFile(fd);
862  errno = save_errno;
863 
864  ereport(elevel,
866  errmsg("could not stat shared memory segment \"%s\": %m",
867  name)));
868  return false;
869  }
870  request_size = st.st_size;
871  }
872  else if (*mapped_size > request_size && ftruncate(fd, request_size))
873  {
874  int save_errno;
875 
876  /* Back out what's already been done. */
877  save_errno = errno;
878  close(fd);
879  if (op == DSM_OP_CREATE)
880  unlink(name);
881  errno = save_errno;
882 
883  ereport(elevel,
885  errmsg("could not resize shared memory segment \"%s\" to %zu bytes: %m",
886  name, request_size)));
887  return false;
888  }
889  else if (*mapped_size < request_size)
890  {
891  /*
892  * Allocate a buffer full of zeros.
893  *
894  * Note: palloc zbuffer, instead of just using a local char array, to
895  * ensure it is reasonably well-aligned; this may save a few cycles
896  * transferring data to the kernel.
897  */
898  char *zbuffer = (char *) palloc0(ZBUFFER_SIZE);
899  uint32 remaining = request_size;
900  bool success = true;
901 
902  /*
903  * Zero-fill the file. We have to do this the hard way to ensure that
904  * all the file space has really been allocated, so that we don't
905  * later seg fault when accessing the memory mapping. This is pretty
906  * pessimal.
907  */
908  while (success && remaining > 0)
909  {
910  Size goal = remaining;
911 
912  if (goal > ZBUFFER_SIZE)
913  goal = ZBUFFER_SIZE;
914  if (write(fd, zbuffer, goal) == goal)
915  remaining -= goal;
916  else
917  success = false;
918  }
919 
920  if (!success)
921  {
922  int save_errno;
923 
924  /* Back out what's already been done. */
925  save_errno = errno;
926  CloseTransientFile(fd);
927  if (op == DSM_OP_CREATE)
928  unlink(name);
929  errno = save_errno ? save_errno : ENOSPC;
930 
931  ereport(elevel,
933  errmsg("could not resize shared memory segment \"%s\" to %zu bytes: %m",
934  name, request_size)));
935  return false;
936  }
937  }
938 
939  /*
940  * If we're reattaching or resizing, we must remove any existing mapping,
941  * unless we've already got the right thing mapped.
942  */
943  if (*mapped_address != NULL)
944  {
945  if (*mapped_size == request_size)
946  return true;
947  if (munmap(*mapped_address, *mapped_size) != 0)
948  {
949  int save_errno;
950 
951  /* Back out what's already been done. */
952  save_errno = errno;
953  CloseTransientFile(fd);
954  if (op == DSM_OP_CREATE)
955  unlink(name);
956  errno = save_errno;
957 
958  ereport(elevel,
960  errmsg("could not unmap shared memory segment \"%s\": %m",
961  name)));
962  return false;
963  }
964  *mapped_address = NULL;
965  *mapped_size = 0;
966  }
967 
968  /* Map it. */
969  address = mmap(NULL, request_size, PROT_READ | PROT_WRITE,
970  MAP_SHARED | MAP_HASSEMAPHORE | MAP_NOSYNC, fd, 0);
971  if (address == MAP_FAILED)
972  {
973  int save_errno;
974 
975  /* Back out what's already been done. */
976  save_errno = errno;
977  CloseTransientFile(fd);
978  if (op == DSM_OP_CREATE)
979  unlink(name);
980  errno = save_errno;
981 
982  ereport(elevel,
984  errmsg("could not map shared memory segment \"%s\": %m",
985  name)));
986  return false;
987  }
988  *mapped_address = address;
989  *mapped_size = request_size;
990  CloseTransientFile(fd);
991 
992  return true;
993 }
int remaining
Definition: informix.c:692
#define MAP_HASSEMAPHORE
Definition: mem.h:30
#define MAP_FAILED
Definition: mem.h:45
#define PG_DYNSHMEM_DIR
Definition: dsm_impl.h:51
#define write(a, b, c)
Definition: win32.h:19
#define MAP_NOSYNC
Definition: mem.h:38
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static int fd(const char *x, int i)
Definition: preproc-init.c:105
static int errcode_for_dynamic_shared_memory(void)
Definition: dsm_impl.c:1088
static bool success
Definition: pg_basebackup.c:98
int OpenTransientFile(FileName fileName, int fileFlags, int fileMode)
Definition: fd.c:2093
unsigned int uint32
Definition: c.h:265
int unlink(const char *filename)
#define ereport(elevel, rest)
Definition: elog.h:122
int CloseTransientFile(int fd)
Definition: fd.c:2254
static int elevel
Definition: vacuumlazy.c:136
void * palloc0(Size size)
Definition: mcxt.c:920
#define ftruncate(a, b)
Definition: win32.h:67
#define NULL
Definition: c.h:226
size_t Size
Definition: c.h:353
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_DYNSHMEM_MMAP_FILE_PREFIX
Definition: dsm_impl.h:52
#define ZBUFFER_SIZE
Definition: dsm_impl.c:114
#define close(a)
Definition: win32.h:17
bool dsm_impl_op ( dsm_op  op,
dsm_handle  handle,
Size  request_size,
void **  impl_private,
void **  mapped_address,
Size mapped_size,
int  elevel 
)

Definition at line 161 of file dsm_impl.c.

References Assert, DSM_IMPL_MMAP, dsm_impl_mmap(), DSM_IMPL_POSIX, DSM_IMPL_SYSV, dsm_impl_sysv(), DSM_IMPL_WINDOWS, DSM_OP_ATTACH, DSM_OP_CREATE, DSM_OP_RESIZE, dynamic_shared_memory_type, elog, ERROR, and NULL.

Referenced by dsm_attach(), dsm_backend_startup(), dsm_cleanup_using_control_segment(), dsm_create(), dsm_detach(), dsm_detach_all(), dsm_postmaster_shutdown(), dsm_postmaster_startup(), dsm_remap(), dsm_resize(), and dsm_unpin_segment().

164 {
165  Assert(op == DSM_OP_CREATE || op == DSM_OP_RESIZE || request_size == 0);
166  Assert((op != DSM_OP_CREATE && op != DSM_OP_ATTACH) ||
167  (*mapped_address == NULL && *mapped_size == 0));
168 
170  {
171 #ifdef USE_DSM_POSIX
172  case DSM_IMPL_POSIX:
173  return dsm_impl_posix(op, handle, request_size, impl_private,
174  mapped_address, mapped_size, elevel);
175 #endif
176 #ifdef USE_DSM_SYSV
177  case DSM_IMPL_SYSV:
178  return dsm_impl_sysv(op, handle, request_size, impl_private,
179  mapped_address, mapped_size, elevel);
180 #endif
181 #ifdef USE_DSM_WINDOWS
182  case DSM_IMPL_WINDOWS:
183  return dsm_impl_windows(op, handle, request_size, impl_private,
184  mapped_address, mapped_size, elevel);
185 #endif
186 #ifdef USE_DSM_MMAP
187  case DSM_IMPL_MMAP:
188  return dsm_impl_mmap(op, handle, request_size, impl_private,
189  mapped_address, mapped_size, elevel);
190 #endif
191  default:
192  elog(ERROR, "unexpected dynamic shared memory type: %d",
194  return false;
195  }
196 }
#define DSM_IMPL_MMAP
Definition: dsm_impl.h:21
#define DSM_IMPL_SYSV
Definition: dsm_impl.h:19
#define DSM_IMPL_WINDOWS
Definition: dsm_impl.h:20
static bool dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size, void **impl_private, void **mapped_address, Size *mapped_size, int elevel)
Definition: dsm_impl.c:798
#define ERROR
Definition: elog.h:43
#define DSM_IMPL_POSIX
Definition: dsm_impl.h:18
int dynamic_shared_memory_type
Definition: dsm_impl.c:111
static int elevel
Definition: vacuumlazy.c:136
static bool dsm_impl_sysv(dsm_op op, dsm_handle handle, Size request_size, void **impl_private, void **mapped_address, Size *mapped_size, int elevel)
Definition: dsm_impl.c:407
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define elog
Definition: elog.h:219
void dsm_impl_pin_segment ( dsm_handle  handle,
void *  impl_private,
void **  impl_private_pm_handle 
)

Definition at line 1006 of file dsm_impl.c.

References _dosmaperr(), DSM_IMPL_WINDOWS, dynamic_shared_memory_type, ereport, errcode_for_dynamic_shared_memory(), errmsg(), ERROR, FALSE, SEGMENT_NAME_PREFIX, and snprintf().

Referenced by dsm_pin_segment().

1008 {
1010  {
1011 #ifdef USE_DSM_WINDOWS
1012  case DSM_IMPL_WINDOWS:
1013  {
1014  HANDLE hmap;
1015 
1016  if (!DuplicateHandle(GetCurrentProcess(), impl_private,
1017  PostmasterHandle, &hmap, 0, FALSE,
1018  DUPLICATE_SAME_ACCESS))
1019  {
1020  char name[64];
1021 
1022  snprintf(name, 64, "%s.%u", SEGMENT_NAME_PREFIX, handle);
1023  _dosmaperr(GetLastError());
1024  ereport(ERROR,
1026  errmsg("could not duplicate handle for \"%s\": %m",
1027  name)));
1028  }
1029 
1030  /*
1031  * Here, we remember the handle that we created in the
1032  * postmaster process. This handle isn't actually usable in
1033  * any process other than the postmaster, but that doesn't
1034  * matter. We're just holding onto it so that, if the segment
1035  * is unpinned, dsm_impl_unpin_segment can close it.
1036  */
1037  *impl_private_pm_handle = hmap;
1038  break;
1039  }
1040 #endif
1041  default:
1042  break;
1043  }
1044 }
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define DSM_IMPL_WINDOWS
Definition: dsm_impl.h:20
static int errcode_for_dynamic_shared_memory(void)
Definition: dsm_impl.c:1088
#define ERROR
Definition: elog.h:43
#define FALSE
Definition: c.h:218
#define SEGMENT_NAME_PREFIX
Definition: dsm_impl.c:116
int dynamic_shared_memory_type
Definition: dsm_impl.c:111
#define ereport(elevel, rest)
Definition: elog.h:122
void _dosmaperr(unsigned long)
Definition: win32error.c:171
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool dsm_impl_sysv ( dsm_op  op,
dsm_handle  handle,
Size  request_size,
void **  impl_private,
void **  mapped_address,
Size mapped_size,
int  elevel 
)
static

Definition at line 407 of file dsm_impl.c.

References DEBUG4, DSM_OP_ATTACH, DSM_OP_CREATE, DSM_OP_DESTROY, DSM_OP_DETACH, DSM_OP_RESIZE, elog, ereport, errcode_for_dynamic_shared_memory(), errmsg(), IPC_CREAT, IPC_EXCL, IPC_PRIVATE, IPC_RMID, IPC_STAT, IPCProtection, MemoryContextAlloc(), NULL, pfree(), PG_SHMAT_FLAGS, snprintf(), and TopMemoryContext.

Referenced by dsm_impl_op().

410 {
411  key_t key;
412  int ident;
413  char *address;
414  char name[64];
415  int *ident_cache;
416 
417  /* Resize is not supported for System V shared memory. */
418  if (op == DSM_OP_RESIZE)
419  {
420  elog(elevel, "System V shared memory segments cannot be resized");
421  return false;
422  }
423 
424  /* Since resize isn't supported, reattach is a no-op. */
425  if (op == DSM_OP_ATTACH && *mapped_address != NULL)
426  return true;
427 
428  /*
429  * POSIX shared memory and mmap-based shared memory identify segments with
430  * names. To avoid needless error message variation, we use the handle as
431  * the name.
432  */
433  snprintf(name, 64, "%u", handle);
434 
435  /*
436  * The System V shared memory namespace is very restricted; names are of
437  * type key_t, which is expected to be some sort of integer data type, but
438  * not necessarily the same one as dsm_handle. Since we use dsm_handle to
439  * identify shared memory segments across processes, this might seem like
440  * a problem, but it's really not. If dsm_handle is bigger than key_t,
441  * the cast below might truncate away some bits from the handle the
442  * user-provided, but it'll truncate exactly the same bits away in exactly
443  * the same fashion every time we use that handle, which is all that
444  * really matters. Conversely, if dsm_handle is smaller than key_t, we
445  * won't use the full range of available key space, but that's no big deal
446  * either.
447  *
448  * We do make sure that the key isn't negative, because that might not be
449  * portable.
450  */
451  key = (key_t) handle;
452  if (key < 1) /* avoid compiler warning if type is unsigned */
453  key = -key;
454 
455  /*
456  * There's one special key, IPC_PRIVATE, which can't be used. If we end
457  * up with that value by chance during a create operation, just pretend it
458  * already exists, so that caller will retry. If we run into it anywhere
459  * else, the caller has passed a handle that doesn't correspond to
460  * anything we ever created, which should not happen.
461  */
462  if (key == IPC_PRIVATE)
463  {
464  if (op != DSM_OP_CREATE)
465  elog(DEBUG4, "System V shared memory key may not be IPC_PRIVATE");
466  errno = EEXIST;
467  return false;
468  }
469 
470  /*
471  * Before we can do anything with a shared memory segment, we have to map
472  * the shared memory key to a shared memory identifier using shmget(). To
473  * avoid repeated lookups, we store the key using impl_private.
474  */
475  if (*impl_private != NULL)
476  {
477  ident_cache = *impl_private;
478  ident = *ident_cache;
479  }
480  else
481  {
482  int flags = IPCProtection;
483  size_t segsize;
484 
485  /*
486  * Allocate the memory BEFORE acquiring the resource, so that we don't
487  * leak the resource if memory allocation fails.
488  */
489  ident_cache = MemoryContextAlloc(TopMemoryContext, sizeof(int));
490 
491  /*
492  * When using shmget to find an existing segment, we must pass the
493  * size as 0. Passing a non-zero size which is greater than the
494  * actual size will result in EINVAL.
495  */
496  segsize = 0;
497 
498  if (op == DSM_OP_CREATE)
499  {
500  flags |= IPC_CREAT | IPC_EXCL;
501  segsize = request_size;
502  }
503 
504  if ((ident = shmget(key, segsize, flags)) == -1)
505  {
506  if (errno != EEXIST)
507  {
508  int save_errno = errno;
509 
510  pfree(ident_cache);
511  errno = save_errno;
512  ereport(elevel,
514  errmsg("could not get shared memory segment: %m")));
515  }
516  return false;
517  }
518 
519  *ident_cache = ident;
520  *impl_private = ident_cache;
521  }
522 
523  /* Handle teardown cases. */
524  if (op == DSM_OP_DETACH || op == DSM_OP_DESTROY)
525  {
526  pfree(ident_cache);
527  *impl_private = NULL;
528  if (*mapped_address != NULL && shmdt(*mapped_address) != 0)
529  {
530  ereport(elevel,
532  errmsg("could not unmap shared memory segment \"%s\": %m",
533  name)));
534  return false;
535  }
536  *mapped_address = NULL;
537  *mapped_size = 0;
538  if (op == DSM_OP_DESTROY && shmctl(ident, IPC_RMID, NULL) < 0)
539  {
540  ereport(elevel,
542  errmsg("could not remove shared memory segment \"%s\": %m",
543  name)));
544  return false;
545  }
546  return true;
547  }
548 
549  /* If we're attaching it, we must use IPC_STAT to determine the size. */
550  if (op == DSM_OP_ATTACH)
551  {
552  struct shmid_ds shm;
553 
554  if (shmctl(ident, IPC_STAT, &shm) != 0)
555  {
556  ereport(elevel,
558  errmsg("could not stat shared memory segment \"%s\": %m",
559  name)));
560  return false;
561  }
562  request_size = shm.shm_segsz;
563  }
564 
565  /* Map it. */
566  address = shmat(ident, NULL, PG_SHMAT_FLAGS);
567  if (address == (void *) -1)
568  {
569  int save_errno;
570 
571  /* Back out what's already been done. */
572  save_errno = errno;
573  if (op == DSM_OP_CREATE)
574  shmctl(ident, IPC_RMID, NULL);
575  errno = save_errno;
576 
577  ereport(elevel,
579  errmsg("could not map shared memory segment \"%s\": %m",
580  name)));
581  return false;
582  }
583  *mapped_address = address;
584  *mapped_size = request_size;
585 
586  return true;
587 }
#define IPC_CREAT
Definition: win32.h:115
#define IPC_EXCL
Definition: win32.h:116
#define IPCProtection
Definition: posix_sema.c:52
#define PG_SHMAT_FLAGS
Definition: mem.h:20
#define IPC_STAT
Definition: win32.h:119
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define DEBUG4
Definition: elog.h:22
static int errcode_for_dynamic_shared_memory(void)
Definition: dsm_impl.c:1088
long key_t
Definition: win32.h:263
void pfree(void *pointer)
Definition: mcxt.c:992
#define IPC_PRIVATE
Definition: win32.h:117
#define ereport(elevel, rest)
Definition: elog.h:122
MemoryContext TopMemoryContext
Definition: mcxt.c:43
static int elevel
Definition: vacuumlazy.c:136
#define IPC_RMID
Definition: win32.h:114
#define NULL
Definition: c.h:226
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:749
#define elog
Definition: elog.h:219
void dsm_impl_unpin_segment ( dsm_handle  handle,
void **  impl_private 
)

Definition at line 1056 of file dsm_impl.c.

References _dosmaperr(), DSM_IMPL_WINDOWS, dynamic_shared_memory_type, ereport, errcode_for_dynamic_shared_memory(), errmsg(), ERROR, FALSE, NULL, SEGMENT_NAME_PREFIX, and snprintf().

Referenced by dsm_unpin_segment().

1057 {
1059  {
1060 #ifdef USE_DSM_WINDOWS
1061  case DSM_IMPL_WINDOWS:
1062  {
1063  if (*impl_private &&
1064  !DuplicateHandle(PostmasterHandle, *impl_private,
1065  NULL, NULL, 0, FALSE,
1066  DUPLICATE_CLOSE_SOURCE))
1067  {
1068  char name[64];
1069 
1070  snprintf(name, 64, "%s.%u", SEGMENT_NAME_PREFIX, handle);
1071  _dosmaperr(GetLastError());
1072  ereport(ERROR,
1074  errmsg("could not duplicate handle for \"%s\": %m",
1075  name)));
1076  }
1077 
1078  *impl_private = NULL;
1079  break;
1080  }
1081 #endif
1082  default:
1083  break;
1084  }
1085 }
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define DSM_IMPL_WINDOWS
Definition: dsm_impl.h:20
static int errcode_for_dynamic_shared_memory(void)
Definition: dsm_impl.c:1088
#define ERROR
Definition: elog.h:43
#define FALSE
Definition: c.h:218
#define SEGMENT_NAME_PREFIX
Definition: dsm_impl.c:116
int dynamic_shared_memory_type
Definition: dsm_impl.c:111
#define ereport(elevel, rest)
Definition: elog.h:122
#define NULL
Definition: c.h:226
void _dosmaperr(unsigned long)
Definition: win32error.c:171
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
static int errcode_for_dynamic_shared_memory ( void  )
static

Definition at line 1088 of file dsm_impl.c.

References errcode(), and errcode_for_file_access().

Referenced by dsm_impl_mmap(), dsm_impl_pin_segment(), dsm_impl_sysv(), and dsm_impl_unpin_segment().

1089 {
1090  if (errno == EFBIG || errno == ENOMEM)
1091  return errcode(ERRCODE_OUT_OF_MEMORY);
1092  else
1093  return errcode_for_file_access();
1094 }
int errcode(int sqlerrcode)
Definition: elog.c:575
int errcode_for_file_access(void)
Definition: elog.c:598

Variable Documentation

const struct config_enum_entry dynamic_shared_memory_options[]
Initial value:
= {
{"sysv", DSM_IMPL_SYSV, false},
{"mmap", DSM_IMPL_MMAP, false},
{"none", DSM_IMPL_NONE, false},
{NULL, 0, false}
}
#define DSM_IMPL_MMAP
Definition: dsm_impl.h:21
#define DSM_IMPL_SYSV
Definition: dsm_impl.h:19
#define NULL
Definition: c.h:226
#define DSM_IMPL_NONE
Definition: dsm_impl.h:17

Definition at line 93 of file dsm_impl.c.