pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
gettimeofday cause crash on Windows
16+ messages / 6 participants
[nested] [flat]

* gettimeofday cause crash on Windows
@ 2015-02-11 12:11  Asif Naeem <anaeem.it@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Asif Naeem @ 2015-02-11 12:11 UTC (permalink / raw)
  To: pgsql-bugs

Hi,

PG95/pg_test_fsync utility (MSVC built) is crashing on Windows and It is
caused by gettimeofday (src\port\gettimeofday.c) function. The following
check-in raised this issue i.e.

commit 8001fe67a3d66c95861ce1f7075ef03953670d13
> Author: Simon Riggs <simon@2ndQuadrant.com>
> Date:   Mon Dec 8 23:36:06 2014 +0900
>     Windows: use GetSystemTimePreciseAsFileTime if available
>     PostgreSQL on Windows 8 or Windows Server 2012 will now
>     get high-resolution timestamps by dynamically loading the
>     GetSystemTimePreciseAsFileTime function. It'll fall back to
>     to GetSystemTimeAsFileTime if the higher precision variant
>     isn't found, so the same binaries without problems on older
>     Windows releases.
>     No attempt is made to detect the Windows version.  Only the
>     presence or absence of the desired function is considered.
>     Craig Ringer
>

It make PG gettimeofday() implementation depend on
init_win32_gettimeofday() function call, otherwise gettimeofday() function
is going to crash the related process because of NULL pg_get_system_time
function pointer. PFA patch gettimeofday_win32_v1.patch, it enables
necessary initialization in related utilities.

PFA patch gettimeofday_win32_suggestion_v1.patch, it suggest minor change
to make it more versatile version of PG gettimeofday() function. It makes
it more crash safe and by default it uses much faster or lesser CPU
intensive GetSystemTimeAsFileTime function. If a pg utility do require high
precision, it can call init_win32_precise_gettimeofday() to try to elevate
the precision when available. Please do let me know if I missed something
or more information is required. Thanks.

Regards,
Muhammad Asif Naeem

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments: download all (2 files, .tar.gz)

