Welcome to mirror list, hosted at ThFree Co, Russian Federation.

exception.h « cygwin « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5b11b0c003b19f831580fbe5442becda0eedf782 (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
/* exception.h

   Copyright 2010, 2011, 2012, 2013 Red Hat, Inc.

This software is a copyrighted work licensed under the terms of the
Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
details. */

#pragma once

#ifdef __x86_64__
#define _exception_list _EXCEPTION_REGISTRATION_RECORD
#endif

#include <exceptions.h>

#ifndef __x86_64__
extern exception_list *_except_list asm ("%fs:0");
#endif

class exception
{
#ifdef __x86_64__
  static bool handler_installed; 
  static int handle (LPEXCEPTION_POINTERS);
#else
  exception_list el;
  exception_list *save;
  static int handle (EXCEPTION_RECORD *, exception_list *, CONTEXT *, void *);
#endif
public:
  exception () __attribute__ ((always_inline))
  {
#ifdef __x86_64__
    if (!handler_installed)
      {
	handler_installed = true;
	/* The unhandled exception filter goes first.  It won't work if the
	   executable is debugged, but then the vectored continue handler
	   kicks in.  For some reason the vectored continue handler doesn't
	   get called if no unhandled exception filter is installed. */
	SetUnhandledExceptionFilter (handle);
	AddVectoredContinueHandler (1, handle);
      }
#else
    save = _except_list;
    el.handler = handle;
    el.prev = _except_list;
    _except_list = &el;
#endif
  };
#ifndef __x86_64__
  ~exception () __attribute__ ((always_inline)) { _except_list = save; }
#endif
};

class cygwin_exception
{
  PUINT_PTR framep;
  PCONTEXT ctx;
  EXCEPTION_RECORD *e;
  void dump_exception ();
public:
  cygwin_exception (PUINT_PTR in_framep, PCONTEXT in_ctx = NULL, EXCEPTION_RECORD *in_e = NULL):
    framep (in_framep), ctx (in_ctx), e (in_e) {}
  void dumpstack ();
  PCONTEXT context () const {return ctx;}
};