Skip to content

Commit 2de9a46

Browse files
committed
Support 64-bit shared memory when building on 64-bit Windows.
Tsutomu Yamada
1 parent 13c5fdb commit 2de9a46

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/backend/port/win32_shmem.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/backend/port/win32_shmem.c,v 1.12 2009/07/24 20:12:42 mha Exp $
9+
* $PostgreSQL: pgsql/src/backend/port/win32_shmem.c,v 1.13 2010/01/02 12:18:45 mha Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -16,7 +16,7 @@
1616
#include "storage/ipc.h"
1717
#include "storage/pg_shmem.h"
1818

19-
unsigned long UsedShmemSegID = 0;
19+
HANDLE UsedShmemSegID = 0;
2020
void *UsedShmemSegAddr = NULL;
2121
static Size UsedShmemSegSize = 0;
2222

@@ -125,6 +125,8 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
125125
hmap2;
126126
char *szShareMem;
127127
int i;
128+
DWORD size_high;
129+
DWORD size_low;
128130

129131
/* Room for a header? */
130132
Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
@@ -133,6 +135,13 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
133135

134136
UsedShmemSegAddr = NULL;
135137

138+
#ifdef _WIN64
139+
size_high = size >> 32;
140+
#else
141+
size_high = 0;
142+
#endif
143+
size_low = (DWORD) size;
144+
136145
/*
137146
* When recycling a shared memory segment, it may take a short while
138147
* before it gets dropped from the global namespace. So re-try after
@@ -147,11 +156,11 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
147156
*/
148157
SetLastError(0);
149158

150-
hmap = CreateFileMapping((HANDLE) 0xFFFFFFFF, /* Use the pagefile */
159+
hmap = CreateFileMapping(INVALID_HANDLE_VALUE, /* Use the pagefile */
151160
NULL, /* Default security attrs */
152161
PAGE_READWRITE, /* Memory is Read/Write */
153-
0L, /* Size Upper 32 Bits */
154-
(DWORD) size, /* Size Lower 32 bits */
162+
size_high, /* Size Upper 32 Bits */
163+
size_low, /* Size Lower 32 bits */
155164
szShareMem);
156165

157166
if (!hmap)
@@ -203,7 +212,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
203212

204213

205214
/* Register on-exit routine to delete the new segment */
206-
on_shmem_exit(pgwin32_SharedMemoryDelete, Int32GetDatum((unsigned long) hmap2));
215+
on_shmem_exit(pgwin32_SharedMemoryDelete, PointerGetDatum(hmap2));
207216

208217
/*
209218
* Get a pointer to the new shared memory segment. Map the whole segment
@@ -235,7 +244,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
235244
/* Save info for possible future use */
236245
UsedShmemSegAddr = memAddress;
237246
UsedShmemSegSize = size;
238-
UsedShmemSegID = (unsigned long) hmap2;
247+
UsedShmemSegID = hmap2;
239248

240249
return hdr;
241250
}
@@ -266,10 +275,10 @@ PGSharedMemoryReAttach(void)
266275
elog(FATAL, "failed to release reserved memory region (addr=%p): %lu",
267276
UsedShmemSegAddr, GetLastError());
268277

269-
hdr = (PGShmemHeader *) MapViewOfFileEx((HANDLE) UsedShmemSegID, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, UsedShmemSegAddr);
278+
hdr = (PGShmemHeader *) MapViewOfFileEx(UsedShmemSegID, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, UsedShmemSegAddr);
270279
if (!hdr)
271-
elog(FATAL, "could not reattach to shared memory (key=%d, addr=%p): %lu",
272-
(int) UsedShmemSegID, UsedShmemSegAddr, GetLastError());
280+
elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): %lu",
281+
UsedShmemSegID, UsedShmemSegAddr, GetLastError());
273282
if (hdr != origUsedShmemSegAddr)
274283
elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)",
275284
hdr, origUsedShmemSegAddr);
@@ -308,7 +317,7 @@ static void
308317
pgwin32_SharedMemoryDelete(int status, Datum shmId)
309318
{
310319
PGSharedMemoryDetach();
311-
if (!CloseHandle((HANDLE) DatumGetInt32(shmId)))
320+
if (!CloseHandle(DatumGetPointer(shmId)))
312321
elog(LOG, "could not close handle to shared memory: %lu", GetLastError());
313322
}
314323

src/include/storage/pg_shmem.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
1818
* Portions Copyright (c) 1994, Regents of the University of California
1919
*
20-
* $PostgreSQL: pgsql/src/include/storage/pg_shmem.h,v 1.25 2009/01/01 17:24:01 momjian Exp $
20+
* $PostgreSQL: pgsql/src/include/storage/pg_shmem.h,v 1.26 2010/01/02 12:18:45 mha Exp $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
@@ -40,7 +40,11 @@ typedef struct PGShmemHeader /* standard header for all Postgres shmem */
4040

4141

4242
#ifdef EXEC_BACKEND
43+
#ifndef WIN32
4344
extern unsigned long UsedShmemSegID;
45+
#else
46+
extern HANDLE UsedShmemSegID;
47+
#endif
4448
extern void *UsedShmemSegAddr;
4549

4650
extern void PGSharedMemoryReAttach(void);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy