Commit f7df8043 authored by Tom Lane's avatar Tom Lane

Remove Windows module-list-dumping code.

This code is evidently allocating memory and thus confusing matters
even more.  Let's see whether we can learn anything with
just VirtualQuery.

Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
parent bb779006
...@@ -79,7 +79,7 @@ libpostgres.a: postgres ...@@ -79,7 +79,7 @@ libpostgres.a: postgres
endif # cygwin endif # cygwin
ifeq ($(PORTNAME), win32) ifeq ($(PORTNAME), win32)
LIBS += -lsecur32 -lpsapi LIBS += -lsecur32
postgres: $(OBJS) $(WIN32RES) postgres: $(OBJS) $(WIN32RES)
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack=$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack=$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS) -o $@$(X)
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
*/ */
#include "postgres.h" #include "postgres.h"
#include <psapi.h>
#include "miscadmin.h" #include "miscadmin.h"
#include "storage/dsm.h" #include "storage/dsm.h"
#include "storage/ipc.h" #include "storage/ipc.h"
...@@ -26,32 +24,6 @@ static Size UsedShmemSegSize = 0; ...@@ -26,32 +24,6 @@ static Size UsedShmemSegSize = 0;
static bool EnableLockPagesPrivilege(int elevel); static bool EnableLockPagesPrivilege(int elevel);
static void pgwin32_SharedMemoryDelete(int status, Datum shmId); static void pgwin32_SharedMemoryDelete(int status, Datum shmId);
/* Dump all modules loaded into proc */
static void
dumpdlls(HANDLE proc)
{
HMODULE dll[1024];
DWORD size_used = 1;
int i,
n;
if (!EnumProcessModules(proc, dll, sizeof(dll), &size_used))
{
elog(LOG, "EnumProcessModules failed: %lu", GetLastError());
return;
}
n = (int) (size_used / sizeof(*dll));
elog(LOG, "EnumProcessModules: %d modules in process 0x%p", n, proc);
for (i = 0; i < n; i++)
{
char name[MAXPGPATH];
if (!GetModuleFileNameEx(proc, dll[i], name, sizeof(name)))
sprintf(name, "GetModuleFileNameEx failed: %lu", GetLastError());
elog(LOG, "%d: 0x%p %s", i + 1, dll[i], name);
}
}
static const char * static const char *
mi_type(DWORD code) mi_type(DWORD code)
{ {
...@@ -83,7 +55,7 @@ mi_state(DWORD code) ...@@ -83,7 +55,7 @@ mi_state(DWORD code)
} }
static void static void
dumpmem(const char *reason, HANDLE proc) dumpmem(const char *reason)
{ {
char *addr = 0; char *addr = 0;
MEMORY_BASIC_INFORMATION mi; MEMORY_BASIC_INFORMATION mi;
...@@ -92,11 +64,11 @@ dumpmem(const char *reason, HANDLE proc) ...@@ -92,11 +64,11 @@ dumpmem(const char *reason, HANDLE proc)
do do
{ {
memset(&mi, 0, sizeof(mi)); memset(&mi, 0, sizeof(mi));
if (!VirtualQueryEx(proc, addr, &mi, sizeof(mi))) if (!VirtualQuery(addr, &mi, sizeof(mi)))
{ {
if (GetLastError() == ERROR_INVALID_PARAMETER) if (GetLastError() == ERROR_INVALID_PARAMETER)
break; break;
elog(LOG, "VirtualQueryEx failed: %lu", GetLastError()); elog(LOG, "VirtualQuery failed: %lu", GetLastError());
break; break;
} }
elog(LOG, "0x%p+0x%p %s (alloc 0x%p) %s", elog(LOG, "0x%p+0x%p %s (alloc 0x%p) %s",
...@@ -104,8 +76,6 @@ dumpmem(const char *reason, HANDLE proc) ...@@ -104,8 +76,6 @@ dumpmem(const char *reason, HANDLE proc)
mi_type(mi.Type), mi.AllocationBase, mi_state(mi.State)); mi_type(mi.Type), mi.AllocationBase, mi_state(mi.State));
addr += mi.RegionSize; addr += mi.RegionSize;
} while (addr > 0); } while (addr > 0);
dumpdlls(proc);
} }
/* /*
...@@ -446,7 +416,7 @@ retry: ...@@ -446,7 +416,7 @@ retry:
/* Log information about the segment's virtual memory use */ /* Log information about the segment's virtual memory use */
if (VirtualQuery(memAddress, &info, sizeof(info)) != 0) if (VirtualQuery(memAddress, &info, sizeof(info)) != 0)
elog(LOG, "mapped shared memory segment at %p, requested size %zu, mapped size %zu", elog(LOG, "mapped shared memory segment at %p, requested size 0x%zx, mapped size 0x%zx",
memAddress, size, info.RegionSize); memAddress, size, info.RegionSize);
else else
elog(LOG, "VirtualQuery(%p) failed: error code %lu", elog(LOG, "VirtualQuery(%p) failed: error code %lu",
...@@ -476,7 +446,7 @@ PGSharedMemoryReAttach(void) ...@@ -476,7 +446,7 @@ PGSharedMemoryReAttach(void)
Assert(UsedShmemSegAddr != NULL); Assert(UsedShmemSegAddr != NULL);
Assert(IsUnderPostmaster); Assert(IsUnderPostmaster);
dumpmem("before VirtualFree", GetCurrentProcess()); dumpmem("before VirtualFree");
/* /*
* Release memory region reservation that was made by the postmaster * Release memory region reservation that was made by the postmaster
...@@ -485,18 +455,20 @@ PGSharedMemoryReAttach(void) ...@@ -485,18 +455,20 @@ PGSharedMemoryReAttach(void)
elog(FATAL, "failed to release reserved memory region (addr=%p): error code %lu", elog(FATAL, "failed to release reserved memory region (addr=%p): error code %lu",
UsedShmemSegAddr, GetLastError()); UsedShmemSegAddr, GetLastError());
dumpmem("after VirtualFree", GetCurrentProcess()); dumpmem("after VirtualFree");
hdr = (PGShmemHeader *) MapViewOfFileEx(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) if (!hdr)
{ {
DWORD maperr = GetLastError(); DWORD maperr = GetLastError();
dumpmem("after MapViewOfFileEx", GetCurrentProcess()); dumpmem("after failed MapViewOfFileEx");
elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): error code %lu", elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): error code %lu",
UsedShmemSegID, UsedShmemSegAddr, maperr); UsedShmemSegID, UsedShmemSegAddr, maperr);
} }
else
dumpmem("after MapViewOfFileEx");
if (hdr != origUsedShmemSegAddr) if (hdr != origUsedShmemSegAddr)
elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)", elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)",
hdr, origUsedShmemSegAddr); hdr, origUsedShmemSegAddr);
...@@ -639,7 +611,5 @@ pgwin32_ReserveSharedMemoryRegion(HANDLE hChild) ...@@ -639,7 +611,5 @@ pgwin32_ReserveSharedMemoryRegion(HANDLE hChild)
return false; return false;
} }
dumpmem("after reserve", hChild);
return true; return true;
} }
# src/makefiles/Makefile.win32 # src/makefiles/Makefile.win32
override CPPFLAGS+= -DPSAPI_VERSION=1
ifdef PGXS ifdef PGXS
BE_DLLLIBS= -L$(libdir) -lpostgres BE_DLLLIBS= -L$(libdir) -lpostgres
override CPPFLAGS+= -I$(includedir_server)/port/win32 override CPPFLAGS+= -I$(includedir_server)/port/win32
......
...@@ -174,10 +174,8 @@ sub mkvcbuild ...@@ -174,10 +174,8 @@ sub mkvcbuild
'repl_gram.y', 'syncrep_scanner.l', 'repl_gram.y', 'syncrep_scanner.l',
'syncrep_gram.y'); 'syncrep_gram.y');
$postgres->AddDefine('BUILDING_DLL'); $postgres->AddDefine('BUILDING_DLL');
$postgres->AddDefine('PSAPI_VERSION=1');
$postgres->AddLibrary('secur32.lib'); $postgres->AddLibrary('secur32.lib');
$postgres->AddLibrary('ws2_32.lib'); $postgres->AddLibrary('ws2_32.lib');
$postgres->AddLibrary('psapi.lib');
$postgres->AddLibrary('wldap32.lib') if ($solution->{options}->{ldap}); $postgres->AddLibrary('wldap32.lib') if ($solution->{options}->{ldap});
$postgres->FullExportDLL('postgres.lib'); $postgres->FullExportDLL('postgres.lib');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment