If using the default values, also set dwType to REG_SZ as our default
[wine] / dlls / winedos / dosvm.c
1 /*
2  * DOS Virtual Machine
3  *
4  * Copyright 1998 Ove Kåven
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * Note: This code hasn't been completely cleaned up yet.
21  */
22
23 #include "config.h"
24
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <errno.h>
30 #include <fcntl.h>
31 #include <signal.h>
32 #ifdef HAVE_UNISTD_H
33 # include <unistd.h>
34 #endif
35 #ifdef HAVE_SYS_TIME_H
36 # include <sys/time.h>
37 #endif
38 #include <sys/types.h>
39
40 #include "wine/winbase16.h"
41 #include "wine/exception.h"
42 #include "windef.h"
43 #include "winbase.h"
44 #include "wingdi.h"
45 #include "winuser.h"
46 #include "wownt32.h"
47 #include "winnt.h"
48 #include "wincon.h"
49
50 #include "thread.h"
51 #include "dosexe.h"
52 #include "dosvm.h"
53 #include "wine/debug.h"
54 #include "excpt.h"
55
56 WINE_DEFAULT_DEBUG_CHANNEL(int);
57 WINE_DECLARE_DEBUG_CHANNEL(module);
58 WINE_DECLARE_DEBUG_CHANNEL(relay);
59
60 WORD DOSVM_psp = 0;
61 WORD DOSVM_retval = 0;
62
63 #ifdef HAVE_SYS_MMAN_H
64 # include <sys/mman.h>
65 #endif
66
67
68 typedef struct _DOSEVENT {
69   int irq,priority;
70   DOSRELAY relay;
71   void *data;
72   struct _DOSEVENT *next;
73 } DOSEVENT, *LPDOSEVENT;
74
75 static struct _DOSEVENT *pending_event, *current_event;
76 static HANDLE event_notifier;
77
78 static CRITICAL_SECTION qcrit;
79 static CRITICAL_SECTION_DEBUG critsect_debug =
80 {
81     0, 0, &qcrit,
82     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
83       0, 0, { 0, (DWORD)(__FILE__ ": qcrit") }
84 };
85 static CRITICAL_SECTION qcrit = { &critsect_debug, -1, 0, 0, 0, 0 };
86
87
88 /***********************************************************************
89  *              DOSVM_HasPendingEvents
90  *
91  * Return true if there are pending events that are not
92  * blocked by currently active event.
93  */
94 static BOOL DOSVM_HasPendingEvents( void )
95 {   
96     if (!pending_event)
97         return FALSE;
98
99     if (!current_event)
100         return TRUE;
101
102     if (pending_event->priority < current_event->priority)
103         return TRUE;
104
105     return FALSE;
106 }
107
108
109 /***********************************************************************
110  *              DOSVM_SendOneEvent
111  *
112  * Process single pending event.
113  *
114  * This function should be called with queue critical section locked. 
115  * The function temporarily releases the critical section if it is 
116  * possible that internal interrupt handler or user procedure will 
117  * be called. This is because we may otherwise get a deadlock if
118  * another thread is waiting for the same critical section.
119  */
120 static void DOSVM_SendOneEvent( CONTEXT86 *context )
121 {
122     LPDOSEVENT event = pending_event;
123
124     /* Remove from pending events list. */
125     pending_event = event->next;
126
127     /* Process active event. */
128     if (event->irq >= 0) 
129     {
130         BYTE intnum = (event->irq < 8) ?
131             (event->irq + 8) : (event->irq - 8 + 0x70);
132             
133         /* Event is an IRQ, move it to current events list. */
134         event->next = current_event;
135         current_event = event;
136
137         TRACE( "Dispatching IRQ %d.\n", event->irq );
138
139         if (ISV86(context))
140         {
141             /* 
142              * Note that if DOSVM_HardwareInterruptRM calls an internal 
143              * interrupt directly, current_event might be cleared 
144              * (and event freed) in this call.
145              */
146             LeaveCriticalSection(&qcrit);
147             DOSVM_HardwareInterruptRM( context, intnum );
148             EnterCriticalSection(&qcrit);
149         }
150         else
151         {
152             /*
153              * This routine only modifies current context so it is
154              * not necessary to release critical section.
155              */
156             DOSVM_HardwareInterruptPM( context, intnum );
157         }
158     } 
159     else 
160     {
161         /* Callback event. */
162         TRACE( "Dispatching callback event.\n" );
163
164         if (ISV86(context))
165         {
166             /*
167              * Call relay immediately in real mode.
168              */
169             LeaveCriticalSection(&qcrit);
170             (*event->relay)( context, event->data );
171             EnterCriticalSection(&qcrit);
172         }
173         else
174         {
175             /*
176              * Force return to relay code. We do not want to
177              * call relay directly because we may be inside a signal handler.
178              */
179             DOSVM_BuildCallFrame( context, event->relay, event->data );
180         }
181
182         free(event);
183     }
184 }
185
186
187 /***********************************************************************
188  *              DOSVM_SendQueuedEvents
189  *
190  * As long as context instruction pointer stays unmodified,
191  * process all pending events that are not blocked by currently
192  * active event.
193  *
194  * This routine assumes that caller has already cleared TEB.vm86_pending 
195  * and checked that interrupts are enabled.
196  */
197 void DOSVM_SendQueuedEvents( CONTEXT86 *context )
198 {   
199     DWORD old_cs = context->SegCs;
200     DWORD old_ip = context->Eip;
201
202     EnterCriticalSection(&qcrit);
203
204     TRACE( "Called in %s mode %s events pending (time=%ld)\n",
205            ISV86(context) ? "real" : "protected",
206            DOSVM_HasPendingEvents() ? "with" : "without",
207            GetTickCount() );
208     TRACE( "cs:ip=%04lx:%08lx, ss:sp=%04lx:%08lx\n",
209            context->SegCs, context->Eip, context->SegSs, context->Esp);
210
211     while (context->SegCs == old_cs &&
212            context->Eip == old_ip &&
213            DOSVM_HasPendingEvents())
214     {
215         DOSVM_SendOneEvent(context);
216
217         /*
218          * Event handling may have turned pending events flag on.
219          * We disable it here because this prevents some
220          * unnecessary calls to this function.
221          */
222         NtCurrentTeb()->vm86_pending = 0;
223     }
224
225 #ifdef MZ_SUPPORTED
226
227     if (DOSVM_HasPendingEvents())
228     {
229         /*
230          * Interrupts disabled, but there are still
231          * pending events, make sure that pending flag is turned on.
232          */
233         TRACE( "Another event is pending, setting VIP flag.\n" );
234         NtCurrentTeb()->vm86_pending |= VIP_MASK;
235     }
236
237 #else
238
239     FIXME("No DOS .exe file support on this platform (yet)\n");
240
241 #endif /* MZ_SUPPORTED */
242
243     LeaveCriticalSection(&qcrit);
244 }
245
246
247 #ifdef MZ_SUPPORTED
248 /***********************************************************************
249  *              QueueEvent (WINEDOS.@)
250  */
251 void WINAPI DOSVM_QueueEvent( INT irq, INT priority, DOSRELAY relay, LPVOID data)
252 {
253   LPDOSEVENT event, cur, prev;
254   BOOL       old_pending;
255
256   if (MZ_Current()) {
257     event = malloc(sizeof(DOSEVENT));
258     if (!event) {
259       ERR("out of memory allocating event entry\n");
260       return;
261     }
262     event->irq = irq; event->priority = priority;
263     event->relay = relay; event->data = data;
264
265     EnterCriticalSection(&qcrit);
266     old_pending = DOSVM_HasPendingEvents();
267
268     /* insert event into linked list, in order *after*
269      * all earlier events of higher or equal priority */
270     cur = pending_event; prev = NULL;
271     while (cur && cur->priority<=priority) {
272       prev = cur;
273       cur = cur->next;
274     }
275     event->next = cur;
276     if (prev) prev->next = event;
277     else pending_event = event;
278
279     if (!old_pending && DOSVM_HasPendingEvents()) {
280       TRACE("new event queued, signalling (time=%ld)\n", GetTickCount());
281       
282       /* Alert VM86 thread about the new event. */
283       kill(dosvm_pid,SIGUSR2);
284
285       /* Wake up DOSVM_Wait so that it can serve pending events. */
286       SetEvent(event_notifier);
287     } else {
288       TRACE("new event queued (time=%ld)\n", GetTickCount());
289     }
290
291     LeaveCriticalSection(&qcrit);
292   } else {
293     /* DOS subsystem not running */
294     /* (this probably means that we're running a win16 app
295      *  which uses DPMI to thunk down to DOS services) */
296     if (irq<0) {
297       /* callback event, perform it with dummy context */
298       CONTEXT86 context;
299       memset(&context,0,sizeof(context));
300       (*relay)(&context,data);
301     } else {
302       ERR("IRQ without DOS task: should not happen\n");
303     }
304   }
305 }
306
307 static void DOSVM_ProcessConsole(void)
308 {
309   INPUT_RECORD msg;
310   DWORD res;
311   BYTE scan, ascii;
312
313   if (ReadConsoleInputA(GetStdHandle(STD_INPUT_HANDLE),&msg,1,&res)) {
314     switch (msg.EventType) {
315     case KEY_EVENT:
316       scan = msg.Event.KeyEvent.wVirtualScanCode;
317       ascii = msg.Event.KeyEvent.uChar.AsciiChar;
318       TRACE("scan %02x, ascii %02x\n", scan, ascii);
319
320       /* set the "break" (release) flag if key released */
321       if (!msg.Event.KeyEvent.bKeyDown) scan |= 0x80;
322
323       /* check whether extended bit is set,
324        * and if so, queue the extension prefix */
325       if (msg.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY) {
326         DOSVM_Int09SendScan(0xE0,0);
327       }
328       DOSVM_Int09SendScan(scan, ascii);
329       break;
330     case MOUSE_EVENT:
331       DOSVM_Int33Console(&msg.Event.MouseEvent);
332       break;
333     case WINDOW_BUFFER_SIZE_EVENT:
334       FIXME("unhandled WINDOW_BUFFER_SIZE_EVENT.\n");
335       break;
336     case MENU_EVENT:
337       FIXME("unhandled MENU_EVENT.\n");
338       break;
339     case FOCUS_EVENT:
340       FIXME("unhandled FOCUS_EVENT.\n");
341       break;
342     default:
343       FIXME("unknown console event: %d\n", msg.EventType);
344     }
345   }
346 }
347
348 static void DOSVM_ProcessMessage(MSG *msg)
349 {
350   BYTE scan = 0;
351
352   TRACE("got message %04x, wparam=%08x, lparam=%08lx\n",msg->message,msg->wParam,msg->lParam);
353   if ((msg->message>=WM_MOUSEFIRST)&&
354       (msg->message<=WM_MOUSELAST)) {
355     DOSVM_Int33Message(msg->message,msg->wParam,msg->lParam);
356   } else {
357     switch (msg->message) {
358     case WM_KEYUP:
359       scan = 0x80;
360     case WM_KEYDOWN:
361       scan |= (msg->lParam >> 16) & 0x7f;
362
363       /* check whether extended bit is set,
364        * and if so, queue the extension prefix */
365       if (msg->lParam & 0x1000000) {
366         /* FIXME: some keys (function keys) have
367          * extended bit set even when they shouldn't,
368          * should check for them */
369         DOSVM_Int09SendScan(0xE0,0);
370       }
371       DOSVM_Int09SendScan(scan,0);
372       break;
373     }
374   }
375 }
376
377
378 /***********************************************************************
379  *              DOSVM_Wait
380  *
381  * Wait for asynchronous events. This routine temporarily enables
382  * interrupts and waits until some asynchronous event has been 
383  * processed.
384  */
385 void WINAPI DOSVM_Wait( CONTEXT86 *waitctx )
386 {
387     if (DOSVM_HasPendingEvents())
388     {
389         CONTEXT86 context = *waitctx;
390         
391         /*
392          * If DOSVM_Wait is called from protected mode we emulate
393          * interrupt reflection and convert context into real mode context.
394          * This is actually the correct thing to do as long as DOSVM_Wait
395          * is only called from those interrupt functions that DPMI reflects
396          * to real mode.
397          *
398          * FIXME: Need to think about where to place real mode stack.
399          * FIXME: If DOSVM_Wait calls are nested stack gets corrupted.
400          *        Can this really happen?
401          */
402         if (!ISV86(&context))
403         {
404             context.EFlags |= V86_FLAG;
405             context.SegSs = 0xffff;
406             context.Esp = 0;
407         }
408
409         context.EFlags |= VIF_MASK;
410         context.SegCs = 0;
411         context.Eip = 0;
412
413         DOSVM_SendQueuedEvents(&context);
414
415         if(context.SegCs || context.Eip)
416             DPMI_CallRMProc( &context, NULL, 0, TRUE );
417     }
418     else
419     {
420         HANDLE objs[2];
421         int    objc = DOSVM_IsWin16() ? 2 : 1;
422         DWORD  waitret;
423
424         objs[0] = event_notifier;
425         objs[1] = GetStdHandle(STD_INPUT_HANDLE);
426
427         waitret = MsgWaitForMultipleObjects( objc, objs, FALSE, 
428                                              INFINITE, QS_ALLINPUT );
429         
430         if (waitret == WAIT_OBJECT_0)
431         {
432             /*
433              * New pending event has been queued, we ignore it
434              * here because it will be processed on next call to
435              * DOSVM_Wait.
436              */
437         }
438         else if (objc == 2 && waitret == WAIT_OBJECT_0 + 1)
439         {
440             DOSVM_ProcessConsole();
441         }
442         else if (waitret == WAIT_OBJECT_0 + objc)
443         {
444             MSG msg;
445             while (PeekMessageA(&msg,0,0,0,PM_REMOVE|PM_NOYIELD)) 
446             {
447                 /* got a message */
448                 DOSVM_ProcessMessage(&msg);
449                 /* we don't need a TranslateMessage here */
450                 DispatchMessageA(&msg);
451             }
452         }
453         else
454         {
455             ERR_(module)( "dosvm wait error=%ld\n", GetLastError() );
456         }
457     }
458 }
459
460
461 DWORD WINAPI DOSVM_Loop( HANDLE hThread )
462 {
463   HANDLE objs[2];
464   MSG msg;
465   DWORD waitret;
466
467   objs[0] = GetStdHandle(STD_INPUT_HANDLE);
468   objs[1] = hThread;
469
470   for(;;) {
471       TRACE_(int)("waiting for action\n");
472       waitret = MsgWaitForMultipleObjects(2, objs, FALSE, INFINITE, QS_ALLINPUT);
473       if (waitret == WAIT_OBJECT_0) {
474           DOSVM_ProcessConsole();
475       }
476       else if (waitret == WAIT_OBJECT_0 + 1) {
477          DWORD rv;
478          if(!GetExitCodeThread(hThread, &rv)) {
479              ERR("Failed to get thread exit code!\n");
480              rv = 0;
481          }
482          return rv;
483       }
484       else if (waitret == WAIT_OBJECT_0 + 2) {
485           while (PeekMessageA(&msg,0,0,0,PM_REMOVE)) {
486               if (msg.hwnd) {
487                   /* it's a window message */
488                   DOSVM_ProcessMessage(&msg);
489                   DispatchMessageA(&msg);
490               } else {
491                   /* it's a thread message */
492                   switch (msg.message) {
493                   case WM_QUIT:
494                       /* stop this madness!! */
495                       return 0;
496                   case WM_USER:
497                       /* run passed procedure in this thread */
498                       /* (sort of like APC, but we signal the completion) */
499                       {
500                           DOS_SPC *spc = (DOS_SPC *)msg.lParam;
501                           TRACE_(int)("calling %p with arg %08lx\n", spc->proc, spc->arg);
502                           (spc->proc)(spc->arg);
503                           TRACE_(int)("done, signalling event %x\n", msg.wParam);
504                           SetEvent( (HANDLE)msg.wParam );
505                       }
506                       break;
507                   default:
508                       DispatchMessageA(&msg);
509                   }
510               }
511           }
512       }
513       else
514       {
515           ERR_(int)("MsgWaitForMultipleObjects returned unexpected value.\n");
516           return 0;
517       }
518   }
519 }
520
521 static WINE_EXCEPTION_FILTER(exception_handler)
522 {
523   EXCEPTION_RECORD *rec = GetExceptionInformation()->ExceptionRecord;
524   CONTEXT *context = GetExceptionInformation()->ContextRecord;
525   int arg = rec->ExceptionInformation[0];
526   BOOL ret;
527
528   switch(rec->ExceptionCode) {
529   case EXCEPTION_VM86_INTx:
530     if (TRACE_ON(relay)) {
531       DPRINTF("Call DOS int 0x%02x ret=%04lx:%04lx\n",
532               arg, context->SegCs, context->Eip );
533       DPRINTF(" eax=%08lx ebx=%08lx ecx=%08lx edx=%08lx esi=%08lx edi=%08lx\n",
534               context->Eax, context->Ebx, context->Ecx, context->Edx,
535               context->Esi, context->Edi );
536       DPRINTF(" ebp=%08lx esp=%08lx ds=%04lx es=%04lx fs=%04lx gs=%04lx flags=%08lx\n",
537               context->Ebp, context->Esp, context->SegDs, context->SegEs,
538               context->SegFs, context->SegGs, context->EFlags );
539       }
540     ret = DOSVM_EmulateInterruptRM( context, arg );
541     if (TRACE_ON(relay)) {
542       DPRINTF("Ret  DOS int 0x%02x ret=%04lx:%04lx\n",
543               arg, context->SegCs, context->Eip );
544       DPRINTF(" eax=%08lx ebx=%08lx ecx=%08lx edx=%08lx esi=%08lx edi=%08lx\n",
545               context->Eax, context->Ebx, context->Ecx, context->Edx,
546               context->Esi, context->Edi );
547       DPRINTF(" ebp=%08lx esp=%08lx ds=%04lx es=%04lx fs=%04lx gs=%04lx flags=%08lx\n",
548               context->Ebp, context->Esp, context->SegDs, context->SegEs,
549               context->SegFs, context->SegGs, context->EFlags );
550     }
551     return ret ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_EXECUTE_HANDLER;
552
553   case EXCEPTION_VM86_STI:
554   /* case EXCEPTION_VM86_PICRETURN: */
555     if (!ISV86(context))
556       ERR( "Protected mode STI caught by real mode handler!\n" );
557     DOSVM_SendQueuedEvents(context);
558     return EXCEPTION_CONTINUE_EXECUTION;
559   }
560   return EXCEPTION_CONTINUE_SEARCH;
561 }
562
563 int WINAPI DOSVM_Enter( CONTEXT86 *context )
564 {
565   if (!ISV86(context))
566       ERR( "Called with protected mode context!\n" );
567
568   __TRY
569   {
570       WOWCallback16Ex( 0, WCB16_REGS, 0, NULL, (DWORD *)context );
571       TRACE_(module)( "vm86 returned: %s\n", strerror(errno) );
572   }
573   __EXCEPT(exception_handler)
574   {
575     TRACE_(module)( "leaving vm86 mode\n" );
576   }
577   __ENDTRY
578
579   return 0;
580 }
581
582 /***********************************************************************
583  *              OutPIC (WINEDOS.@)
584  */
585 void WINAPI DOSVM_PIC_ioport_out( WORD port, BYTE val)
586 {
587     if (port != 0x20)
588     {
589         FIXME( "Unsupported PIC port %04x\n", port );
590     }
591     else if (val == 0x20 || (val >= 0x60 && val <= 0x67)) 
592     {
593         EnterCriticalSection(&qcrit);
594
595         if (!current_event)
596         {
597             WARN( "%s without active IRQ\n",
598                   val == 0x20 ? "EOI" : "Specific EOI" );
599         }
600         else if (val != 0x20 && val - 0x60 != current_event->irq)
601         {
602             WARN( "Specific EOI but current IRQ %d is not %d\n", 
603                   current_event->irq, val - 0x60 );
604         }
605         else
606         {
607             LPDOSEVENT event = current_event;
608
609             TRACE( "Received %s for current IRQ %d, clearing event\n",
610                    val == 0x20 ? "EOI" : "Specific EOI", event->irq );
611
612             current_event = event->next;
613             if (event->relay)
614                 (*event->relay)(NULL,event->data);
615             free(event);
616
617             if (DOSVM_HasPendingEvents()) 
618             {
619                 TRACE( "Another event pending, setting pending flag\n" );
620                 NtCurrentTeb()->vm86_pending |= VIP_MASK;
621             }
622         }
623
624         LeaveCriticalSection(&qcrit);
625     } 
626     else 
627     {
628         FIXME( "Unrecognized PIC command %02x\n", val );
629     }
630 }
631
632 #else /* !MZ_SUPPORTED */
633
634 /***********************************************************************
635  *              Enter (WINEDOS.@)
636  */
637 INT WINAPI DOSVM_Enter( CONTEXT86 *context )
638 {
639  ERR_(module)("DOS realmode not supported on this architecture!\n");
640  return -1;
641 }
642
643 /***********************************************************************
644  *              Wait (WINEDOS.@)
645  */
646 void WINAPI DOSVM_Wait( CONTEXT86 *waitctx ) { }
647
648 /***********************************************************************
649  *              OutPIC (WINEDOS.@)
650  */
651 void WINAPI DOSVM_PIC_ioport_out( WORD port, BYTE val) {}
652
653 /***********************************************************************
654  *              QueueEvent (WINEDOS.@)
655  */
656 void WINAPI DOSVM_QueueEvent( INT irq, INT priority, DOSRELAY relay, LPVOID data)
657 {
658   if (irq<0) {
659     /* callback event, perform it with dummy context */
660     CONTEXT86 context;
661     memset(&context,0,sizeof(context));
662     (*relay)(&context,data);
663   } else {
664     ERR("IRQ without DOS task: should not happen\n");
665   }
666 }
667
668 #endif /* MZ_SUPPORTED */
669
670
671 /**********************************************************************
672  *         DOSVM_AcknowledgeIRQ
673  *
674  * This routine should be called by all internal IRQ handlers.
675  */
676 void WINAPI DOSVM_AcknowledgeIRQ( CONTEXT86 *context )
677 {
678     /*
679      * Send EOI to PIC.
680      */
681     DOSVM_PIC_ioport_out( 0x20, 0x20 );
682
683     /*
684      * Protected mode IRQ handlers are supposed
685      * to turn VIF flag on before they return.
686      */
687     if (!ISV86(context))
688         NtCurrentTeb()->dpmi_vif = 1;
689 }
690
691
692 /**********************************************************************
693  *         DOSVM_BiosData
694  *
695  * Get pointer to BIOS data area. This is not at fixed location
696  * because those Win16 programs that do not use any real mode code have
697  * protected NULL pointer catching block at low linear memory and
698  * BIOS data has been moved to another location.
699  */
700 BIOSDATA *DOSVM_BiosData( void )
701 {
702     LDT_ENTRY entry;
703     FARPROC16 proc;
704
705     proc = GetProcAddress16( GetModuleHandle16( "KERNEL" ), 
706                              (LPCSTR)(ULONG_PTR)193 );
707     wine_ldt_get_entry( LOWORD(proc), &entry );
708     return (BIOSDATA *)wine_ldt_get_base( &entry );
709 }
710
711
712 /**********************************************************************
713  *          DllMain  (DOSVM.Init)
714  */
715 BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
716 {
717     TRACE_(module)("(%p,%ld,%p)\n", hinstDLL, fdwReason, lpvReserved);
718
719     if (fdwReason == DLL_PROCESS_ATTACH)
720     {
721         DisableThreadLibraryCalls(hinstDLL);
722         DOSVM_InitSegments();
723
724         event_notifier = CreateEventA(NULL, FALSE, FALSE, NULL);
725         if(!event_notifier)
726           ERR("Failed to create event object!\n");
727     }
728     return TRUE;
729 }