RtlpExecuteHandlerForException(): Permit nesting for FSCTL_DISMOUNT_VOLUME.
[captive.git] / src / libcaptive / rtl / except.c
1 /* $Id$
2  * Implementation of reactos RtlpExecuteHandler() of libcaptive
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 /* No reactos public include prototype for RtlpExecuteHandlerForException() */
23 #include <glib/gtypes.h>
24 #include <glib/gmessages.h>
25 #include "reactos/ntos/except.h"
26
27
28 EXCEPTION_DISPOSITION RtlpExecuteHandlerForException(PEXCEPTION_RECORD ExceptionRecord,
29                 PEXCEPTION_REGISTRATION RegistrationFrame,PCONTEXT Context,PVOID DispatcherContext,PEXCEPTION_HANDLER ExceptionHandler)
30 {
31 static gint nested=0;
32 EXCEPTION_DISPOSITION r;
33
34         g_return_val_if_fail(ExceptionRecord!=NULL,ExceptionNestedException);
35         g_return_val_if_fail(RegistrationFrame!=NULL,ExceptionNestedException);
36         /* 'Context' can be NULL during ExRaiseStatus() */
37         g_return_val_if_fail(DispatcherContext!=NULL,ExceptionNestedException);
38         g_return_val_if_fail(ExceptionHandler!=NULL,ExceptionNestedException);
39
40         /* Nest-counting is provided here just for debugging reasons. */
41         /* Nesting must be permitted for proper FSCTL_DISMOUNT_VOLUME execution. */
42
43         nested++;
44         r=(*ExceptionHandler)(ExceptionRecord,RegistrationFrame,Context,DispatcherContext);
45         nested--;
46         g_assert(nested>=0);
47
48         g_assert(r==ExceptionContinueExecution || r==ExceptionContinueSearch);
49         return r;
50 }
51
52
53 EXCEPTION_DISPOSITION RtlpExecuteHandlerForUnwind(PEXCEPTION_RECORD ExceptionRecord,
54                 PEXCEPTION_REGISTRATION RegistrationFrame,PCONTEXT Context,PVOID DispatcherContext,PEXCEPTION_HANDLER ExceptionHandler)
55 {
56 static gint nested=0;
57 EXCEPTION_DISPOSITION r;
58
59         g_return_val_if_fail(ExceptionRecord!=NULL,ExceptionNestedException);
60         g_return_val_if_fail(RegistrationFrame!=NULL,ExceptionNestedException);
61         /* 'Context' can be NULL during ExRaiseStatus() */
62         g_return_val_if_fail(DispatcherContext!=NULL,ExceptionNestedException);
63         g_return_val_if_fail(ExceptionHandler!=NULL,ExceptionNestedException);
64
65         /* Nest-counting is provided here just for debugging reasons. */
66         if (nested)
67                 g_assert_not_reached();
68
69         nested++;
70         r=(*ExceptionHandler)(ExceptionRecord,RegistrationFrame,Context,DispatcherContext);
71         nested--;
72         g_assert(!nested);
73
74         g_assert(r==ExceptionContinueExecution || r==ExceptionContinueSearch);
75         return r;
76 }