exception.c 19.9 KB
Newer Older
1 2
/*
 * NT exception handling routines
3
 *
4 5
 * Copyright 1999 Turchanov Sergey
 * Copyright 1999 Alexandre Julliard
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21
 */

22
#include "config.h"
23
#include "wine/port.h"
24

25
#include <assert.h>
26
#include <errno.h>
27
#include <signal.h>
28
#include <stdarg.h>
29

30
#include "ntstatus.h"
31
#define WIN32_NO_STATUS
32
#include "windef.h"
33
#include "winternl.h"
34
#include "wine/exception.h"
35
#include "wine/server.h"
36
#include "wine/list.h"
37
#include "wine/debug.h"
38
#include "excpt.h"
39
#include "ntdll_misc.h"
40

41
WINE_DEFAULT_DEBUG_CHANNEL(seh);
42 43 44 45

/* Exception record for handling exceptions happening inside exception handlers */
typedef struct
{
46 47
    EXCEPTION_REGISTRATION_RECORD frame;
    EXCEPTION_REGISTRATION_RECORD *prevFrame;
48 49
} EXC_NESTED_FRAME;

50 51 52 53 54 55 56 57
typedef struct
{
    struct list                 entry;
    PVECTORED_EXCEPTION_HANDLER func;
} VECTORED_HANDLER;

static struct list vectored_handlers = LIST_INIT(vectored_handlers);

58 59
static RTL_CRITICAL_SECTION vectored_handlers_section;
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
60 61 62
{
    0, 0, &vectored_handlers_section,
    { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
63
      0, 0, { (DWORD_PTR)(__FILE__ ": vectored_handlers_section") }
64
};
65
static RTL_CRITICAL_SECTION vectored_handlers_section = { &critsect_debug, -1, 0, 0, 0, 0 };
66

67 68
#ifdef __i386__
# define GET_IP(context) ((LPVOID)(context)->Eip)
69
#elif defined(__sparc__)
70
# define GET_IP(context) ((LPVOID)(context)->pc)
71
#elif defined(__powerpc__)
72
# define GET_IP(context) ((LPVOID)(context)->Iar)
73 74
#elif defined(__ALPHA__)
# define GET_IP(context) ((LPVOID)(context)->Fir)
75 76
#elif defined(__x86_64__)
# define GET_IP(context) ((LPVOID)(context)->Rip)
77
#else
78 79 80
# error You must define GET_IP for this CPU
#endif

81 82 83 84 85
/*******************************************************************
 *         EXC_RaiseHandler
 *
 * Handler for exceptions happening inside a handler.
 */
86 87
static DWORD EXC_RaiseHandler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
                               CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
88 89 90 91 92 93 94 95 96 97 98 99 100 101
{
    if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
        return ExceptionContinueSearch;
    /* We shouldn't get here so we store faulty frame in dispatcher */
    *dispatcher = ((EXC_NESTED_FRAME*)frame)->prevFrame;
    return ExceptionNestedException;
}


/*******************************************************************
 *         EXC_UnwindHandler
 *
 * Handler for exceptions happening inside an unwind handler.
 */
102 103
static DWORD EXC_UnwindHandler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
                                CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
104 105 106 107 108 109 110 111 112 113 114 115 116 117
{
    if (!(rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)))
        return ExceptionContinueSearch;
    /* We shouldn't get here so we store faulty frame in dispatcher */
    *dispatcher = ((EXC_NESTED_FRAME*)frame)->prevFrame;
    return ExceptionCollidedUnwind;
}


/*******************************************************************
 *         EXC_CallHandler
 *
 * Call an exception handler, setting up an exception frame to catch exceptions
 * happening during the handler execution.
118 119
 *
 * For i386 this function is implemented in assembler in signal_i386.c.
120
 */
121
#ifndef __i386__
122 123
static DWORD EXC_CallHandler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
                              CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher,
124
                              PEXCEPTION_HANDLER handler, PEXCEPTION_HANDLER nested_handler)
125 126 127 128 129 130
{
    EXC_NESTED_FRAME newframe;
    DWORD ret;

    newframe.frame.Handler = nested_handler;
    newframe.prevFrame     = frame;
131
    __wine_push_frame( &newframe.frame );
132
    ret = handler( record, frame, context, dispatcher );
133
    __wine_pop_frame( &newframe.frame );
134 135
    return ret;
}
136 137 138 139 140 141
#else
/* in signal_i386.c */
extern DWORD EXC_CallHandler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
                              CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher,
                              PEXCEPTION_HANDLER handler, PEXCEPTION_HANDLER nested_handler);
