Mercurial > projects > ldc
annotate tango/lib/compiler/llvmdc/eh.d @ 404:3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 27 Jul 2008 13:51:55 +0200 |
parents | 5bea8a1ef905 |
children | dc7dff3ce72e |
rev | line source |
---|---|
330
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
1 /** |
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
2 * This module contains functions and structures required for |
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
3 * exception handling. |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
4 */ |
330
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
5 module eh; |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
6 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
7 import util.console; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
8 |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
318
diff
changeset
|
9 // debug = EH_personality; |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
10 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
11 private extern(C) void abort(); |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
12 private extern(C) int printf(char*, ...); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
13 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
14 // D runtime functions |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
15 extern(C) { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
16 int _d_isbaseof(ClassInfo oc, ClassInfo c); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
17 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
18 |
330
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
19 // libunwind headers |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
20 extern(C) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
21 { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
22 enum _Unwind_Reason_Code |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
23 { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
24 NO_REASON = 0, |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
25 FOREIGN_EXCEPTION_CAUGHT = 1, |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
26 FATAL_PHASE2_ERROR = 2, |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
27 FATAL_PHASE1_ERROR = 3, |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
28 NORMAL_STOP = 4, |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
29 END_OF_STACK = 5, |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
30 HANDLER_FOUND = 6, |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
31 INSTALL_CONTEXT = 7, |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
32 CONTINUE_UNWIND = 8 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
33 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
34 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
35 enum _Unwind_Action |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
36 { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
37 SEARCH_PHASE = 1, |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
38 CLEANUP_PHASE = 2, |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
39 HANDLER_PHASE = 3, |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
40 FORCE_UNWIND = 4 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
41 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
42 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
43 alias void* _Unwind_Context_Ptr; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
44 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
45 alias void function(_Unwind_Reason_Code, _Unwind_Exception*) _Unwind_Exception_Cleanup_Fn; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
46 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
47 struct _Unwind_Exception |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
48 { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
49 char[8] exception_class; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
50 _Unwind_Exception_Cleanup_Fn exception_cleanup; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
51 int private_1; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
52 int private_2; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
53 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
54 |
404
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
55 version(X86) { version(linux) { |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
56 void _Unwind_Resume(_Unwind_Exception*); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
57 _Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception*); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
58 ulong _Unwind_GetLanguageSpecificData(_Unwind_Context_Ptr context); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
59 ulong _Unwind_GetIP(_Unwind_Context_Ptr context); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
60 ulong _Unwind_SetIP(_Unwind_Context_Ptr context, ulong new_value); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
61 ulong _Unwind_SetGR(_Unwind_Context_Ptr context, int index, ulong new_value); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
62 ulong _Unwind_GetRegionStart(_Unwind_Context_Ptr context); |
404
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
63 } } |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
64 else |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
65 { |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
66 // runtime calls these directly |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
67 void _Unwind_Resume(_Unwind_Exception*) |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
68 { |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
69 console("_Unwind_Resume is not implemented on this platform.\n"); |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
70 } |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
71 _Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception*) |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
72 { |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
73 console("_Unwind_RaiseException is not implemented on this platform.\n"); |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
74 return _Unwind_Reason_Code.FATAL_PHASE1_ERROR; |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
75 } |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
76 } |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
77 |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
78 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
79 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
80 |
330
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
81 // helpers for reading certain DWARF data |
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
82 //TODO: It may not be a good idea to use exceptions for error handling within exception handling code |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
83 private ubyte* get_uleb128(ubyte* addr, ref size_t res) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
84 { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
85 res = 0; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
86 size_t bitsize = 0; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
87 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
88 // read as long as high bit is set |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
89 while(*addr & 0x80) { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
90 res |= (*addr & 0x7f) << bitsize; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
91 bitsize += 7; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
92 addr += 1; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
93 if(bitsize >= size_t.sizeof*8) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
94 throw new Exception("tried to read uleb128 that exceeded size of size_t"); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
95 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
96 // read last |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
97 if(bitsize != 0 && *addr >= 1 << size_t.sizeof*8 - bitsize) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
98 throw new Exception("tried to read uleb128 that exceeded size of size_t"); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
99 res |= (*addr) << bitsize; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
100 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
101 return addr + 1; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
102 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
103 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
104 private ubyte* get_sleb128(ubyte* addr, ref ptrdiff_t res) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
105 { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
106 res = 0; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
107 size_t bitsize = 0; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
108 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
109 // read as long as high bit is set |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
110 while(*addr & 0x80) { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
111 res |= (*addr & 0x7f) << bitsize; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
112 bitsize += 7; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
113 addr += 1; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
114 if(bitsize >= size_t.sizeof*8) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
115 throw new Exception("tried to read sleb128 that exceeded size of size_t"); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
116 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
117 // read last |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
118 if(bitsize != 0 && *addr >= 1 << size_t.sizeof*8 - bitsize) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
119 throw new Exception("tried to read sleb128 that exceeded size of size_t"); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
120 res |= (*addr) << bitsize; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
121 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
122 // take care of sign |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
123 if(bitsize < size_t.sizeof*8 && ((*addr) & 0x40)) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
124 res |= cast(ptrdiff_t)(-1) ^ ((1 << (bitsize+7)) - 1); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
125 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
126 return addr + 1; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
127 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
128 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
129 |
330
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
130 // exception struct used by the runtime. |
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
131 // _d_throw allocates a new instance and passes the address of its |
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
132 // _Unwind_Exception member to the unwind call. The personality |
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
133 // routine is then able to get the whole struct by looking at the data |
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
134 // surrounding the unwind info. |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
135 struct _d_exception |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
136 { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
137 Object exception_object; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
138 _Unwind_Exception unwind_info; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
139 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
140 |
330
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
141 // the 8-byte string identifying the type of exception |
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
142 // the first 4 are for vendor, the second 4 for language |
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
143 //TODO: This may be the wrong way around |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
144 char[8] _d_exception_class = "LLDCD1\0\0"; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
145 |
404
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
146 |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
147 // |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
148 // x86 Linux specific implementation of personality function |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
149 // and helpers |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
150 // |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
151 version(X86) version(linux) { |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
152 |
330
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
153 // the personality routine gets called by the unwind handler and is responsible for |
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
154 // reading the EH tables and deciding what to do |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
155 extern(C) _Unwind_Reason_Code _d_eh_personality(int ver, _Unwind_Action actions, ulong exception_class, _Unwind_Exception* exception_info, _Unwind_Context_Ptr context) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
156 { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
157 // check ver: the C++ Itanium ABI only allows ver == 1 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
158 if(ver != 1) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
159 return _Unwind_Reason_Code.FATAL_PHASE1_ERROR; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
160 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
161 // check exceptionClass |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
162 //TODO: Treat foreign exceptions with more respect |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
163 if((cast(char*)&exception_class)[0..8] != _d_exception_class) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
164 return _Unwind_Reason_Code.FATAL_PHASE1_ERROR; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
165 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
166 // find call site table, action table and classinfo table |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
167 // Note: callsite and action tables do not contain static-length |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
168 // data and will be parsed as needed |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
169 // Note: classinfo_table points past the end of the table |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
170 ubyte* callsite_table; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
171 ubyte* action_table; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
172 ClassInfo* classinfo_table; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
173 _d_getLanguageSpecificTables(context, callsite_table, action_table, classinfo_table); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
174 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
175 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
176 /* |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
177 find landing pad and action table index belonging to ip by walking |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
178 the callsite_table |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
179 */ |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
180 ubyte* callsite_walker = callsite_table; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
181 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
182 // get the instruction pointer |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
183 // will be used to find the right entry in the callsite_table |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
184 // -1 because it will point past the last instruction |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
185 ulong ip = _Unwind_GetIP(context) - 1; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
186 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
187 // address block_start is relative to |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
188 ulong region_start = _Unwind_GetRegionStart(context); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
189 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
190 // table entries |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
191 uint block_start_offset, block_size; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
192 ulong landing_pad; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
193 size_t action_offset; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
194 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
195 while(true) { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
196 // if we've gone through the list and found nothing... |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
197 if(callsite_walker >= action_table) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
198 return _Unwind_Reason_Code.CONTINUE_UNWIND; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
199 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
200 block_start_offset = *cast(uint*)callsite_walker; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
201 block_size = *(cast(uint*)callsite_walker + 1); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
202 landing_pad = *(cast(uint*)callsite_walker + 2); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
203 if(landing_pad) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
204 landing_pad += region_start; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
205 callsite_walker = get_uleb128(callsite_walker + 3*uint.sizeof, action_offset); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
206 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
207 debug(EH_personality_verbose) printf("%d %d %d\n", block_start_offset, block_size, landing_pad); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
208 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
209 // since the list is sorted, as soon as we're past the ip |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
210 // there's no handler to be found |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
211 if(ip < region_start + block_start_offset) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
212 return _Unwind_Reason_Code.CONTINUE_UNWIND; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
213 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
214 // if we've found our block, exit |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
215 if(ip < region_start + block_start_offset + block_size) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
216 break; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
217 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
218 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
219 debug(EH_personality) printf("Found correct landing pad and actionOffset %d\n", action_offset); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
220 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
221 // now we need the exception's classinfo to find a handler |
330
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
222 // the exception_info is actually a member of a larger _d_exception struct |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
223 // the runtime allocated. get that now |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
224 _d_exception* exception_struct = cast(_d_exception*)(cast(ubyte*)exception_info - _d_exception.unwind_info.offsetof); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
225 |
330
5bea8a1ef905
[svn r351] Remove unused runtime file for DMD-style exception handling.
ChristianK
parents:
319
diff
changeset
|
226 // if there's no action offset and no landing pad, continue unwinding |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
227 if(!action_offset && !landing_pad) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
228 return _Unwind_Reason_Code.CONTINUE_UNWIND; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
229 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
230 // if there's no action offset but a landing pad, this is a cleanup handler |
318
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
231 else if(!action_offset && landing_pad) |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
232 return _d_eh_install_finally_context(actions, landing_pad, exception_struct, context); |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
233 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
234 /* |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
235 walk action table chain, comparing classinfos using _d_isbaseof |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
236 */ |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
237 ubyte* action_walker = action_table + action_offset - 1; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
238 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
239 ptrdiff_t ti_offset, next_action_offset; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
240 while(true) { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
241 action_walker = get_sleb128(action_walker, ti_offset); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
242 // it is intentional that we not modify action_walker here |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
243 // next_action_offset is from current action_walker position |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
244 get_sleb128(action_walker, next_action_offset); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
245 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
246 // negative are 'filters' which we don't use |
318
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
247 assert(ti_offset >= 0 && "Filter actions are unsupported"); |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
248 |
318
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
249 // zero means cleanup, which we require to be the last action |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
250 if(ti_offset == 0) { |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
251 assert(next_action_offset == 0 && "Cleanup action must be last in chain"); |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
252 return _d_eh_install_finally_context(actions, landing_pad, exception_struct, context); |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
253 } |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
254 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
255 // get classinfo for action and check if the one in the |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
256 // exception structure is a base |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
257 ClassInfo catch_ci = classinfo_table[-ti_offset]; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
258 debug(EH_personality) printf("Comparing catch %s to exception %s\n", catch_ci.name.ptr, exception_struct.exception_object.classinfo.name.ptr); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
259 if(_d_isbaseof(exception_struct.exception_object.classinfo, catch_ci)) |
318
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
260 return _d_eh_install_catch_context(actions, ti_offset, landing_pad, exception_struct, context); |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
261 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
262 // we've walked through all actions and found nothing... |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
263 if(next_action_offset == 0) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
264 return _Unwind_Reason_Code.CONTINUE_UNWIND; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
265 else |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
266 action_walker += next_action_offset; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
267 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
268 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
269 assert(false); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
270 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
271 |
318
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
272 // These are the register numbers for SetGR that |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
273 // llvm's eh.exception and eh.selector intrinsics |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
274 // will pick up. |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
275 // Found by trial-and-error and probably platform dependent! |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
276 private int eh_exception_regno = 0; |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
277 private int eh_selector_regno = 2; |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
278 |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
279 private _Unwind_Reason_Code _d_eh_install_catch_context(_Unwind_Action actions, ptrdiff_t switchval, ulong landing_pad, _d_exception* exception_struct, _Unwind_Context_Ptr context) |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
280 { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
281 debug(EH_personality) printf("Found catch clause!\n"); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
282 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
283 if(actions & _Unwind_Action.SEARCH_PHASE) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
284 return _Unwind_Reason_Code.HANDLER_FOUND; |
318
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
285 |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
286 else if(actions & _Unwind_Action.HANDLER_PHASE) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
287 { |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
318
diff
changeset
|
288 debug(EH_personality) printf("Setting switch value to: %d!\n", switchval); |
318
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
289 _Unwind_SetGR(context, eh_exception_regno, cast(ulong)cast(void*)(exception_struct.exception_object)); |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
290 _Unwind_SetGR(context, eh_selector_regno, switchval); |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
291 _Unwind_SetIP(context, landing_pad); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
292 return _Unwind_Reason_Code.INSTALL_CONTEXT; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
293 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
294 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
295 assert(false); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
296 } |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
297 |
318
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
298 private _Unwind_Reason_Code _d_eh_install_finally_context(_Unwind_Action actions, ulong landing_pad, _d_exception* exception_struct, _Unwind_Context_Ptr context) |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
299 { |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
300 // if we're merely in search phase, continue |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
301 if(actions & _Unwind_Action.SEARCH_PHASE) |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
302 return _Unwind_Reason_Code.CONTINUE_UNWIND; |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
303 |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
304 debug(EH_personality) printf("Calling cleanup routine...\n"); |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
305 |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
306 _Unwind_SetGR(context, eh_exception_regno, cast(ulong)exception_struct); |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
318
diff
changeset
|
307 _Unwind_SetGR(context, eh_selector_regno, 0); |
318
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
308 _Unwind_SetIP(context, landing_pad); |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
309 return _Unwind_Reason_Code.INSTALL_CONTEXT; |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
310 } |
8e570dbe4087
[svn r339] Add cleanup handling when within an action chain and some more documentation to the eh personality function.
ChristianK
parents:
314
diff
changeset
|
311 |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
312 private void _d_getLanguageSpecificTables(_Unwind_Context_Ptr context, ref ubyte* callsite, ref ubyte* action, ref ClassInfo* ci) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
313 { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
314 ubyte* data = cast(ubyte*)_Unwind_GetLanguageSpecificData(context); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
315 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
316 //TODO: Do proper DWARF reading here |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
317 assert(*data++ == 0xff); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
318 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
319 assert(*data++ == 0x00); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
320 size_t cioffset; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
321 data = get_uleb128(data, cioffset); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
322 ci = cast(ClassInfo*)(data + cioffset); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
323 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
324 assert(*data++ == 0x03); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
325 size_t callsitelength; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
326 data = get_uleb128(data, callsitelength); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
327 action = data + callsitelength; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
328 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
329 callsite = data; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
330 } |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
331 |
404
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
332 } // end of x86 Linux specific implementation |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
333 |
3ad8295cfac6
Mark most of the current EH implementation as x86 Linux specific.
Christian Kamm <kamm incasoftware de>
parents:
330
diff
changeset
|
334 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
335 extern(C) void _d_throw_exception(Object e) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
336 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
337 if (e !is null) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
338 { |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
339 _d_exception* exc_struct = new _d_exception; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
340 exc_struct.unwind_info.exception_class[] = _d_exception_class; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
341 exc_struct.exception_object = e; |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
342 _Unwind_Reason_Code ret = _Unwind_RaiseException(&exc_struct.unwind_info); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
343 console("_Unwind_RaiseException failed with reason code: ")(ret)("\n"); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
344 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
345 abort(); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff
changeset
|
346 } |
314
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
347 |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
348 extern(C) void _d_eh_resume_unwind(_d_exception* exception_struct) |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
349 { |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
350 _Unwind_Resume(&exception_struct.unwind_info); |
8d98e42ece93
[svn r335] The basics of exception handling are in place.
ChristianK
parents:
133
diff
changeset
|
351 } |