1 // New abi Support -*- C++ -*-
3 // Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc.
5 // This file is part of GCC.
7 // GCC is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2, or (at your option)
12 // GCC is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with GCC; see the file COPYING. If not, write to
19 // the Free Software Foundation, 59 Temple Place - Suite 330,
20 // Boston, MA 02111-1307, USA.
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 // Written by Nathan Sidwell, Codesourcery LLC, <nathan@codesourcery.com>
36 #include <exception_defines.h>
37 #include "unwind-cxx.h"
43 struct uncatch_exception
46 ~uncatch_exception () { __cxa_begin_catch (&p
->unwindHeader
); }
51 uncatch_exception::uncatch_exception ()
53 __cxa_eh_globals
*globals
= __cxa_get_globals_fast ();
55 p
= globals
->caughtExceptions
;
57 globals
->caughtExceptions
= p
->nextException
;
58 globals
->uncaughtExceptions
+= 1;
62 // Allocate and construct array.
64 __cxa_vec_new(std::size_t element_count
,
65 std::size_t element_size
,
66 std::size_t padding_size
,
67 void (*constructor
) (void *),
68 void (*destructor
) (void *))
70 return __cxa_vec_new2(element_count
, element_size
, padding_size
,
71 constructor
, destructor
,
72 &operator new[], &operator delete []);
76 __cxa_vec_new2(std::size_t element_count
,
77 std::size_t element_size
,
78 std::size_t padding_size
,
79 void (*constructor
) (void *),
80 void (*destructor
) (void *),
81 void *(*alloc
) (std::size_t),
82 void (*dealloc
) (void *))
84 std::size_t size
= element_count
* element_size
+ padding_size
;
85 char *base
= static_cast <char *> (alloc (size
));
92 reinterpret_cast <std::size_t *> (base
)[-1] = element_count
;
96 __cxa_vec_ctor(base
, element_count
, element_size
,
97 constructor
, destructor
);
102 uncatch_exception ue
;
103 dealloc(base
- padding_size
);
105 __throw_exception_again
;
111 __cxa_vec_new3(std::size_t element_count
,
112 std::size_t element_size
,
113 std::size_t padding_size
,
114 void (*constructor
) (void *),
115 void (*destructor
) (void *),
116 void *(*alloc
) (std::size_t),
117 void (*dealloc
) (void *, std::size_t))
119 std::size_t size
= element_count
* element_size
+ padding_size
;
120 char *base
= static_cast<char *>(alloc (size
));
126 base
+= padding_size
;
127 reinterpret_cast<std::size_t *>(base
)[-1] = element_count
;
131 __cxa_vec_ctor(base
, element_count
, element_size
,
132 constructor
, destructor
);
137 uncatch_exception ue
;
138 dealloc(base
- padding_size
, size
);
140 __throw_exception_again
;
147 __cxa_vec_ctor(void *array_address
,
148 std::size_t element_count
,
149 std::size_t element_size
,
150 void (*constructor
) (void *),
151 void (*destructor
) (void *))
154 char *ptr
= static_cast<char *>(array_address
);
159 for (; ix
!= element_count
; ix
++, ptr
+= element_size
)
165 uncatch_exception ue
;
166 __cxa_vec_cleanup(array_address
, ix
, element_size
, destructor
);
168 __throw_exception_again
;
172 // Construct an array by copying.
174 __cxa_vec_cctor(void *dest_array
,
176 std::size_t element_count
,
177 std::size_t element_size
,
178 void (*constructor
) (void *, void *),
179 void (*destructor
) (void *))
182 char *dest_ptr
= static_cast<char *>(dest_array
);
183 char *src_ptr
= static_cast<char *>(src_array
);
188 for (; ix
!= element_count
;
189 ix
++, src_ptr
+= element_size
, dest_ptr
+= element_size
)
190 constructor(dest_ptr
, src_ptr
);
195 uncatch_exception ue
;
196 __cxa_vec_cleanup(dest_array
, ix
, element_size
, destructor
);
198 __throw_exception_again
;
204 __cxa_vec_dtor(void *array_address
,
205 std::size_t element_count
,
206 std::size_t element_size
,
207 void (*destructor
) (void *))
211 char *ptr
= static_cast<char *>(array_address
);
212 std::size_t ix
= element_count
;
214 ptr
+= element_count
* element_size
;
227 uncatch_exception ue
;
228 __cxa_vec_cleanup(array_address
, ix
, element_size
, destructor
);
230 __throw_exception_again
;
235 // Destruct array as a result of throwing an exception.
236 // [except.ctor]/3 If a destructor called during stack unwinding
237 // exits with an exception, terminate is called.
239 __cxa_vec_cleanup(void *array_address
,
240 std::size_t element_count
,
241 std::size_t element_size
,
242 void (*destructor
) (void *))
246 char *ptr
= static_cast <char *> (array_address
);
247 std::size_t ix
= element_count
;
249 ptr
+= element_count
* element_size
;
266 // Destruct and release array.
268 __cxa_vec_delete(void *array_address
,
269 std::size_t element_size
,
270 std::size_t padding_size
,
271 void (*destructor
) (void *))
273 __cxa_vec_delete2(array_address
, element_size
, padding_size
,
275 &operator delete []);
279 __cxa_vec_delete2(void *array_address
,
280 std::size_t element_size
,
281 std::size_t padding_size
,
282 void (*destructor
) (void *),
283 void (*dealloc
) (void *))
288 char* base
= static_cast<char *>(array_address
);
292 std::size_t element_count
= reinterpret_cast<std::size_t *>(base
)[-1];
293 base
-= padding_size
;
296 __cxa_vec_dtor(array_address
, element_count
, element_size
,
302 uncatch_exception ue
;
305 __throw_exception_again
;
312 __cxa_vec_delete3(void *array_address
,
313 std::size_t element_size
,
314 std::size_t padding_size
,
315 void (*destructor
) (void *),
316 void (*dealloc
) (void *, std::size_t))
321 char* base
= static_cast <char *> (array_address
);
322 std::size_t size
= 0;
326 std::size_t element_count
= reinterpret_cast<std::size_t *> (base
)[-1];
327 base
-= padding_size
;
328 size
= element_count
* element_size
+ padding_size
;
331 __cxa_vec_dtor(array_address
, element_count
, element_size
,
337 uncatch_exception ue
;
340 __throw_exception_again
;
345 } // namespace __cxxabiv1