mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Support 64-bit shared memory when building on 64-bit Windows.
Tsutomu Yamada
This commit is contained in:
parent
13c5fdb5c8
commit
2de9a463ff
@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/port/win32_shmem.c,v 1.12 2009/07/24 20:12:42 mha Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/port/win32_shmem.c,v 1.13 2010/01/02 12:18:45 mha Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -16,7 +16,7 @@
|
||||
#include "storage/ipc.h"
|
||||
#include "storage/pg_shmem.h"
|
||||
|
||||
unsigned long UsedShmemSegID = 0;
|
||||
HANDLE UsedShmemSegID = 0;
|
||||
void *UsedShmemSegAddr = NULL;
|
||||
static Size UsedShmemSegSize = 0;
|
||||
|
||||
@ -125,6 +125,8 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
|
||||
hmap2;
|
||||
char *szShareMem;
|
||||
int i;
|
||||
DWORD size_high;
|
||||
DWORD size_low;
|
||||
|
||||
/* Room for a header? */
|
||||
Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
|
||||
@ -133,6 +135,13 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
|
||||
|
||||
UsedShmemSegAddr = NULL;
|
||||
|
||||
#ifdef _WIN64
|
||||
size_high = size >> 32;
|
||||
#else
|
||||
size_high = 0;
|
||||
#endif
|
||||
size_low = (DWORD) size;
|
||||
|
||||
/*
|
||||
* When recycling a shared memory segment, it may take a short while
|
||||
* before it gets dropped from the global namespace. So re-try after
|
||||
@ -147,11 +156,11 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
|
||||
*/
|
||||
SetLastError(0);
|
||||
|
||||
hmap = CreateFileMapping((HANDLE) 0xFFFFFFFF, /* Use the pagefile */
|
||||
hmap = CreateFileMapping(INVALID_HANDLE_VALUE, /* Use the pagefile */
|
||||
NULL, /* Default security attrs */
|
||||
PAGE_READWRITE, /* Memory is Read/Write */
|
||||
0L, /* Size Upper 32 Bits */
|
||||
(DWORD) size, /* Size Lower 32 bits */
|
||||
size_high, /* Size Upper 32 Bits */
|
||||
size_low, /* Size Lower 32 bits */
|
||||
szShareMem);
|
||||
|
||||
if (!hmap)
|
||||
@ -203,7 +212,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
|
||||
|
||||
|
||||
/* Register on-exit routine to delete the new segment */
|
||||
on_shmem_exit(pgwin32_SharedMemoryDelete, Int32GetDatum((unsigned long) hmap2));
|
||||
on_shmem_exit(pgwin32_SharedMemoryDelete, PointerGetDatum(hmap2));
|
||||
|
||||
/*
|
||||
* Get a pointer to the new shared memory segment. Map the whole segment
|
||||
@ -235,7 +244,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
|
||||
/* Save info for possible future use */
|
||||
UsedShmemSegAddr = memAddress;
|
||||
UsedShmemSegSize = size;
|
||||
UsedShmemSegID = (unsigned long) hmap2;
|
||||
UsedShmemSegID = hmap2;
|
||||
|
||||
return hdr;
|
||||
}
|
||||
@ -266,10 +275,10 @@ PGSharedMemoryReAttach(void)
|
||||
elog(FATAL, "failed to release reserved memory region (addr=%p): %lu",
|
||||
UsedShmemSegAddr, GetLastError());
|
||||
|
||||
hdr = (PGShmemHeader *) MapViewOfFileEx((HANDLE) UsedShmemSegID, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, UsedShmemSegAddr);
|
||||
hdr = (PGShmemHeader *) MapViewOfFileEx(UsedShmemSegID, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, UsedShmemSegAddr);
|
||||
if (!hdr)
|
||||
elog(FATAL, "could not reattach to shared memory (key=%d, addr=%p): %lu",
|
||||
(int) UsedShmemSegID, UsedShmemSegAddr, GetLastError());
|
||||
elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): %lu",
|
||||
UsedShmemSegID, UsedShmemSegAddr, GetLastError());
|
||||
if (hdr != origUsedShmemSegAddr)
|
||||
elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)",
|
||||
hdr, origUsedShmemSegAddr);
|
||||
@ -308,7 +317,7 @@ static void
|
||||
pgwin32_SharedMemoryDelete(int status, Datum shmId)
|
||||
{
|
||||
PGSharedMemoryDetach();
|
||||
if (!CloseHandle((HANDLE) DatumGetInt32(shmId)))
|
||||
if (!CloseHandle(DatumGetPointer(shmId)))
|
||||
elog(LOG, "could not close handle to shared memory: %lu", GetLastError());
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/storage/pg_shmem.h,v 1.25 2009/01/01 17:24:01 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/storage/pg_shmem.h,v 1.26 2010/01/02 12:18:45 mha Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -40,7 +40,11 @@ typedef struct PGShmemHeader /* standard header for all Postgres shmem */
|
||||
|
||||
|
||||
#ifdef EXEC_BACKEND
|
||||
#ifndef WIN32
|
||||
extern unsigned long UsedShmemSegID;
|
||||
#else
|
||||
extern HANDLE UsedShmemSegID;
|
||||
#endif
|
||||
extern void *UsedShmemSegAddr;
|
||||
|
||||
extern void PGSharedMemoryReAttach(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user