1212 */
1313#include "postgres.h"
1414
15- #include <psapi.h>
16-
1715#include "miscadmin.h"
1816#include "storage/dsm.h"
1917#include "storage/ipc.h"
@@ -26,32 +24,6 @@ static Size UsedShmemSegSize = 0;
2624static bool EnableLockPagesPrivilege (int elevel );
2725static void pgwin32_SharedMemoryDelete (int status , Datum shmId );
2826
29- /* Dump all modules loaded into proc */
30- static void
31- dumpdlls (HANDLE proc )
32- {
33- HMODULE dll [1024 ];
34- DWORD size_used = 1 ;
35- int i ,
36- n ;
37-
38- if (!EnumProcessModules (proc , dll , sizeof (dll ), & size_used ))
39- {
40- elog (LOG , "EnumProcessModules failed: %lu" , GetLastError ());
41- return ;
42- }
43- n = (int ) (size_used / sizeof (* dll ));
44- elog (LOG , "EnumProcessModules: %d modules in process 0x%p" , n , proc );
45- for (i = 0 ; i < n ; i ++ )
46- {
47- char name [MAXPGPATH ];
48-
49- if (!GetModuleFileNameEx (proc , dll [i ], name , sizeof (name )))
50- sprintf (name , "GetModuleFileNameEx failed: %lu" , GetLastError ());
51- elog (LOG , "%d: 0x%p %s" , i + 1 , dll [i ], name );
52- }
53- }
54-
5527static const char *
5628mi_type (DWORD code )
5729{
@@ -83,7 +55,7 @@ mi_state(DWORD code)
8355}
8456
8557static void
86- dumpmem (const char * reason , HANDLE proc )
58+ dumpmem (const char * reason )
8759{
8860 char * addr = 0 ;
8961 MEMORY_BASIC_INFORMATION mi ;
@@ -92,20 +64,18 @@ dumpmem(const char *reason, HANDLE proc)
9264 do
9365 {
9466 memset (& mi , 0 , sizeof (mi ));
95- if (!VirtualQueryEx ( proc , addr , & mi , sizeof (mi )))
67+ if (!VirtualQuery ( addr , & mi , sizeof (mi )))
9668 {
9769 if (GetLastError () == ERROR_INVALID_PARAMETER )
9870 break ;
99- elog (LOG , "VirtualQueryEx failed: %lu" , GetLastError ());
71+ elog (LOG , "VirtualQuery failed: %lu" , GetLastError ());
10072 break ;
10173 }
10274 elog (LOG , "0x%p+0x%p %s (alloc 0x%p) %s" ,
10375 mi .BaseAddress , (void * ) mi .RegionSize ,
10476 mi_type (mi .Type ), mi .AllocationBase , mi_state (mi .State ));
10577 addr += mi .RegionSize ;
10678 } while (addr > 0 );
107-
108- dumpdlls (proc );
10979}
11080
11181/*
@@ -446,7 +416,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port,
446416
447417 /* Log information about the segment's virtual memory use */
448418 if (VirtualQuery (memAddress , & info , sizeof (info )) != 0 )
449- elog (LOG , "mapped shared memory segment at %p, requested size %zu , mapped size %zu " ,
419+ elog (LOG , "mapped shared memory segment at %p, requested size 0x%zx , mapped size 0x%zx " ,
450420 memAddress , size , info .RegionSize );
451421 else
452422 elog (LOG , "VirtualQuery(%p) failed: error code %lu" ,
@@ -476,7 +446,7 @@ PGSharedMemoryReAttach(void)
476446 Assert (UsedShmemSegAddr != NULL );
477447 Assert (IsUnderPostmaster );
478448
479- dumpmem ("before VirtualFree" , GetCurrentProcess () );
449+ dumpmem ("before VirtualFree" );
480450
481451 /*
482452 * Release memory region reservation that was made by the postmaster
@@ -485,18 +455,20 @@ PGSharedMemoryReAttach(void)
485455 elog (FATAL , "failed to release reserved memory region (addr=%p): error code %lu" ,
486456 UsedShmemSegAddr , GetLastError ());
487457
488- dumpmem ("after VirtualFree" , GetCurrentProcess () );
458+ dumpmem ("after VirtualFree" );
489459
490460 hdr = (PGShmemHeader * ) MapViewOfFileEx (UsedShmemSegID , FILE_MAP_READ | FILE_MAP_WRITE , 0 , 0 , 0 , UsedShmemSegAddr );
491461 if (!hdr )
492462 {
493463 DWORD maperr = GetLastError ();
494464
495- dumpmem ("after MapViewOfFileEx" , GetCurrentProcess () );
465+ dumpmem ("after failed MapViewOfFileEx" );
496466
497467 elog (FATAL , "could not reattach to shared memory (key=%p, addr=%p): error code %lu" ,
498468 UsedShmemSegID , UsedShmemSegAddr , maperr );
499469 }
470+ else
471+ dumpmem ("after MapViewOfFileEx" );
500472 if (hdr != origUsedShmemSegAddr )
501473 elog (FATAL , "reattaching to shared memory returned unexpected address (got %p, expected %p)" ,
502474 hdr , origUsedShmemSegAddr );
@@ -639,7 +611,5 @@ pgwin32_ReserveSharedMemoryRegion(HANDLE hChild)
639611 return false;
640612 }
641613
642- dumpmem ("after reserve" , hChild );
643-
644614 return true;
645615}
0 commit comments