PostgreSQL Source Code  git master
win32_shmem.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * win32_shmem.c
4  * Implement shared memory using win32 facilities
5  *
6  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
7  *
8  * IDENTIFICATION
9  * src/backend/port/win32_shmem.c
10  *
11  *-------------------------------------------------------------------------
12  */
13 #include "postgres.h"
14 
15 #include "miscadmin.h"
16 #include "storage/dsm.h"
17 #include "storage/ipc.h"
18 #include "storage/pg_shmem.h"
19 #include "utils/guc_hooks.h"
20 
21 
22 /*
23  * Early in a process's life, Windows asynchronously creates threads for the
24  * process's "default thread pool"
25  * (https://docs.microsoft.com/en-us/windows/desktop/ProcThread/thread-pools).
26  * Occasionally, thread creation allocates a stack after
27  * PGSharedMemoryReAttach() has released UsedShmemSegAddr and before it has
28  * mapped shared memory at UsedShmemSegAddr. This would cause mapping to fail
29  * if the allocator preferred the just-released region for allocating the new
30  * thread stack. We observed such failures in some Windows Server 2016
31  * configurations. To give the system another region to prefer, reserve and
32  * release an additional, protective region immediately before reserving or
33  * releasing shared memory. The idea is that, if the allocator handed out
34  * REGION1 pages before REGION2 pages at one occasion, it will do so whenever
35  * both regions are free. Windows Server 2016 exhibits that behavior, and a
36  * system behaving differently would have less need to protect
37  * UsedShmemSegAddr. The protective region must be at least large enough for
38  * one thread stack. However, ten times as much is less than 2% of the 32-bit
39  * address space and is negligible relative to the 64-bit address space.
40  */
41 #define PROTECTIVE_REGION_SIZE (10 * WIN32_STACK_RLIMIT)
42 void *ShmemProtectiveRegion = NULL;
43 
44 HANDLE UsedShmemSegID = INVALID_HANDLE_VALUE;
45 void *UsedShmemSegAddr = NULL;
47 
48 static bool EnableLockPagesPrivilege(int elevel);
49 static void pgwin32_SharedMemoryDelete(int status, Datum shmId);
50 
51 /*
52  * Generate shared memory segment name. Expand the data directory, to generate
53  * an identifier unique for this data directory. Then replace all backslashes
54  * with forward slashes, since backslashes aren't permitted in global object names.
55  *
56  * Store the shared memory segment in the Global\ namespace (requires NT2 TSE or
57  * 2000, but that's all we support for other reasons as well), to make sure you can't
58  * open two postmasters in different sessions against the same data directory.
59  *
60  * XXX: What happens with junctions? It's only someone breaking things on purpose,
61  * and this is still better than before, but we might want to do something about
62  * that sometime in the future.
63  */
64 static char *
66 {
67  char *retptr;
68  DWORD bufsize;
69  DWORD r;
70  char *cp;
71 
72  bufsize = GetFullPathName(DataDir, 0, NULL, NULL);
73  if (bufsize == 0)
74  elog(FATAL, "could not get size for full pathname of datadir %s: error code %lu",
75  DataDir, GetLastError());
76 
77  retptr = malloc(bufsize + 18); /* 18 for Global\PostgreSQL: */
78  if (retptr == NULL)
79  elog(FATAL, "could not allocate memory for shared memory name");
80 
81  strcpy(retptr, "Global\\PostgreSQL:");
82  r = GetFullPathName(DataDir, bufsize, retptr + 18, NULL);
83  if (r == 0 || r > bufsize)
84  elog(FATAL, "could not generate full pathname for datadir %s: error code %lu",
85  DataDir, GetLastError());
86 
87  /*
88  * XXX: Intentionally overwriting the Global\ part here. This was not the
89  * original approach, but putting it in the actual Global\ namespace
90  * causes permission errors in a lot of cases, so we leave it in the
91  * default namespace for now.
92  */
93  for (cp = retptr; *cp; cp++)
94  if (*cp == '\\')
95  *cp = '/';
96 
97  return retptr;
98 }
99 
100 
101 /*
102  * PGSharedMemoryIsInUse
103  *
104  * Is a previously-existing shmem segment still existing and in use?
105  *
106  * The point of this exercise is to detect the case where a prior postmaster
107  * crashed, but it left child backends that are still running. Therefore
108  * we only care about shmem segments that are associated with the intended
109  * DataDir. This is an important consideration since accidental matches of
110  * shmem segment IDs are reasonably common.
111  */
112 bool
113 PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2)
114 {
115  char *szShareMem;
116  HANDLE hmap;
117 
118  szShareMem = GetSharedMemName();
119 
120  hmap = OpenFileMapping(FILE_MAP_READ, FALSE, szShareMem);
121 
122  free(szShareMem);
123 
124  if (hmap == NULL)
125  return false;
126 
127  CloseHandle(hmap);
128  return true;
129 }
130 
131 /*
132  * EnableLockPagesPrivilege
133  *
134  * Try to acquire SeLockMemoryPrivilege so we can use large pages.
135  */
136 static bool
138 {
139  HANDLE hToken;
140  TOKEN_PRIVILEGES tp;
141  LUID luid;
142 
143  if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
144  {
145  ereport(elevel,
146  (errmsg("could not enable user right \"%s\": error code %lu",
147 
148  /*
149  * translator: This is a term from Windows and should be translated to
150  * match the Windows localization.
151  */
152  _("Lock pages in memory"),
153  GetLastError()),
154  errdetail("Failed system call was %s.", "OpenProcessToken")));
155  return FALSE;
156  }
157 
158  if (!LookupPrivilegeValue(NULL, SE_LOCK_MEMORY_NAME, &luid))
159  {
160  ereport(elevel,
161  (errmsg("could not enable user right \"%s\": error code %lu", _("Lock pages in memory"), GetLastError()),
162  errdetail("Failed system call was %s.", "LookupPrivilegeValue")));
163  CloseHandle(hToken);
164  return FALSE;
165  }
166  tp.PrivilegeCount = 1;
167  tp.Privileges[0].Luid = luid;
168  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
169 
170  if (!AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL))
171  {
172  ereport(elevel,
173  (errmsg("could not enable user right \"%s\": error code %lu", _("Lock pages in memory"), GetLastError()),
174  errdetail("Failed system call was %s.", "AdjustTokenPrivileges")));
175  CloseHandle(hToken);
176  return FALSE;
177  }
178 
179  if (GetLastError() != ERROR_SUCCESS)
180  {
181  if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
182  ereport(elevel,
183  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
184  errmsg("could not enable user right \"%s\"", _("Lock pages in memory")),
185  errhint("Assign user right \"%s\" to the Windows user account which runs PostgreSQL.",
186  _("Lock pages in memory"))));
187  else
188  ereport(elevel,
189  (errmsg("could not enable user right \"%s\": error code %lu", _("Lock pages in memory"), GetLastError()),
190  errdetail("Failed system call was %s.", "AdjustTokenPrivileges")));
191  CloseHandle(hToken);
192  return FALSE;
193  }
194 
195  CloseHandle(hToken);
196 
197  return TRUE;
198 }
199 
200 /*
201  * PGSharedMemoryCreate
202  *
203  * Create a shared memory segment of the given size and initialize its
204  * standard header.
205  */
208  PGShmemHeader **shim)
209 {
210  void *memAddress;
211  PGShmemHeader *hdr;
212  HANDLE hmap,
213  hmap2;
214  char *szShareMem;
215  int i;
216  DWORD size_high;
217  DWORD size_low;
218  SIZE_T largePageSize = 0;
219  Size orig_size = size;
220  DWORD flProtect = PAGE_READWRITE;
221  DWORD desiredAccess;
222 
223  ShmemProtectiveRegion = VirtualAlloc(NULL, PROTECTIVE_REGION_SIZE,
224  MEM_RESERVE, PAGE_NOACCESS);
225  if (ShmemProtectiveRegion == NULL)
226  elog(FATAL, "could not reserve memory region: error code %lu",
227  GetLastError());
228 
229  /* Room for a header? */
230  Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
231 
232  szShareMem = GetSharedMemName();
233 
234  UsedShmemSegAddr = NULL;
235 
237  {
238  /* Does the processor support large pages? */
239  largePageSize = GetLargePageMinimum();
240  if (largePageSize == 0)
241  {
243  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
244  errmsg("the processor does not support large pages")));
245  ereport(DEBUG1,
246  (errmsg_internal("disabling huge pages")));
247  }
249  {
250  ereport(DEBUG1,
251  (errmsg_internal("disabling huge pages")));
252  }
253  else
254  {
255  /* Huge pages available and privilege enabled, so turn on */
256  flProtect = PAGE_READWRITE | SEC_COMMIT | SEC_LARGE_PAGES;
257 
258  /* Round size up as appropriate. */
259  if (size % largePageSize != 0)
260  size += largePageSize - (size % largePageSize);
261  }
262  }
263 
264 retry:
265 #ifdef _WIN64
266  size_high = size >> 32;
267 #else
268  size_high = 0;
269 #endif
270  size_low = (DWORD) size;
271 
272  /*
273  * When recycling a shared memory segment, it may take a short while
274  * before it gets dropped from the global namespace. So re-try after
275  * sleeping for a second, and continue retrying 10 times. (both the 1
276  * second time and the 10 retries are completely arbitrary)
277  */
278  for (i = 0; i < 10; i++)
279  {
280  /*
281  * In case CreateFileMapping() doesn't set the error code to 0 on
282  * success
283  */
284  SetLastError(0);
285 
286  hmap = CreateFileMapping(INVALID_HANDLE_VALUE, /* Use the pagefile */
287  NULL, /* Default security attrs */
288  flProtect,
289  size_high, /* Size Upper 32 Bits */
290  size_low, /* Size Lower 32 bits */
291  szShareMem);
292 
293  if (!hmap)
294  {
295  if (GetLastError() == ERROR_NO_SYSTEM_RESOURCES &&
297  (flProtect & SEC_LARGE_PAGES) != 0)
298  {
299  elog(DEBUG1, "CreateFileMapping(%zu) with SEC_LARGE_PAGES failed, "
300  "huge pages disabled",
301  size);
302 
303  /*
304  * Use the original size, not the rounded-up value, when
305  * falling back to non-huge pages.
306  */
307  size = orig_size;
308  flProtect = PAGE_READWRITE;
309  goto retry;
310  }
311  else
312  ereport(FATAL,
313  (errmsg("could not create shared memory segment: error code %lu", GetLastError()),
314  errdetail("Failed system call was CreateFileMapping(size=%zu, name=%s).",
315  size, szShareMem)));
316  }
317 
318  /*
319  * If the segment already existed, CreateFileMapping() will return a
320  * handle to the existing one and set ERROR_ALREADY_EXISTS.
321  */
322  if (GetLastError() == ERROR_ALREADY_EXISTS)
323  {
324  CloseHandle(hmap); /* Close the handle, since we got a valid one
325  * to the previous segment. */
326  hmap = NULL;
327  Sleep(1000);
328  continue;
329  }
330  break;
331  }
332 
333  /*
334  * If the last call in the loop still returned ERROR_ALREADY_EXISTS, this
335  * shared memory segment exists and we assume it belongs to somebody else.
336  */
337  if (!hmap)
338  ereport(FATAL,
339  (errmsg("pre-existing shared memory block is still in use"),
340  errhint("Check if there are any old server processes still running, and terminate them.")));
341 
342  free(szShareMem);
343 
344  /*
345  * Make the handle inheritable
346  */
347  if (!DuplicateHandle(GetCurrentProcess(), hmap, GetCurrentProcess(), &hmap2, 0, TRUE, DUPLICATE_SAME_ACCESS))
348  ereport(FATAL,
349  (errmsg("could not create shared memory segment: error code %lu", GetLastError()),
350  errdetail("Failed system call was DuplicateHandle.")));
351 
352  /*
353  * Close the old, non-inheritable handle. If this fails we don't really
354  * care.
355  */
356  if (!CloseHandle(hmap))
357  elog(LOG, "could not close handle to shared memory: error code %lu", GetLastError());
358 
359  desiredAccess = FILE_MAP_WRITE | FILE_MAP_READ;
360 
361 #ifdef FILE_MAP_LARGE_PAGES
362  /* Set large pages if wanted. */
363  if ((flProtect & SEC_LARGE_PAGES) != 0)
364  desiredAccess |= FILE_MAP_LARGE_PAGES;
365 #endif
366 
367  /*
368  * Get a pointer to the new shared memory segment. Map the whole segment
369  * at once, and let the system decide on the initial address.
370  */
371  memAddress = MapViewOfFileEx(hmap2, desiredAccess, 0, 0, 0, NULL);
372  if (!memAddress)
373  ereport(FATAL,
374  (errmsg("could not create shared memory segment: error code %lu", GetLastError()),
375  errdetail("Failed system call was MapViewOfFileEx.")));
376 
377 
378 
379  /*
380  * OK, we created a new segment. Mark it as created by this process. The
381  * order of assignments here is critical so that another Postgres process
382  * can't see the header as valid but belonging to an invalid PID!
383  */
384  hdr = (PGShmemHeader *) memAddress;
385  hdr->creatorPID = getpid();
386  hdr->magic = PGShmemMagic;
387 
388  /*
389  * Initialize space allocation status for segment.
390  */
391  hdr->totalsize = size;
392  hdr->freeoffset = MAXALIGN(sizeof(PGShmemHeader));
393  hdr->dsm_control = 0;
394 
395  /* Save info for possible future use */
396  UsedShmemSegAddr = memAddress;
397  UsedShmemSegSize = size;
398  UsedShmemSegID = hmap2;
399 
400  /* Register on-exit routine to delete the new segment */
402 
403  *shim = hdr;
404  return hdr;
405 }
406 
407 /*
408  * PGSharedMemoryReAttach
409  *
410  * This is called during startup of a postmaster child process to re-attach to
411  * an already existing shared memory segment, using the handle inherited from
412  * the postmaster.
413  *
414  * ShmemProtectiveRegion, UsedShmemSegID and UsedShmemSegAddr are implicit
415  * parameters to this routine. The caller must have already restored them to
416  * the postmaster's values.
417  */
418 void
420 {
421  PGShmemHeader *hdr;
422  void *origUsedShmemSegAddr = UsedShmemSegAddr;
423 
424  Assert(ShmemProtectiveRegion != NULL);
425  Assert(UsedShmemSegAddr != NULL);
427 
428  /*
429  * Release memory region reservations made by the postmaster
430  */
431  if (VirtualFree(ShmemProtectiveRegion, 0, MEM_RELEASE) == 0)
432  elog(FATAL, "failed to release reserved memory region (addr=%p): error code %lu",
433  ShmemProtectiveRegion, GetLastError());
434  if (VirtualFree(UsedShmemSegAddr, 0, MEM_RELEASE) == 0)
435  elog(FATAL, "failed to release reserved memory region (addr=%p): error code %lu",
436  UsedShmemSegAddr, GetLastError());
437 
438  hdr = (PGShmemHeader *) MapViewOfFileEx(UsedShmemSegID, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, UsedShmemSegAddr);
439  if (!hdr)
440  elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): error code %lu",
441  UsedShmemSegID, UsedShmemSegAddr, GetLastError());
442  if (hdr != origUsedShmemSegAddr)
443  elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)",
444  hdr, origUsedShmemSegAddr);
445  if (hdr->magic != PGShmemMagic)
446  elog(FATAL, "reattaching to shared memory returned non-PostgreSQL memory");
447  dsm_set_control_handle(hdr->dsm_control);
448 
449  UsedShmemSegAddr = hdr; /* probably redundant */
450 }
451 
452 /*
453  * PGSharedMemoryNoReAttach
454  *
455  * This is called during startup of a postmaster child process when we choose
456  * *not* to re-attach to the existing shared memory segment. We must clean up
457  * to leave things in the appropriate state.
458  *
459  * The child process startup logic might or might not call PGSharedMemoryDetach
460  * after this; make sure that it will be a no-op if called.
461  *
462  * ShmemProtectiveRegion, UsedShmemSegID and UsedShmemSegAddr are implicit
463  * parameters to this routine. The caller must have already restored them to
464  * the postmaster's values.
465  */
466 void
468 {
469  Assert(ShmemProtectiveRegion != NULL);
470  Assert(UsedShmemSegAddr != NULL);
472 
473  /*
474  * Under Windows we will not have mapped the segment, so we don't need to
475  * un-map it. Just reset UsedShmemSegAddr to show we're not attached.
476  */
477  UsedShmemSegAddr = NULL;
478 
479  /*
480  * We *must* close the inherited shmem segment handle, else Windows will
481  * consider the existence of this process to mean it can't release the
482  * shmem segment yet. We can now use PGSharedMemoryDetach to do that.
483  */
485 }
486 
487 /*
488  * PGSharedMemoryDetach
489  *
490  * Detach from the shared memory segment, if still attached. This is not
491  * intended to be called explicitly by the process that originally created the
492  * segment (it will have an on_shmem_exit callback registered to do that).
493  * Rather, this is for subprocesses that have inherited an attachment and want
494  * to get rid of it.
495  *
496  * ShmemProtectiveRegion, UsedShmemSegID and UsedShmemSegAddr are implicit
497  * parameters to this routine.
498  */
499 void
501 {
502  /*
503  * Releasing the protective region liberates an unimportant quantity of
504  * address space, but be tidy.
505  */
506  if (ShmemProtectiveRegion != NULL)
507  {
508  if (VirtualFree(ShmemProtectiveRegion, 0, MEM_RELEASE) == 0)
509  elog(LOG, "failed to release reserved memory region (addr=%p): error code %lu",
510  ShmemProtectiveRegion, GetLastError());
511 
512  ShmemProtectiveRegion = NULL;
513  }
514 
515  /* Unmap the view, if it's mapped */
516  if (UsedShmemSegAddr != NULL)
517  {
518  if (!UnmapViewOfFile(UsedShmemSegAddr))
519  elog(LOG, "could not unmap view of shared memory: error code %lu",
520  GetLastError());
521 
522  UsedShmemSegAddr = NULL;
523  }
524 
525  /* And close the shmem handle, if we have one */
526  if (UsedShmemSegID != INVALID_HANDLE_VALUE)
527  {
528  if (!CloseHandle(UsedShmemSegID))
529  elog(LOG, "could not close handle to shared memory: error code %lu",
530  GetLastError());
531 
532  UsedShmemSegID = INVALID_HANDLE_VALUE;
533  }
534 }
535 
536 
537 /*
538  * pgwin32_SharedMemoryDelete
539  *
540  * Detach from and delete the shared memory segment
541  * (called as an on_shmem_exit callback, hence funny argument list)
542  */
543 static void
545 {
548 }
549 
550 /*
551  * pgwin32_ReserveSharedMemoryRegion(hChild)
552  *
553  * Reserve the memory region that will be used for shared memory in a child
554  * process. It is called before the child process starts, to make sure the
555  * memory is available.
556  *
557  * Once the child starts, DLLs loading in different order or threads getting
558  * scheduled differently may allocate memory which can conflict with the
559  * address space we need for our shared memory. By reserving the shared
560  * memory region before the child starts, and freeing it only just before we
561  * attempt to get access to the shared memory forces these allocations to
562  * be given different address ranges that don't conflict.
563  *
564  * NOTE! This function executes in the postmaster, and should for this
565  * reason not use elog(FATAL) since that would take down the postmaster.
566  */
567 int
569 {
570  void *address;
571 
572  Assert(ShmemProtectiveRegion != NULL);
573  Assert(UsedShmemSegAddr != NULL);
574  Assert(UsedShmemSegSize != 0);
575 
576  /* ShmemProtectiveRegion */
577  address = VirtualAllocEx(hChild, ShmemProtectiveRegion,
579  MEM_RESERVE, PAGE_NOACCESS);
580  if (address == NULL)
581  {
582  /* Don't use FATAL since we're running in the postmaster */
583  elog(LOG, "could not reserve shared memory region (addr=%p) for child %p: error code %lu",
584  ShmemProtectiveRegion, hChild, GetLastError());
585  return false;
586  }
587  if (address != ShmemProtectiveRegion)
588  {
589  /*
590  * Should never happen - in theory if allocation granularity causes
591  * strange effects it could, so check just in case.
592  *
593  * Don't use FATAL since we're running in the postmaster.
594  */
595  elog(LOG, "reserved shared memory region got incorrect address %p, expected %p",
596  address, ShmemProtectiveRegion);
597  return false;
598  }
599 
600  /* UsedShmemSegAddr */
601  address = VirtualAllocEx(hChild, UsedShmemSegAddr, UsedShmemSegSize,
602  MEM_RESERVE, PAGE_READWRITE);
603  if (address == NULL)
604  {
605  elog(LOG, "could not reserve shared memory region (addr=%p) for child %p: error code %lu",
606  UsedShmemSegAddr, hChild, GetLastError());
607  return false;
608  }
609  if (address != UsedShmemSegAddr)
610  {
611  elog(LOG, "reserved shared memory region got incorrect address %p, expected %p",
612  address, UsedShmemSegAddr);
613  return false;
614  }
615 
616  return true;
617 }
618 
619 /*
620  * This function is provided for consistency with sysv_shmem.c and does not
621  * provide any useful information for Windows. To obtain the large page size,
622  * use GetLargePageMinimum() instead.
623  */
624 void
625 GetHugePageSize(Size *hugepagesize, int *mmap_flags)
626 {
627  if (hugepagesize)
628  *hugepagesize = 0;
629  if (mmap_flags)
630  *mmap_flags = 0;
631 }
632 
633 /*
634  * GUC check_hook for huge_page_size
635  */
636 bool
638 {
639  if (*newval != 0)
640  {
641  GUC_check_errdetail("huge_page_size must be 0 on this platform.");
642  return false;
643  }
644  return true;
645 }
#define MAXALIGN(LEN)
Definition: c.h:747
size_t Size
Definition: c.h:541
int errmsg_internal(const char *fmt,...)
Definition: elog.c:993
int errdetail(const char *fmt,...)
Definition: elog.c:1039
int errhint(const char *fmt,...)
Definition: elog.c:1153
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define _(x)
Definition: elog.c:90
#define LOG
Definition: elog.h:27
#define FATAL
Definition: elog.h:37
#define DEBUG1
Definition: elog.h:26
#define ereport(elevel,...)
Definition: elog.h:145
bool IsUnderPostmaster
Definition: globals.c:113
char * DataDir
Definition: globals.c:66
#define newval
#define GUC_check_errdetail
Definition: guc.h:434
GucSource
Definition: guc.h:108
int huge_pages
Definition: guc_tables.c:529
#define free(a)
Definition: header.h:65
#define malloc(a)
Definition: header.h:50
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:225
static rewind_source * source
Definition: pg_rewind.c:81
@ HUGE_PAGES_ON
Definition: pg_shmem.h:53
@ HUGE_PAGES_TRY
Definition: pg_shmem.h:54
#define PGShmemMagic
Definition: pg_shmem.h:32
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:670
uintptr_t Datum
Definition: postgres.h:412
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:660
dsm_handle dsm_control
Definition: pg_shmem.h:36
Size freeoffset
Definition: pg_shmem.h:35
pid_t creatorPID
Definition: pg_shmem.h:33
int32 magic
Definition: pg_shmem.h:31
Size totalsize
Definition: pg_shmem.h:34
#define PROTECTIVE_REGION_SIZE
Definition: win32_shmem.c:41
PGShmemHeader * PGSharedMemoryCreate(Size size, PGShmemHeader **shim)
Definition: win32_shmem.c:207
void PGSharedMemoryDetach(void)
Definition: win32_shmem.c:500
void PGSharedMemoryReAttach(void)
Definition: win32_shmem.c:419
bool check_huge_page_size(int *newval, void **extra, GucSource source)
Definition: win32_shmem.c:637
void * ShmemProtectiveRegion
Definition: win32_shmem.c:42
HANDLE UsedShmemSegID
Definition: win32_shmem.c:44
void GetHugePageSize(Size *hugepagesize, int *mmap_flags)
Definition: win32_shmem.c:625
void * UsedShmemSegAddr
Definition: win32_shmem.c:45
int pgwin32_ReserveSharedMemoryRegion(HANDLE hChild)
Definition: win32_shmem.c:568
static bool EnableLockPagesPrivilege(int elevel)
Definition: win32_shmem.c:137
bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2)
Definition: win32_shmem.c:113
static void pgwin32_SharedMemoryDelete(int status, Datum shmId)
Definition: win32_shmem.c:544
static Size UsedShmemSegSize
Definition: win32_shmem.c:46
void PGSharedMemoryNoReAttach(void)
Definition: win32_shmem.c:467
static char * GetSharedMemName(void)
Definition: win32_shmem.c:65