#endif
142

143 144 145 146 147 148 149 150
/**********************************************************************
 *           wait_suspend
 *
 * Wait until the thread is no longer suspended.
 */
void wait_suspend( CONTEXT *context )
{
    LARGE_INTEGER timeout;
151
    int saved_errno = errno;
152 153 154 155

    /* store the context we got at suspend time */
    SERVER_START_REQ( set_thread_context )
    {
156
        req->handle  = wine_server_obj_handle( GetCurrentThread() );
157 158 159 160 161 162 163 164 165
        req->flags   = CONTEXT_FULL;
        req->suspend = 1;
        wine_server_add_data( req, context, sizeof(*context) );
        wine_server_call( req );
    }
    SERVER_END_REQ;

    /* wait with 0 timeout, will only return once the thread is no longer suspended */
    timeout.QuadPart = 0;
166
    NTDLL_wait_for_multiple_objects( 0, NULL, SELECT_INTERRUPTIBLE, &timeout, 0 );
167 168 169 170

    /* retrieve the new context */
    SERVER_START_REQ( get_thread_context )
    {
171
        req->handle  = wine_server_obj_handle( GetCurrentThread() );
172 173 174 175 176 177
        req->flags   = CONTEXT_FULL;
        req->suspend = 1;
        wine_server_set_reply( req, context, sizeof(*context) );
        wine_server_call( req );
    }
    SERVER_END_REQ;
178 179

    errno = saved_errno;
180 181 182
}


183
/**********************************************************************
184
 *           send_debug_event
185 186 187
 *
 * Send an EXCEPTION_DEBUG_EVENT event to the debugger.
 */
188
static NTSTATUS send_debug_event( EXCEPTION_RECORD *rec, int first_chance, CONTEXT *context )
189
{
190
    int ret;
191 192
    HANDLE handle = 0;

193 194
    if (!NtCurrentTeb()->Peb->BeingDebugged) return 0;  /* no debugger present */

195
    SERVER_START_REQ( queue_exception_event )
196 197
    {
        req->first   = first_chance;
198 199
        wine_server_add_data( req, context, sizeof(*context) );
        wine_server_add_data( req, rec, sizeof(*rec) );
200
        if (!wine_server_call( req )) handle = wine_server_ptr_handle( reply->handle );
201
    }
202
    SERVER_END_REQ;
203
    if (!handle) return 0;
204

205
    NTDLL_wait_for_multiple_objects( 1, &handle, SELECT_INTERRUPTIBLE, NULL, 0 );
206

207
    SERVER_START_REQ( get_exception_status )
208
    {
209
        req->handle = wine_server_obj_handle( handle );
210
        wine_server_set_reply( req, context, sizeof(*context) );
211
        ret = wine_server_call( req );
212
    }
213
    SERVER_END_REQ;
214
    return ret;
215 216 217
}


218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
/**********************************************************************
 *           call_vectored_handlers
 *
 * Call the vectored handlers chain.
 */
static LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
{
    struct list *ptr;
    LONG ret = EXCEPTION_CONTINUE_SEARCH;
    EXCEPTION_POINTERS except_ptrs;

    except_ptrs.ExceptionRecord = rec;
    except_ptrs.ContextRecord = context;

    RtlEnterCriticalSection( &vectored_handlers_section );
    LIST_FOR_EACH( ptr, &vectored_handlers )
    {
        VECTORED_HANDLER *handler = LIST_ENTRY( ptr, VECTORED_HANDLER, entry );
        ret = handler->func( &except_ptrs );
        if (ret == EXCEPTION_CONTINUE_EXECUTION) break;
    }
    RtlLeaveCriticalSection( &vectored_handlers_section );
    return ret;
}


244 245
/**********************************************************************
 *           call_stack_handlers
246
 *
247
 * Call the stack handlers chain.
248
 */
