diff --git a/dlls/kernel/Makefile.in b/dlls/kernel/Makefile.in index 95c0e53079e..a3f0683fc28 100644 --- a/dlls/kernel/Makefile.in +++ b/dlls/kernel/Makefile.in @@ -7,10 +7,13 @@ SOVERSION = 1.0 ALTNAMES = comm kernel stress system toolhelp windebug win87em wprocs C_SRCS = \ + debugger.c \ format_msg.c \ kernel_main.c \ stress.c \ + sync.c \ thunk.c \ + time.c \ toolhelp.c \ utthunk.c \ win87em.c \ diff --git a/scheduler/debugger.c b/dlls/kernel/debugger.c similarity index 100% rename from scheduler/debugger.c rename to dlls/kernel/debugger.c diff --git a/dlls/kernel/sync.c b/dlls/kernel/sync.c new file mode 100644 index 00000000000..1fa398dd658 --- /dev/null +++ b/dlls/kernel/sync.c @@ -0,0 +1,598 @@ +/* + * Kernel synchronization objects + * + * Copyright 1998 Alexandre Julliard + */ + +#include +#include "winerror.h" +#include "winnls.h" +#include "wine/unicode.h" +#include "syslevel.h" +#include "server.h" +#include "debugtools.h" + +DEFAULT_DEBUG_CHANNEL(win32); + +/* + * Events + */ + + +/*********************************************************************** + * CreateEventA (KERNEL32.156) + */ +HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset, + BOOL initial_state, LPCSTR name ) +{ + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct create_event_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->manual_reset = manual_reset; + req->initial_state = initial_state; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + SetLastError(0); + server_call( REQ_CREATE_EVENT ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; +} + + +/*********************************************************************** + * CreateEventW (KERNEL32.157) + */ +HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset, + BOOL initial_state, LPCWSTR name ) +{ + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct create_event_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->manual_reset = manual_reset; + req->initial_state = initial_state; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + SetLastError(0); + server_call( REQ_CREATE_EVENT ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; +} + + +/*********************************************************************** + * WIN16_CreateEvent (KERNEL.457) + */ +HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state ) +{ + return CreateEventA( NULL, manual_reset, initial_state, NULL ); +} + + +/*********************************************************************** + * OpenEventA (KERNEL32.536) + */ +HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name ) +{ + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_event_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->access = access; + req->inherit = inherit; + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + server_call( REQ_OPEN_EVENT ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; +} + + +/*********************************************************************** + * OpenEventW (KERNEL32.537) + */ +HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name ) +{ + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_event_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->access = access; + req->inherit = inherit; + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + server_call( REQ_OPEN_EVENT ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; +} + + +/*********************************************************************** + * EVENT_Operation + * + * Execute an event operation (set,reset,pulse). + */ +static BOOL EVENT_Operation( HANDLE handle, enum event_op op ) +{ + BOOL ret; + SERVER_START_REQ + { + struct event_op_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + req->op = op; + ret = !server_call( REQ_EVENT_OP ); + } + SERVER_END_REQ; + return ret; +} + + +/*********************************************************************** + * PulseEvent (KERNEL32.557) + */ +BOOL WINAPI PulseEvent( HANDLE handle ) +{ + return EVENT_Operation( handle, PULSE_EVENT ); +} + + +/*********************************************************************** + * SetEvent (KERNEL32.644) + */ +BOOL WINAPI SetEvent( HANDLE handle ) +{ + return EVENT_Operation( handle, SET_EVENT ); +} + + +/*********************************************************************** + * ResetEvent (KERNEL32.586) + */ +BOOL WINAPI ResetEvent( HANDLE handle ) +{ + return EVENT_Operation( handle, RESET_EVENT ); +} + + +/*********************************************************************** + * NOTE: The Win95 VWin32_Event routines given below are really low-level + * routines implemented directly by VWin32. The user-mode libraries + * implement Win32 synchronisation routines on top of these low-level + * primitives. We do it the other way around here :-) + */ + +/*********************************************************************** + * VWin32_EventCreate (KERNEL.442) + */ +HANDLE WINAPI VWin32_EventCreate(VOID) +{ + HANDLE hEvent = CreateEventA( NULL, FALSE, 0, NULL ); + return ConvertToGlobalHandle( hEvent ); +} + +/*********************************************************************** + * VWin32_EventDestroy (KERNEL.443) + */ +VOID WINAPI VWin32_EventDestroy(HANDLE event) +{ + CloseHandle( event ); +} + +/*********************************************************************** + * VWin32_EventWait (KERNEL.450) + */ +VOID WINAPI VWin32_EventWait(HANDLE event) +{ + SYSLEVEL_ReleaseWin16Lock(); + WaitForSingleObject( event, INFINITE ); + SYSLEVEL_RestoreWin16Lock(); +} + +/*********************************************************************** + * VWin32_EventSet (KERNEL.451) + */ +VOID WINAPI VWin32_EventSet(HANDLE event) +{ + SetEvent( event ); +} + + + +/*********************************************************************** + * CreateMutexA (KERNEL32.166) + */ +HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name ) +{ + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct create_mutex_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->owned = owner; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + SetLastError(0); + server_call( REQ_CREATE_MUTEX ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; +} + + +/*********************************************************************** + * CreateMutexW (KERNEL32.167) + */ +HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name ) +{ + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct create_mutex_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->owned = owner; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + SetLastError(0); + server_call( REQ_CREATE_MUTEX ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; +} + + +/* + * Mutexes + */ + + +/*********************************************************************** + * OpenMutexA (KERNEL32.541) + */ +HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name ) +{ + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_mutex_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->access = access; + req->inherit = inherit; + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + server_call( REQ_OPEN_MUTEX ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; +} + + +/*********************************************************************** + * OpenMutexW (KERNEL32.542) + */ +HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name ) +{ + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_mutex_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + + req->access = access; + req->inherit = inherit; + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + server_call( REQ_OPEN_MUTEX ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; +} + + +/*********************************************************************** + * ReleaseMutex (KERNEL32.582) + */ +BOOL WINAPI ReleaseMutex( HANDLE handle ) +{ + BOOL ret; + SERVER_START_REQ + { + struct release_mutex_request *req = server_alloc_req( sizeof(*req), 0 ); + req->handle = handle; + ret = !server_call( REQ_RELEASE_MUTEX ); + } + SERVER_END_REQ; + return ret; +} + + +/* + * Semaphores + */ + + +/*********************************************************************** + * CreateSemaphoreA (KERNEL32.174) + */ +HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name ) +{ + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + + /* Check parameters */ + + if ((max <= 0) || (initial < 0) || (initial > max)) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + + SERVER_START_REQ + { + struct create_semaphore_request *req = server_alloc_req( sizeof(*req), + len * sizeof(WCHAR) ); + + req->initial = (unsigned int)initial; + req->max = (unsigned int)max; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + SetLastError(0); + server_call( REQ_CREATE_SEMAPHORE ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; +} + + +/*********************************************************************** + * CreateSemaphoreW (KERNEL32.175) + */ +HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial, + LONG max, LPCWSTR name ) +{ + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + + /* Check parameters */ + + if ((max <= 0) || (initial < 0) || (initial > max)) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + + SERVER_START_REQ + { + struct create_semaphore_request *req = server_alloc_req( sizeof(*req), + len * sizeof(WCHAR) ); + + req->initial = (unsigned int)initial; + req->max = (unsigned int)max; + req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + SetLastError(0); + server_call( REQ_CREATE_SEMAPHORE ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; +} + + +/*********************************************************************** + * OpenSemaphoreA (KERNEL32.545) + */ +HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name ) +{ + HANDLE ret; + DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_semaphore_request *req = server_alloc_req( sizeof(*req), + len * sizeof(WCHAR) ); + req->access = access; + req->inherit = inherit; + if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); + server_call( REQ_OPEN_SEMAPHORE ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; +} + + +/*********************************************************************** + * OpenSemaphoreW (KERNEL32.546) + */ +HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name ) +{ + HANDLE ret; + DWORD len = name ? strlenW(name) : 0; + if (len >= MAX_PATH) + { + SetLastError( ERROR_FILENAME_EXCED_RANGE ); + return 0; + } + SERVER_START_REQ + { + struct open_semaphore_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); + req->access = access; + req->inherit = inherit; + memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); + server_call( REQ_OPEN_SEMAPHORE ); + ret = req->handle; + } + SERVER_END_REQ; + if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ + return ret; +} + + +/*********************************************************************** + * ReleaseSemaphore (KERNEL32.583) + */ +BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous ) +{ + NTSTATUS status = NtReleaseSemaphore( handle, count, previous ); + if (status) SetLastError( RtlNtStatusToDosError(status) ); + return !status; +} + + +/* + * Pipes + */ + + +/*********************************************************************** + * CreateNamedPipeA (KERNEL32.168) + */ +HANDLE WINAPI CreateNamedPipeA( LPCSTR name, DWORD dwOpenMode, + DWORD dwPipeMode, DWORD nMaxInstances, + DWORD nOutBufferSize, DWORD nInBufferSize, + DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr ) +{ + FIXME("(Name=%s, OpenMode=%#08lx, dwPipeMode=%#08lx, MaxInst=%ld, OutBSize=%ld, InBuffSize=%ld, DefTimeOut=%ld, SecAttr=%p): stub\n", + debugstr_a(name), dwOpenMode, dwPipeMode, nMaxInstances, + nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr ); + SetLastError (ERROR_UNKNOWN); + return INVALID_HANDLE_VALUE; +} + + +/*********************************************************************** + * CreateNamedPipeW (KERNEL32.169) + */ +HANDLE WINAPI CreateNamedPipeW( LPCWSTR name, DWORD dwOpenMode, + DWORD dwPipeMode, DWORD nMaxInstances, + DWORD nOutBufferSize, DWORD nInBufferSize, + DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr ) +{ + FIXME("(Name=%s, OpenMode=%#08lx, dwPipeMode=%#08lx, MaxInst=%ld, OutBSize=%ld, InBuffSize=%ld, DefTimeOut=%ld, SecAttr=%p): stub\n", + debugstr_w(name), dwOpenMode, dwPipeMode, nMaxInstances, + nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr ); + + SetLastError (ERROR_UNKNOWN); + return INVALID_HANDLE_VALUE; +} + + +/*********************************************************************** + * PeekNamedPipe (KERNEL32.552) + */ +BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer, + LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage ) +{ + FIXME("(%08x, %p, %08lx, %p, %p, %p): stub\n", + hPipe, lpvBuffer, cbBuffer, lpcbRead, lpcbAvail, lpcbMessage); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + + +/*********************************************************************** + * WaitNamedPipeA (KERNEL32.@) + */ +BOOL WINAPI WaitNamedPipeA (LPCSTR lpNamedPipeName, DWORD nTimeOut) +{ + FIXME("%s 0x%08lx\n",lpNamedPipeName,nTimeOut); + SetLastError(ERROR_PIPE_NOT_CONNECTED); + return FALSE; +} + + +/*********************************************************************** + * WaitNamedPipeW (KERNEL32.@) + */ +BOOL WINAPI WaitNamedPipeW (LPCWSTR lpNamedPipeName, DWORD nTimeOut) +{ + FIXME("%s 0x%08lx\n",debugstr_w(lpNamedPipeName),nTimeOut); + SetLastError(ERROR_PIPE_NOT_CONNECTED); + return FALSE; +} diff --git a/dlls/kernel/time.c b/dlls/kernel/time.c new file mode 100644 index 00000000000..3db968e269f --- /dev/null +++ b/dlls/kernel/time.c @@ -0,0 +1,246 @@ +/* + * Win32 kernel functions + * + * Copyright 1995 Martin von Loewis and Cameron Heide + */ + +#include +#include +#include +#include +#include "file.h" +#include "winerror.h" +#include "debugtools.h" + +DEFAULT_DEBUG_CHANNEL(win32); + +/* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */ +#define SETTIME_MAX_ADJUST 120 + +/* TIME_GetBias: helper function calculates delta local time from UTC */ +static int TIME_GetBias( time_t utc, int *pdaylight) +{ + struct tm *ptm = localtime(&utc); + *pdaylight = ptm->tm_isdst; /* daylight for local timezone */ + ptm = gmtime(&utc); + ptm->tm_isdst = *pdaylight; /* use local daylight, not that of Greenwich */ + return (int)(utc-mktime(ptm)); +} + + +/*********************************************************************** + * SetLocalTime (KERNEL32.655) + * + * FIXME: correct ? Is the timezone param of settimeofday() needed ? + * I don't have any docu about SetLocal/SystemTime(), argl... + */ +BOOL WINAPI SetLocalTime(const SYSTEMTIME *systime) +{ + struct timeval tv; + struct tm t; + time_t sec; + time_t oldsec=time(NULL); + int err; + + /* get the number of seconds */ + t.tm_sec = systime->wSecond; + t.tm_min = systime->wMinute; + t.tm_hour = systime->wHour; + t.tm_mday = systime->wDay; + t.tm_mon = systime->wMonth - 1; + t.tm_year = systime->wYear - 1900; + t.tm_isdst = -1; + sec = mktime (&t); + + /* set the new time */ + tv.tv_sec = sec; + tv.tv_usec = systime->wMilliseconds * 1000; + + /* error and sanity check*/ + if( sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST ){ + err = 1; + SetLastError(ERROR_INVALID_PARAMETER); + } else { + err=settimeofday(&tv, NULL); /* 0 is OK, -1 is error */ + if(err == 0) + return TRUE; + SetLastError(ERROR_PRIVILEGE_NOT_HELD); + } + ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n", + systime->wYear, systime->wMonth, systime->wDay, systime->wHour, + systime->wMinute, systime->wSecond, + sec-oldsec, err == -1 ? "No Permission" : + sec==(time_t)-1 ? "" : "is too large." ); + return FALSE; +} + + +/*********************************************************************** + * GetSystemTimeAdjustment (KERNEL32.407) + * + */ +DWORD WINAPI GetSystemTimeAdjustment( LPDWORD lpTimeAdjustment, + LPDWORD lpTimeIncrement, + LPBOOL lpTimeAdjustmentDisabled ) +{ + *lpTimeAdjustment = 0; + *lpTimeIncrement = 0; + *lpTimeAdjustmentDisabled = TRUE; + return TRUE; +} + + +/*********************************************************************** + * SetSystemTime (KERNEL32.507) + */ +BOOL WINAPI SetSystemTime(const SYSTEMTIME *systime) +{ + struct timeval tv; + struct timezone tz; + struct tm t; + time_t sec, oldsec; + int dst, bias; + int err; + + /* call gettimeofday to get the current timezone */ + gettimeofday(&tv, &tz); + oldsec=tv.tv_sec; + /* get delta local time from utc */ + bias=TIME_GetBias(oldsec,&dst); + + /* get the number of seconds */ + t.tm_sec = systime->wSecond; + t.tm_min = systime->wMinute; + t.tm_hour = systime->wHour; + t.tm_mday = systime->wDay; + t.tm_mon = systime->wMonth - 1; + t.tm_year = systime->wYear - 1900; + t.tm_isdst = dst; + sec = mktime (&t); + /* correct for timezone and daylight */ + sec += bias; + + /* set the new time */ + tv.tv_sec = sec; + tv.tv_usec = systime->wMilliseconds * 1000; + + /* error and sanity check*/ + if( sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST ){ + err = 1; + SetLastError(ERROR_INVALID_PARAMETER); + } else { + err=settimeofday(&tv, NULL); /* 0 is OK, -1 is error */ + if(err == 0) + return TRUE; + SetLastError(ERROR_PRIVILEGE_NOT_HELD); + } + ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n", + systime->wYear, systime->wMonth, systime->wDay, systime->wHour, + systime->wMinute, systime->wSecond, + sec-oldsec, err == -1 ? "No Permission" : + sec==(time_t)-1 ? "" : "is too large." ); + return FALSE; +} + + +/*********************************************************************** + * GetTimeZoneInformation (KERNEL32.302) + */ +DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION tzinfo) +{ + time_t gmt; + int bias, daylight; + + memset(tzinfo, 0, sizeof(TIME_ZONE_INFORMATION)); + + gmt = time(NULL); + bias=TIME_GetBias(gmt,&daylight); + + tzinfo->Bias = -bias / 60; + tzinfo->StandardBias = 0; + tzinfo->DaylightBias = -60; + + return TIME_ZONE_ID_UNKNOWN; +} + + +/*********************************************************************** + * SetTimeZoneInformation (KERNEL32.515) + */ +BOOL WINAPI SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION tzinfo) +{ + struct timezone tz; + + tz.tz_minuteswest = tzinfo->Bias; +#ifdef DST_NONE + tz.tz_dsttime = DST_NONE; +#else + tz.tz_dsttime = 0; +#endif + return !settimeofday(NULL, &tz); +} + + +/*********************************************************************** + * SystemTimeToTzSpecificLocalTime (KERNEL32.683) + */ +BOOL WINAPI SystemTimeToTzSpecificLocalTime( + LPTIME_ZONE_INFORMATION lpTimeZoneInformation, + LPSYSTEMTIME lpUniversalTime, + LPSYSTEMTIME lpLocalTime) +{ + FIXME(":stub\n"); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +/********************************************************************* + * TIME_ClockTimeToFileTime + * (olorin@fandra.org, 20-Sep-1998) + * Converts clock_t into FILETIME. + * Used by GetProcessTime. + * Differences to UnixTimeToFileTime: + * 1) Divided by CLK_TCK + * 2) Time is relative. There is no 'starting date', so there is + * no need in offset correction, like in UnixTimeToFileTime + * FIXME: This function should be moved to a more appropriate .c file + * FIXME: On floating point operations, it is assumed that + * floating values are truncated on conversion to integer. + */ +static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime) +{ + double td = (unix_time*10000000.0)/CLK_TCK; + /* Yes, double, because long int might overflow here. */ +#if SIZEOF_LONG_LONG >= 8 + unsigned long long t = td; + filetime->dwLowDateTime = (UINT) t; + filetime->dwHighDateTime = (UINT) (t >> 32); +#else + double divider = 1. * (1 << 16) * (1 << 16); + filetime->dwHighDateTime = (UINT) (td / divider); + filetime->dwLowDateTime = (UINT) (td - filetime->dwHighDateTime*divider); + /* using floor() produces wierd results, better leave this as it is + * ( with (UINT32) convertion ) + */ +#endif +} + +/********************************************************************* + * GetProcessTimes [KERNEL32.262] + * + * FIXME: lpCreationTime, lpExitTime are NOT INITIALIZED. + * olorin@fandra.org: Would be nice to substract the cpu time, + * used by Wine at startup. + * Also, there is a need to separate times + * used by different applications. + */ +BOOL WINAPI GetProcessTimes( HANDLE hprocess,LPFILETIME lpCreationTime,LPFILETIME lpExitTime, + LPFILETIME lpKernelTime, LPFILETIME lpUserTime ) +{ + struct tms tms; + + times(&tms); + TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime); + TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime); + return TRUE; +} diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c index 7409b4a667e..928a244eb02 100644 --- a/dlls/ntdll/sync.c +++ b/dlls/ntdll/sync.c @@ -177,7 +177,9 @@ NTSTATUS WINAPI NtOpenEvent( NTSTATUS WINAPI NtSetEvent( HANDLE handle, PULONG NumberOfThreadsReleased ) { NTSTATUS ret; - FIXME("(0x%08x,%p)\n", handle, NumberOfThreadsReleased); + + /* FIXME: set NumberOfThreadsReleased */ + SERVER_START_REQ { struct event_op_request *req = server_alloc_req( sizeof(*req), 0 ); diff --git a/include/ntddk.h b/include/ntddk.h index 7d7a66d9761..620a4affac5 100644 --- a/include/ntddk.h +++ b/include/ntddk.h @@ -912,11 +912,14 @@ NTSTATUS WINAPI NtClose( NTSTATUS WINAPI NtTerminateProcess( HANDLE handle, LONG exit_code ); NTSTATUS WINAPI NtTerminateThread( HANDLE handle, LONG exit_code ); +NTSTATUS WINAPI NtClearEvent(HANDLE); NTSTATUS WINAPI NtCreateEvent(PHANDLE,ACCESS_MASK,const OBJECT_ATTRIBUTES *,BOOLEAN,BOOLEAN); NTSTATUS WINAPI NtCreateSemaphore(PHANDLE,ACCESS_MASK,const OBJECT_ATTRIBUTES*,ULONG,ULONG); -NTSTATUS WINAPI NtReleaseSemaphore( IN HANDLE SemaphoreHandle, - IN ULONG ReleaseCount, - IN PULONG PreviousCount); +NTSTATUS WINAPI NtOpenEvent(PHANDLE,ACCESS_MASK,const OBJECT_ATTRIBUTES *attr); +NTSTATUS WINAPI NtPulseEvent(HANDLE,PULONG); +NTSTATUS WINAPI NtReleaseSemaphore(HANDLE,ULONG,PULONG); +NTSTATUS WINAPI NtResetEvent(HANDLE,PULONG); +NTSTATUS WINAPI NtSetEvent(HANDLE,PULONG); NTSTATUS WINAPI RtlInitializeCriticalSection( RTL_CRITICAL_SECTION *crit ); NTSTATUS WINAPI RtlDeleteCriticalSection( RTL_CRITICAL_SECTION *crit ); diff --git a/loader/task.c b/loader/task.c index 34ab004cb17..a5b6be1e4e7 100644 --- a/loader/task.c +++ b/loader/task.c @@ -10,6 +10,7 @@ #include #include "wine/winbase16.h" +#include "ntddk.h" #include "callback.h" #include "drive.h" #include "file.h" @@ -327,7 +328,7 @@ BOOL TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, TEB *teb, LPCSTR cmdline, /* Create scheduler event for 16-bit tasks */ if ( !(pTask->flags & TDBF_WIN32) ) - pTask->hEvent = CreateEventA( NULL, TRUE, FALSE, NULL ); + NtCreateEvent( &pTask->hEvent, EVENT_ALL_ACCESS, NULL, TRUE, FALSE ); /* Enter task handle into thread and process */ @@ -600,7 +601,7 @@ void TASK_Reschedule(void) pNewTask->priority--; hCurrentTask = hNewTask; - SetEvent( pNewTask->hEvent ); + NtSetEvent( pNewTask->hEvent, NULL ); /* This is set just in case some app reads it ... */ pNewTask->ss_sp = pNewTask->teb->cur_stack; @@ -609,7 +610,7 @@ void TASK_Reschedule(void) /* If we need to put the current task to sleep, do it ... */ if ( (mode == MODE_YIELD || mode == MODE_SLEEP) && hOldTask != hCurrentTask ) { - ResetEvent( pOldTask->hEvent ); + NtResetEvent( pOldTask->hEvent, NULL ); ReleaseThunkLock( &lockCount ); SYSLEVEL_CheckNotLevel( 1 ); diff --git a/scheduler/Makefile.in b/scheduler/Makefile.in index b64b88a6953..a6f8003ab55 100644 --- a/scheduler/Makefile.in +++ b/scheduler/Makefile.in @@ -8,14 +8,10 @@ MODULE = scheduler C_SRCS = \ client.c \ critsection.c \ - debugger.c \ - event.c \ handle.c \ - mutex.c \ pipe.c \ process.c \ pthread.c \ - semaphore.c \ services.c \ synchro.c \ sysdeps.c \ diff --git a/scheduler/critsection.c b/scheduler/critsection.c index 9c223a7fc42..dabc37c4ef6 100644 --- a/scheduler/critsection.c +++ b/scheduler/critsection.c @@ -34,7 +34,7 @@ void WINAPI MakeCriticalSectionGlobal( CRITICAL_SECTION *crit ) { /* let's assume that only one thread at a time will try to do this */ HANDLE sem = crit->LockSemaphore; - if (!sem) sem = CreateSemaphoreA( NULL, 0, 1, NULL ); + if (!sem) NtCreateSemaphore( &sem, SEMAPHORE_ALL_ACCESS, NULL, 0, 1 ); crit->LockSemaphore = ConvertToGlobalHandle( sem ); } diff --git a/scheduler/event.c b/scheduler/event.c deleted file mode 100644 index 7df111e6734..00000000000 --- a/scheduler/event.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Win32 events - * - * Copyright 1998 Alexandre Julliard - */ - -#include -#include -#include "winerror.h" -#include "winnls.h" -#include "wine/unicode.h" -#include "syslevel.h" -#include "server.h" - - -/*********************************************************************** - * CreateEventA (KERNEL32.156) - */ -HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset, - BOOL initial_state, LPCSTR name ) -{ - HANDLE ret; - DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; - if (len >= MAX_PATH) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - SERVER_START_REQ - { - struct create_event_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - - req->manual_reset = manual_reset; - req->initial_state = initial_state; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); - SetLastError(0); - server_call( REQ_CREATE_EVENT ); - ret = req->handle; - } - SERVER_END_REQ; - if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ - return ret; -} - - -/*********************************************************************** - * CreateEventW (KERNEL32.157) - */ -HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset, - BOOL initial_state, LPCWSTR name ) -{ - HANDLE ret; - DWORD len = name ? strlenW(name) : 0; - if (len >= MAX_PATH) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - SERVER_START_REQ - { - struct create_event_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - - req->manual_reset = manual_reset; - req->initial_state = initial_state; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); - SetLastError(0); - server_call( REQ_CREATE_EVENT ); - ret = req->handle; - } - SERVER_END_REQ; - if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ - return ret; -} - -/*********************************************************************** - * WIN16_CreateEvent (KERNEL.457) - */ -HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state ) -{ - return CreateEventA( NULL, manual_reset, initial_state, NULL ); -} - - -/*********************************************************************** - * OpenEventA (KERNEL32.536) - */ -HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name ) -{ - HANDLE ret; - DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; - if (len >= MAX_PATH) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - SERVER_START_REQ - { - struct open_event_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - - req->access = access; - req->inherit = inherit; - if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); - server_call( REQ_OPEN_EVENT ); - ret = req->handle; - } - SERVER_END_REQ; - if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ - return ret; -} - - -/*********************************************************************** - * OpenEventW (KERNEL32.537) - */ -HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name ) -{ - HANDLE ret; - DWORD len = name ? strlenW(name) : 0; - if (len >= MAX_PATH) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - SERVER_START_REQ - { - struct open_event_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - - req->access = access; - req->inherit = inherit; - memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); - server_call( REQ_OPEN_EVENT ); - ret = req->handle; - } - SERVER_END_REQ; - if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ - return ret; -} - - -/*********************************************************************** - * EVENT_Operation - * - * Execute an event operation (set,reset,pulse). - */ -static BOOL EVENT_Operation( HANDLE handle, enum event_op op ) -{ - BOOL ret; - SERVER_START_REQ - { - struct event_op_request *req = server_alloc_req( sizeof(*req), 0 ); - req->handle = handle; - req->op = op; - ret = !server_call( REQ_EVENT_OP ); - } - SERVER_END_REQ; - return ret; -} - - -/*********************************************************************** - * PulseEvent (KERNEL32.557) - */ -BOOL WINAPI PulseEvent( HANDLE handle ) -{ - return EVENT_Operation( handle, PULSE_EVENT ); -} - - -/*********************************************************************** - * SetEvent (KERNEL32.644) - */ -BOOL WINAPI SetEvent( HANDLE handle ) -{ - return EVENT_Operation( handle, SET_EVENT ); -} - - -/*********************************************************************** - * ResetEvent (KERNEL32.586) - */ -BOOL WINAPI ResetEvent( HANDLE handle ) -{ - return EVENT_Operation( handle, RESET_EVENT ); -} - - -/*********************************************************************** - * NOTE: The Win95 VWin32_Event routines given below are really low-level - * routines implemented directly by VWin32. The user-mode libraries - * implement Win32 synchronisation routines on top of these low-level - * primitives. We do it the other way around here :-) - */ - -/*********************************************************************** - * VWin32_EventCreate (KERNEL.442) - */ -HANDLE WINAPI VWin32_EventCreate(VOID) -{ - HANDLE hEvent = CreateEventA( NULL, FALSE, 0, NULL ); - return ConvertToGlobalHandle( hEvent ); -} - -/*********************************************************************** - * VWin32_EventDestroy (KERNEL.443) - */ -VOID WINAPI VWin32_EventDestroy(HANDLE event) -{ - CloseHandle( event ); -} - -/*********************************************************************** - * VWin32_EventWait (KERNEL.450) - */ -VOID WINAPI VWin32_EventWait(HANDLE event) -{ - SYSLEVEL_ReleaseWin16Lock(); - WaitForSingleObject( event, INFINITE ); - SYSLEVEL_RestoreWin16Lock(); -} - -/*********************************************************************** - * VWin32_EventSet (KERNEL.451) - */ -VOID WINAPI VWin32_EventSet(HANDLE event) -{ - SetEvent( event ); -} - diff --git a/scheduler/mutex.c b/scheduler/mutex.c deleted file mode 100644 index 0816d8d2a13..00000000000 --- a/scheduler/mutex.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Win32 mutexes - * - * Copyright 1998 Alexandre Julliard - */ - -#include -#include -#include "winerror.h" -#include "winnls.h" -#include "wine/unicode.h" -#include "server.h" - - -/*********************************************************************** - * CreateMutexA (KERNEL32.166) - */ -HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name ) -{ - HANDLE ret; - DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; - if (len >= MAX_PATH) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - SERVER_START_REQ - { - struct create_mutex_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - - req->owned = owner; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); - SetLastError(0); - server_call( REQ_CREATE_MUTEX ); - ret = req->handle; - } - SERVER_END_REQ; - if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ - return ret; -} - - -/*********************************************************************** - * CreateMutexW (KERNEL32.167) - */ -HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name ) -{ - HANDLE ret; - DWORD len = name ? strlenW(name) : 0; - if (len >= MAX_PATH) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - SERVER_START_REQ - { - struct create_mutex_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - - req->owned = owner; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); - SetLastError(0); - server_call( REQ_CREATE_MUTEX ); - ret = req->handle; - } - SERVER_END_REQ; - if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ - return ret; -} - - -/*********************************************************************** - * OpenMutexA (KERNEL32.541) - */ -HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name ) -{ - HANDLE ret; - DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; - if (len >= MAX_PATH) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - SERVER_START_REQ - { - struct open_mutex_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - - req->access = access; - req->inherit = inherit; - if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); - server_call( REQ_OPEN_MUTEX ); - ret = req->handle; - } - SERVER_END_REQ; - if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ - return ret; -} - - -/*********************************************************************** - * OpenMutexW (KERNEL32.542) - */ -HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name ) -{ - HANDLE ret; - DWORD len = name ? strlenW(name) : 0; - if (len >= MAX_PATH) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - SERVER_START_REQ - { - struct open_mutex_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - - req->access = access; - req->inherit = inherit; - memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); - server_call( REQ_OPEN_MUTEX ); - ret = req->handle; - } - SERVER_END_REQ; - if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ - return ret; -} - - -/*********************************************************************** - * ReleaseMutex (KERNEL32.582) - */ -BOOL WINAPI ReleaseMutex( HANDLE handle ) -{ - BOOL ret; - SERVER_START_REQ - { - struct release_mutex_request *req = server_alloc_req( sizeof(*req), 0 ); - req->handle = handle; - ret = !server_call( REQ_RELEASE_MUTEX ); - } - SERVER_END_REQ; - return ret; -} diff --git a/scheduler/semaphore.c b/scheduler/semaphore.c deleted file mode 100644 index 0a5fee4e506..00000000000 --- a/scheduler/semaphore.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Win32 semaphores - * - * Copyright 1998 Alexandre Julliard - */ - -#include -#include -#include "winerror.h" -#include "winnls.h" -#include "wine/unicode.h" -#include "server.h" - - -/*********************************************************************** - * CreateSemaphoreA (KERNEL32.174) - */ -HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name ) -{ - HANDLE ret; - DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; - - /* Check parameters */ - - if ((max <= 0) || (initial < 0) || (initial > max)) - { - SetLastError( ERROR_INVALID_PARAMETER ); - return 0; - } - if (len >= MAX_PATH) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - - SERVER_START_REQ - { - struct create_semaphore_request *req = server_alloc_req( sizeof(*req), - len * sizeof(WCHAR) ); - - req->initial = (unsigned int)initial; - req->max = (unsigned int)max; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); - SetLastError(0); - server_call( REQ_CREATE_SEMAPHORE ); - ret = req->handle; - } - SERVER_END_REQ; - if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ - return ret; -} - - -/*********************************************************************** - * CreateSemaphoreW (KERNEL32.175) - */ -HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial, - LONG max, LPCWSTR name ) -{ - HANDLE ret; - DWORD len = name ? strlenW(name) : 0; - - /* Check parameters */ - - if ((max <= 0) || (initial < 0) || (initial > max)) - { - SetLastError( ERROR_INVALID_PARAMETER ); - return 0; - } - if (len >= MAX_PATH) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - - SERVER_START_REQ - { - struct create_semaphore_request *req = server_alloc_req( sizeof(*req), - len * sizeof(WCHAR) ); - - req->initial = (unsigned int)initial; - req->max = (unsigned int)max; - req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); - SetLastError(0); - server_call( REQ_CREATE_SEMAPHORE ); - ret = req->handle; - } - SERVER_END_REQ; - if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ - return ret; -} - - -/*********************************************************************** - * OpenSemaphoreA (KERNEL32.545) - */ -HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name ) -{ - HANDLE ret; - DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0; - if (len >= MAX_PATH) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - SERVER_START_REQ - { - struct open_semaphore_request *req = server_alloc_req( sizeof(*req), - len * sizeof(WCHAR) ); - req->access = access; - req->inherit = inherit; - if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len ); - server_call( REQ_OPEN_SEMAPHORE ); - ret = req->handle; - } - SERVER_END_REQ; - if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ - return ret; -} - - -/*********************************************************************** - * OpenSemaphoreW (KERNEL32.546) - */ -HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name ) -{ - HANDLE ret; - DWORD len = name ? strlenW(name) : 0; - if (len >= MAX_PATH) - { - SetLastError( ERROR_FILENAME_EXCED_RANGE ); - return 0; - } - SERVER_START_REQ - { - struct open_semaphore_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) ); - req->access = access; - req->inherit = inherit; - memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) ); - server_call( REQ_OPEN_SEMAPHORE ); - ret = req->handle; - } - SERVER_END_REQ; - if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */ - return ret; -} - - -/*********************************************************************** - * ReleaseSemaphore (KERNEL32.583) - */ -BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous ) -{ - NTSTATUS status = NtReleaseSemaphore( handle, count, previous ); - if (status) SetLastError( RtlNtStatusToDosError(status) ); - return !status; -} diff --git a/scheduler/syslevel.c b/scheduler/syslevel.c index 5a7523e406e..e6bb1124a10 100644 --- a/scheduler/syslevel.c +++ b/scheduler/syslevel.c @@ -6,13 +6,14 @@ #include #include +#include "ntddk.h" #include "syslevel.h" #include "heap.h" #include "selectors.h" #include "stackframe.h" #include "debugtools.h" -DEFAULT_DEBUG_CHANNEL(win32) +DEFAULT_DEBUG_CHANNEL(win32); static SYSLEVEL Win16Mutex; static SEGPTR segpWin16Mutex; @@ -230,7 +231,7 @@ VOID SYSLEVEL_CheckNotLevel( INT level ) { ERR("(%d): Holding lock of level %d!\n", level, i ); - DebugBreak(); + DbgBreakPoint(); break; } } diff --git a/win32/Makefile.in b/win32/Makefile.in index e52d5446d33..42c69a40cb3 100644 --- a/win32/Makefile.in +++ b/win32/Makefile.in @@ -13,7 +13,6 @@ C_SRCS = \ init.c \ kernel32.c \ newfns.c \ - process.c \ time.c all: $(MODULE).o diff --git a/win32/except.c b/win32/except.c index 82f3f44a058..a7d4cf9c671 100644 --- a/win32/except.c +++ b/win32/except.c @@ -154,7 +154,7 @@ DWORD WINAPI UnhandledExceptionFilter(PEXCEPTION_POINTERS epointers) attr.bInheritHandle = TRUE; TRACE("Starting debugger (fmt=%s)\n", format); - hEvent = CreateEventA(&attr, FALSE, FALSE, NULL); + NtCreateEvent( &hEvent, EVENT_ALL_ACCESS, NULL, FALSE, FALSE ); sprintf(buffer, format, GetCurrentProcessId(), hEvent); memset(&startup, 0, sizeof(startup)); startup.cb = sizeof(startup); diff --git a/win32/kernel32.c b/win32/kernel32.c index 74fe4da3599..0bbc94f42ad 100644 --- a/win32/kernel32.c +++ b/win32/kernel32.c @@ -49,21 +49,3 @@ BOOL WINAPI UpdateResourceW( SetLastError(ERROR_CALL_NOT_IMPLEMENTED); return FALSE; } - - -/*********************************************************************** - * WaitNamedPipeA [KERNEL32.725] - */ -BOOL WINAPI WaitNamedPipeA (LPCSTR lpNamedPipeName, DWORD nTimeOut) -{ FIXME("%s 0x%08lx\n",lpNamedPipeName,nTimeOut); - SetLastError(ERROR_PIPE_NOT_CONNECTED); - return FALSE; -} -/*********************************************************************** - * WaitNamedPipeW [KERNEL32.726] - */ -BOOL WINAPI WaitNamedPipeW (LPCWSTR lpNamedPipeName, DWORD nTimeOut) -{ FIXME("%s 0x%08lx\n",debugstr_w(lpNamedPipeName),nTimeOut); - SetLastError(ERROR_PIPE_NOT_CONNECTED); - return FALSE; -} diff --git a/win32/newfns.c b/win32/newfns.c index 11e09994168..3f62d39dfc9 100644 --- a/win32/newfns.c +++ b/win32/newfns.c @@ -50,59 +50,6 @@ BOOL WINAPI FlushInstructionCache(DWORD x,DWORD y,DWORD z) { return TRUE; } -/*********************************************************************** - * CreateNamedPipeA (KERNEL32.168) - */ -HANDLE WINAPI CreateNamedPipeA (LPCSTR lpName, DWORD dwOpenMode, - DWORD dwPipeMode, DWORD nMaxInstances, - DWORD nOutBufferSize, DWORD nInBufferSize, - DWORD nDefaultTimeOut, - LPSECURITY_ATTRIBUTES lpSecurityAttributes) -{ - FIXME("(Name=%s, OpenMode=%#08lx, dwPipeMode=%#08lx, MaxInst=%ld, OutBSize=%ld, InBuffSize=%ld, DefTimeOut=%ld, SecAttr=%p): stub\n", - debugstr_a(lpName), dwOpenMode, dwPipeMode, nMaxInstances, - nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes); - /* if (nMaxInstances > PIPE_UNLIMITED_INSTANCES) { - SetLastError (ERROR_INVALID_PARAMETER); - return INVALID_HANDLE_VALUE; - } */ - - SetLastError (ERROR_UNKNOWN); - return INVALID_HANDLE_VALUE; -} - -/*********************************************************************** - * CreateNamedPipeW (KERNEL32.169) - */ -HANDLE WINAPI CreateNamedPipeW (LPCWSTR lpName, DWORD dwOpenMode, - DWORD dwPipeMode, DWORD nMaxInstances, - DWORD nOutBufferSize, DWORD nInBufferSize, - DWORD nDefaultTimeOut, - LPSECURITY_ATTRIBUTES lpSecurityAttributes) -{ - FIXME("(Name=%s, OpenMode=%#08lx, dwPipeMode=%#08lx, MaxInst=%ld, OutBSize=%ld, InBuffSize=%ld, DefTimeOut=%ld, SecAttr=%p): stub\n", - debugstr_w(lpName), dwOpenMode, dwPipeMode, nMaxInstances, - nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes); - - SetLastError (ERROR_UNKNOWN); - return INVALID_HANDLE_VALUE; -} - -/*********************************************************************** - * PeekNamedPipe (KERNEL32.552) - */ -BOOL WINAPI PeekNamedPipe (HANDLE hPipe, - LPVOID lpvBuffer, DWORD cbBuffer, - LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage) -{ - FIXME("(%08x, %p, %08lx, %p, %p, %p): stub\n", - hPipe, lpvBuffer, cbBuffer, lpcbRead, lpcbAvail, lpcbMessage); - - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; -} - - /*********************************************************************** * GetSystemPowerStatus (KERNEL32.621) */ diff --git a/win32/process.c b/win32/process.c deleted file mode 100644 index 36bdfccb885..00000000000 --- a/win32/process.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Win32 kernel functions - * - * Copyright 1995 Martin von Loewis - */ - -#include -#include -#include -#include "winbase.h" -#include "winerror.h" -#include "heap.h" -#include "thread.h" -#include "process.h" -#include "file.h" -#include "task.h" -#include "toolhelp.h" -#include "debugtools.h" - -DEFAULT_DEBUG_CHANNEL(win32); - - -/********************************************************************* - * Process_ClockTimeToFileTime - * (olorin@fandra.org, 20-Sep-1998) - * Converts clock_t into FILETIME. - * Used by GetProcessTime. - * Differences to UnixTimeToFileTime: - * 1) Divided by CLK_TCK - * 2) Time is relative. There is no 'starting date', so there is - * no need in offset correction, like in UnixTimeToFileTime - * FIXME: This function should be moved to a more appropriate .c file - * FIXME: On floating point operations, it is assumed that - * floating values are truncated on conversion to integer. - */ -void Process_ClockTimeToFileTime( clock_t unix_time, LPFILETIME filetime ) -{ - double td = (unix_time*10000000.0)/CLK_TCK; - /* Yes, double, because long int might overflow here. */ -#if SIZEOF_LONG_LONG >= 8 - unsigned long long t = td; - filetime->dwLowDateTime = (UINT) t; - filetime->dwHighDateTime = (UINT) (t >> 32); -#else - double divider = 1. * (1 << 16) * (1 << 16); - filetime->dwHighDateTime = (UINT) (td / divider); - filetime->dwLowDateTime = (UINT) (td - filetime->dwHighDateTime*divider); - /* using floor() produces wierd results, better leave this as it is - * ( with (UINT32) convertion ) - */ -#endif -} - -/********************************************************************* - * GetProcessTimes [KERNEL32.262] - * - * FIXME: lpCreationTime, lpExitTime are NOT INITIALIZED. - * olorin@fandra.org: Would be nice to substract the cpu time, - * used by Wine at startup. - * Also, there is a need to separate times - * used by different applications. - */ -BOOL WINAPI GetProcessTimes( - HANDLE hprocess,LPFILETIME lpCreationTime,LPFILETIME lpExitTime, - LPFILETIME lpKernelTime, LPFILETIME lpUserTime -) { - struct tms tms; - - times(&tms); - Process_ClockTimeToFileTime(tms.tms_utime,lpUserTime); - Process_ClockTimeToFileTime(tms.tms_stime,lpKernelTime); - return TRUE; -} - diff --git a/win32/time.c b/win32/time.c index 42d422c71de..fa0a9c29f4e 100644 --- a/win32/time.c +++ b/win32/time.c @@ -14,20 +14,6 @@ DEFAULT_DEBUG_CHANNEL(win32) -/* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */ -#define SETTIME_MAX_ADJUST 120 - -/* TIME_GetBias: helper function calculates delta local time from UTC */ -static int TIME_GetBias( time_t utc, int *pdaylight) -{ - struct tm *ptm = localtime(&utc); - *pdaylight = ptm->tm_isdst; /* daylight for local timezone */ - ptm = gmtime(&utc); - ptm->tm_isdst = *pdaylight; /* use local daylight, not that of Greenwich */ - return (int)(utc-mktime(ptm)); -} - - /*********************************************************************** * GetLocalTime (KERNEL32.228) */ @@ -51,69 +37,6 @@ VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) systime->wMilliseconds = (tv.tv_usec / 1000) % 1000; } - -/*********************************************************************** - * SetLocalTime (KERNEL32.655) - * - * FIXME: correct ? Is the timezone param of settimeofday() needed ? - * I don't have any docu about SetLocal/SystemTime(), argl... - */ -BOOL WINAPI SetLocalTime(const SYSTEMTIME *systime) -{ - struct timeval tv; - struct tm t; - time_t sec; - time_t oldsec=time(NULL); - int err; - - /* get the number of seconds */ - t.tm_sec = systime->wSecond; - t.tm_min = systime->wMinute; - t.tm_hour = systime->wHour; - t.tm_mday = systime->wDay; - t.tm_mon = systime->wMonth - 1; - t.tm_year = systime->wYear - 1900; - t.tm_isdst = -1; - sec = mktime (&t); - - /* set the new time */ - tv.tv_sec = sec; - tv.tv_usec = systime->wMilliseconds * 1000; - - /* error and sanity check*/ - if( sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST ){ - err = 1; - SetLastError(ERROR_INVALID_PARAMETER); - } else { - err=settimeofday(&tv, NULL); /* 0 is OK, -1 is error */ - if(err == 0) - return TRUE; - SetLastError(ERROR_PRIVILEGE_NOT_HELD); - } - ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n", - systime->wYear, systime->wMonth, systime->wDay, systime->wHour, - systime->wMinute, systime->wSecond, - sec-oldsec, err == -1 ? "No Permission" : - sec==(time_t)-1 ? "" : "is too large." ); - return FALSE; -} - - -/*********************************************************************** - * GetSystemTimeAdjustment (KERNEL32.407) - * - */ -DWORD WINAPI GetSystemTimeAdjustment( LPDWORD lpTimeAdjustment, - LPDWORD lpTimeIncrement, - LPBOOL lpTimeAdjustmentDisabled ) -{ - *lpTimeAdjustment = 0; - *lpTimeIncrement = 0; - *lpTimeAdjustmentDisabled = TRUE; - return TRUE; -} - - /*********************************************************************** * GetSystemTime (KERNEL32.285) */ @@ -138,98 +61,6 @@ VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) } -/*********************************************************************** - * SetSystemTime (KERNEL32.507) - */ -BOOL WINAPI SetSystemTime(const SYSTEMTIME *systime) -{ - struct timeval tv; - struct timezone tz; - struct tm t; - time_t sec, oldsec; - int dst, bias; - int err; - - /* call gettimeofday to get the current timezone */ - gettimeofday(&tv, &tz); - oldsec=tv.tv_sec; - /* get delta local time from utc */ - bias=TIME_GetBias(oldsec,&dst); - - - /* get the number of seconds */ - t.tm_sec = systime->wSecond; - t.tm_min = systime->wMinute; - t.tm_hour = systime->wHour; - t.tm_mday = systime->wDay; - t.tm_mon = systime->wMonth - 1; - t.tm_year = systime->wYear - 1900; - t.tm_isdst = dst; - sec = mktime (&t); - /* correct for timezone and daylight */ - sec += bias; - - /* set the new time */ - tv.tv_sec = sec; - tv.tv_usec = systime->wMilliseconds * 1000; - - /* error and sanity check*/ - if( sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST ){ - err = 1; - SetLastError(ERROR_INVALID_PARAMETER); - } else { - err=settimeofday(&tv, NULL); /* 0 is OK, -1 is error */ - if(err == 0) - return TRUE; - SetLastError(ERROR_PRIVILEGE_NOT_HELD); - } - ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n", - systime->wYear, systime->wMonth, systime->wDay, systime->wHour, - systime->wMinute, systime->wSecond, - sec-oldsec, err == -1 ? "No Permission" : - sec==(time_t)-1 ? "" : "is too large." ); - return FALSE; -} - - -/*********************************************************************** - * GetTimeZoneInformation (KERNEL32.302) - */ -DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION tzinfo) -{ - time_t gmt; - int bias, daylight; - - memset(tzinfo, 0, sizeof(TIME_ZONE_INFORMATION)); - - gmt = time(NULL); - bias=TIME_GetBias(gmt,&daylight); - - tzinfo->Bias = -bias / 60; - tzinfo->StandardBias = 0; - tzinfo->DaylightBias = -60; - - return TIME_ZONE_ID_UNKNOWN; -} - - -/*********************************************************************** - * SetTimeZoneInformation (KERNEL32.515) - */ -BOOL WINAPI SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION tzinfo) -{ - struct timezone tz; - - tz.tz_minuteswest = tzinfo->Bias; -#ifdef DST_NONE - tz.tz_dsttime = DST_NONE; -#else - tz.tz_dsttime = 0; -#endif - return !settimeofday(NULL, &tz); -} - - /*********************************************************************** * GetSystemTimeAsFileTime (KERNEL32) */ @@ -241,15 +72,3 @@ VOID WINAPI GetSystemTimeAsFileTime(LPFILETIME systemtimeAsfiletime) DOSFS_UnixTimeToFileTime( now.tv_sec, systemtimeAsfiletime, now.tv_usec * 10 ); } -/*********************************************************************** - * SystemTimeToTzSpecificLocalTime (KERNEL32.683) - */ -BOOL WINAPI SystemTimeToTzSpecificLocalTime( - LPTIME_ZONE_INFORMATION lpTimeZoneInformation, - LPSYSTEMTIME lpUniversalTime, - LPSYSTEMTIME lpLocalTime) { - - FIXME(":stub\n"); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; -}