Release 980927

Sun Sep 27 14:25:38 1998  Petter Reinholdtsen <pere@td.org.uit.no>

	* [files/drive.c]
	Make sure GetDriveType32A() handles param NULL.  Added some
	doc on function.

Sun Sep 27 14:07:26 1998  Huw D M Davies <daviesh@abacus.physics.ox.ac.uk>

	* [controls/edit.c] [windows/win.c]
	Don't call SetWindowLong() in EDIT_WM_NCREATE.
	Fix SetWindowLong(GWL_[EX]STYLE) to work for 16bit windows. Remove
	UpdateWindow() call. 

Sun Sep 27 13:41:22 1998  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [scheduler/*.c] [server/event.c] [server/mutex.c]
	  [server/semaphore.c]
	Implemented server-side synchronisation objects.

Sun Sep 27 01:13:35 1998  Alex Priem <alexp@sci.kun.nl>

	* [dlls/comctl32/treeview.c] [include/treeview.h] [include/comctl.h]
	Treeview implementation.

	* [dlls/comctl32/trackbar.c] [include/trackbar.h] 
	Trackbar implementation.

Sat Sep 26 20:49:13 1998  Ulrich Weigand <weigand@informatik.uni-erlangen.de>

	* [if1632/thunk.c] [tools/build.c] [win32/kernel32.c]
	Bugfix: several problems with flat thunks fixed.

	* [memory/selector.c]
	Bugfix: IsBad...Ptr16 didn't work for limit_in_pages segments.

	* [scheduler/thread.c]
	Bugfix: CreateThread: Allow id parameter == NULL.

	* [objects/gdiobj.c]
	Bugfix: IsGDIObject: Return correct object type for stock objects.

	* [msdos/dpmi.c]
	Bugfix: fixed typo in INT_DoRealModeInt.

	* [msdos/int21.c]
	Bugfix: int21 READ *must* use WIN16_hread, not _hread16.

	* [if1632/kernel.spec] [if1632/dummy.c] [if1632/thunk.c]
	  [loader/ne/module.c] [scheduler/event.c] [scheduler/synchro.c]
	  [scheduler/thread.c] [win32/kernel32.c] [win32/ordinals.c]
	Added names/stubs for all undocumented KERNEL routines (Win95).
	Added the following undoc. 16-bit equivalents to Win32 routines:
	KERNEL.441-443,449-453,456-462,471-476,479-486,488.
	Added stubs for some other KERNEL routines.

	* [memory/heap.c] [memory/global.c] [include/global.h]
	Implemented Local32... 32-bit local heap routines (KERNEL.208-215, 229).

	* [miscemu/instr.c] [loader/module.c] [include/module.h]
	Implemented __GP fault handling and HasGPHandler (KERNEL.338).

	* [misc/error.c]
	Implemented LogParamErrorRegs (KERNEL.327).

	* [loader/task.c] [include/windows.h]
	Implemented GetCodeInfo (KERNEL.104).

	* [loader/task.c] [scheduler/thread.c] [include/thread.h]
	Implemented [GS]etThreadQueue and [GS]etFastQueue (KERNEL.463/4, 624/5).

	* [if1632/gdi.spec] [objects/dc.c] [objects/dib.c]
	  [objects/bitmap.c] [include/windows.h]
	Bugfix: fixed wrong parameter for CreateDIBSection16.
	Added [GS]etDIBColorTable16, stub for GetBoundsRect16.
	Partially implemented BITMAP_GetObject16 for DIBs.

	* [if1632/gdi.spec] [relay32/gdi32.spec] [objects/palette.c]
	Added some GDI stubs.

	* [if1632/Makefile.in] [if1632/display.spec] [if1632/mouse.spec]
	  [if1632/keyboard.spec] [if1632/builtin.c] [windows/keyboard.c]
	Added some stubs for Win16 drivers: KEYBOARD, MOUSE, DISPLAY.

	* [if1632/wprocs.spec] [msdos/vxd.c]
	Added some stubs for VxDs: VMM, ConfigMG, TimerAPI.

	* [msdos/int2f.c]
	Added some stubs for real-mode network drivers.

Sat Sep 26 18:18:18 1998  Marcus Meissner <marcus@jet.franken.de>

	* [configure.in]
	Merged in some more of the FreeBSD ports/emulators/wine patches. 
	(Maintainer(s) of this port: You can just submit these
	patches to Alexandre directly.)

	 * [loader/pe_image.c]
	Check filesize of image against size derived from header
	to spot truncated executeables without crashing.

	* [files/directory.c]
	Set envvar "COMSPEC". One win32(!!) program crashes without it.

	* [multimedia/mmio.c]
	Added mmioSetInfo32.

	* [include/file.h]
	Return STD_ERROR_HANDLE for AUX and PRT dos handles.

	* [loader/module.c]
	Handle executeables with spaces in their names a bit better in
	CreateProcess.

	* [relay32/msvfw32.spec][if1632/msvideo.spec][multimedia/msvideo.c][include/vfw.h]
	Started on MS Video support (can load Win32 ICMs).

	* [tools/testrun]
	A bit smarter use of ps.

	* [memory/virtual.c]
	Report PAGE_GUARDed pages as PAGE_PROTECTED (AutoCAD LT R17 fails
	without that check (since Win95 doesn't know about PAGE_GUARD)).

Sat Sep 26 15:04:05 1998  Ove Kaaven <ovek@arcticnet.no>

	* [include/miscemu.h] [if1632/builtin.c] [loader/task.c]
	  [miscemu/instr.c] [msdos/dpmi.c] [msdos/int21.c]
	  [msdos/interrupts.c] [windows/user.c]
	INT_[S|G]etHandler was renamed to INT_[S|G]etPMHandler.
	Added handlers to deal with real-mode interrupts; DOS
	programs are now able to hook real-mode interrupts.

	* [loader/dos/module.c] [msdos/dosmem.c] [msdos/int21.c]
	Moved real-mode interrupt table initialization to
	msdos/dosmem.c, and made new V86 tasks get a full copy
	of the existing "system memory" instead of almost empty
	space. Misc fixes.

	* [include/dosexe.h] [loader/dos/module.c] [msdos/dpmi.c]
	  [msdos/int2f.c]
	First shot at letting DOS programs start up DPMI (but DPMI
	is still disabled for DOS programs, for pkunzip's sake).

	* [include/debugger.h] [debugger/break.c] [debugger/dbg.y]
	  [debugger/registers.c] [debugger/memory.c] [debugger/info.c]
	  [loader/dos/dosvm.c]
	First shot at making Wine's debugger work for DOS programs.
	The -debug flag works, as do "nexti" and "stepi".

Sat Sep 26 13:13:13 1998  Juergen Schmied <juergen.schmied@metronet.de>

	* [dlls/shell32/dataobject.c]
	New classes IEnumFORMATETC implemented, IDataObject stubs.
	
	* [dlls/shell32/*.*][relay32/shell32.spec]
	Bugfixes.
	New: ICM_InsertItem(), ILCreateFromPath().
	Implemented: ILCloneFirst().
	Stubs: ILIsEqual(), ILFindChild(), SHLogILFromFSIL(),
	  PathMatchSpec(), PathIsExe().
	Changed: ILGetSize(), _ILIsDesktop(), PathCombine().

	* [include/shlobj.h]
	New SHLGUID's
	New structures: DVTARGETDEVICE32, STGMEDIUM32, FORMATETC32,
	CLIPFORMAT32.
	New interfaces: IEnumFORMATETC, IDataObject, ICommDlgBrowser
	IDockingWindowFrame, IServiceProvider.

	* [dlls/shell32/folders.c]
	Stubs for IShellLink.

	* [loader/resource.c]
	Small fixes.

	* [misc/crtdll.c][relay32/crtdll.spec]
	New __dllonexit().

	* [windows/message.c]
	SendNotifyMessageA, SendMessageCallBack32A half implemented.

	* [controls/edit.c]
	EDIT_WM_SetText set EF_UPDATE flag not for ES_MULTILINE.

	* [files/file.c]
	Handling of fileposition fixed.

Fri Sep 25 18:13:30 1998  Patrik Stridvall <ps@leissner.se>

	* [include/windows.h] [include/wintypes.h]
	  [ole/ole2nls.h] [relay32/kernel32.spec]
	Implemented EnumDateFormats and EnumTimeFormats.
	Only adds US English support.

	* [Makefile.in] [configure.in] 
	  [dlls/Makefile.in] [dlls/psapi/Makefile.in] 
	  [dlls/psapi/psapi_main.c] 
	New files to implement stubs for PSAPI.DLL (NT only).

	* [relay32/Makefile.in] [relay32/builtin32.c] 
	  [relay32/psapi.spec]
	New spec file for PSAPI.DLL (NT only).

	* [scheduler/handle.c]
	HANDLE_GetObjPtr should only interpret the pseudo handles as the
	current thread or the current process if a thread or a process is
	requested.

	* [include/winversion.h] [misc/version.c]
	Adds the global function VERSION_GetVersion() so functions can
	have different behavior depending on the -winver flag.

	* [include/oledlg.h] [ole/oledlg.c]
	Minor fixes. 

	* [windows/winproc.c]
	Minor changes.

	* [include/imm.h] [misc/imm.c]
	Now returns correct values under both Windows 95 and NT 4.0.

Thu Sep 24 22:11:44 1998  Kristian Nielsen  <kristian.nielsen@risoe.dk>

	* [configure.in] [include/acconfig.h] [include/thread.h]
	  [scheduler/sysdeps.c]
	Autoconfig test for non-reentrant libc.

Wed Sep 23 19:52:12 1998  Matthew Becker <mbecker@glasscity.net>

	* [*/*.c]
	Miscellaneous documentation updates and debugging output 
	standardizations.

	* [objects/clipping.c]
	Added ExtSelectClipRgn.