249
static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
250
{
251
    EXCEPTION_REGISTRATION_RECORD *frame, *dispatch, *nested_frame;
252
    DWORD res;
253

254
    frame = NtCurrentTeb()->Tib.ExceptionList;
255
    nested_frame = NULL;
256
    while (frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL)
257 258
    {
        /* Check frame address */
259 260
        if (((void*)frame < NtCurrentTeb()->Tib.StackLimit) ||
            ((void*)(frame+1) > NtCurrentTeb()->Tib.StackBase) ||
261
            (ULONG_PTR)frame & 3)
262 263 264 265 266 267
        {
            rec->ExceptionFlags |= EH_STACK_INVALID;
            break;
        }

        /* Call handler */
268
        TRACE( "calling handler at %p code=%x flags=%x\n",
269
               frame->Handler, rec->ExceptionCode, rec->ExceptionFlags );
270
        res = EXC_CallHandler( rec, frame, context, &dispatch, frame->Handler, EXC_RaiseHandler );
271
        TRACE( "handler at %p returned %x\n", frame->Handler, res );
272

273 274 275 276 277 278 279 280 281 282
        if (frame == nested_frame)
        {
            /* no longer nested */
            nested_frame = NULL;
            rec->ExceptionFlags &= ~EH_NESTED_CALL;
        }

        switch(res)
        {
        case ExceptionContinueExecution:
283 284
            if (!(rec->ExceptionFlags & EH_NONCONTINUABLE)) return STATUS_SUCCESS;
            return STATUS_NONCONTINUABLE_EXCEPTION;
285 286 287 288 289 290 291
        case ExceptionContinueSearch:
            break;
        case ExceptionNestedException:
            if (nested_frame < dispatch) nested_frame = dispatch;
            rec->ExceptionFlags |= EH_NESTED_CALL;
            break;
        default:
292
            return STATUS_INVALID_DISPOSITION;
293 294 295
        }
        frame = frame->Prev;
    }
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
    return STATUS_UNHANDLED_EXCEPTION;
}


/*******************************************************************
 *		raise_exception
 *
 * Implementation of NtRaiseException.
 */
static NTSTATUS raise_exception( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
{
    NTSTATUS status;

    if (first_chance)
    {
        DWORD c;

313
        TRACE( "code=%x flags=%x addr=%p\n",
314 315
               rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
        for (c = 0; c < rec->NumberParameters; c++)
316
            TRACE( " info[%d]=%08lx\n", c, rec->ExceptionInformation[c] );
317 318 319 320 321 322 323 324 325 326 327 328 329 330
        if (rec->ExceptionCode == EXCEPTION_WINE_STUB)
        {
            if (rec->ExceptionInformation[1] >> 16)
                MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n",
                         rec->ExceptionAddress,
                         (char*)rec->ExceptionInformation[0], (char*)rec->ExceptionInformation[1] );
            else
                MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n",
                         rec->ExceptionAddress,
                         (char*)rec->ExceptionInformation[0], rec->ExceptionInformation[1] );
        }
#ifdef __i386__
        else
        {
331
            TRACE(" eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n",
332 333
                  context->Eax, context->Ebx, context->Ecx,
                  context->Edx, context->Esi, context->Edi );
334
            TRACE(" ebp=%08x esp=%08x cs=%04x ds=%04x es=%04x fs=%04x gs=%04x flags=%08x\n",
335 336 337 338 339 340 341 342
                  context->Ebp, context->Esp, context->SegCs, context->SegDs,
                  context->SegEs, context->SegFs, context->SegGs, context->EFlags );
        }
#endif
        status = send_debug_event( rec, TRUE, context );
        if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED)
            return STATUS_SUCCESS;

343 344 345 346 347
#ifdef __i386__
        /* fix up instruction pointer in context for EXCEPTION_BREAKPOINT */
        if (rec->ExceptionCode == EXCEPTION_BREAKPOINT) context->Eip--;
#endif

348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
        if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION)
            return STATUS_SUCCESS;

        if ((status = call_stack_handlers( rec, context )) != STATUS_UNHANDLED_EXCEPTION)
            return status;
    }

    /* last chance exception */

    status = send_debug_event( rec, FALSE, context );
    if (status != DBG_CONTINUE)
    {
        if (rec->ExceptionFlags & EH_STACK_INVALID)
            ERR("Exception frame is not in stack limits => unable to dispatch exception.\n");
        else if (rec->ExceptionCode == STATUS_NONCONTINUABLE_EXCEPTION)
            ERR("Process attempted to continue execution after noncontinuable exception.\n");
        else
365
            ERR("Unhandled exception code %x flags %x addr %p\n",
366 367 368 369 370 371 372 373 374 375 376 377 378
                rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
        NtTerminateProcess( NtCurrentProcess(), 1 );
    }
    return STATUS_SUCCESS;
}


/*******************************************************************
 *		NtRaiseException (NTDLL.@)
 */
NTSTATUS WINAPI NtRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
{
    NTSTATUS status = raise_exception( rec, context, first_chance );
379
    if (status == STATUS_SUCCESS) NtSetContextThread( GetCurrentThread(), context );
380 381 382
    return status;
}

383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
/***********************************************************************
 *		RtlCaptureContext (NTDLL.@)
 */
void WINAPI __regs_RtlCaptureContext( CONTEXT *context_out, CONTEXT *context_in )
{
    *context_out = *context_in;
}

/**********************************************************************/

#ifdef DEFINE_REGS_ENTRYPOINT
DEFINE_REGS_ENTRYPOINT( RtlCaptureContext, 4, 4 )
#else
void WINAPI RtlCaptureContext( CONTEXT *context_out )
{
    memset( context_out, 0, sizeof(*context_out) );
}
#endif


403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
/***********************************************************************
 *		RtlRaiseException (NTDLL.@)
 */
void WINAPI __regs_RtlRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context )
{
    NTSTATUS status = raise_exception( rec, context, TRUE );
    if (status != STATUS_SUCCESS)
    {
        EXCEPTION_RECORD newrec;
        newrec.ExceptionCode    = status;
        newrec.ExceptionFlags   = EH_NONCONTINUABLE;
        newrec.ExceptionRecord  = rec;
        newrec.NumberParameters = 0;
        RtlRaiseException( &newrec );  /* never returns */
    }
418 419
}

420 421
/**********************************************************************/

422
#ifdef DEFINE_REGS_ENTRYPOINT
423
DEFINE_REGS_ENTRYPOINT( RtlRaiseException, 4, 4 )
424 425 426 427
#else
void WINAPI RtlRaiseException( EXCEPTION_RECORD *rec )
{
    CONTEXT context;
428
    RtlCaptureContext( &context );
429
    __regs_RtlRaiseException( rec, &context );
430 431 432
}
#endif

433 434

/*******************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
435
 *		RtlUnwind (NTDLL.@)
436
 */
437 438
void WINAPI __regs_RtlUnwind( EXCEPTION_REGISTRATION_RECORD* pEndFrame, PVOID unusedEip,
                              PEXCEPTION_RECORD pRecord, PVOID returnEax, CONTEXT *context )
439 440
{
    EXCEPTION_RECORD record, newrec;
441
    EXCEPTION_REGISTRATION_RECORD *frame, *dispatch;
442
    DWORD res;
443

444
#ifdef __i386__
445
    context->Eax = (DWORD)returnEax;
446
#endif
447

448 449 450 451 452 453
    /* build an exception record, if we do not have one */
    if (!pRecord)
    {
        record.ExceptionCode    = STATUS_UNWIND;
        record.ExceptionFlags   = 0;
        record.ExceptionRecord  = NULL;
454
        record.ExceptionAddress = GET_IP(context);
455 456 457 458 459
        record.NumberParameters = 0;
        pRecord = &record;
    }

    pRecord->ExceptionFlags |= EH_UNWINDING | (pEndFrame ? 0 : EH_EXIT_UNWIND);
460

461
    TRACE( "code=%x flags=%x\n", pRecord->ExceptionCode, pRecord->ExceptionFlags );
462

463
    /* get chain of exception frames */
464
    frame = NtCurrentTeb()->Tib.ExceptionList;
465
    while ((frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL) && (frame != pEndFrame))
466 467 468 469 470 471 472 473 474 475
    {
        /* Check frame address */
        if (pEndFrame && (frame > pEndFrame))
        {
            newrec.ExceptionCode    = STATUS_INVALID_UNWIND_TARGET;
            newrec.ExceptionFlags   = EH_NONCONTINUABLE;
            newrec.ExceptionRecord  = pRecord;
            newrec.NumberParameters = 0;
            RtlRaiseException( &newrec );  /* never returns */
        }
476 477
        if (((void*)frame < NtCurrentTeb()->Tib.StackLimit) ||
            ((void*)(frame+1) > NtCurrentTeb()->Tib.StackBase) ||
478
            (UINT_PTR)frame & 3)
479 480 481 482 483 484 485 486 487
        {
            newrec.ExceptionCode    = STATUS_BAD_STACK;
            newrec.ExceptionFlags   = EH_NONCONTINUABLE;
            newrec.ExceptionRecord  = pRecord;
            newrec.NumberParameters = 0;
            RtlRaiseException( &newrec );  /* never returns */
        }

        /* Call handler */
488
        TRACE( "calling handler at %p code=%x flags=%x\n",
489 490
               frame->Handler, pRecord->ExceptionCode, pRecord->ExceptionFlags );
        res = EXC_CallHandler( pRecord, frame, context, &dispatch, frame->Handler, EXC_UnwindHandler );
491
        TRACE( "handler at %p returned %x\n", frame->Handler, res );
492 493

        switch(res)
494 495 496 497 498 499 500 501 502 503 504 505 506 507
        {
        case ExceptionContinueSearch:
            break;
        case ExceptionCollidedUnwind:
            frame = dispatch;
            break;
        default:
            newrec.ExceptionCode    = STATUS_INVALID_DISPOSITION;
            newrec.ExceptionFlags   = EH_NONCONTINUABLE;
            newrec.ExceptionRecord  = pRecord;
            newrec.NumberParameters = 0;
            RtlRaiseException( &newrec );  /* never returns */
            break;
        }
508
        frame = __wine_pop_frame( frame );
509 510 511
    }
}

