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 */
1616#include "storage/ipc.h"
1717#include "storage/pg_shmem.h"
1818
19- unsigned long UsedShmemSegID = 0 ;
19+ HANDLE UsedShmemSegID = 0 ;
2020void * UsedShmemSegAddr = NULL ;
2121static 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
308317pgwin32_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
0 commit comments