Wed Sep 23 00:03:28 EDT 1998  Pete Ratzlaff <pratzlaff@cfa.harvard.edu>

	* [include/windows.h] [if1632/user.spec] [relay32/user32.spec]
	  [windows/keyboard.c]
	Added, marginally implemented, GetKeyboardLayoutName().
	Only returns US English keyboard name.

Tue Sep 22 16:32:41 1998  Marcel Baur <mbaur@iiic.ethz.ch>

	* [programs/control/*]
	New Winelib application.

Mon Sep 21 00:29:18 1998  Peter Hunnisett <hunnise@nortel.ca>

	* [include/dplay.h][multimedia/dplay.c][ole/compobj.c]
	Added all DirectPlayLobby interfaces and enhanced DirectPlay
	and DirectPlayLobby support. Still not all that much. Useful
	enough if you just need to start a program, don't try any
	real dplay/lobby stuff.

	* [documentation/status/directplay]
	Added a very little bit.

	* [graphics/ddraw.c]
	- Call to SetWindowLong32A wasn't working because there was no
	  memory set aside when the window class was registered.
	- Fixed some xlib reference counting and change the behaviour
	  of DirectDrawSurface3_SetPalette to mimic observed behaviour
	  (palette is associated will all backbuffers)
	- Also stored all palette colour fields and spit back our saved
	  colour fields rather than query X for them.
	- Added plenty of AddRef and Release traces.
	- Added Xlib support for using -desktop option.
	- Fixed Xlib message handling. Messages weren't being passed to
	  the application. Fixes mouse movements in some xlib DDraw games.
	- Added a few stubs.

	* [windows/win.c][include/winerror.h]
	Fixed up some error handling in WIN_SetWindowLong. SetLastError
	wasn't being used. Could cause problems with 0 return codes.
	Added new error in winerror (1400).

	* [AUTHORS] [include/authors.h]
	Added myself as a Wine author.

Sun Sep 20 21:22:44 1998  Alexander Larsson  <alla@lysator.liu.se>

	* [loader/module.c]
	Changed GetModuleFileName32A so that is returns the
	long version of the filename. Note that just the name
	is long, not the directories.

Sat Sep 19 20:05:30 1998 Per Ångström <pang@mind.nu> 

	* [controls/menu.c]
	Made a couple of fixes to make life easier for applications that alter
	their menus at runtime.

	* [windows/defdlg.c]
	Removed the cast of the return value from dialog procedures to a 16-bit
	bool. The return value needs to retain all its 32 bits, since it is not 
	always a bool, such as when responding to the WM_NCHITTEST message.

Fri Sep 18 11:30:38 1998  Sergey Turchanov <turchanov@usa.net>

	* [loader/resource.c]
	Fixed very funny bug (though gravely affecting further excecution)
	with FindResource[Ex]32 functions.

	* [include/multimon.h] [windows/multimon.c] [relay32/user32.spec]
	  [include/windows.h] [windows/sysmetrics.c]
	Default implementation for Multimonitor API.

	* [include/windows.h] [windows/winpos.c]
	Fixed incorrect declaration (and behaviour) of GetWindowRect32.

Wed Sep 16 10:21:15 1998  Gerard Patel <G.Patel@Wanadoo.fr>

	* [controls/edit.c]
	Fixed EDIT_EM_GetLine to use correctly length of lines.

Tue Sep 15 20:40:16 1998  Eric Kohl <ekohl@abo.rhein-zeitung.de>

	* [misc/tweak.c][include/tweak.h][controls/menu.c]
	Replaced the tweak graphic routines by calls to DrawEdge32().

	* [misc/tweak.c][include/tweak.h][documentation/win95look]
	  [wine.ini][*/*]
	Changed "look and feel" selection. Allows Win3.1, Win95 and
	Win98 (no GUI code implemented) look and feel.

	* [dlls/comctl32/header.c][include/header.h][include/commctrl.h]
	Started callback item support and did some minor improvements.

	* [dlls/comctl32/imagelist.c]
	Fixed bug in transparent image display.
	ImageList_GetIcon is still buggy :-(

	* [dlls/comctl32/toolbar.c]
	Fixed button drawing (partial hack).

	* [dlls/comctl32/commctrl.c]
	Fixed MenuHelp().

	* [controls/button.c]
	Added 3d effect for groupbox.

	* [windows/msgbox.c]
	Added font support for message boxes.

	* [windows/nonclient.c]
	Fixed window moving bug.

	* [dlls/comctl32/*.c]
	Various improvements.

	* [dlls/comctl32/listview.c][dlls/comctl32/rebar.c]
	  [include/commctrl.h]
	More messages.

	* [windows/syscolor.c][include/windows.h]
	Introduced new Win98 system colors.

Tue Sep 15 18:29:45 1998 Wesley Filardo <eightknots@aol.com>

	* [files/profile.c]
	Added support in PROFILE_LoadWineIni for -config option

	* [misc/main.c] [include/options.h]
	Added -config option.

Tue Sep 15 18:22:26 1998  Petter Reinholdtsen <pere@td.org.uit.no>

	* [documentation/Makefile.in]
	Make sure directory exists before installing into it.

Tue Sep 15 01:47:33 1998  Pablo Saratxaga <pablo.sarachaga@ping.be>

	* [ole/nls/*] [ole/ole2nls.c] [include/winnls.h]
	Fixed a few errors and completed some NLS files.

Mon Sep 14 01:23:45 1998  Joseph Pranevich <knight@baltimore.wwaves.com>

	* [include/miscemu.h] [msdos/interrupts.c]
	Removed a compilation warning, added INT 25 to the list of interrupts
	callable from DOS applications, added a debug message when unsupported
	interrupts are used.

Sun Sep 13 19:55:22 1998  Lawson Whitney <lawson_whitney@juno.com>

	* [if1632/relay.c]
	CallProcEx32W should not reverse arguments.

Sun Aug 17 21:18:12 1998  Eric Pouech  <eric.pouech@lemel.fr>

	* [multimedia/midi.c] [multimedia/init.c] [multimedia/mmsys.c] 
	  [include/multimedia.h] [include/mmsystem.h] 
	  [multimedia/Makefile.in] [multimedia/midipatch.c]
	  [if1632/multimedia.spec]
	Made MIDI input and output functional on OSS capable systems.

	* [multimedia/timer.c]
	Changes to trigger callbacks at the accurate pace even when
	fake timers are used.
diff --git a/scheduler/client.c b/scheduler/client.c
index e39d82d..1e7aa44 100644
--- a/scheduler/client.c
+++ b/scheduler/client.c
@@ -15,8 +15,8 @@
 
 #include "process.h"
 #include "thread.h"
-#include "server.h"
 #include "server/request.h"
+#include "server.h"
 #include "winerror.h"
 
 /* Some versions of glibc don't define this */
@@ -24,14 +24,11 @@
 #define SCM_RIGHTS 1
 #endif
 
-#define CHECK_LEN(len,wanted) \
-  if ((len) == (wanted)) ; \
-  else CLIENT_ProtocolError( __FUNCTION__ ": len %d != %d\n", (len), (wanted) );
 
 /***********************************************************************
  *           CLIENT_ProtocolError
  */
-static void CLIENT_ProtocolError( const char *err, ... )
+void CLIENT_ProtocolError( const char *err, ... )
 {
     THDB *thdb = THREAD_Current();
     va_list args;
@@ -96,8 +93,8 @@
  *
  * Send a request to the server.
  */
-static void CLIENT_SendRequest( enum request req, int pass_fd,
-                                int n, ... /* arg_1, len_1, etc. */ )
+void CLIENT_SendRequest( enum request req, int pass_fd,
+                         int n, ... /* arg_1, len_1, etc. */ )
 {
     struct iovec vec[16];
     va_list args;
@@ -198,8 +195,8 @@
  *
  * Wait for a reply from the server.
  */
-static unsigned int CLIENT_WaitReply( int *len, int *passed_fd,
-                                      int n, ... /* arg_1, len_1, etc. */ )
+unsigned int CLIENT_WaitReply( int *len, int *passed_fd,
+                               int n, ... /* arg_1, len_1, etc. */ )
 {
     struct iovec vec[16];
     va_list args;
@@ -454,4 +451,3 @@
     CHECK_LEN( len, sizeof(reply) );
     return reply.signaled;
 }
-
diff --git a/scheduler/event.c b/scheduler/event.c
index 1ca9d16..650bf6e 100644
--- a/scheduler/event.c
+++ b/scheduler/event.c
@@ -11,6 +11,9 @@
 #include "process.h"
 #include "thread.h"
 #include "heap.h"
+#include "syslevel.h"
+#include "server/request.h"
+#include "server.h"
 
 typedef struct
 {
@@ -83,12 +86,24 @@
 HANDLE32 WINAPI CreateEvent32A( SECURITY_ATTRIBUTES *sa, BOOL32 manual_reset,
                                 BOOL32 initial_state, LPCSTR name )
 {
+    struct create_event_request req;
+    struct create_event_reply reply;
+    int len = name ? strlen(name) + 1 : 0;
     HANDLE32 handle;
     EVENT *event;
 
+    req.manual_reset = manual_reset;
+    req.initial_state = initial_state;
+    req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
+
+    CLIENT_SendRequest( REQ_CREATE_EVENT, -1, 2, &req, sizeof(req), name, len );
+    CLIENT_WaitReply( &len, NULL, 1, &reply, sizeof(reply) );
+    CHECK_LEN( len, sizeof(reply) );
+    if (reply.handle == -1) return NULL;
+
     SYSTEM_LOCK();
-    event = (EVENT *)K32OBJ_Create( K32OBJ_EVENT, sizeof(*event),
-                                    name, EVENT_ALL_ACCESS, sa, &handle );
+    event = (EVENT *)K32OBJ_Create( K32OBJ_EVENT, sizeof(*event), name,
+                                    reply.handle, EVENT_ALL_ACCESS, sa, &handle );
     if (event)
     {
         /* Finish initializing it */
@@ -114,6 +129,14 @@
     return ret;
 }
 
+/***********************************************************************
+ *           WIN16_CreateEvent    (KERNEL.457)
+ */
+HANDLE32 WINAPI WIN16_CreateEvent( BOOL32 manual_reset, BOOL32 initial_state )
+{
+    return CreateEvent32A( NULL, manual_reset, initial_state, NULL );
+}
+
 
 /***********************************************************************
  *           OpenEvent32A    (KERNEL32.536)
@@ -150,14 +173,23 @@
  */
 BOOL32 WINAPI PulseEvent( HANDLE32 handle )
 {
+    struct event_op_request req;
     EVENT *event;
     SYSTEM_LOCK();
     if (!(event = (EVENT *)HANDLE_GetObjPtr(PROCESS_Current(), handle,
-                                            K32OBJ_EVENT, EVENT_MODIFY_STATE, NULL)))
+                                            K32OBJ_EVENT, EVENT_MODIFY_STATE,
+                                            &req.handle )))
     {
         SYSTEM_UNLOCK();
         return FALSE;
     }
+    if (req.handle != -1)
+    {
+        SYSTEM_UNLOCK();
+        req.op = PULSE_EVENT;
+        CLIENT_SendRequest( REQ_EVENT_OP, -1, 1, &req, sizeof(req) );
+        return !CLIENT_WaitReply( NULL, NULL, 0 );
+    }
     event->signaled = TRUE;
     SYNC_WakeUp( &event->wait_queue, event->manual_reset ? INFINITE32 : 1 );
     event->signaled = FALSE;
@@ -172,14 +204,23 @@
  */
 BOOL32 WINAPI SetEvent( HANDLE32 handle )
 {
+    struct event_op_request req;
     EVENT *event;
     SYSTEM_LOCK();
     if (!(event = (EVENT *)HANDLE_GetObjPtr(PROCESS_Current(), handle,
-                                            K32OBJ_EVENT, EVENT_MODIFY_STATE, NULL)))
+                                            K32OBJ_EVENT, EVENT_MODIFY_STATE,
+                                            &req.handle )))
     {
         SYSTEM_UNLOCK();
         return FALSE;
     }
+    if (req.handle != -1)
+    {
+        SYSTEM_UNLOCK();
+        req.op = SET_EVENT;
+        CLIENT_SendRequest( REQ_EVENT_OP, -1, 1, &req, sizeof(req) );
+        return !CLIENT_WaitReply( NULL, NULL, 0 );
+    }
     event->signaled = TRUE;
     SYNC_WakeUp( &event->wait_queue, event->manual_reset ? INFINITE32 : 1 );
     K32OBJ_DecCount( &event->header );
@@ -193,14 +234,23 @@
  */
 BOOL32 WINAPI ResetEvent( HANDLE32 handle )
 {
+    struct event_op_request req;
     EVENT *event;
     SYSTEM_LOCK();
     if (!(event = (EVENT *)HANDLE_GetObjPtr(PROCESS_Current(), handle,
-                                            K32OBJ_EVENT, EVENT_MODIFY_STATE, NULL)))
+                                            K32OBJ_EVENT, EVENT_MODIFY_STATE,
+                                            &req.handle )))
     {
         SYSTEM_UNLOCK();
         return FALSE;
     }
+    if (req.handle != -1)
+    {
+        SYSTEM_UNLOCK();
+        req.op = RESET_EVENT;
+        CLIENT_SendRequest( REQ_EVENT_OP, -1, 1, &req, sizeof(req) );
+        return !CLIENT_WaitReply( NULL, NULL, 0 );
+    }
     event->signaled = FALSE;
     K32OBJ_DecCount( &event->header );
     SYSTEM_UNLOCK();
@@ -272,3 +322,48 @@
     obj->type = K32OBJ_UNKNOWN;
     HeapFree( SystemHeap, 0, 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)
+ */
+HANDLE32 WINAPI VWin32_EventCreate(VOID)
+{
+    return CreateEvent32A( NULL, FALSE, 0, NULL );
+}
+
+/***********************************************************************
+ *       VWin32_EventDestroy	(KERNEL.443)
+ */
+VOID WINAPI VWin32_EventDestroy(HANDLE32 event)
+{
+    CloseHandle( event );
+}
+
+/***********************************************************************
+ *       VWin32_EventWait	(KERNEL.450) 
+ */
+VOID WINAPI VWin32_EventWait(HANDLE32 event)
+{
+    SYSLEVEL_ReleaseWin16Lock();
+    WaitForSingleObject( event, INFINITE32 );
+    SYSLEVEL_RestoreWin16Lock();
+}
+
+/***********************************************************************
+ *       VWin32_EventSet	(KERNEL.451)
+ */
+VOID WINAPI VWin32_EventSet(HANDLE32 event)
+{
+    SetEvent( event );
+}
+
diff --git a/scheduler/handle.c b/scheduler/handle.c
index 0f5bdc0..3dfd03a 100644
--- a/scheduler/handle.c
+++ b/scheduler/handle.c
@@ -163,23 +163,23 @@
                      handle, entry->access, access );
         ptr = entry->ptr;
         if (server_handle) *server_handle = entry->server;
-        if (ptr && ((type == K32OBJ_UNKNOWN) || (ptr->type == type)))
-            K32OBJ_IncCount( ptr );
-        else
-            ptr = NULL;
     }
     else if (handle == CURRENT_THREAD_PSEUDOHANDLE)
     {
        ptr = (K32OBJ *)THREAD_Current();
        if (server_handle) *server_handle = CURRENT_THREAD_PSEUDOHANDLE;
-       K32OBJ_IncCount( ptr );
     }
     else if (handle == CURRENT_PROCESS_PSEUDOHANDLE)
     {
        ptr = (K32OBJ *)PROCESS_Current();
        if (server_handle) *server_handle = CURRENT_PROCESS_PSEUDOHANDLE;
-       K32OBJ_IncCount( ptr );
     }
+
+    if (ptr && ((type == K32OBJ_UNKNOWN) || (ptr->type == type)))
+        K32OBJ_IncCount( ptr );
+    else
+        ptr = NULL;
+
     SYSTEM_UNLOCK();
     if (!ptr) SetLastError( ERROR_INVALID_HANDLE );
     return ptr;
diff --git a/scheduler/k32obj.c b/scheduler/k32obj.c
index aebca61..7eaab60 100644
--- a/scheduler/k32obj.c
+++ b/scheduler/k32obj.c
@@ -164,7 +164,7 @@
  * Returns NULL if there was an error _or_ if the object already existed.
  * The refcount of the object must be decremented once it is initialized.
  */
