Commit 2de9a463 authored by Magnus Hagander's avatar Magnus Hagander

Support 64-bit shared memory when building on 64-bit Windows.

Tsutomu Yamada
parent 13c5fdb5
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* *
* IDENTIFICATION * 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 @@ ...@@ -16,7 +16,7 @@
#include "storage/ipc.h" #include "storage/ipc.h"
#include "storage/pg_shmem.h" #include "storage/pg_shmem.h"
unsigned long UsedShmemSegID = 0; HANDLE UsedShmemSegID = 0;
void *UsedShmemSegAddr = NULL; void *UsedShmemSegAddr = NULL;
static Size UsedShmemSegSize = 0; static Size UsedShmemSegSize = 0;
...@@ -125,6 +125,8 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) ...@@ -125,6 +125,8 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
hmap2; hmap2;
char *szShareMem; char *szShareMem;
int i; int i;
DWORD size_high;
DWORD size_low;
/* Room for a header? */ /* Room for a header? */
Assert(size > MAXALIGN(sizeof(PGShmemHeader))); Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
...@@ -133,6 +135,13 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) ...@@ -133,6 +135,13 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
UsedShmemSegAddr = NULL; 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 * When recycling a shared memory segment, it may take a short while
* before it gets dropped from the global namespace. So re-try after * before it gets dropped from the global namespace. So re-try after
...@@ -147,11 +156,11 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) ...@@ -147,11 +156,11 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
*/ */
SetLastError(0); SetLastError(0);
hmap = CreateFileMapping((HANDLE) 0xFFFFFFFF, /* Use the pagefile */ hmap = CreateFileMapping(INVALID_HANDLE_VALUE, /* Use the pagefile */
NULL, /* Default security attrs */ NULL, /* Default security attrs */
PAGE_READWRITE, /* Memory is Read/Write */ PAGE_READWRITE, /* Memory is Read/Write */
0L, /* Size Upper 32 Bits */ size_high, /* Size Upper 32 Bits */
(DWORD) size, /* Size Lower 32 bits */ size_low, /* Size Lower 32 bits */
szShareMem); szShareMem);
if (!hmap) if (!hmap)
...@@ -203,7 +212,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) ...@@ -203,7 +212,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
/* Register on-exit routine to delete the new segment */ /* 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 * Get a pointer to the new shared memory segment. Map the whole segment
...@@ -235,7 +244,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) ...@@ -235,7 +244,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
/* Save info for possible future use */ /* Save info for possible future use */
UsedShmemSegAddr = memAddress; UsedShmemSegAddr = memAddress;
UsedShmemSegSize = size; UsedShmemSegSize = size;
UsedShmemSegID = (unsigned long) hmap2; UsedShmemSegID = hmap2;
return hdr; return hdr;
} }
...@@ -266,10 +275,10 @@ PGSharedMemoryReAttach(void) ...@@ -266,10 +275,10 @@ PGSharedMemoryReAttach(void)
elog(FATAL, "failed to release reserved memory region (addr=%p): %lu", elog(FATAL, "failed to release reserved memory region (addr=%p): %lu",
UsedShmemSegAddr, GetLastError()); 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) if (!hdr)
elog(FATAL, "could not reattach to shared memory (key=%d, addr=%p): %lu", elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): %lu",
(int) UsedShmemSegID, UsedShmemSegAddr, GetLastError()); UsedShmemSegID, UsedShmemSegAddr, GetLastError());
if (hdr != origUsedShmemSegAddr) if (hdr != origUsedShmemSegAddr)
elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)", elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)",
hdr, origUsedShmemSegAddr); hdr, origUsedShmemSegAddr);
...@@ -308,7 +317,7 @@ static void ...@@ -308,7 +317,7 @@ static void
pgwin32_SharedMemoryDelete(int status, Datum shmId) pgwin32_SharedMemoryDelete(int status, Datum shmId)
{ {
PGSharedMemoryDetach(); PGSharedMemoryDetach();
if (!CloseHandle((HANDLE) DatumGetInt32(shmId))) if (!CloseHandle(DatumGetPointer(shmId)))
elog(LOG, "could not close handle to shared memory: %lu", GetLastError()); elog(LOG, "could not close handle to shared memory: %lu", GetLastError());
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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 */ ...@@ -40,7 +40,11 @@ typedef struct PGShmemHeader /* standard header for all Postgres shmem */
#ifdef EXEC_BACKEND #ifdef EXEC_BACKEND
#ifndef WIN32
extern unsigned long UsedShmemSegID; extern unsigned long UsedShmemSegID;
#else
extern HANDLE UsedShmemSegID;
#endif
extern void *UsedShmemSegAddr; extern void *UsedShmemSegAddr;
extern void PGSharedMemoryReAttach(void); extern void PGSharedMemoryReAttach(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment