From 9ad5628639e81127bd856717e9e21ecb79957bd0 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 14 Jul 2005 10:32:46 +0000 Subject: [PATCH] Moved the server start time to the init_thread request and got rid of the init_process request (based on a patch by Felix Nawothnig). --- dlls/kernel/kernel_main.c | 35 +++++++++++++++++++++++++++++++ dlls/kernel/process.c | 38 ---------------------------------- dlls/ntdll/nt.c | 32 +--------------------------- dlls/ntdll/ntdll_misc.h | 1 + dlls/ntdll/server.c | 7 +++++-- dlls/ntdll/time.c | 23 ++++++++++++++++++++ include/wine/server_protocol.h | 18 ++-------------- server/object.h | 2 +- server/process.c | 7 ------- server/protocol.def | 8 +------ server/request.c | 8 +++---- server/request.h | 2 -- server/thread.c | 1 + server/trace.c | 13 +----------- 14 files changed, 75 insertions(+), 120 deletions(-) diff --git a/dlls/kernel/kernel_main.c b/dlls/kernel/kernel_main.c index b043894ee9..2fc8fcbe35 100644 --- a/dlls/kernel/kernel_main.c +++ b/dlls/kernel/kernel_main.c @@ -28,6 +28,10 @@ #ifdef HAVE_SYS_STAT_H # include #endif +#include +#ifdef HAVE_SYS_TIME_H +# include +#endif #include #include "windef.h" @@ -56,6 +60,8 @@ static CRITICAL_SECTION_DEBUG critsect_debug = }; static CRITICAL_SECTION ldt_section = { &critsect_debug, -1, 0, 0, 0, 0 }; +static DWORD server_start_time; + /*********************************************************************** * locking for LDT routines */ @@ -102,6 +108,10 @@ static BOOL process_attach(void) { HMODULE16 hModule; SYSTEM_INFO si; + SYSTEM_TIMEOFDAY_INFORMATION sti; + + NtQuerySystemInformation( SystemTimeOfDayInformation, &sti, sizeof(sti), NULL ); + RtlTimeToSecondsSince1970( &sti.liKeBootTime, &server_start_time ); /* FIXME: should probably be done in ntdll */ GetSystemInfo( &si ); @@ -263,3 +273,28 @@ INT WINAPI MulDiv( INT nMultiplicand, INT nMultiplier, INT nDivisor) if ((ret > 2147483647) || (ret < -2147483647)) return -1; return ret; } + + +/*********************************************************************** + * GetSystemMSecCount (SYSTEM.6) + * GetTickCount (KERNEL32.@) + * + * Get the number of milliseconds the system has been running. + * + * PARAMS + * None. + * + * RETURNS + * The current tick count. + * + * NOTES + * -The value returned will wrap arounf every 2^32 milliseconds. + * -Under Windows, tick 0 is the moment at which the system is rebooted. + * Under Wine, tick 0 begins at the moment the wineserver process is started, + */ +DWORD WINAPI GetTickCount(void) +{ + struct timeval t; + gettimeofday( &t, NULL ); + return ((t.tv_sec - server_start_time) * 1000) + (t.tv_usec / 1000); +} diff --git a/dlls/kernel/process.c b/dlls/kernel/process.c index a05804cdb5..436f5875ad 100644 --- a/dlls/kernel/process.c +++ b/dlls/kernel/process.c @@ -64,7 +64,6 @@ static DWORD shutdown_flags = 0; static DWORD shutdown_priority = 0x280; static DWORD process_dword; -static unsigned int server_startticks; int main_create_flags = 0; HMODULE kernel32_handle = 0; @@ -933,7 +932,6 @@ static void init_windows_dirs(void) static BOOL process_init(void) { static const WCHAR kernel32W[] = {'k','e','r','n','e','l','3','2',0}; - BOOL ret; PEB *peb = NtCurrentTeb()->Peb; RTL_USER_PROCESS_PARAMETERS *params = peb->ProcessParameters; extern void __wine_dbg_kernel32_init(void); @@ -946,17 +944,6 @@ static BOOL process_init(void) setbuf(stderr,NULL); setlocale(LC_CTYPE,""); - /* Retrieve startup info from the server */ - SERVER_START_REQ( init_process ) - { - if ((ret = !wine_server_call_err( req ))) - { - server_startticks = reply->server_start; - } - } - SERVER_END_REQ; - if (!ret) return FALSE; - if (!params->AllocationSize) { /* This is wine specific: we have no parent (we're started from unix) @@ -2887,31 +2874,6 @@ DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType) } -/*********************************************************************** - * GetSystemMSecCount (SYSTEM.6) - * GetTickCount (KERNEL32.@) - * - * Get the number of milliseconds the system has been running. - * - * PARANS - * None. - * - * RETURNS - * The current tick count. - * - * NOTES - * -The value returned will wrap arounf every 2^32 milliseconds. - * -Under Windows, tick 0 is the moment at which the system is rebooted. - * Under Wine, tick 0 begins at the moment the wineserver process is started, - */ -DWORD WINAPI GetTickCount(void) -{ - struct timeval t; - gettimeofday( &t, NULL ); - return ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - server_startticks; -} - - /*********************************************************************** * GetCurrentProcess (KERNEL32.@) * diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c index 8f9cac90a1..de489f1b17 100644 --- a/dlls/ntdll/nt.c +++ b/dlls/ntdll/nt.c @@ -36,9 +36,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(ntdll); -/* FIXME: fixed at 2005/2/22 */ -static LONGLONG boottime = (LONGLONG)1275356510 * 100000000; - /* * Token */ @@ -530,33 +527,6 @@ NTSTATUS WINAPI NtSetIntervalProfile( return STATUS_SUCCESS; } -/****************************************************************************** - * NtQueryPerformanceCounter [NTDLL.@] - * - * Note: Windows uses a timer clocked at a multiple of 1193182 Hz. There is a - * good number of applications that crash when the returned frequency is either - * lower or higher then what Windows gives. Also too high counter values are - * reported to give problems. - */ -NTSTATUS WINAPI NtQueryPerformanceCounter( - OUT PLARGE_INTEGER Counter, - OUT PLARGE_INTEGER Frequency) -{ - LARGE_INTEGER time; - - if (!Counter) return STATUS_ACCESS_VIOLATION; - NtQuerySystemTime( &time ); - time.QuadPart -= boottime; - /* convert a counter that increments at a rate of 10 MHz - * to one of 1193182 Hz, with some care for arithmetic - * overflow ( will not overflow until 3396 or so ) and - * good accuracy ( 21/176 = 0.119318182) */ - Counter->QuadPart = (time.QuadPart * 21) / 176; - if (Frequency) - Frequency->QuadPart = 1193182; - return 0; -} - /****************************************************************************** * NtQuerySystemInformation [NTDLL.@] * ZwQuerySystemInformation [NTDLL.@] @@ -657,7 +627,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( memset(&sti, 0 , sizeof(sti)); /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */ - sti.liKeBootTime.QuadPart = boottime; + RtlSecondsSince1970ToTime( server_start_time, &sti.liKeBootTime ); if (Length <= sizeof(sti)) { diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index 63c76da7f4..352b9e7246 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -52,6 +52,7 @@ extern ULONG thread_init(void); extern void virtual_init(void); /* server support */ +extern time_t server_start_time; extern void server_init_process(void); extern size_t server_init_thread( int unix_pid, int unix_tid, void *entry_point ); extern void DECLSPEC_NORETURN server_protocol_error( const char *err, ... ); diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c index f68849efdf..8c0ee8ea14 100644 --- a/dlls/ntdll/server.c +++ b/dlls/ntdll/server.c @@ -81,6 +81,8 @@ struct cmsg_fd }; #endif /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */ +time_t server_start_time = 0; /* time of server startup */ + static sigset_t block_set; /* signals to block during server calls */ static int fd_socket = -1; /* socket to exchange file descriptors with the server */ @@ -919,8 +921,9 @@ size_t server_init_thread( int unix_pid, int unix_tid, void *entry_point ) ret = wine_server_call( req ); NtCurrentTeb()->ClientId.UniqueProcess = (HANDLE)reply->pid; NtCurrentTeb()->ClientId.UniqueThread = (HANDLE)reply->tid; - info_size = reply->info_size; - version = reply->version; + info_size = reply->info_size; + version = reply->version; + server_start_time = reply->server_start; } SERVER_END_REQ; diff --git a/dlls/ntdll/time.c b/dlls/ntdll/time.c index 3dc70ac4b4..2b754d1eb9 100644 --- a/dlls/ntdll/time.c +++ b/dlls/ntdll/time.c @@ -797,6 +797,29 @@ NTSTATUS WINAPI NtQuerySystemTime( PLARGE_INTEGER Time ) return STATUS_SUCCESS; } +/****************************************************************************** + * NtQueryPerformanceCounter [NTDLL.@] + * + * Note: Windows uses a timer clocked at a multiple of 1193182 Hz. There is a + * good number of applications that crash when the returned frequency is either + * lower or higher then what Windows gives. Also too high counter values are + * reported to give problems. + */ +NTSTATUS WINAPI NtQueryPerformanceCounter( PLARGE_INTEGER Counter, PLARGE_INTEGER Frequency ) +{ + struct timeval now; + + if (!Counter) return STATUS_ACCESS_VIOLATION; + gettimeofday( &now, 0 ); + /* convert a counter that increments at a rate of 1 MHz + * to one of 1.193182 MHz, with some care for arithmetic + * overflow ( will not overflow for 5000 years ) and + * good accuracy ( 105/88 = 1.19318182) */ + Counter->QuadPart = (((now.tv_sec - server_start_time) * (ULONGLONG)1000000 + now.tv_usec) * 105) / 88; + if (Frequency) Frequency->QuadPart = 1193182; + return STATUS_SUCCESS; +} + /*********************************************************************** * TIME_GetTZAsStr [internal] * diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h index 59e1f56641..be5317fa98 100644 --- a/include/wine/server_protocol.h +++ b/include/wine/server_protocol.h @@ -237,18 +237,6 @@ struct new_thread_reply -struct init_process_request -{ - struct request_header __header; -}; -struct init_process_reply -{ - struct reply_header __header; - unsigned int server_start; -}; - - - struct get_startup_info_request { struct request_header __header; @@ -304,6 +292,7 @@ struct init_thread_reply process_id_t pid; thread_id_t tid; size_t info_size; + time_t server_start; int version; }; @@ -3554,7 +3543,6 @@ enum request REQ_new_process, REQ_get_new_process_info, REQ_new_thread, - REQ_init_process, REQ_get_startup_info, REQ_init_process_done, REQ_init_thread, @@ -3764,7 +3752,6 @@ union generic_request struct new_process_request new_process_request; struct get_new_process_info_request get_new_process_info_request; struct new_thread_request new_thread_request; - struct init_process_request init_process_request; struct get_startup_info_request get_startup_info_request; struct init_process_done_request init_process_done_request; struct init_thread_request init_thread_request; @@ -3972,7 +3959,6 @@ union generic_reply struct new_process_reply new_process_reply; struct get_new_process_info_reply get_new_process_info_reply; struct new_thread_reply new_thread_reply; - struct init_process_reply init_process_reply; struct get_startup_info_reply get_startup_info_reply; struct init_process_done_reply init_process_done_reply; struct init_thread_reply init_thread_reply; @@ -4174,6 +4160,6 @@ union generic_reply struct set_mailslot_info_reply set_mailslot_info_reply; }; -#define SERVER_PROTOCOL_VERSION 186 +#define SERVER_PROTOCOL_VERSION 187 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */ diff --git a/server/object.h b/server/object.h index dfccf98a2e..56a6bcd8dc 100644 --- a/server/object.h +++ b/server/object.h @@ -172,7 +172,7 @@ extern int foreground; extern const char *server_argv0; /* server start time used for GetTickCount() */ -extern unsigned int server_start_ticks; +extern time_t server_start_time; /* name space for synchronization objects */ extern struct namespace *sync_namespace; diff --git a/server/process.c b/server/process.c index 99f1476490..a1d03d39a8 100644 --- a/server/process.c +++ b/server/process.c @@ -964,13 +964,6 @@ DECL_HANDLER(get_startup_info) info->data_size = 0; } - -/* initialize a new process */ -DECL_HANDLER(init_process) -{ - reply->server_start = server_start_ticks; -} - /* signal the end of the process initialization */ DECL_HANDLER(init_process_done) { diff --git a/server/protocol.def b/server/protocol.def index e9458abfd3..25bc6d7a08 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -237,13 +237,6 @@ struct security_descriptor @END -/* Initialize a process; called from the new process context */ -@REQ(init_process) -@REPLY - unsigned int server_start; /* server start time (GetTickCount) */ -@END - - /* Retrieve the new process startup info */ @REQ(get_startup_info) @REPLY @@ -284,6 +277,7 @@ struct security_descriptor process_id_t pid; /* process id of the new thread's process */ thread_id_t tid; /* thread id of the new thread */ size_t info_size; /* total size of startup info */ + time_t server_start; /* server start time */ int version; /* protocol version */ @END diff --git a/server/request.c b/server/request.c index 7c0a2a55dc..1fd19c17fb 100644 --- a/server/request.c +++ b/server/request.c @@ -112,7 +112,7 @@ static const struct fd_ops master_socket_fd_ops = struct thread *current = NULL; /* thread handling the current request */ unsigned int global_error = 0; /* global error code for when no thread is current */ -unsigned int server_start_ticks = 0; /* tick count offset from server startup */ +time_t server_start_time = 0; /* server startup time */ static struct master_socket *master_socket; /* the master socket object */ @@ -454,7 +454,7 @@ unsigned int get_tick_count(void) { struct timeval t; gettimeofday( &t, NULL ); - return (t.tv_sec * 1000) + (t.tv_usec / 1000) - server_start_ticks; + return ((t.tv_sec - server_start_time) * 1000) + (t.tv_usec / 1000); } static void master_socket_dump( struct object *obj, int verbose ) @@ -776,8 +776,8 @@ void open_master_socket(void) msghdr.msg_iov = &myiovec; msghdr.msg_iovlen = 1; - /* init startup ticks */ - server_start_ticks = get_tick_count(); + /* init startup time */ + server_start_time = time(NULL); } /* master socket timer expiration handler */ diff --git a/server/request.h b/server/request.h index c317ff4539..ea47a77536 100644 --- a/server/request.h +++ b/server/request.h @@ -106,7 +106,6 @@ inline static void set_reply_data_ptr( void *data, size_t size ) DECL_HANDLER(new_process); DECL_HANDLER(get_new_process_info); DECL_HANDLER(new_thread); -DECL_HANDLER(init_process); DECL_HANDLER(get_startup_info); DECL_HANDLER(init_process_done); DECL_HANDLER(init_thread); @@ -315,7 +314,6 @@ static const req_handler req_handlers[REQ_NB_REQUESTS] = (req_handler)req_new_process, (req_handler)req_get_new_process_info, (req_handler)req_new_thread, - (req_handler)req_init_process, (req_handler)req_get_startup_info, (req_handler)req_init_process_done, (req_handler)req_init_thread, diff --git a/server/thread.c b/server/thread.c index f1f4f271a9..93c08ce135 100644 --- a/server/thread.c +++ b/server/thread.c @@ -888,6 +888,7 @@ DECL_HANDLER(init_thread) reply->pid = get_process_id( process ); reply->tid = get_thread_id( current ); reply->version = SERVER_PROTOCOL_VERSION; + reply->server_start = server_start_time; return; error: diff --git a/server/trace.c b/server/trace.c index 03e2a2ae56..304cc6ac99 100644 --- a/server/trace.c +++ b/server/trace.c @@ -606,15 +606,6 @@ static void dump_new_thread_reply( const struct new_thread_reply *req ) fprintf( stderr, " handle=%p", req->handle ); } -static void dump_init_process_request( const struct init_process_request *req ) -{ -} - -static void dump_init_process_reply( const struct init_process_reply *req ) -{ - fprintf( stderr, " server_start=%08x", req->server_start ); -} - static void dump_get_startup_info_request( const struct get_startup_info_request *req ) { } @@ -663,6 +654,7 @@ static void dump_init_thread_reply( const struct init_thread_reply *req ) fprintf( stderr, " pid=%04x,", req->pid ); fprintf( stderr, " tid=%04x,", req->tid ); fprintf( stderr, " info_size=%d,", req->info_size ); + fprintf( stderr, " server_start=%ld,", (long)req->server_start ); fprintf( stderr, " version=%d", req->version ); } @@ -3066,7 +3058,6 @@ static const dump_func req_dumpers[REQ_NB_REQUESTS] = { (dump_func)dump_new_process_request, (dump_func)dump_get_new_process_info_request, (dump_func)dump_new_thread_request, - (dump_func)dump_init_process_request, (dump_func)dump_get_startup_info_request, (dump_func)dump_init_process_done_request, (dump_func)dump_init_thread_request, @@ -3272,7 +3263,6 @@ static const dump_func reply_dumpers[REQ_NB_REQUESTS] = { (dump_func)dump_new_process_reply, (dump_func)dump_get_new_process_info_reply, (dump_func)dump_new_thread_reply, - (dump_func)dump_init_process_reply, (dump_func)dump_get_startup_info_reply, (dump_func)0, (dump_func)dump_init_thread_reply, @@ -3478,7 +3468,6 @@ static const char * const req_names[REQ_NB_REQUESTS] = { "new_process", "get_new_process_info", "new_thread", - "init_process", "get_startup_info", "init_process_done", "init_thread",