-K32OBJ *K32OBJ_Create( K32OBJ_TYPE type, DWORD size, LPCSTR name,
+K32OBJ *K32OBJ_Create( K32OBJ_TYPE type, DWORD size, LPCSTR name, int server_handle,
                        DWORD access, SECURITY_ATTRIBUTES *sa, HANDLE32 *handle)
 {
     BOOL32 inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
@@ -177,12 +177,13 @@
         if (obj->type == type)
         {
             SetLastError( ERROR_ALREADY_EXISTS );
-            *handle = HANDLE_Alloc( PROCESS_Current(), obj, access, inherit, -1 );
+            *handle = HANDLE_Alloc( PROCESS_Current(), obj, access, inherit, server_handle );
         }
         else
         {
             SetLastError( ERROR_DUP_NAME );
             *handle = INVALID_HANDLE_VALUE32;
+            if (server_handle != -1) CLIENT_CloseHandle( server_handle );
         }
         K32OBJ_DecCount( obj );
         return NULL;
@@ -195,6 +196,7 @@
     {
         SYSTEM_UNLOCK();
         *handle = INVALID_HANDLE_VALUE32;
+        if (server_handle != -1) CLIENT_CloseHandle( server_handle );
         return NULL;
     }
     obj->type     = type;
@@ -209,12 +211,13 @@
         HeapFree( SystemHeap, 0, obj );
         SYSTEM_UNLOCK();
         *handle = INVALID_HANDLE_VALUE32;
+        if (server_handle != -1) CLIENT_CloseHandle( server_handle );
         return NULL;
     }
 
     /* Allocate a handle */
 
-    *handle = HANDLE_Alloc( PROCESS_Current(), obj, access, inherit, -1 );
+    *handle = HANDLE_Alloc( PROCESS_Current(), obj, access, inherit, server_handle );
     SYSTEM_UNLOCK();
     return obj;
 }
diff --git a/scheduler/mutex.c b/scheduler/mutex.c
index 084fae0..4a32e15 100644
--- a/scheduler/mutex.c
+++ b/scheduler/mutex.c
@@ -11,6 +11,8 @@
 #include "process.h"
 #include "thread.h"
 #include "heap.h"
+#include "server/request.h"
+#include "server.h"
 
 typedef struct _MUTEX
 {
@@ -81,12 +83,24 @@
 HANDLE32 WINAPI CreateMutex32A( SECURITY_ATTRIBUTES *sa, BOOL32 owner,
                                 LPCSTR name )
 {
+    struct create_mutex_request req;
+    struct create_mutex_reply reply;
+    int len = name ? strlen(name) + 1 : 0;
     HANDLE32 handle;
     MUTEX *mutex;
 
+    req.owned   = owner;
+    req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
+
+    CLIENT_SendRequest( REQ_CREATE_MUTEX, -1, 2, &req, sizeof(req), name, len );
+    CLIENT_WaitReply( &len, NULL, 1, &reply, sizeof(reply) );
+    CHECK_LEN( len, sizeof(reply) );
+    if (reply.handle == -1) return NULL;
+
     SYSTEM_LOCK();
     mutex = (MUTEX *)K32OBJ_Create( K32OBJ_MUTEX, sizeof(*mutex),
-                                    name, MUTEX_ALL_ACCESS, sa, &handle );
+                                    name, reply.handle, MUTEX_ALL_ACCESS,
+                                    sa, &handle );
     if (mutex)
     {
         /* Finish initializing it */
@@ -165,14 +179,22 @@
  */
 BOOL32 WINAPI ReleaseMutex( HANDLE32 handle )
 {
+    struct release_mutex_request req;
     MUTEX *mutex;
     SYSTEM_LOCK();
     if (!(mutex = (MUTEX *)HANDLE_GetObjPtr(PROCESS_Current(), handle,
-                                            K32OBJ_MUTEX, MUTEX_MODIFY_STATE, NULL)))
+                                            K32OBJ_MUTEX, MUTEX_MODIFY_STATE,
+                                            &req.handle )))
     {
         SYSTEM_UNLOCK();
         return FALSE;
     }