gettimeofday_win32_suggestion_v1.patch (application/octet-stream, 1.8K) download diff --git a/src/backend/main/main.c b/src/backend/main/main.c index 582198f..f9994d0 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -263,8 +263,11 @@ startup_hacks(const char *progname) SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); #ifndef HAVE_GETTIMEOFDAY - /* Figure out which syscall to use to capture timestamp information */ - init_win32_gettimeofday(); + /* + * Try to utilize high resolution syscall to capture timestamp + * information + */ + init_win32_precise_gettimeofday(); #endif } diff --git a/src/include/port.h b/src/include/port.h index 26d7fcd..e53d19e 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -329,7 +329,7 @@ extern FILE *pgwin32_popen(const char *command, const char *type); /* Last parameter not used */ extern int gettimeofday(struct timeval * tp, struct timezone * tzp); /* On windows we need to call some backend start setup for accurate timing */ -extern void init_win32_gettimeofday(void); +extern void init_win32_precise_gettimeofday(void); #endif #else /* !WIN32 */ diff --git a/src/port/gettimeofday.c b/src/port/gettimeofday.c index eabf161..e81e03b 100644 --- a/src/port/gettimeofday.c +++ b/src/port/gettimeofday.c @@ -49,14 +49,14 @@ static const unsigned __int64 epoch = UINT64CONST(116444736000000000); typedef VOID (WINAPI *PgGetSystemTimeFn)(LPFILETIME); /* Storage for the function we pick at runtime */ -static PgGetSystemTimeFn pg_get_system_time = NULL; +static PgGetSystemTimeFn pg_get_system_time = &GetSystemTimeAsFileTime; /* * During backend startup, determine if GetSystemTimePreciseAsFileTime is * available and use it; if not, fall back to GetSystemTimeAsFileTime. */ void -init_win32_gettimeofday(void) +init_win32_precise_gettimeofday(void) { /* * Because it's guaranteed that kernel32.dll will be linked into our
gettimeofday_win32_v1.patch (application/octet-stream, 1.7K) download diff --git a/contrib/pg_test_fsync/pg_test_fsync.c b/contrib/pg_test_fsync/pg_test_fsync.c index c842762..906bfe2 100644 --- a/contrib/pg_test_fsync/pg_test_fsync.c +++ b/contrib/pg_test_fsync/pg_test_fsync.c @@ -98,6 +98,11 @@ main(int argc, char *argv[]) { progname = get_progname(argv[0]); +#if defined(WIN32) && !defined(HAVE_GETTIMEOFDAY) + /* Figure out which syscall to use to capture timestamp information */ + init_win32_gettimeofday(); +#endif + handle_args(argc, argv); /* Prevent leaving behind the test file */ diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index fbf7106..84ad5ba 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -1955,6 +1955,11 @@ main(int argc, char **argv) progname = get_progname(argv[0]); set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup")); +#if defined(WIN32) && !defined(HAVE_GETTIMEOFDAY) + /* Figure out which syscall to use to capture timestamp information */ + init_win32_gettimeofday(); +#endif + if (argc > 1) { if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c index a16089f..db34f0e 100644 --- a/src/bin/pg_resetxlog/pg_resetxlog.c +++ b/src/bin/pg_resetxlog/pg_resetxlog.c @@ -99,6 +99,11 @@ main(int argc, char *argv[]) progname = get_progname(argv[0]); +#if defined(WIN32) && !defined(HAVE_GETTIMEOFDAY) + /* Figure out which syscall to use to capture timestamp information */ + init_win32_gettimeofday(); +#endif + if (argc > 1) { if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
^ permalink raw reply [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-12 12:48  Michael Paquier <michael.paquier@gmail.com>
  parent: Asif Naeem <anaeem.it@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Michael Paquier @ 2015-02-12 12:48 UTC (permalink / raw)
  To: Asif Naeem <anaeem.it@gmail.com>; +Cc: pgsql-bugs

On Wed, Feb 11, 2015 at 9:11 PM, Asif Naeem <anaeem.it@gmail.com> wrote:
>
> Hi,
>
> PG95/pg_test_fsync utility (MSVC built) is crashing on Windows and It is caused by gettimeofday (src\port\gettimeofday.c) function. The following check-in raised this issue i.e.
>
>> commit 8001fe67a3d66c95861ce1f7075ef03953670d13
>> Author: Simon Riggs <simon@2ndQuadrant.com>
>> Date:   Mon Dec 8 23:36:06 2014 +0900
>>     Windows: use GetSystemTimePreciseAsFileTime if available
>>     PostgreSQL on Windows 8 or Windows Server 2012 will now
>>     get high-resolution timestamps by dynamically loading the
>>     GetSystemTimePreciseAsFileTime function. It'll fall back to
>>     to GetSystemTimeAsFileTime if the higher precision variant
>>     isn't found, so the same binaries without problems on older
>>     Windows releases.
>>     No attempt is made to detect the Windows version.  Only the
>>     presence or absence of the desired function is considered.
>>     Craig Ringer
>
>
> It make PG gettimeofday() implementation depend on init_win32_gettimeofday() function call, otherwise gettimeofday() function is going to crash the related process because of NULL pg_get_system_time function pointer. PFA patch gettimeofday_win32_v1.patch, it enables necessary initialization in related utilities.
>
> PFA patch gettimeofday_win32_suggestion_v1.patch, it suggest minor change to make it more versatile version of PG gettimeofday() function. It makes it more crash safe and by default it uses much faster or lesser CPU intensive GetSystemTimeAsFileTime function. If a pg utility do require high precision, it can call init_win32_precise_gettimeofday() to try to elevate the precision when available. Please do let me know if I missed something or more information is required.

I didn't follow much the thread implementing this feature, but this
commit has somewhat not taken into account the fact that the contents
of src/port could as well be used for the frontends, per se the
comments on top of init_win32_gettimeofday mentioning only the backend
startup, something not wrong in itself, but not completely right
either. So what we have now is an unpleasant crash trigger for any
client applications on Windows < 2k12 linking to libpqport that call
gettimeofday(). I would not be surprised that we would get bug reports
of the type "why my client binary crashes suddendly with 9.5" if we
keep the code as-is.

So ISTM that your patch does the correct thing by setting
pg_get_system_time to &GetSystemTimeAsFileTime to not break any
existing applications, and that we should as well update any in-core
binary tools to switch to the precise API. I rewrote your first patch
as the attached, which is really needed to fix the potential crash
problems with some comment cleanup, in addition to a second patch that
switches the frontend binaries to use the precise routine. After a
quick scan of the code it seems that you have forgotten nothing, we
need to switch correctly to the precise API for pg_test_fsync,
pg_resetxlog and pg_basebackup. If anything else is forgotten, we
could always add it later, for now any existing frontend binaries
would not crash.

It will be important to mention as well in the release notes how
client binaries can update to the precise API as well.
Regards,
-- 
Michael

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments: download all (2 files, .tar.gz)

0001-Switch-gettimeofday-to-use-GetSystemTimeAsFileTime-o.patch (text/x-diff, 3.6K) download From 24b6bc3ce36b73bcb0d6d32fe702e2761e337e85 Mon Sep 17 00:00:00 2001 From: Michael Paquier <michael@otacoo.com> Date: Wed, 11 Feb 2015 16:21:13 -0800 Subject: [PATCH 1/2] Switch gettimeofday to use GetSystemTimeAsFileTime on win32 by default Since commit 8001fe6, processes or client binaries running on Windows can initialize the syscall function used to map gettimeofday in libpgport by calling a dedicated initialization function. However this was done in a way where any process calling gettimeofday from libpgport needs mandatorily to call this initialization function, making for example any client binary calling gettimeofday() crash on Windows should it not be initialized. This commit switches gettimeofday to use by default GetSystemTimeAsFileTime, which is backward-compatible with the old behavior to prevent any crashes. Existing client binaries can simply upgrade to the precise API by calling the initialization function. Do at the same time some wordsmithing in gettimeofday.c, which considered only backends in the comments. Per patch and report from Asif Naheem. --- src/backend/main/main.c | 7 +++++-- src/include/port.h | 7 +++++-- src/port/gettimeofday.c | 12 +++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/backend/main/main.c b/src/backend/main/main.c index 582198f..d712f4c 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -263,8 +263,11 @@ startup_hacks(const char *progname) SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); #ifndef HAVE_GETTIMEOFDAY - /* Figure out which syscall to use to capture timestamp information */ - init_win32_gettimeofday(); + /* + * Attempt upgrade to the highest resolution syscall to capture + * timestamp information. + */ + pgwin32_upgrade_gettimeofday(); #endif } diff --git a/src/include/port.h b/src/include/port.h index 26d7fcd..60501d8 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -328,8 +328,11 @@ extern FILE *pgwin32_popen(const char *command, const char *type); #ifndef HAVE_GETTIMEOFDAY /* Last parameter not used */ extern int gettimeofday(struct timeval * tp, struct timezone * tzp); -/* On windows we need to call some backend start setup for accurate timing */ -extern void init_win32_gettimeofday(void); +/* + * On windows this function can be called to upgrade to a higher level of + * precision for capture of timestamp information. + */ +extern void pgwin32_upgrade_gettimeofday(void); #endif #else /* !WIN32 */ diff --git a/src/port/gettimeofday.c b/src/port/gettimeofday.c index eabf161..167df15 100644 --- a/src/port/gettimeofday.c +++ b/src/port/gettimeofday.c @@ -48,15 +48,17 @@ static const unsigned __int64 epoch = UINT64CONST(116444736000000000); */ typedef VOID (WINAPI *PgGetSystemTimeFn)(LPFILETIME); -/* Storage for the function we pick at runtime */ -static PgGetSystemTimeFn pg_get_system_time = NULL; +/* Storage for the function picked up at runtime */ +static PgGetSystemTimeFn pg_get_system_time = &GetSystemTimeAsFileTime; /* - * During backend startup, determine if GetSystemTimePreciseAsFileTime is - * available and use it; if not, fall back to GetSystemTimeAsFileTime. + * Determine if GetSystemTimePreciseAsFileTime is available and use it to + * allow the use of the highest level of resolution for timestamp information + * timestamp resolution on system. If it is not available, fall back to + * GetSystemTimeAsFileTime. */ void -init_win32_gettimeofday(void) +pgwin32_upgrade_gettimeofday(void) { /* * Because it's guaranteed that kernel32.dll will be linked into our -- 1.9.2.msysgit.0
0002-Switch-client-binaries-to-use-precise-timestamp-rout.patch (text/x-diff, 2.3K) download From 9d4d2d255e8057365c6c0a8904bee5db5f97b4a1 Mon Sep 17 00:00:00 2001 From: Michael Paquier <michael@otacoo.com> Date: Wed, 11 Feb 2015 16:36:15 -0800 Subject: [PATCH 2/2] Switch client binaries to use precise timestamp routine on Windows The following client binaries are updated: - pg_basebackup - pg_resetxlog - pg_test_fsync Patch and report from Asif Naheem. --- contrib/pg_test_fsync/pg_test_fsync.c | 8 ++++++++ src/bin/pg_basebackup/pg_basebackup.c | 8 ++++++++ src/bin/pg_resetxlog/pg_resetxlog.c | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/contrib/pg_test_fsync/pg_test_fsync.c b/contrib/pg_test_fsync/pg_test_fsync.c index c842762..269bd08 100644 --- a/contrib/pg_test_fsync/pg_test_fsync.c +++ b/contrib/pg_test_fsync/pg_test_fsync.c @@ -98,6 +98,14 @@ main(int argc, char *argv[]) { progname = get_progname(argv[0]); +#if defined(WIN32) && !defined(HAVE_GETTIMEOFDAY) + /* + * Attempt upgrade to more precise function to retrieve timestamp + * information. + */ + pgwin32_upgrade_gettimeofday(); +#endif + handle_args(argc, argv); /* Prevent leaving behind the test file */ diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index fbf7106..cf215f0 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -1955,6 +1955,14 @@ main(int argc, char **argv) progname = get_progname(argv[0]); set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup")); +#if defined(WIN32) && !defined(HAVE_GETTIMEOFDAY) + /* + * Attempt upgrade to more precise function to retrieve timestamp + * information. + */ + pgwin32_upgrade_gettimeofday(); +#endif + if (argc > 1) { if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c index a16089f..a862d71 100644 --- a/src/bin/pg_resetxlog/pg_resetxlog.c +++ b/src/bin/pg_resetxlog/pg_resetxlog.c @@ -99,6 +99,14 @@ main(int argc, char *argv[]) progname = get_progname(argv[0]); +#if defined(WIN32) && !defined(HAVE_GETTIMEOFDAY) + /* + * Attempt upgrade to more precise function to retrieve timestamp + * information. + */ + pgwin32_upgrade_gettimeofday(); +#endif + if (argc > 1) { if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) -- 1.9.2.msysgit.0
^ permalink raw reply [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-12 12:54  Andres Freund <andres@2ndquadrant.com>
  parent: Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Andres Freund @ 2015-02-12 12:54 UTC (permalink / raw)
  To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Asif Naeem <anaeem.it@gmail.com>; pgsql-bugs

On 2015-02-12 04:48:00 -0800, Michael Paquier wrote:
> I didn't follow much the thread implementing this feature, but this
> commit has somewhat not taken into account the fact that the contents
> of src/port could as well be used for the frontends, per se the
> comments on top of init_win32_gettimeofday mentioning only the backend
> startup, something not wrong in itself, but not completely right
> either. So what we have now is an unpleasant crash trigger for any
> client applications on Windows < 2k12 linking to libpqport that call
> gettimeofday(). I would not be surprised that we would get bug reports
> of the type "why my client binary crashes suddendly with 9.5" if we
> keep the code as-is.

> So ISTM that your patch does the correct thing by setting
> pg_get_system_time to &GetSystemTimeAsFileTime to not break any
> existing applications, and that we should as well update any in-core
> binary tools to switch to the precise API

I think I'd rather have it crash so people are forced to adjust the
client applications. The number of things linking to pgport should be
rather low.

Greetings,

Andres Freund


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-12 13:09  Michael Paquier <michael.paquier@gmail.com>
  parent: Andres Freund <andres@2ndquadrant.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Michael Paquier @ 2015-02-12 13:09 UTC (permalink / raw)
  To: Andres Freund <andres@2ndquadrant.com>; +Cc: Asif Naeem <anaeem.it@gmail.com>; pgsql-bugs

On Thu, Feb 12, 2015 at 9:54 PM, Andres Freund <andres@2ndquadrant.com> wrote:
> On 2015-02-12 04:48:00 -0800, Michael Paquier wrote:
>> I didn't follow much the thread implementing this feature, but this
>> commit has somewhat not taken into account the fact that the contents
>> of src/port could as well be used for the frontends, per se the
>> comments on top of init_win32_gettimeofday mentioning only the backend
>> startup, something not wrong in itself, but not completely right
>> either. So what we have now is an unpleasant crash trigger for any
>> client applications on Windows < 2k12 linking to libpqport that call
>> gettimeofday(). I would not be surprised that we would get bug reports
>> of the type "why my client binary crashes suddendly with 9.5" if we
>> keep the code as-is.
>
>> So ISTM that your patch does the correct thing by setting
>> pg_get_system_time to &GetSystemTimeAsFileTime to not break any
>> existing applications, and that we should as well update any in-core
>> binary tools to switch to the precise API
>
> I think I'd rather have it crash so people are forced to adjust the
> client applications. The number of things linking to pgport should be
> rather low.

I'd take it on the safe side, not the hard one :)

FWIW, applications are not broken if they use GetSystemTimeAsFileTime,
simply less precise. So we should push for improvements, not mandatory
moves without a deprecation period.
-- 
Michael


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-12 13:13  Andres Freund <andres@2ndquadrant.com>
  parent: Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Andres Freund @ 2015-02-12 13:13 UTC (permalink / raw)
  To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Asif Naeem <anaeem.it@gmail.com>; pgsql-bugs

On 2015-02-12 22:09:43 +0900, Michael Paquier wrote:
> On Thu, Feb 12, 2015 at 9:54 PM, Andres Freund <andres@2ndquadrant.com> wrote:
> > On 2015-02-12 04:48:00 -0800, Michael Paquier wrote:
> >> I didn't follow much the thread implementing this feature, but this
> >> commit has somewhat not taken into account the fact that the contents
> >> of src/port could as well be used for the frontends, per se the
> >> comments on top of init_win32_gettimeofday mentioning only the backend
> >> startup, something not wrong in itself, but not completely right
> >> either. So what we have now is an unpleasant crash trigger for any
> >> client applications on Windows < 2k12 linking to libpqport that call
> >> gettimeofday(). I would not be surprised that we would get bug reports
> >> of the type "why my client binary crashes suddendly with 9.5" if we
> >> keep the code as-is.
> >
> >> So ISTM that your patch does the correct thing by setting
> >> pg_get_system_time to &GetSystemTimeAsFileTime to not break any
> >> existing applications, and that we should as well update any in-core
> >> binary tools to switch to the precise API
> >
> > I think I'd rather have it crash so people are forced to adjust the
> > client applications. The number of things linking to pgport should be
> > rather low.
> 
> I'd take it on the safe side, not the hard one :)

Meh. If this were libpq, I'd tend to agree, but it isn't.

> FWIW, applications are not broken if they use GetSystemTimeAsFileTime,
> simply less precise. So we should push for improvements, not mandatory
> moves without a deprecation period.

pgport isn't an actual enduser library. And we feel free to yank stuff
in/out of it all the time.

Greetings,

Andres Freund

-- 
 Andres Freund	                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-12 14:20  Asif Naeem <anaeem.it@gmail.com>
  parent: Andres Freund <andres@2ndquadrant.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Asif Naeem @ 2015-02-12 14:20 UTC (permalink / raw)
  To: Andres Freund <andres@2ndquadrant.com>; +Cc: Michael Paquier <michael.paquier@gmail.com>; pgsql-bugs

Don’t you feel gettimeofday() implementation is incomplete in current
state, Is there any other example of function port in PG that could lead to
crash if its related init_* function is not called earlier ?. As mentioned
by Michael, it seems not enough documented (release notes etc), at least it
need to give warning etc instead of simply crash the related process.
GetSystemTimeAsFileTime() function is less precise but it is quite fast and
less CPU intensive then GetSystemTimePreciseAsFileTime() function,
GetSystemTimePreciseAsFileTime() can effect performance of an application.
With the proposed patch, gettimeofday() function is more safe and more
versatile, a contrib may use it as per its need of precision. Thanks.

Regards,
Muhammad Asif Naeem


On Thu, Feb 12, 2015 at 6:13 PM, Andres Freund <andres@2ndquadrant.com>
wrote:

> On 2015-02-12 22:09:43 +0900, Michael Paquier wrote:
> > On Thu, Feb 12, 2015 at 9:54 PM, Andres Freund <andres@2ndquadrant.com>
> wrote:
> > > On 2015-02-12 04:48:00 -0800, Michael Paquier wrote:
> > >> I didn't follow much the thread implementing this feature, but this
> > >> commit has somewhat not taken into account the fact that the contents
> > >> of src/port could as well be used for the frontends, per se the
> > >> comments on top of init_win32_gettimeofday mentioning only the backend
> > >> startup, something not wrong in itself, but not completely right
> > >> either. So what we have now is an unpleasant crash trigger for any
> > >> client applications on Windows < 2k12 linking to libpqport that call
> > >> gettimeofday(). I would not be surprised that we would get bug reports
> > >> of the type "why my client binary crashes suddendly with 9.5" if we
> > >> keep the code as-is.
> > >
> > >> So ISTM that your patch does the correct thing by setting
> > >> pg_get_system_time to &GetSystemTimeAsFileTime to not break any
> > >> existing applications, and that we should as well update any in-core
> > >> binary tools to switch to the precise API
> > >
> > > I think I'd rather have it crash so people are forced to adjust the
> > > client applications. The number of things linking to pgport should be
> > > rather low.
> >
> > I'd take it on the safe side, not the hard one :)
>
> Meh. If this were libpq, I'd tend to agree, but it isn't.
>
> > FWIW, applications are not broken if they use GetSystemTimeAsFileTime,
> > simply less precise. So we should push for improvements, not mandatory
> > moves without a deprecation period.
>
> pgport isn't an actual enduser library. And we feel free to yank stuff
> in/out of it all the time.
>
> Greetings,
>
> Andres Freund
>
> --
>  Andres Freund                     http://www.2ndQuadrant.com/
>  PostgreSQL Development, 24x7 Support, Training & Services
>

^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-12 15:14  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Asif Naeem <anaeem.it@gmail.com>
  0 siblings, 2 replies; 16+ messages in thread

From: Alvaro Herrera @ 2015-02-12 15:14 UTC (permalink / raw)
  To: Asif Naeem <anaeem.it@gmail.com>; +Cc: Andres Freund <andres@2ndquadrant.com>; Michael Paquier <michael.paquier@gmail.com>; pgsql-bugs

Asif Naeem wrote:
> Don’t you feel gettimeofday() implementation is incomplete in current
> state, Is there any other example of function port in PG that could lead to
> crash if its related init_* function is not called earlier ?. As mentioned
> by Michael, it seems not enough documented (release notes etc), at least it
> need to give warning etc instead of simply crash the related process.
> GetSystemTimeAsFileTime() function is less precise but it is quite fast and
> less CPU intensive then GetSystemTimePreciseAsFileTime() function,
> GetSystemTimePreciseAsFileTime() can effect performance of an application.
> With the proposed patch, gettimeofday() function is more safe and more
> versatile, a contrib may use it as per its need of precision. Thanks.

Ideally we would the Precise dance automatically, without requiring the
program to call an initialization function.  Otherwise, programs may
never be updated to use Precise rather than the stock function.  I guess
this is the reason Andres prefers a crash: to force programs to be
updated to include the initialization step.

I wonder if it would work to set the function initially to the
initialization function, so that on the first call the Precise version,
if it exists, is detected (or the stock version otherwise) and set as
the function to call for later -- without requiring a jump in every
subsequent execution of gettimeofday(), of course.  The initialization
function itself would have to return the value returned by
GetSystemTimePreciseAsFileTime, of course.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-12 17:42  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  1 sibling, 0 replies; 16+ messages in thread

From: Tom Lane @ 2015-02-12 17:42 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Asif Naeem <anaeem.it@gmail.com>; Andres Freund <andres@2ndquadrant.com>; Michael Paquier <michael.paquier@gmail.com>; pgsql-bugs

Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> I wonder if it would work to set the function initially to the
> initialization function, so that on the first call the Precise version,
> if it exists, is detected (or the stock version otherwise) and set as
> the function to call for later -- without requiring a jump in every
> subsequent execution of gettimeofday(), of course.  The initialization
> function itself would have to return the value returned by
> GetSystemTimePreciseAsFileTime, of course.

+1.  The idea that we are going to alter the calling requirements around a
POSIX-standard function is utterly horrible.  It will break third-party
code, very probably.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-12 17:53  Andres Freund <andres@2ndquadrant.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  1 sibling, 1 reply; 16+ messages in thread

From: Andres Freund @ 2015-02-12 17:53 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Asif Naeem <anaeem.it@gmail.com>; Michael Paquier <michael.paquier@gmail.com>; pgsql-bugs

On 2015-02-12 12:14:03 -0300, Alvaro Herrera wrote:
> Asif Naeem wrote:
> > Don’t you feel gettimeofday() implementation is incomplete in current
> > state, Is there any other example of function port in PG that could lead to
> > crash if its related init_* function is not called earlier ?. As mentioned
> > by Michael, it seems not enough documented (release notes etc), at least it
> > need to give warning etc instead of simply crash the related process.
> > GetSystemTimeAsFileTime() function is less precise but it is quite fast and
> > less CPU intensive then GetSystemTimePreciseAsFileTime() function,
> > GetSystemTimePreciseAsFileTime() can effect performance of an application.
> > With the proposed patch, gettimeofday() function is more safe and more
> > versatile, a contrib may use it as per its need of precision. Thanks.
> 
> Ideally we would the Precise dance automatically, without requiring the
> program to call an initialization function.  Otherwise, programs may
> never be updated to use Precise rather than the stock function.  I guess
> this is the reason Andres prefers a crash: to force programs to be
> updated to include the initialization step.
> 
> I wonder if it would work to set the function initially to the
> initialization function, so that on the first call the Precise version,
> if it exists, is detected (or the stock version otherwise) and set as
> the function to call for later -- without requiring a jump in every
> subsequent execution of gettimeofday(), of course.  The initialization
> function itself would have to return the value returned by
> GetSystemTimePreciseAsFileTime, of course.

Yes, that sounds like a good idea.

Greetings,

Andres Freund

-- 
 Andres Freund	                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-12 19:41  Asif Naeem <anaeem.it@gmail.com>
  parent: Andres Freund <andres@2ndquadrant.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Asif Naeem @ 2015-02-12 19:41 UTC (permalink / raw)
  To: Andres Freund <andres@2ndquadrant.com>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; Michael Paquier <michael.paquier@gmail.com>; pgsql-bugs

Superb idea. PFA patch. Please do let me know if I missed something. Thanks.

On Thu, Feb 12, 2015 at 10:53 PM, Andres Freund <andres@2ndquadrant.com>
wrote:

> On 2015-02-12 12:14:03 -0300, Alvaro Herrera wrote:
> > Asif Naeem wrote:
> > > Don’t you feel gettimeofday() implementation is incomplete in current
> > > state, Is there any other example of function port in PG that could
> lead to
> > > crash if its related init_* function is not called earlier ?. As
> mentioned
> > > by Michael, it seems not enough documented (release notes etc), at
> least it
> > > need to give warning etc instead of simply crash the related process.
> > > GetSystemTimeAsFileTime() function is less precise but it is quite
> fast and
> > > less CPU intensive then GetSystemTimePreciseAsFileTime() function,
> > > GetSystemTimePreciseAsFileTime() can effect performance of an
> application.
> > > With the proposed patch, gettimeofday() function is more safe and more
> > > versatile, a contrib may use it as per its need of precision. Thanks.
> >
> > Ideally we would the Precise dance automatically, without requiring the
> > program to call an initialization function.  Otherwise, programs may
> > never be updated to use Precise rather than the stock function.  I guess
> > this is the reason Andres prefers a crash: to force programs to be
> > updated to include the initialization step.
> >
> > I wonder if it would work to set the function initially to the
> > initialization function, so that on the first call the Precise version,
> > if it exists, is detected (or the stock version otherwise) and set as
> > the function to call for later -- without requiring a jump in every
> > subsequent execution of gettimeofday(), of course.  The initialization
> > function itself would have to return the value returned by
> > GetSystemTimePreciseAsFileTime, of course.
>
> Yes, that sounds like a good idea.
>
> Greetings,
>
> Andres Freund
>
> --
>  Andres Freund                     http://www.2ndQuadrant.com/
>  PostgreSQL Development, 24x7 Support, Training & Services
>

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

gettimeofday_win32_v2.patch (application/octet-stream, 2.3K) download diff --git a/src/backend/main/main.c b/src/backend/main/main.c index 582198f..2f07a58 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -261,12 +261,6 @@ startup_hacks(const char *progname) /* In case of general protection fault, don't show GUI popup box */ SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); - -#ifndef HAVE_GETTIMEOFDAY - /* Figure out which syscall to use to capture timestamp information */ - init_win32_gettimeofday(); -#endif - } #endif /* WIN32 */ diff --git a/src/include/port.h b/src/include/port.h index 26d7fcd..a1ab42e 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -328,8 +328,6 @@ extern FILE *pgwin32_popen(const char *command, const char *type); #ifndef HAVE_GETTIMEOFDAY /* Last parameter not used */ extern int gettimeofday(struct timeval * tp, struct timezone * tzp); -/* On windows we need to call some backend start setup for accurate timing */ -extern void init_win32_gettimeofday(void); #endif #else /* !WIN32 */ diff --git a/src/port/gettimeofday.c b/src/port/gettimeofday.c index eabf161..660ed5e 100644 --- a/src/port/gettimeofday.c +++ b/src/port/gettimeofday.c @@ -30,6 +30,8 @@ #include <sys/time.h> +static void +init_gettimeofday(LPFILETIME lpSystemTimeAsFileTime); /* FILETIME of Jan 1 1970 00:00:00, the PostgreSQL epoch */ static const unsigned __int64 epoch = UINT64CONST(116444736000000000); @@ -49,14 +51,14 @@ static const unsigned __int64 epoch = UINT64CONST(116444736000000000); typedef VOID (WINAPI *PgGetSystemTimeFn)(LPFILETIME); /* Storage for the function we pick at runtime */ -static PgGetSystemTimeFn pg_get_system_time = NULL; +static PgGetSystemTimeFn pg_get_system_time = &init_gettimeofday; /* - * During backend startup, determine if GetSystemTimePreciseAsFileTime is + * One time initializer, determine if GetSystemTimePreciseAsFileTime is * available and use it; if not, fall back to GetSystemTimeAsFileTime. */ -void -init_win32_gettimeofday(void) +static void +init_gettimeofday(LPFILETIME lpSystemTimeAsFileTime) { /* * Because it's guaranteed that kernel32.dll will be linked into our @@ -88,6 +90,7 @@ init_win32_gettimeofday(void) pg_get_system_time = &GetSystemTimeAsFileTime; } + (*pg_get_system_time)(lpSystemTimeAsFileTime); } /*
^ permalink raw reply [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-13 02:59  Michael Paquier <michael.paquier@gmail.com>
  parent: Asif Naeem <anaeem.it@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Michael Paquier @ 2015-02-13 02:59 UTC (permalink / raw)
  To: Asif Naeem <anaeem.it@gmail.com>; +Cc: Andres Freund <andres@2ndquadrant.com>; Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs

On Fri, Feb 13, 2015 at 4:41 AM, Asif Naeem wrote:
> On Thu, Feb 12, 2015 at 10:53 PM, Andres Freund wrote:
>>
>> On 2015-02-12 12:14:03 -0300, Alvaro Herrera wrote:
>> > Asif Naeem wrote:
>> > > Don't you feel gettimeofday() implementation is incomplete in current
>> > > state, Is there any other example of function port in PG that could
>> > > lead to
>> > > crash if its related init_* function is not called earlier ?. As
>> > > mentioned
>> > > by Michael, it seems not enough documented (release notes etc), at
>> > > least it
>> > > need to give warning etc instead of simply crash the related process.
>> > > GetSystemTimeAsFileTime() function is less precise but it is quite
>> > > fast and
>> > > less CPU intensive then GetSystemTimePreciseAsFileTime() function,
>> > > GetSystemTimePreciseAsFileTime() can effect performance of an
>> > > application.
>> > > With the proposed patch, gettimeofday() function is more safe and more
>> > > versatile, a contrib may use it as per its need of precision. Thanks.
>> >
>> > Ideally we would the Precise dance automatically, without requiring the
>> > program to call an initialization function.  Otherwise, programs may
>> > never be updated to use Precise rather than the stock function.  I guess
>> > this is the reason Andres prefers a crash: to force programs to be
>> > updated to include the initialization step.
>> >
>> > I wonder if it would work to set the function initially to the
>> > initialization function, so that on the first call the Precise version,
>> > if it exists, is detected (or the stock version otherwise) and set as
>> > the function to call for later -- without requiring a jump in every
>> > subsequent execution of gettimeofday(), of course.  The initialization
>> > function itself would have to return the value returned by
>> > GetSystemTimePreciseAsFileTime, of course.
>>
>> Yes, that sounds like a good idea.

+1. Excellent idea.

> Superb idea. PFA patch. Please do let me know if I missed something. Thanks.

I looked at your patch and tested it with msvc and it looks good to me.

Note not related to this patch at all: shouldn't we update the
copyright notice on top of this gettimeofday.c btw with some PGDG
stuff?
-- 
Michael


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-21 17:20  Robert Haas <robertmhaas@gmail.com>
  parent: Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Robert Haas @ 2015-02-21 17:20 UTC (permalink / raw)
  To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Asif Naeem <anaeem.it@gmail.com>; Andres Freund <andres@2ndquadrant.com>; Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs

On Thu, Feb 12, 2015 at 9:59 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> I looked at your patch and tested it with msvc and it looks good to me.

Committed with cosmetic adjustments.  Hopefully one of you fine
gentlemen will jump in to help if this turns out to break, because I
don't do Windows.

> Note not related to this patch at all: shouldn't we update the
> copyright notice on top of this gettimeofday.c btw with some PGDG
> stuff?

I think so.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-21 18:00  Robert Haas <robertmhaas@gmail.com>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Robert Haas @ 2015-02-21 18:00 UTC (permalink / raw)
  To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Asif Naeem <anaeem.it@gmail.com>; Andres Freund <andres@2ndquadrant.com>; Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs

On Sat, Feb 21, 2015 at 12:20 PM, Robert Haas <robertmhaas@gmail.com> wrote:
> On Thu, Feb 12, 2015 at 9:59 PM, Michael Paquier
> <michael.paquier@gmail.com> wrote:
>> I looked at your patch and tested it with msvc and it looks good to me.
>
> Committed with cosmetic adjustments.  Hopefully one of you fine
> gentlemen will jump in to help if this turns out to break, because I
> don't do Windows.

currawong doesn't like this:

"c:\prog\bf\root\HEAD\pgsql.build\pgsql.sln" (default target) (1) ->
(postgres target) ->
  .\src\port\gettimeofday.c(53): error C2440: 'initializing' : cannot
convert from 'void (__cdecl *)(LPFILETIME)' to 'PgGetSystemTimeFn'


"c:\prog\bf\root\HEAD\pgsql.build\pgsql.sln" (default target) (1) ->
(misc\libpgport target) ->
  .\src\port\gettimeofday.c(53): error C2440: 'initializing' : cannot
convert from 'void (__cdecl *)(LPFILETIME)' to 'PgGetSystemTimeFn'

    0 Warning(s)
    2 Error(s)

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-21 18:59  Robert Haas <robertmhaas@gmail.com>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 2 replies; 16+ messages in thread

From: Robert Haas @ 2015-02-21 18:59 UTC (permalink / raw)
  To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Asif Naeem <anaeem.it@gmail.com>; Andres Freund <andres@2ndquadrant.com>; Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs

On Sat, Feb 21, 2015 at 1:00 PM, Robert Haas <robertmhaas@gmail.com> wrote:
> On Sat, Feb 21, 2015 at 12:20 PM, Robert Haas <robertmhaas@gmail.com> wrote:
>> On Thu, Feb 12, 2015 at 9:59 PM, Michael Paquier
>> <michael.paquier@gmail.com> wrote:
>>> I looked at your patch and tested it with msvc and it looks good to me.
>>
>> Committed with cosmetic adjustments.  Hopefully one of you fine
>> gentlemen will jump in to help if this turns out to break, because I
>> don't do Windows.
>
> currawong doesn't like this:
>
> "c:\prog\bf\root\HEAD\pgsql.build\pgsql.sln" (default target) (1) ->
> (postgres target) ->
>   .\src\port\gettimeofday.c(53): error C2440: 'initializing' : cannot
> convert from 'void (__cdecl *)(LPFILETIME)' to 'PgGetSystemTimeFn'
>
>
> "c:\prog\bf\root\HEAD\pgsql.build\pgsql.sln" (default target) (1) ->
> (misc\libpgport target) ->
>   .\src\port\gettimeofday.c(53): error C2440: 'initializing' : cannot
> convert from 'void (__cdecl *)(LPFILETIME)' to 'PgGetSystemTimeFn'
>
>     0 Warning(s)
>     2 Error(s)

I assume that the problem here must be whatever secret sauce WINAPI
pours on the declaration.  PgSystemTimeFn is declared like this:

typedef VOID (WINAPI *PgGetSystemTimeFn)(LPFILETIME);

...and the function we're trying to assign to a variable of that type
is declared like this:

static void init_gettimeofday(LPFILETIME lpSystemTimeAsFileTime);

Either "void" does not mean the same thing as "VOID", which would be
exceedingly evil, or the WINAPI in there matters, which is still evil,
but somewhat more understandable.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-21 19:07  Asif Naeem <anaeem.it@gmail.com>
  parent: Robert Haas <robertmhaas@gmail.com>
  1 sibling, 0 replies; 16+ messages in thread

From: Asif Naeem @ 2015-02-21 19:07 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Michael Paquier <michael.paquier@gmail.com>; Andres Freund <andres@2ndquadrant.com>; Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs

Thank you Robert. I have built latest source code (master branch) with MSVC
2013, it seem working fine i.e.

Build succeeded.
>     0 Warning(s)
>     0 Error(s)


I will try to mimic currawong environment (MSVC 2008) to reproduce the
issue. Thanks.


On Sat, Feb 21, 2015 at 11:59 PM, Robert Haas <robertmhaas@gmail.com> wrote:

> On Sat, Feb 21, 2015 at 1:00 PM, Robert Haas <robertmhaas@gmail.com>
> wrote:
> > On Sat, Feb 21, 2015 at 12:20 PM, Robert Haas <robertmhaas@gmail.com>
> wrote:
> >> On Thu, Feb 12, 2015 at 9:59 PM, Michael Paquier
> >> <michael.paquier@gmail.com> wrote:
> >>> I looked at your patch and tested it with msvc and it looks good to me.
> >>
> >> Committed with cosmetic adjustments.  Hopefully one of you fine
> >> gentlemen will jump in to help if this turns out to break, because I
> >> don't do Windows.
> >
> > currawong doesn't like this:
> >
> > "c:\prog\bf\root\HEAD\pgsql.build\pgsql.sln" (default target) (1) ->
> > (postgres target) ->
> >   .\src\port\gettimeofday.c(53): error C2440: 'initializing' : cannot
> > convert from 'void (__cdecl *)(LPFILETIME)' to 'PgGetSystemTimeFn'
> >
> >
> > "c:\prog\bf\root\HEAD\pgsql.build\pgsql.sln" (default target) (1) ->
> > (misc\libpgport target) ->
> >   .\src\port\gettimeofday.c(53): error C2440: 'initializing' : cannot
> > convert from 'void (__cdecl *)(LPFILETIME)' to 'PgGetSystemTimeFn'
> >
> >     0 Warning(s)
> >     2 Error(s)
>
> I assume that the problem here must be whatever secret sauce WINAPI
> pours on the declaration.  PgSystemTimeFn is declared like this:
>
> typedef VOID (WINAPI *PgGetSystemTimeFn)(LPFILETIME);
>
> ...and the function we're trying to assign to a variable of that type
> is declared like this:
>
> static void init_gettimeofday(LPFILETIME lpSystemTimeAsFileTime);
>
> Either "void" does not mean the same thing as "VOID", which would be
> exceedingly evil, or the WINAPI in there matters, which is still evil,
> but somewhat more understandable.
>
> --
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>

^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: gettimeofday cause crash on Windows
@ 2015-02-21 22:16  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Robert Haas <robertmhaas@gmail.com>
  1 sibling, 0 replies; 16+ messages in thread

From: Tom Lane @ 2015-02-21 22:16 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Michael Paquier <michael.paquier@gmail.com>; Asif Naeem <anaeem.it@gmail.com>; Andres Freund <andres@2ndquadrant.com>; Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs

Robert Haas <robertmhaas@gmail.com> writes:
> I assume that the problem here must be whatever secret sauce WINAPI
> pours on the declaration.

A bit of googling says that that expands to _stdcall which is not like
_cdecl.  I tried fixing this blindly; might not work, but it can't be
any more broken.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 16+ messages in thread


end of thread, other threads:[~2015-02-21 22:16 UTC | newest]

Thread overview: 16+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-02-11 12:11 gettimeofday cause crash on Windows Asif Naeem <anaeem.it@gmail.com>
2015-02-12 12:48 ` Michael Paquier <michael.paquier@gmail.com>
2015-02-12 12:54   ` Andres Freund <andres@2ndquadrant.com>
2015-02-12 13:09     ` Michael Paquier <michael.paquier@gmail.com>
2015-02-12 13:13       ` Andres Freund <andres@2ndquadrant.com>
2015-02-12 14:20         ` Asif Naeem <anaeem.it@gmail.com>
2015-02-12 15:14           ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-02-12 17:42             ` Tom Lane <tgl@sss.pgh.pa.us>
2015-02-12 17:53             ` Andres Freund <andres@2ndquadrant.com>
2015-02-12 19:41               ` Asif Naeem <anaeem.it@gmail.com>
2015-02-13 02:59                 ` Michael Paquier <michael.paquier@gmail.com>
2015-02-21 17:20                   ` Robert Haas <robertmhaas@gmail.com>
2015-02-21 18:00                     ` Robert Haas <robertmhaas@gmail.com>
2015-02-21 18:59                       ` Robert Haas <robertmhaas@gmail.com>
2015-02-21 19:07                         ` Asif Naeem <anaeem.it@gmail.com>
2015-02-21 22:16                         ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox