12
12
*/
13
13
#include "postgres.h"
14
14
15
- #include <psapi.h>
16
-
17
15
#include "miscadmin.h"
18
16
#include "storage/dsm.h"
19
17
#include "storage/ipc.h"
@@ -26,32 +24,6 @@ static Size UsedShmemSegSize = 0;
26
24
static bool EnableLockPagesPrivilege (int elevel );
27
25
static void pgwin32_SharedMemoryDelete (int status ,Datum shmId );
28
26
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
-
55
27
static const char *
56
28
mi_type (DWORD code )
57
29
{
@@ -83,7 +55,7 @@ mi_state(DWORD code)
83
55
}
84
56
85
57
static void
86
- dumpmem (const char * reason , HANDLE proc )
58
+ dumpmem (const char * reason )
87
59
{
88
60
char * addr = 0 ;
89
61
MEMORY_BASIC_INFORMATION mi ;
@@ -92,20 +64,18 @@ dumpmem(const char *reason, HANDLE proc)
92
64
do
93
65
{
94
66
memset (& mi ,0 ,sizeof (mi ));
95
- if (!VirtualQueryEx ( proc , addr ,& mi ,sizeof (mi )))
67
+ if (!VirtualQuery ( addr ,& mi ,sizeof (mi )))
96
68
{
97
69
if (GetLastError ()== ERROR_INVALID_PARAMETER )
98
70
break ;
99
- elog (LOG ,"VirtualQueryEx failed: %lu" ,GetLastError ());
71
+ elog (LOG ,"VirtualQuery failed: %lu" ,GetLastError ());
100
72
break ;
101
73
}
102
74
elog (LOG ,"0x%p+0x%p %s (alloc 0x%p) %s" ,
103
75
mi .BaseAddress , (void * )mi .RegionSize ,
104
76
mi_type (mi .Type ),mi .AllocationBase ,mi_state (mi .State ));
105
77
addr += mi .RegionSize ;
106
78
}while (addr > 0 );
107
-
108
- dumpdlls (proc );
109
79
}
110
80
111
81
/*
@@ -446,7 +416,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port,
446
416
447
417
/* Log information about the segment's virtual memory use */
448
418
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 size0x%zx , mapped size0x%zx " ,
450
420
memAddress ,size ,info .RegionSize );
451
421
else
452
422
elog (LOG ,"VirtualQuery(%p) failed: error code %lu" ,
@@ -476,7 +446,7 @@ PGSharedMemoryReAttach(void)
476
446
Assert (UsedShmemSegAddr != NULL );
477
447
Assert (IsUnderPostmaster );
478
448
479
- dumpmem ("before VirtualFree" , GetCurrentProcess () );
449
+ dumpmem ("before VirtualFree" );
480
450
481
451
/*
482
452
* Release memory region reservation that was made by the postmaster
@@ -485,18 +455,20 @@ PGSharedMemoryReAttach(void)
485
455
elog (FATAL ,"failed to release reserved memory region (addr=%p): error code %lu" ,
486
456
UsedShmemSegAddr ,GetLastError ());
487
457
488
- dumpmem ("after VirtualFree" , GetCurrentProcess () );
458
+ dumpmem ("after VirtualFree" );
489
459
490
460
hdr = (PGShmemHeader * )MapViewOfFileEx (UsedShmemSegID ,FILE_MAP_READ |FILE_MAP_WRITE ,0 ,0 ,0 ,UsedShmemSegAddr );
491
461
if (!hdr )
492
462
{
493
463
DWORD maperr = GetLastError ();
494
464
495
- dumpmem ("after MapViewOfFileEx" , GetCurrentProcess () );
465
+ dumpmem ("afterfailed MapViewOfFileEx" );
496
466
497
467
elog (FATAL ,"could not reattach to shared memory (key=%p, addr=%p): error code %lu" ,
498
468
UsedShmemSegID ,UsedShmemSegAddr ,maperr );
499
469
}
470
+ else
471
+ dumpmem ("after MapViewOfFileEx" );
500
472
if (hdr != origUsedShmemSegAddr )
501
473
elog (FATAL ,"reattaching to shared memory returned unexpected address (got %p, expected %p)" ,
502
474
hdr ,origUsedShmemSegAddr );
@@ -639,7 +611,5 @@ pgwin32_ReserveSharedMemoryRegion(HANDLE hChild)
639
611
return false;
640
612
}
641
613
642
- dumpmem ("after reserve" ,hChild );
643
-
644
614
return true;
645
615
}