+    if (req.handle != -1)
+    {
+        SYSTEM_UNLOCK();
+        CLIENT_SendRequest( REQ_RELEASE_MUTEX, -1, 1, &req, sizeof(req) );
+        return !CLIENT_WaitReply( NULL, NULL, 0 );
+    }
     if (!mutex->count || (mutex->owner != GetCurrentThreadId()))
     {
         SYSTEM_UNLOCK();
diff --git a/scheduler/process.c b/scheduler/process.c
index adaf782..4ffcd1f 100644
--- a/scheduler/process.c
+++ b/scheduler/process.c
@@ -649,12 +649,24 @@
 }
 
 /***********************************************************************
- *           SetProcessWorkingSetSize    (KERNEL32)
+ *		SetProcessWorkingSetSize	[KERNEL32.662]
+ * Sets the min/max working set sizes for a specified process.
+ *
+ * PARAMS
+ *    hProcess [I] Handle to the process of interest
+ *    minset   [I] Specifies minimum working set size
+ *    maxset   [I] Specifies maximum working set size
+ *
+ * RETURNS  STD
  */
 BOOL32 WINAPI SetProcessWorkingSetSize(HANDLE32 hProcess,DWORD minset,
                                        DWORD maxset)
 {
-    FIXME(process,"(0x%08x,%ld,%ld): stub\n",hProcess,minset,maxset);
+    FIXME(process,"(0x%08x,%ld,%ld): stub - harmless\n",hProcess,minset,maxset);
+    if(( minset == -1) && (maxset == -1)) {
+        /* Trim the working set to zero */
+        /* Swap the process out of physical RAM */
+    }
     return TRUE;
 }
 
diff --git a/scheduler/semaphore.c b/scheduler/semaphore.c
index 626150e..7c71a10 100644
--- a/scheduler/semaphore.c
+++ b/scheduler/semaphore.c
@@ -11,6 +11,8 @@
 #include "process.h"
 #include "thread.h"
 #include "heap.h"
+#include "server/request.h"
+#include "server.h"
 
 typedef struct
 {
@@ -44,6 +46,9 @@
 HANDLE32 WINAPI CreateSemaphore32A( SECURITY_ATTRIBUTES *sa, LONG initial,
                                     LONG max, LPCSTR name )
 {
+    struct create_semaphore_request req;
+    struct create_semaphore_reply reply;
+    int len = name ? strlen(name) + 1 : 0;
     HANDLE32 handle;
     SEMAPHORE *sem;
 
@@ -55,9 +60,19 @@
         return INVALID_HANDLE_VALUE32;
     }
 
+    req.initial = (unsigned int)initial;
+    req.max     = (unsigned int)max;
+    req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
+
+    CLIENT_SendRequest( REQ_CREATE_SEMAPHORE, -1, 2, &req, sizeof(req), name, len );
+    CLIENT_WaitReply( &len, NULL, 1, &reply, sizeof(reply) );
+    CHECK_LEN( len, sizeof(reply) );
+    if (reply.handle == -1) return NULL;
+
     SYSTEM_LOCK();
     sem = (SEMAPHORE *)K32OBJ_Create( K32OBJ_SEMAPHORE, sizeof(*sem),
-                                      name, SEMAPHORE_ALL_ACCESS, sa, &handle);
+                                      name, reply.handle, SEMAPHORE_ALL_ACCESS,
+                                      sa, &handle);
     if (sem)
     {
         /* Finish initializing it */
@@ -119,16 +134,35 @@
  */
 BOOL32 WINAPI ReleaseSemaphore( HANDLE32 handle, LONG count, LONG *previous )
 {
+    struct release_semaphore_request req;
     SEMAPHORE *sem;
 
+    if (count < 0)
+    {
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return FALSE;
+    }
     SYSTEM_LOCK();
     if (!(sem = (SEMAPHORE *)HANDLE_GetObjPtr( PROCESS_Current(), handle,
                                                K32OBJ_SEMAPHORE,
-                                               SEMAPHORE_MODIFY_STATE, NULL )))
+                                               SEMAPHORE_MODIFY_STATE, &req.handle )))
     {
         SYSTEM_UNLOCK();
         return FALSE;
     }
+    if (req.handle != -1)
+    {
+        struct release_semaphore_reply reply;
+        int len;
+
+        SYSTEM_UNLOCK();
+        req.count = (unsigned int)count;
+        CLIENT_SendRequest( REQ_RELEASE_SEMAPHORE, -1, 1, &req, sizeof(req) );
+        if (CLIENT_WaitReply( &len, NULL, 1, &reply, sizeof(reply) )) return FALSE;
+        CHECK_LEN( len, sizeof(reply) );
+        if (previous) *previous = reply.prev_count;
+        return TRUE;
+    }
     if (previous) *previous = sem->count;
     if (sem->count + count > sem->max)
     {
diff --git a/scheduler/synchro.c b/scheduler/synchro.c
index 4ed9a25..f7ba381 100644
--- a/scheduler/synchro.c
+++ b/scheduler/synchro.c
@@ -13,6 +13,7 @@
 #include "process.h"
 #include "thread.h"
 #include "winerror.h"
+#include "syslevel.h"
 #include "server.h"
 #include "debug.h"
 
@@ -398,3 +399,34 @@
 {
     return SYNC_DoWait( count, handles, wait_all, timeout, alertable, FALSE );
 }
+
+
+/***********************************************************************
+ *           WIN16_WaitForSingleObject   (KERNEL.460)
+ */
+DWORD WINAPI WIN16_WaitForSingleObject( HANDLE32 handle, DWORD timeout )
+{
+    DWORD retval;
+
+    SYSLEVEL_ReleaseWin16Lock();
+    retval = WaitForSingleObject( handle, timeout );
+    SYSLEVEL_RestoreWin16Lock();
+
+    return retval;
+}
+
+/***********************************************************************
+ *           WIN16_WaitForMultipleObjects   (KERNEL.461)
+ */
+DWORD WINAPI WIN16_WaitForMultipleObjects( DWORD count, const HANDLE32 *handles,
+                                           BOOL32 wait_all, DWORD timeout )
+{
+    DWORD retval;
+
+    SYSLEVEL_ReleaseWin16Lock();
+    retval = WaitForMultipleObjects( count, handles, wait_all, timeout );
+    SYSLEVEL_RestoreWin16Lock();
+
+    return retval;
+}
+
diff --git a/scheduler/sysdeps.c b/scheduler/sysdeps.c
index 9ec3b7a..f883f12 100644
--- a/scheduler/sysdeps.c
+++ b/scheduler/sysdeps.c
@@ -22,7 +22,7 @@
 /* Xlib critical section (FIXME: does not belong here) */
 CRITICAL_SECTION X11DRV_CritSection = { 0, };
 
-#ifdef __linux__
+#ifdef HAVE_CLONE_SYSCALL
 # ifdef HAVE_SCHED_H
 #  include <sched.h>
 # endif
@@ -35,10 +35,10 @@
 /* If we didn't get the flags, we probably didn't get the prototype either */
 extern int clone( int (*fn)(void *arg), void *stack, int flags, void *arg );
 # endif  /* CLONE_VM */
-#endif  /* __linux__ */
+#endif  /* HAVE_CLONE_SYSCALL */
 
 
-#ifdef __linux__
+#ifdef USE_THREADS
 /***********************************************************************
  *           __errno_location
  *
@@ -84,7 +84,7 @@
     SET_FS( thdb->teb_sel );
     THREAD_Start( thdb );
 }
-#endif  /* __linux__ */
+#endif  /* USE_THREADS */
 
 
 /***********************************************************************
@@ -95,15 +95,23 @@
  */
 int SYSDEPS_SpawnThread( THDB *thread )
 {
-#ifdef __linux__
+#ifdef USE_THREADS
+
+#ifdef HAVE_CLONE_SYSCALL
     if (clone( (int (*)(void *))SYSDEPS_StartThread, thread->teb.stack_top,
                CLONE_VM | CLONE_FS | CLONE_FILES | SIGCHLD, thread ) < 0)
         return -1;
     /* FIXME: close the child socket in the parent process */
 /*    close( thread->socket );*/
-#else
+#endif
+
+#ifdef HAVE_RFORK
+    FIXME(thread, "Threads using rfork() not implemented\n" );
+#endif
+
+#else  /* !USE_THREADS */
     FIXME(thread, "CreateThread: stub\n" );
-#endif  /* __linux__ */
+#endif  /* USE_THREADS */
     return 0;
 }
 
diff --git a/scheduler/thread.c b/scheduler/thread.c
index b836b9c..3a0ff97 100644
--- a/scheduler/thread.c
+++ b/scheduler/thread.c
@@ -83,6 +83,33 @@
     }
 }
 
+/***********************************************************************
+ *           THREAD_IdToTHDB
+ *
+ * Convert a thread id to a THDB, making sure it is valid.
+ */
+THDB *THREAD_IdToTHDB( DWORD id )
+{
+    THDB *thdb;
+
+    if (!id) return THREAD_Current();
+    thdb = THREAD_ID_TO_THDB( id );
+    if (!K32OBJ_IsValid( &thdb->header, K32OBJ_THREAD ))
+    {
+        /* Allow task handles to be used; convert to main thread */
+        if ( IsTask( id ) )
+        {
+            TDB *pTask = (TDB *)GlobalLock16( id );
+            if (pTask) return pTask->thdb;
+        }
+        
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return NULL;
+    }
+    return thdb;
+}
+
+
 
 /***********************************************************************
  *           THREAD_AddQueue
@@ -361,7 +388,7 @@
                            THREAD_ALL_ACCESS, inherit, server_handle );
     if (handle == INVALID_HANDLE_VALUE32) goto error;
     if (SYSDEPS_SpawnThread( thread ) == -1) goto error;
-    *id = THDB_TO_THREAD_ID( thread );
+    if (id) *id = THDB_TO_THREAD_ID( thread );
     return handle;
 
 error:
@@ -882,3 +909,19 @@
     return ret;
 }
 
+/**********************************************************************
+ * VWin32_BoostThreadGroup [KERNEL.535]
+ */
+VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT32 boost )
+{
+    FIXME(thread, "(0x%08lx,%d): stub\n", threadId, boost);
+}
+
+/**********************************************************************
+ * VWin32_BoostThreadStatic [KERNEL.536]
+ */
+VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT32 boost )
+{
+    FIXME(thread, "(0x%08lx,%d): stub\n", threadId, boost);
+}
+