diff --git a/dlls/kernel/kernel.spec b/dlls/kernel/kernel.spec index fad93d726bf..9bc3781ea6f 100644 --- a/dlls/kernel/kernel.spec +++ b/dlls/kernel/kernel.spec @@ -389,8 +389,8 @@ owner kernel32 477 stub WOAFullScreen 478 stub WOATerminateProcess 479 pascal KERNEL_479(long) VWin32_EventSet # ??? -480 pascal16 _EnterWin16Lock() SYSLEVEL_EnterWin16Lock -481 pascal16 _LeaveWin16Lock() SYSLEVEL_LeaveWin16Lock +480 pascal16 _EnterWin16Lock() _EnterWin16Lock +481 pascal16 _LeaveWin16Lock() _LeaveWin16Lock 482 pascal LoadSystemLibrary32(str) LoadLibrary32_16 # FIXME! 483 pascal MapProcessHandle(long) MapProcessHandle 484 pascal SetProcessDWORD(long s_word long) SetProcessDword diff --git a/dlls/kernel/sync.c b/dlls/kernel/sync.c index 1fa398dd658..c6026a0786b 100644 --- a/dlls/kernel/sync.c +++ b/dlls/kernel/sync.c @@ -8,7 +8,6 @@ #include "winerror.h" #include "winnls.h" #include "wine/unicode.h" -#include "syslevel.h" #include "server.h" #include "debugtools.h" @@ -222,9 +221,11 @@ VOID WINAPI VWin32_EventDestroy(HANDLE event) */ VOID WINAPI VWin32_EventWait(HANDLE event) { - SYSLEVEL_ReleaseWin16Lock(); + DWORD mutex_count; + + ReleaseThunkLock( &mutex_count ); WaitForSingleObject( event, INFINITE ); - SYSLEVEL_RestoreWin16Lock(); + RestoreThunkLock( mutex_count ); } /*********************************************************************** diff --git a/dlls/kernel/thunk.c b/dlls/kernel/thunk.c index 8a25b0da54f..a6ac464b255 100644 --- a/dlls/kernel/thunk.c +++ b/dlls/kernel/thunk.c @@ -24,7 +24,6 @@ #include "module.h" #include "selectors.h" #include "stackframe.h" -#include "syslevel.h" #include "task.h" DEFAULT_DEBUG_CHANNEL(thunk); @@ -1134,7 +1133,9 @@ void WINAPI K32Thk1632Prolog( CONTEXT86 *context ) context->Ebp, context->Esp, NtCurrentTeb()->cur_stack); } - SYSLEVEL_ReleaseWin16Lock(); + /* entry_point is never used again once the entry point has + been called. Thus we re-use it to hold the Win16Lock count */ + ReleaseThunkLock(&CURRENT_STACK16->entry_point); } /*********************************************************************** @@ -1144,7 +1145,7 @@ void WINAPI K32Thk1632Epilog( CONTEXT86 *context ) { LPBYTE code = (LPBYTE)context->Eip - 13; - SYSLEVEL_RestoreWin16Lock(); + RestoreThunkLock(CURRENT_STACK16->entry_point); /* We undo the SYSTHUNK hack if necessary. See K32Thk1632Prolog. */ diff --git a/dlls/kernel/wowthunk.c b/dlls/kernel/wowthunk.c index 983be2756d1..9cf189430b8 100644 --- a/dlls/kernel/wowthunk.c +++ b/dlls/kernel/wowthunk.c @@ -10,7 +10,6 @@ #include "file.h" #include "heap.h" #include "miscemu.h" -#include "syslevel.h" #include "stackframe.h" #include "builtin16.h" #include "debugtools.h" @@ -315,6 +314,7 @@ DWORD WINAPI LoadLibraryEx32W16( LPCSTR lpszLibFile, DWORD hFile, DWORD dwFlags { HMODULE hModule; DOS_FULL_NAME full_name; + DWORD mutex_count; /* if the file can not be found, call LoadLibraryExA anyway, since it might be a buildin module. This case is handled in MODULE_LoadLibraryExA */ @@ -323,10 +323,9 @@ DWORD WINAPI LoadLibraryEx32W16( LPCSTR lpszLibFile, DWORD hFile, DWORD dwFlags strcpy ( full_name.short_name, lpszLibFile ); } - SYSLEVEL_ReleaseWin16Lock(); + ReleaseThunkLock( &mutex_count ); hModule = LoadLibraryExA( full_name.short_name, (HANDLE)hFile, dwFlags ); - SYSLEVEL_RestoreWin16Lock(); - + RestoreThunkLock( mutex_count ); return (DWORD)hModule; } @@ -344,11 +343,11 @@ DWORD WINAPI GetProcAddress32W16( DWORD hModule, LPCSTR lpszProc ) DWORD WINAPI FreeLibrary32W16( DWORD hLibModule ) { BOOL retv; + DWORD mutex_count; - SYSLEVEL_ReleaseWin16Lock(); + ReleaseThunkLock( &mutex_count ); retv = FreeLibrary( (HMODULE)hLibModule ); - SYSLEVEL_RestoreWin16Lock(); - + RestoreThunkLock( mutex_count ); return (DWORD)retv; } @@ -361,11 +360,12 @@ static DWORD WOW_CallProc32W16( BOOL Ex ) DWORD nrofargs, argconvmask; FARPROC proc32; DWORD *args, ret; + DWORD mutex_count; VA_LIST16 valist; int i; int aix; - SYSLEVEL_ReleaseWin16Lock(); + ReleaseThunkLock( &mutex_count ); VA_START16( valist ); nrofargs = VA_ARG16( valist, DWORD ); @@ -446,8 +446,7 @@ static DWORD WOW_CallProc32W16( BOOL Ex ) TRACE("returns %08lx\n",ret); HeapFree( GetProcessHeap(), 0, args ); - SYSLEVEL_RestoreWin16Lock(); - + RestoreThunkLock( mutex_count ); return ret; } diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c index eabc6bbb63e..8ec240188c3 100644 --- a/dlls/ntdll/signal_i386.c +++ b/dlls/ntdll/signal_i386.c @@ -432,12 +432,6 @@ static void save_context( CONTEXT *context, const SIGCONTEXT *sigcontext ) } #endif /* linux */ - if (!fs) - { - fs = SYSLEVEL_EmergencyTeb; - __set_fs(fs); - ERR("fallback to emergency TEB\n"); - } __set_fs(fs); context->Eax = EAX_sig(sigcontext); diff --git a/dlls/user/user_main.c b/dlls/user/user_main.c index 68f49fd8f8c..09b72b73863 100644 --- a/dlls/user/user_main.c +++ b/dlls/user/user_main.c @@ -135,9 +135,6 @@ BOOL WINAPI USER_Init(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) /* Load the graphics driver */ if (!load_driver()) return FALSE; - /* Initialize window handling (critical section) */ - WIN_Init(); - /* Initialize system colors and metrics*/ SYSMETRICS_Init(); SYSCOLOR_Init(); diff --git a/dlls/win32s/w32skernel.c b/dlls/win32s/w32skernel.c index c418caf9228..d1716a6516d 100644 --- a/dlls/win32s/w32skernel.c +++ b/dlls/win32s/w32skernel.c @@ -8,6 +8,7 @@ #include #include "winbase.h" +#include "wine/windef16.h" /*********************************************************************** * GetWin32sDirectory diff --git a/dlls/win32s/win32s16.c b/dlls/win32s/win32s16.c index bf7243c5abe..d815bccef68 100644 --- a/dlls/win32s/win32s16.c +++ b/dlls/win32s/win32s16.c @@ -8,6 +8,7 @@ #include #include #include "windef.h" +#include "wine/windef16.h" #include "debugtools.h" DEFAULT_DEBUG_CHANNEL(dll); diff --git a/dlls/winmm/mmsystem.c b/dlls/winmm/mmsystem.c index 21ae14b77ad..8dafea15439 100644 --- a/dlls/winmm/mmsystem.c +++ b/dlls/winmm/mmsystem.c @@ -27,7 +27,6 @@ #include "wine/winestring.h" #include "heap.h" #include "winemm.h" -#include "syslevel.h" #include "selectors.h" #include "module.h" #include "debugtools.h" diff --git a/dlls/winmm/time.c b/dlls/winmm/time.c index 97f860298ad..822b5f7f071 100644 --- a/dlls/winmm/time.c +++ b/dlls/winmm/time.c @@ -13,10 +13,9 @@ #include "winuser.h" #include "winemm.h" #include "services.h" -#include "syslevel.h" #include "debugtools.h" -DEFAULT_DEBUG_CHANNEL(mmtime) +DEFAULT_DEBUG_CHANNEL(mmtime); /* * FIXME @@ -383,10 +382,8 @@ DWORD WINAPI timeGetTime(void) /* FIXME: releasing the win16 lock here is a temporary hack (I hope) * that lets mciavi.drv run correctly */ - if ( _ConfirmWin16Lock() ) { - SYSLEVEL_ReleaseWin16Lock(); - SYSLEVEL_RestoreWin16Lock(); - } - + DWORD count; + ReleaseThunkLock(&count); + RestoreThunkLock(count); return MULTIMEDIA_MMTimeStart()->mmSysTimeMS; } diff --git a/files/dos_fs.c b/files/dos_fs.c index f0ab2f40f9f..5e8d88fee26 100644 --- a/files/dos_fs.c +++ b/files/dos_fs.c @@ -31,7 +31,6 @@ #include "file.h" #include "heap.h" #include "msdos.h" -#include "syslevel.h" #include "server.h" #include "options.h" #include "debugtools.h" @@ -1501,7 +1500,7 @@ int DOSFS_FindNext( const char *path, const char *short_mask, LPCSTR short_name, long_name; int count; - SYSLEVEL_EnterWin16Lock(); + _EnterWin16Lock(); /* Check the cached directory */ if (!(info.dir && info.path == path && info.short_mask == short_mask @@ -1538,7 +1537,7 @@ int DOSFS_FindNext( const char *path, const char *short_mask, memset( &info, '\0', sizeof(info) ); } - SYSLEVEL_LeaveWin16Lock(); + _LeaveWin16Lock(); return count; } diff --git a/include/heap.h b/include/heap.h index 8bd9518794b..f231f4d6c67 100644 --- a/include/heap.h +++ b/include/heap.h @@ -10,6 +10,7 @@ #include "config.h" #include "winbase.h" +#include "wine/windef16.h" /* for SEGPTR */ extern HANDLE SystemHeap; extern HANDLE SegptrHeap; diff --git a/include/syslevel.h b/include/syslevel.h index 800a4d273f3..c75755f0d77 100644 --- a/include/syslevel.h +++ b/include/syslevel.h @@ -10,32 +10,9 @@ #include "windef.h" #include "winbase.h" -typedef struct tagSYSLEVEL -{ - CRITICAL_SECTION crst; - INT level; -} SYSLEVEL; - extern WORD SYSLEVEL_Win16CurrentTeb; extern WORD SYSLEVEL_EmergencyTeb; -void SYSLEVEL_Init(void); -VOID WINAPI SYSLEVEL_EnterWin16Lock(void); -VOID WINAPI SYSLEVEL_LeaveWin16Lock(void); -VOID SYSLEVEL_ReleaseWin16Lock(void); -VOID SYSLEVEL_RestoreWin16Lock(void); VOID SYSLEVEL_CheckNotLevel( INT level ); -VOID WINAPI GetpWin16Lock(SYSLEVEL **lock); -SEGPTR WINAPI GetpWin16Lock16(void); -DWORD WINAPI _ConfirmWin16Lock(void); - -VOID WINAPI _CreateSysLevel(SYSLEVEL *lock, INT level); -VOID WINAPI _EnterSysLevel(SYSLEVEL *lock); -VOID WINAPI _LeaveSysLevel(SYSLEVEL *lock); -DWORD WINAPI _ConfirmSysLevel(SYSLEVEL *lock); - -VOID WINAPI ReleaseThunkLock(DWORD *mutex_count); -VOID WINAPI RestoreThunkLock(DWORD mutex_count); - #endif /* __WINE_SYSLEVEL_H */ diff --git a/include/win.h b/include/win.h index 6329bb2948e..1eb5530295a 100644 --- a/include/win.h +++ b/include/win.h @@ -174,7 +174,6 @@ typedef struct #define UNC_IN_BEGINPAINT 0x0020 /* Window functions */ -extern void WIN_Init( void ); extern void WIN_LockWnds( void ); extern void WIN_UnlockWnds( void ); extern int WIN_SuspendWndsLock( void ); diff --git a/include/winbase.h b/include/winbase.h index fac2794197a..663e4cac029 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -1476,8 +1476,6 @@ BOOL WINAPI LookupPrivilegeValueW(LPCWSTR,LPCWSTR,LPVOID); BOOL WINAPI MakeSelfRelativeSD(PSECURITY_DESCRIPTOR,PSECURITY_DESCRIPTOR,LPDWORD); HMODULE WINAPI MapHModuleSL(WORD); WORD WINAPI MapHModuleLS(HMODULE); -SEGPTR WINAPI MapLS(LPVOID); -LPVOID WINAPI MapSL(SEGPTR); LPVOID WINAPI MapViewOfFile(HANDLE,DWORD,DWORD,DWORD,DWORD); LPVOID WINAPI MapViewOfFileEx(HANDLE,DWORD,DWORD,DWORD,DWORD,LPVOID); BOOL WINAPI MoveFileA(LPCSTR,LPCSTR); @@ -1599,7 +1597,6 @@ BOOL WINAPI TlsFree(DWORD); LPVOID WINAPI TlsGetValue(DWORD); BOOL WINAPI TlsSetValue(DWORD,LPVOID); BOOL WINAPI TransmitCommChar(HANDLE,CHAR); -VOID WINAPI UnMapLS(SEGPTR); BOOL WINAPI UnlockFile(HANDLE,DWORD,DWORD,DWORD,DWORD); BOOL WINAPI UnmapViewOfFile(LPVOID); LPVOID WINAPI VirtualAlloc(LPVOID,DWORD,DWORD,DWORD); @@ -1875,6 +1872,25 @@ INT WINAPI lstrcmpiW(LPCWSTR,LPCWSTR); #define ZeroMemory RtlZeroMemory #define CopyMemory RtlCopyMemory +/* undocumented functions */ + +typedef struct tagSYSLEVEL +{ + CRITICAL_SECTION crst; + INT level; +} SYSLEVEL; + +VOID WINAPI GetpWin16Lock(SYSLEVEL**); +DWORD WINAPI MapLS(LPVOID); +LPVOID WINAPI MapSL(DWORD); +VOID WINAPI ReleaseThunkLock(DWORD*); +VOID WINAPI RestoreThunkLock(DWORD); +VOID WINAPI UnMapLS(DWORD); +DWORD WINAPI _ConfirmWin16Lock(void); +DWORD WINAPI _ConfirmSysLevel(SYSLEVEL*); +VOID WINAPI _EnterSysLevel(SYSLEVEL*); +VOID WINAPI _LeaveSysLevel(SYSLEVEL*); + /* a few optimizations for i386/gcc */ #if defined(__i386__) && defined(__GNUC__) diff --git a/include/windef.h b/include/windef.h index cc89b02b36b..056f499a163 100644 --- a/include/windef.h +++ b/include/windef.h @@ -234,14 +234,6 @@ typedef FLOAT *LPFLOAT; typedef BOOL *PBOOL; typedef BOOL *LPBOOL; -/* Special case: a segmented pointer is just a pointer in the user's code. */ - -#ifdef __WINE__ -typedef DWORD SEGPTR; -#else -typedef void* SEGPTR; -#endif /* __WINE__ */ - /* Handle types that exist both in Win16 and Win32. */ #ifdef STRICT diff --git a/include/wine/winbase16.h b/include/wine/winbase16.h index 27569b69efd..a37dfeef8b8 100644 --- a/include/wine/winbase16.h +++ b/include/wine/winbase16.h @@ -78,6 +78,7 @@ INT16 WINAPI GetInstanceData16(HINSTANCE16,WORD,INT16); BOOL16 WINAPI GetModuleName16(HINSTANCE16,LPSTR,INT16); INT16 WINAPI GetModuleUsage16(HINSTANCE16); UINT16 WINAPI GetNumTasks16(void); +SEGPTR WINAPI GetpWin16Lock16(void); DWORD WINAPI GetSelectorLimit16(WORD); FARPROC16 WINAPI GetSetKernelDOSProc16(FARPROC16 DosProc); HINSTANCE16 WINAPI GetTaskDS16(void); @@ -117,6 +118,9 @@ VOID WINAPI SwitchStackTo16(WORD,WORD,WORD); BOOL16 WINAPI WaitEvent16(HTASK16); VOID WINAPI WriteOutProfiles16(void); VOID WINAPI hmemcpy16(LPVOID,LPCVOID,LONG); +VOID WINAPI _CreateSysLevel(SYSLEVEL*,INT); +VOID WINAPI _EnterWin16Lock(void); +VOID WINAPI _LeaveWin16Lock(void); INT16 WINAPI AccessResource16(HINSTANCE16,HRSRC16); diff --git a/include/wine/windef16.h b/include/wine/windef16.h index 616ffd100cc..cf0907b1bda 100644 --- a/include/wine/windef16.h +++ b/include/wine/windef16.h @@ -14,6 +14,7 @@ typedef short INT16; typedef unsigned short UINT16; typedef unsigned short BOOL16; +typedef DWORD SEGPTR; typedef UINT16 HANDLE16; typedef HANDLE16 *LPHANDLE16; diff --git a/include/winsock.h b/include/winsock.h index 101d1200e9f..75da6620361 100644 --- a/include/winsock.h +++ b/include/winsock.h @@ -153,7 +153,7 @@ typedef struct WSAData { char szSystemStatus[WSASYS_STATUS_LEN+1]; WORD iMaxSockets; WORD iMaxUdpDg; - SEGPTR lpVendorInfo; + char *lpVendorInfo; } WSADATA, *LPWSADATA; #include "poppack.h" diff --git a/loader/module.c b/loader/module.c index ae2d2980e96..d2c0fb82f6e 100644 --- a/loader/module.c +++ b/loader/module.c @@ -17,7 +17,6 @@ #include "heap.h" #include "neexe.h" #include "process.h" -#include "syslevel.h" #include "selectors.h" #include "debugtools.h" #include "callback.h" @@ -798,9 +797,10 @@ HINSTANCE16 WINAPI WinExec16( LPCSTR lpCmdLine, UINT16 nCmdShow ) if (ret == 21) /* 32-bit module */ { - SYSLEVEL_ReleaseWin16Lock(); + DWORD count; + ReleaseThunkLock( &count ); ret = WinExec( lpCmdLine, nCmdShow ); - SYSLEVEL_RestoreWin16Lock(); + RestoreThunkLock( count ); } return ret; } @@ -1452,11 +1452,11 @@ HMODULE WINAPI LoadLibraryW(LPCWSTR libnameW) HMODULE WINAPI LoadLibrary32_16( LPCSTR libname ) { HMODULE hModule; + DWORD count; - SYSLEVEL_ReleaseWin16Lock(); + ReleaseThunkLock( &count ); hModule = LoadLibraryA( libname ); - SYSLEVEL_RestoreWin16Lock(); - + RestoreThunkLock( count ); return hModule; } diff --git a/loader/ne/module.c b/loader/ne/module.c index fa2cd39bcca..4111aa832e5 100644 --- a/loader/ne/module.c +++ b/loader/ne/module.c @@ -22,7 +22,6 @@ #include "global.h" #include "process.h" #include "snoop.h" -#include "syslevel.h" #include "builtin16.h" #include "stackframe.h" #include "debugtools.h" @@ -1120,7 +1119,7 @@ static void NE_InitProcess(void) SEGTABLEENTRY *pSegTable = NE_SEG_TABLE( pModule ); WORD sp; - SYSLEVEL_EnterWin16Lock(); + _EnterWin16Lock(); if ( pModule->count > 0 ) { @@ -1197,7 +1196,7 @@ static void NE_InitProcess(void) ExitThread( LOWORD(context.Eax) ); } - SYSLEVEL_LeaveWin16Lock(); + _LeaveWin16Lock(); ExitThread( hInstance ); } diff --git a/loader/task.c b/loader/task.c index 4d3bf8dca8d..74910881e1c 100644 --- a/loader/task.c +++ b/loader/task.c @@ -27,8 +27,8 @@ #include "thread.h" #include "toolhelp.h" #include "winnt.h" -#include "winsock.h" #include "syslevel.h" +#include "winsock.h" #include "debugtools.h" #include "services.h" #include "server.h" @@ -336,9 +336,9 @@ BOOL TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, TEB *teb, LPCSTR cmdline, /* Add the task to the linked list */ - SYSLEVEL_EnterWin16Lock(); + _EnterWin16Lock(); TASK_LinkTask( hTask ); - SYSLEVEL_LeaveWin16Lock(); + _LeaveWin16Lock(); return TRUE; } @@ -384,12 +384,12 @@ void TASK_ExitTask(void) DWORD lockCount; /* Enter the Win16Lock to protect global data structures */ - SYSLEVEL_EnterWin16Lock(); + _EnterWin16Lock(); pTask = (TDB *)GlobalLock16( GetCurrentTask() ); if ( !pTask ) { - SYSLEVEL_LeaveWin16Lock(); + _LeaveWin16Lock(); return; } @@ -486,7 +486,7 @@ void TASK_Reschedule(void) enum { MODE_YIELD, MODE_SLEEP, MODE_WAKEUP } mode; DWORD lockCount; - SYSLEVEL_EnterWin16Lock(); + _EnterWin16Lock(); /* Check what we need to do */ hOldTask = GetCurrentTask(); @@ -521,7 +521,7 @@ void TASK_Reschedule(void) else { /* nothing to do */ - SYSLEVEL_LeaveWin16Lock(); + _LeaveWin16Lock(); return; } } @@ -555,7 +555,7 @@ void TASK_Reschedule(void) if ( mode == MODE_YIELD && hNewTask && hNewTask == hCurrentTask ) { TRACE("returning to the current task (%04x)\n", hCurrentTask ); - SYSLEVEL_LeaveWin16Lock(); + _LeaveWin16Lock(); /* Allow Win32 threads to thunk down even while a Win16 task is in a tight PeekMessage() or Yield() loop ... */ @@ -600,7 +600,7 @@ void TASK_Reschedule(void) RestoreThunkLock( lockCount ); } - SYSLEVEL_LeaveWin16Lock(); + _LeaveWin16Lock(); } /*********************************************************************** diff --git a/objects/gdiobj.c b/objects/gdiobj.c index 58d21a1a758..868c6183a29 100644 --- a/objects/gdiobj.c +++ b/objects/gdiobj.c @@ -26,7 +26,6 @@ #include "debugtools.h" #include "gdi.h" #include "tweak.h" -#include "syslevel.h" DEFAULT_DEBUG_CHANNEL(gdi); @@ -178,7 +177,7 @@ static GDIOBJHDR * StockObjects[NB_STOCK_OBJECTS] = HBITMAP hPseudoStockBitmap; /* 1x1 bitmap for memory DCs */ -static SYSLEVEL GDI_level; +static SYSLEVEL GDI_level = { CRITICAL_SECTION_INIT, 3 }; static WORD GDI_HeapSel; @@ -327,8 +326,6 @@ BOOL GDI_Init(void) HPALETTE16 hpalette; HINSTANCE16 instance; - _CreateSysLevel( &GDI_level, 3 ); - /* create GDI heap */ if ((instance = LoadLibrary16( "GDI.EXE" )) < 32) return FALSE; GDI_HeapSel = GlobalHandleToSel16( instance ); diff --git a/scheduler/process.c b/scheduler/process.c index c01c46b647d..7c659935829 100644 --- a/scheduler/process.c +++ b/scheduler/process.c @@ -25,7 +25,6 @@ #include "heap.h" #include "task.h" #include "ldt.h" -#include "syslevel.h" #include "thread.h" #include "winerror.h" #include "server.h" @@ -211,9 +210,6 @@ static BOOL process_init( char *argv[] ) SERVER_END_REQ; if (!ret) return FALSE; - /* Remember TEB selector of initial process for emergency use */ - SYSLEVEL_EmergencyTeb = NtCurrentTeb()->teb_sel; - /* Create the system and process heaps */ if (!HEAP_CreateSystemHeap()) return FALSE; current_process.heap = HeapCreate( HEAP_GROWABLE, 0, 0 ); @@ -227,9 +223,6 @@ static BOOL process_init( char *argv[] ) /* Initialize the critical sections */ InitializeCriticalSection( ¤t_process.crit_section ); - /* Initialize syslevel handling */ - SYSLEVEL_Init(); - /* Parse command line arguments */ OPTIONS_ParseOptions( argv ); @@ -456,7 +449,7 @@ void PROCESS_InitWine( int argc, char *argv[] ) main_exe_name[0] = 0; CloseHandle( main_exe_file ); main_exe_file = INVALID_HANDLE_VALUE; - SYSLEVEL_EnterWin16Lock(); + _EnterWin16Lock(); found: /* allocate main thread stack */ @@ -846,7 +839,8 @@ void WINAPI ExitProcess( DWORD status ) */ void WINAPI ExitProcess16( WORD status ) { - SYSLEVEL_ReleaseWin16Lock(); + DWORD count; + ReleaseThunkLock( &count ); ExitProcess( status ); } diff --git a/scheduler/synchro.c b/scheduler/synchro.c index f5d447001e2..5718b1afa33 100644 --- a/scheduler/synchro.c +++ b/scheduler/synchro.c @@ -12,7 +12,6 @@ #include "file.h" /* for DOSFS_UnixTimeToFileTime */ #include "thread.h" #include "winerror.h" -#include "syslevel.h" #include "server.h" @@ -154,12 +153,11 @@ DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, */ DWORD WINAPI WIN16_WaitForSingleObject( HANDLE handle, DWORD timeout ) { - DWORD retval; + DWORD retval, mutex_count; - SYSLEVEL_ReleaseWin16Lock(); + ReleaseThunkLock( &mutex_count ); retval = WaitForSingleObject( handle, timeout ); - SYSLEVEL_RestoreWin16Lock(); - + RestoreThunkLock( mutex_count ); return retval; } @@ -169,12 +167,11 @@ DWORD WINAPI WIN16_WaitForSingleObject( HANDLE handle, DWORD timeout ) DWORD WINAPI WIN16_WaitForMultipleObjects( DWORD count, const HANDLE *handles, BOOL wait_all, DWORD timeout ) { - DWORD retval; + DWORD retval, mutex_count; - SYSLEVEL_ReleaseWin16Lock(); + ReleaseThunkLock( &mutex_count ); retval = WaitForMultipleObjects( count, handles, wait_all, timeout ); - SYSLEVEL_RestoreWin16Lock(); - + RestoreThunkLock( mutex_count ); return retval; } @@ -186,13 +183,11 @@ DWORD WINAPI WIN16_WaitForMultipleObjectsEx( DWORD count, BOOL wait_all, DWORD timeout, BOOL alertable ) { - DWORD retval; - - SYSLEVEL_ReleaseWin16Lock(); - retval = WaitForMultipleObjectsEx( count, handles, - wait_all, timeout, alertable ); - SYSLEVEL_RestoreWin16Lock(); + DWORD retval, mutex_count; + ReleaseThunkLock( &mutex_count ); + retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, alertable ); + RestoreThunkLock( mutex_count ); return retval; } diff --git a/scheduler/syslevel.c b/scheduler/syslevel.c index e6bb1124a10..1b544c1f35a 100644 --- a/scheduler/syslevel.c +++ b/scheduler/syslevel.c @@ -15,28 +15,11 @@ DEFAULT_DEBUG_CHANNEL(win32); -static SYSLEVEL Win16Mutex; -static SEGPTR segpWin16Mutex; +static SYSLEVEL Win16Mutex = { CRITICAL_SECTION_INIT, 1 }; /* Global variable to save current TEB while in 16-bit code */ WORD SYSLEVEL_Win16CurrentTeb = 0; -/* TEB of initial process for emergency use */ -WORD SYSLEVEL_EmergencyTeb = 0; - - -/************************************************************************ - * SYSLEVEL_Init - */ -void SYSLEVEL_Init(void) -{ - SYSLEVEL **w16Mutex = SEGPTR_ALLOC(sizeof(SYSLEVEL *)); - - *w16Mutex = &Win16Mutex; - segpWin16Mutex = SEGPTR_GET(w16Mutex); - - _CreateSysLevel( &Win16Mutex, 1 ); -} /************************************************************************ * GetpWin16Lock (KERNEL32.93) @@ -49,8 +32,15 @@ VOID WINAPI GetpWin16Lock(SYSLEVEL **lock) /************************************************************************ * GetpWin16Lock16 (KERNEL.449) */ -SEGPTR WINAPI GetpWin16Lock16(void) -{ +SEGPTR WINAPI GetpWin16Lock16(void) +{ + static SEGPTR segpWin16Mutex; + if (!segpWin16Mutex) + { + SYSLEVEL **w16Mutex = SEGPTR_ALLOC(sizeof(SYSLEVEL *)); + *w16Mutex = &Win16Mutex; + segpWin16Mutex = SEGPTR_GET(w16Mutex); + } return segpWin16Mutex; } @@ -157,20 +147,21 @@ VOID WINAPI _CheckNotSysLevel(SYSLEVEL *lock) /************************************************************************ - * SYSLEVEL_EnterWin16Lock [KERNEL.480] + * _EnterWin16Lock [KERNEL.480] */ -VOID WINAPI SYSLEVEL_EnterWin16Lock(VOID) +VOID WINAPI _EnterWin16Lock(void) { _EnterSysLevel(&Win16Mutex); } /************************************************************************ - * SYSLEVEL_LeaveWin16Lock [KERNEL.481] + * _LeaveWin16Lock [KERNEL.481] */ -VOID WINAPI SYSLEVEL_LeaveWin16Lock(VOID) +VOID WINAPI _LeaveWin16Lock(void) { _LeaveSysLevel(&Win16Mutex); } + /************************************************************************ * _ConfirmWin16Lock (KERNEL32.96) */ @@ -200,25 +191,6 @@ VOID WINAPI RestoreThunkLock(DWORD mutex_count) _EnterSysLevel(&Win16Mutex); } -/************************************************************************ - * SYSLEVEL_ReleaseWin16Lock - */ -VOID SYSLEVEL_ReleaseWin16Lock(VOID) -{ - /* entry_point is never used again once the entry point has - been called. Thus we re-use it to hold the Win16Lock count */ - - ReleaseThunkLock(&CURRENT_STACK16->entry_point); -} - -/************************************************************************ - * SYSLEVEL_RestoreWin16Lock - */ -VOID SYSLEVEL_RestoreWin16Lock(VOID) -{ - RestoreThunkLock(CURRENT_STACK16->entry_point); -} - /************************************************************************ * SYSLEVEL_CheckNotLevel */ @@ -235,4 +207,3 @@ VOID SYSLEVEL_CheckNotLevel( INT level ) break; } } - diff --git a/tools/winebuild/relay.c b/tools/winebuild/relay.c index 72efee3cac9..70eba96a50a 100644 --- a/tools/winebuild/relay.c +++ b/tools/winebuild/relay.c @@ -478,9 +478,9 @@ static void BuildCallTo16Core( FILE *outfile, int short_ret, int reg_func ) /* Enter Win16 Mutex */ if ( UsePIC ) - fprintf( outfile, "\tcall " PREFIX "SYSLEVEL_EnterWin16Lock@PLT\n" ); + fprintf( outfile, "\tcall " PREFIX "_EnterWin16Lock@PLT\n" ); else - fprintf( outfile, "\tcall " PREFIX "SYSLEVEL_EnterWin16Lock\n" ); + fprintf( outfile, "\tcall " PREFIX "_EnterWin16Lock\n" ); /* Print debugging info */ if (debugging) @@ -574,9 +574,9 @@ static void BuildCallTo16Core( FILE *outfile, int short_ret, int reg_func ) /* Leave Win16 Mutex */ if ( UsePIC ) - fprintf( outfile, "\tcall " PREFIX "SYSLEVEL_LeaveWin16Lock@PLT\n" ); + fprintf( outfile, "\tcall " PREFIX "_LeaveWin16Lock@PLT\n" ); else - fprintf( outfile, "\tcall " PREFIX "SYSLEVEL_LeaveWin16Lock\n" ); + fprintf( outfile, "\tcall " PREFIX "_LeaveWin16Lock\n" ); /* Get return value */ fprintf( outfile, "\tpopl %%eax\n" ); diff --git a/windows/queue.c b/windows/queue.c index 6cf34e50564..98e655d6c27 100644 --- a/windows/queue.c +++ b/windows/queue.c @@ -11,7 +11,6 @@ #include "winerror.h" #include "wine/winbase16.h" #include "wine/winuser16.h" -#include "syslevel.h" #include "module.h" #include "queue.h" #include "task.h" diff --git a/windows/win.c b/windows/win.c index b35f52ff732..33fff0a8b51 100644 --- a/windows/win.c +++ b/windows/win.c @@ -31,7 +31,6 @@ #include "winerror.h" #include "mdi.h" #include "local.h" -#include "syslevel.h" #include "stackframe.h" #include "debugtools.h" @@ -51,16 +50,7 @@ static WORD wDragWidth = 4; static WORD wDragHeight= 3; /* thread safeness */ -static SYSLEVEL WIN_SysLevel; - -/*********************************************************************** - * WIN_Init - */ -void WIN_Init( void ) -{ - /* Initialisation of the critical section for thread safeness */ - _CreateSysLevel( &WIN_SysLevel, 2 ); -} +static SYSLEVEL WIN_SysLevel = { CRITICAL_SECTION_INIT, 2 }; /*********************************************************************** * WIN_LockWnds diff --git a/windows/winhelp.c b/windows/winhelp.c index dfa5a273ebb..22117e20d18 100644 --- a/windows/winhelp.c +++ b/windows/winhelp.c @@ -13,7 +13,6 @@ #include "wine/winbase16.h" #include "heap.h" #include "ldt.h" -#include "syslevel.h" DEFAULT_DEBUG_CHANNEL(win); @@ -36,8 +35,10 @@ BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand, DWORD dwData ) { BOOL ret; + DWORD mutex_count; + /* We might call WinExec() */ - SYSLEVEL_ReleaseWin16Lock(); + ReleaseThunkLock( &mutex_count ); if (!(ret = WinHelpA( hWnd, lpHelpFile, wCommand, (DWORD)PTR_SEG_TO_LIN(dwData) ))) { @@ -49,7 +50,7 @@ BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand, } } - SYSLEVEL_RestoreWin16Lock(); + RestoreThunkLock( mutex_count ); return ret; }