From: Bernhard Übelacker <bernhardu@mailbox.org> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=59287 - Unsure if there is a better way to make this configurable? - Is adding the message to GetTickCount ok for performance reasons? How can a user be better warned if they have an uptime above 25 days and their application uses this Api? --- dlls/kernel32/sync.c | 12 +++++++++++- server/main.c | 8 +++++++- server/object.h | 1 + server/request.c | 7 ++++--- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dlls/kernel32/sync.c b/dlls/kernel32/sync.c index b354b1c5653..35fc00a29da 100644 --- a/dlls/kernel32/sync.c +++ b/dlls/kernel32/sync.c @@ -101,8 +101,18 @@ ULONGLONG WINAPI DECLSPEC_HOTPATCH GetTickCount64(void) */ DWORD WINAPI DECLSPEC_HOTPATCH GetTickCount(void) { + DWORD ret; + static int once; /* note: we ignore TickCountMultiplier */ - return user_shared_data->TickCount.LowPart; + ret = user_shared_data->TickCount.LowPart; + if ((ret & 0x80000000) && !once) + { + once = 1; + MESSAGE("The value returning from GetTickCount excceeds the signed integer maximum, " + "which may make some applications fail. " + "Consider using the wineserver option --serverboottime.\n"); + } + return ret; } /*********************************************************************** diff --git a/server/main.c b/server/main.c index 46419a09cb4..64315d48688 100644 --- a/server/main.c +++ b/server/main.c @@ -46,6 +46,7 @@ int debug_level = 0; int foreground = 0; timeout_t master_socket_timeout = 3 * -TICKS_PER_SEC; /* master socket timeout, default is 3 seconds */ const char *server_argv0; +int serverboottime = 0; /* parse-line args */ @@ -60,6 +61,7 @@ static void usage( FILE *fh ) fprintf(fh, " -p[n], --persistent[=n] make server persistent, optionally for n seconds\n"); fprintf(fh, " -v, --version display version information and exit\n"); fprintf(fh, " -w, --wait wait until the current wineserver terminates\n"); + fprintf(fh, " -s, --serverboottime return ticks from start of wineserver\n"); fprintf(fh, "\n"); } @@ -94,6 +96,9 @@ static void option_callback( int optc, char *optarg ) else master_socket_timeout = TIMEOUT_INFINITE; break; + case 's': + serverboottime = 1; + break; case 'v': fprintf( stderr, "%s\n", PACKAGE_STRING ); exit(0); @@ -120,6 +125,7 @@ static struct long_option {"persistent", 2, 'p'}, {"version", 0, 'v'}, {"wait", 0, 'w'}, + {"serverboottime", 0, 's'}, { NULL } }; @@ -245,7 +251,7 @@ int main( int argc, char *argv[] ) { setvbuf( stderr, NULL, _IOLBF, 0 ); server_argv0 = argv[0]; - parse_options( argc, argv, "d::fhk::p::vw", long_options, option_callback ); + parse_options( argc, argv, "d::fhk::p::vws", long_options, option_callback ); /* setup temporary handlers before the real signal initialization is done */ signal( SIGPIPE, SIG_IGN ); diff --git a/server/object.h b/server/object.h index cab8ad25a59..6199643d772 100644 --- a/server/object.h +++ b/server/object.h @@ -343,6 +343,7 @@ extern int debug_level; extern int foreground; extern timeout_t master_socket_timeout; extern const char *server_argv0; +extern int serverboottime; /* server start time used for GetTickCount() */ extern timeout_t server_start_time; diff --git a/server/request.c b/server/request.c index 432a5918892..4bd7fb8745b 100644 --- a/server/request.c +++ b/server/request.c @@ -512,14 +512,15 @@ timeout_t monotonic_counter(void) static mach_timebase_info_data_t timebase; if (!timebase.denom) mach_timebase_info( &timebase ); - return mach_continuous_time() * timebase.numer / timebase.denom / 100; + if (!serverboottime) + return mach_continuous_time() * timebase.numer / timebase.denom / 100; #elif defined(HAVE_CLOCK_GETTIME) struct timespec ts; #ifdef CLOCK_BOOTTIME - if (!clock_gettime( CLOCK_BOOTTIME, &ts )) + if (!serverboottime && !clock_gettime( CLOCK_BOOTTIME, &ts )) return (timeout_t)ts.tv_sec * TICKS_PER_SEC + ts.tv_nsec / 100; #endif - if (!clock_gettime( CLOCK_MONOTONIC, &ts )) + if (!serverboottime && !clock_gettime( CLOCK_MONOTONIC, &ts )) return (timeout_t)ts.tv_sec * TICKS_PER_SEC + ts.tv_nsec / 100; #endif return current_time - server_start_time; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10005