summaryrefslogtreecommitdiffhomepage
path: root/include/ntapi/nt_exception.h
blob: 75bf36100ea511be460661025380dc15d21f5bc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef _NT_EXCEPTION_H_
#define _NT_EXCEPTION_H_

#include "nt_abi.h"
#include "nt_object.h"
#include "nt_thread.h"

/* exception limits */
#define NT_EXCEPTION_MAX_PARAMS		(0x0F)

/* exception flags */
#define NT_EXCEPTION_FLAG_NONCONTINUABLE	(1 << 0)
#define NT_EXCEPTION_FLAG_UNWINDING		(1 << 1)
#define NT_EXCEPTION_FLAG_EXIT_UNWIND		(1 << 2)
#define NT_EXCEPTION_FLAG_STACK_INVALID		(1 << 3)
#define NT_EXCEPTION_FLAG_NESTED_CALL		(1 << 4)
#define NT_EXCEPTION_FLAG_TARGET_UNWIND		(1 << 5)
#define NT_EXCEPTION_FLAG_COLLIDED_UNWIND 	(1 << 6)
#define NT_EXCEPTION_FLAG_UNWIND		(  NT_EXCEPTION_UNWINDING    \
						|| NT_EXCEPTION_EXIT_UNWIND   \
						|| NT_EXCEPTION_TARGET_UNWIND  \
						|| NT_EXCEPTION_COLLIDED_UNWIND )

/* exception definitions */
typedef struct _nt_exception_record	nt_exception_record;
typedef struct _nt_dispatcher_context   nt_dispatcher_context;
typedef struct _nt_unwind_history_table	nt_unwind_history_table;

typedef enum _nt_exception_disposition {
	NT_EXCEPTION_CONTINUE_EXECUTION,
	NT_EXCEPTION_CONTINUE_SEARCH,
	NT_EXCEPTION_NESTED_EXCEPTION,
	NT_EXCEPTION_COLLIDED_UNWIND
} nt_exception_disposition;

typedef struct _nt_exception_record {
	uint32_t			exception_code;
	uint32_t			exception_flags;
	struct _nt_exception_record *	exception_record;
	void *				exception_address;
	uint32_t			number_of_params;
	uintptr_t			exception_information[NT_EXCEPTION_MAX_PARAMS];
} nt_exception_record;

typedef struct _nt_runtime_function {
	uint32_t	raddr_fn_start;
	uint32_t	raddr_fn_end;
	uint32_t	raddr_uw_info;
} nt_runtime_function;

typedef nt_exception_disposition (*nt_exception_routine)(
	nt_exception_record *,
	uintptr_t,
	nt_thread_context *,
	nt_dispatcher_context *);

typedef struct _nt_dispatcher_context {
	uintptr_t			control_pc;
	uintptr_t			image_base;
	nt_runtime_function *		fn_entry;
	uintptr_t			establisher_frame;
	uintptr_t			target_ip;
	nt_thread_context *		tctx;
	nt_exception_routine		language_handler;
	void *				handler_data;
	nt_unwind_history_table *	history_table;
	uint32_t			scope_index;
	uint32_t			__pad;
} nt_dispatcher_context;

/* exception interfaces */
typedef int32_t __stdcall ntapi_zw_raise_exception(
	__in	nt_exception_record *	exception_record,
	__in	nt_thread_context *	context,
	__in	unsigned char		search_frames);

typedef int32_t __stdcall ntapi_zw_continue(
	__in	nt_thread_context *	context,
	__in	unsigned char		test_alert);

#endif