summaryrefslogtreecommitdiffstats
path: root/private/crt32/misc/i386/sehsupp.c
blob: 1dbce51bb445354513f2e5260897546e2d482db1 (plain) (blame)
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
/***
*sehsupp.c - helper functions for Structured Exception Handling support
*
*	Copyright (C) 1993, Microsoft Corporation. All rights reserved.
*
*Purpose:
*	Contains _rt_probe_read.  Helper for the SEH runtime support
*	routines (longjmp in particular).  Much of the SEH code is written
*	in asm, so these routines are available when probing memory in ways
*	that must be guarded with __try/__except in case of access violation.
*
*Revision History:
*	12-05-93  PML	Module created.
*	12-22-93  GJF	Made #define WIN32_LEAN_AND_MEAN conditional.
*	01-12-94  PML	Rewritten - still need helpers, just different ones
*
*******************************************************************************/

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif

#include <windows.h>

/***
*BOOL __stdcall _rt_probe_read4 - Check if a DWORD is readable
*
*Purpose:
*  Internal support function called by longjmp.  Check if a DWORD is
*  readable under a __try/__except.
*
*Entry:
*  DWORD * p - Pointer to DWORD to be probed
*
*Exit:
*  Success: TRUE - Able to read
*  Failure: FALSE - Access violation while reading
*
******************************************************************************/

BOOL __stdcall _rt_probe_read4(
    DWORD * ptr)
{
    BOOL readable;

    __try
    {
	*(volatile DWORD *)ptr;
	readable = TRUE;
    }
    __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION
		? EXCEPTION_EXECUTE_HANDLER
		: EXCEPTION_CONTINUE_SEARCH)
    {
	readable = FALSE;
    }

    return readable;
}