Skip to content

Commit 5ec9183

Browse files
author
Howard Hinnant
committed
Reviewing cxa_exception.cpp and marking as implemented as I go. Not marking as implemented on arm when I'm not sure about that platform.
llvm-svn: 146072
1 parent 851e948 commit 5ec9183

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

libcxxabi/src/cxa_exception.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@
1919
#include <pthread.h>
2020

2121
#include "cxa_exception.hpp"
22+
#include "cxa_handlers.hpp"
2223

2324
namespace __cxxabiv1 {
2425
static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\0
2526
static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1
2627

2728
// Utility routines
28-
static __cxa_exception *exception_from_thrown_object(void *p) throw() {
29+
static inline __cxa_exception *exception_from_thrown_object(void *p) throw() {
2930
return ((__cxa_exception *) p) - 1;
3031
}
3132

32-
static void * thrown_object_from_exception(void *p) throw() {
33+
static inline void * thrown_object_from_exception(void *p) throw() {
3334
return (void *) (((__cxa_exception *) p) + 1 );
3435
}
3536

36-
static size_t object_size_from_exception_size(size_t size) throw() {
37+
static inline size_t object_size_from_exception_size(size_t size) throw() {
3738
return size + sizeof (__cxa_exception);
3839
}
3940

@@ -90,15 +91,15 @@ static void do_free(void *ptr) throw() {
9091
return is_fallback_ptr(ptr) ? fallback_free(ptr) : std::free(ptr);
9192
}
9293

93-
/* Howard says:
94+
/*
9495
If reason isn't _URC_FOREIGN_EXCEPTION_CAUGHT, then the terminateHandler
9596
stored in exc is called. Otherwise the exceptionDestructor stored in
9697
exc is called, and then the memory for the exception is deallocated.
9798
*/
9899
static void exception_cleanup_func(_Unwind_Reason_Code reason, struct _Unwind_Exception* exc) {
99100
__cxa_exception *exception = exception_from_exception_object(exc);
100101
if (_URC_FOREIGN_EXCEPTION_CAUGHT != reason)
101-
exception->terminateHandler ();
102+
std::__terminate(exception->terminateHandler);
102103

103104
void * thrown_object = thrown_object_from_exception(exception);
104105
if (NULL != exception->exceptionDestructor)
@@ -115,7 +116,7 @@ static LIBCXXABI_NORETURN void failed_throw(__cxa_exception *exception) throw()
115116
// a handler must call:
116117
// * void *__cxa_begin_catch(void *exceptionObject );
117118
(void) __cxa_begin_catch(&exception->unwindHeader);
118-
std::terminate();
119+
std::__terminate(exception->terminateHandler);
119120
}
120121

121122
extern "C" {
@@ -150,15 +151,13 @@ void * __cxa_allocate_dependent_exception () throw() {
150151
if (NULL == ptr)
151152
std::terminate();
152153
std::memset(ptr, 0, actual_size);
153-
// bookkeeping here ?
154154
return ptr;
155155
}
156156

157157

158158
// This function shall free a dependent_exception.
159159
// It does not affect the reference count of the primary exception.
160160
void __cxa_free_dependent_exception (void * dependent_exception) throw() {
161-
// I'm pretty sure there's no bookkeeping here
162161
do_free(dependent_exception);
163162
}
164163

@@ -228,11 +227,7 @@ void * __cxa_begin_catch(void * exceptionObject) throw() {
228227
__cxa_eh_globals *globals = __cxa_get_globals();
229228
__cxa_exception *exception = exception_from_exception_object(exceptionObject);
230229

231-
// TODO add stuff for dependent exceptions.
232-
233-
// TODO - should this be atomic?
234230
// Increment the handler count, removing the flag about being rethrown
235-
// assert(exception->handlerCount != 0);
236231
exception->handlerCount = exception->handlerCount < 0 ?
237232
-exception->handlerCount + 1 : exception->handlerCount + 1;
238233

libcxxabi/src/cxa_handlers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <new>
1515
#include <exception>
1616
#include "abort_message.h"
17+
#include "cxa_handlers.hpp"
1718

1819
namespace std
1920
{

libcxxabi/src/cxa_handlers.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===------------------------- cxa_handlers.cpp ---------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is dual licensed under the MIT and the University of Illinois Open
6+
// Source Licenses. See LICENSE.TXT for details.
7+
//
8+
//
9+
// This file implements the functionality associated with the terminate_handler,
10+
// unexpected_handler, and new_handler.
11+
//===----------------------------------------------------------------------===//
12+
13+
#include <exception>
14+
15+
namespace std
16+
{
17+
18+
_LIBCPP_HIDDEN
19+
_ATTRIBUTE(noreturn)
20+
void
21+
__unexpected(unexpected_handler func);
22+
23+
_LIBCPP_HIDDEN
24+
_ATTRIBUTE(noreturn)
25+
void
26+
__terminate(terminate_handler func) _NOEXCEPT;
27+
28+
} // std

libcxxabi/www/spec.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@
112112
</p>
113113
</blockquote>
114114
</td>
115-
<td></td>
116-
<td></td>
115+
<td>&#10003;</td>
116+
<td>&#10003;</td>
117117
<td></td>
118118
</tr>
119119

@@ -130,9 +130,9 @@
130130
</p>
131131
</blockquote>
132132
</td>
133-
<td></td>
134-
<td></td>
135-
<td></td>
133+
<td>&#10003;</td>
134+
<td>&#10003;</td>
135+
<td>&#10003;</td>
136136
</tr>
137137

138138
<tr>
@@ -166,8 +166,8 @@
166166
</p>
167167
</blockquote>
168168
</td>
169-
<td></td>
170-
<td></td>
169+
<td>&#10003;</td>
170+
<td>&#10003;</td>
171171
<td></td>
172172
</tr>
173173

0 commit comments

Comments
 (0)