aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander <magnus@hagander.net>2010-01-02 12:18:45 +0000
committerMagnus Hagander <magnus@hagander.net>2010-01-02 12:18:45 +0000
commit2de9a463ff076caefd19e16c123e9f60491d1180 (patch)
tree16fdb9ffdc6a479f4c85a580fb46b340ec0dc215
parent13c5fdb5c8f8e1275bc3c31f196e574ab5177f3d (diff)
downloadpostgresql-2de9a463ff076caefd19e16c123e9f60491d1180.tar.gz
postgresql-2de9a463ff076caefd19e16c123e9f60491d1180.zip
Support 64-bit shared memory when building on 64-bit Windows.
Tsutomu Yamada
-rw-r--r--src/backend/port/win32_shmem.c31
-rw-r--r--src/include/storage/pg_shmem.h6
2 files changed, 25 insertions, 12 deletions
diff --git a/src/backend/port/win32_shmem.c b/src/backend/port/win32_shmem.c
index 9a17b86a9b1..c585e94730e 100644
--- a/src/backend/port/win32_shmem.c
+++ b/src/backend/port/win32_shmem.c
@@ -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());
}
diff --git a/src/include/storage/pg_shmem.h b/src/include/storage/pg_shmem.h
index fb6f24f0115..c32a63d2897 100644
--- a/src/include/storage/pg_shmem.h
+++ b/src/include/storage/pg_shmem.h
@@ -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);