512 513
/**********************************************************************/

514
#ifdef DEFINE_REGS_ENTRYPOINT
515
DEFINE_REGS_ENTRYPOINT( RtlUnwind, 16, 16 )
516
#else
517 518
void WINAPI RtlUnwind( PVOID pEndFrame, PVOID unusedEip,
                       PEXCEPTION_RECORD pRecord, PVOID returnEax )
519 520
{
    CONTEXT context;
521
    RtlCaptureContext( &context );
522
    __regs_RtlUnwind( pEndFrame, unusedEip, pRecord, returnEax, &context );
523 524 525
}
#endif

526 527

/***********************************************************************
528
 *            RtlRaiseStatus  (NTDLL.@)
529 530 531 532 533 534 535 536 537 538 539 540 541
 *
 * Raise an exception with ExceptionCode = status
 */
void WINAPI RtlRaiseStatus( NTSTATUS status )
{
    EXCEPTION_RECORD ExceptionRec;

    ExceptionRec.ExceptionCode    = status;
    ExceptionRec.ExceptionFlags   = EH_NONCONTINUABLE;
    ExceptionRec.ExceptionRecord  = NULL;
    ExceptionRec.NumberParameters = 0;
    RtlRaiseException( &ExceptionRec );
}
542 543


544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
/*******************************************************************
 *         RtlAddVectoredExceptionHandler   (NTDLL.@)
 */
PVOID WINAPI RtlAddVectoredExceptionHandler( ULONG first, PVECTORED_EXCEPTION_HANDLER func )
{
    VECTORED_HANDLER *handler = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*handler) );
    if (handler)
    {
        handler->func = func;
        RtlEnterCriticalSection( &vectored_handlers_section );
        if (first) list_add_head( &vectored_handlers, &handler->entry );
        else list_add_tail( &vectored_handlers, &handler->entry );
        RtlLeaveCriticalSection( &vectored_handlers_section );
    }
    return handler;
}


/*******************************************************************
 *         RtlRemoveVectoredExceptionHandler   (NTDLL.@)
 */
ULONG WINAPI RtlRemoveVectoredExceptionHandler( PVOID handler )
{
    struct list *ptr;
    ULONG ret = FALSE;

    RtlEnterCriticalSection( &vectored_handlers_section );
    LIST_FOR_EACH( ptr, &vectored_handlers )
    {
573 574
        VECTORED_HANDLER *curr_handler = LIST_ENTRY( ptr, VECTORED_HANDLER, entry );
        if (curr_handler == handler)
575 576 577 578 579 580 581 582 583 584 585 586
        {
            list_remove( ptr );
            ret = TRUE;
            break;
        }
    }
    RtlLeaveCriticalSection( &vectored_handlers_section );
    if (ret) RtlFreeHeap( GetProcessHeap(), 0, handler );
    return ret;
}


587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
/*************************************************************
 *            __wine_spec_unimplemented_stub
 *
 * ntdll-specific implementation to avoid depending on kernel functions.
 * Can be removed once ntdll.spec no longer contains stubs.
 */
void __wine_spec_unimplemented_stub( const char *module, const char *function )
{
    EXCEPTION_RECORD record;

    record.ExceptionCode    = EXCEPTION_WINE_STUB;
    record.ExceptionFlags   = EH_NONCONTINUABLE;
    record.ExceptionRecord  = NULL;
    record.ExceptionAddress = __wine_spec_unimplemented_stub;
    record.NumberParameters = 2;
    record.ExceptionInformation[0] = (ULONG_PTR)module;
    record.ExceptionInformation[1] = (ULONG_PTR)function;
    RtlRaiseException( &record );
}