1 // New abi Support -*- C++ -*-
3 // Copyright (C) 2000, 2001, 2003, 2004 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, 51 Franklin Street, Fifth Floor,
20 // Boston, MA 02110-1301, 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
); }
52 operator=(const uncatch_exception
&);
54 uncatch_exception(const uncatch_exception
&);
57 uncatch_exception::uncatch_exception() : p(0)
59 __cxa_eh_globals
*globals
= __cxa_get_globals_fast ();
61 p
= globals
->caughtExceptions
;
63 globals
->caughtExceptions
= p
->nextException
;
64 globals
->uncaughtExceptions
+= 1;
68 // Allocate and construct array.
70 __cxa_vec_new(std::size_t element_count
,
71 std::size_t element_size
,
72 std::size_t padding_size
,
73 __cxa_cdtor_type constructor
,
74 __cxa_cdtor_type destructor
)
76 return __cxa_vec_new2(element_count
, element_size
, padding_size
,
77 constructor
, destructor
,
78 &operator new[], &operator delete []);
82 __cxa_vec_new2(std::size_t element_count
,
83 std::size_t element_size
,
84 std::size_t padding_size
,
85 __cxa_cdtor_type constructor
,
86 __cxa_cdtor_type destructor
,
87 void *(*alloc
) (std::size_t),
88 void (*dealloc
) (void *))
90 std::size_t size
= element_count
* element_size
+ padding_size
;
91 char *base
= static_cast <char *> (alloc (size
));
98 reinterpret_cast <std::size_t *> (base
)[-1] = element_count
;
99 #ifdef _GLIBCXX_ELTSIZE_IN_COOKIE
100 reinterpret_cast <std::size_t *> (base
)[-2] = element_size
;
105 __cxa_vec_ctor(base
, element_count
, element_size
,
106 constructor
, destructor
);
111 uncatch_exception ue
;
112 dealloc(base
- padding_size
);
114 __throw_exception_again
;
120 __cxa_vec_new3(std::size_t element_count
,
121 std::size_t element_size
,
122 std::size_t padding_size
,
123 __cxa_cdtor_type constructor
,
124 __cxa_cdtor_type destructor
,
125 void *(*alloc
) (std::size_t),
126 void (*dealloc
) (void *, std::size_t))
128 std::size_t size
= element_count
* element_size
+ padding_size
;
129 char *base
= static_cast<char *>(alloc (size
));
135 base
+= padding_size
;
136 reinterpret_cast<std::size_t *>(base
)[-1] = element_count
;
137 #ifdef _GLIBCXX_ELTSIZE_IN_COOKIE
138 reinterpret_cast <std::size_t *> (base
)[-2] = element_size
;
143 __cxa_vec_ctor(base
, element_count
, element_size
,
144 constructor
, destructor
);
149 uncatch_exception ue
;
150 dealloc(base
- padding_size
, size
);
152 __throw_exception_again
;
158 extern "C" __cxa_vec_ctor_return_type
159 __cxa_vec_ctor(void *array_address
,
160 std::size_t element_count
,
161 std::size_t element_size
,
162 __cxa_cdtor_type constructor
,
163 __cxa_cdtor_type destructor
)
166 char *ptr
= static_cast<char *>(array_address
);
171 for (; ix
!= element_count
; ix
++, ptr
+= element_size
)
177 uncatch_exception ue
;
178 __cxa_vec_cleanup(array_address
, ix
, element_size
, destructor
);
180 __throw_exception_again
;
182 _GLIBCXX_CXA_VEC_CTOR_RETURN (array_address
);
185 // Construct an array by copying.
186 extern "C" __cxa_vec_ctor_return_type
187 __cxa_vec_cctor(void *dest_array
,
189 std::size_t element_count
,
190 std::size_t element_size
,
191 __cxa_cdtor_return_type (*constructor
) (void *, void *),
192 __cxa_cdtor_type destructor
)
195 char *dest_ptr
= static_cast<char *>(dest_array
);
196 char *src_ptr
= static_cast<char *>(src_array
);
201 for (; ix
!= element_count
;
202 ix
++, src_ptr
+= element_size
, dest_ptr
+= element_size
)
203 constructor(dest_ptr
, src_ptr
);
208 uncatch_exception ue
;
209 __cxa_vec_cleanup(dest_array
, ix
, element_size
, destructor
);
211 __throw_exception_again
;
213 _GLIBCXX_CXA_VEC_CTOR_RETURN (dest_array
);
218 __cxa_vec_dtor(void *array_address
,
219 std::size_t element_count
,
220 std::size_t element_size
,
221 __cxa_cdtor_type destructor
)
225 char *ptr
= static_cast<char *>(array_address
);
226 std::size_t ix
= element_count
;
228 ptr
+= element_count
* element_size
;
241 uncatch_exception ue
;
242 __cxa_vec_cleanup(array_address
, ix
, element_size
, destructor
);
244 __throw_exception_again
;
249 // Destruct array as a result of throwing an exception.
250 // [except.ctor]/3 If a destructor called during stack unwinding
251 // exits with an exception, terminate is called.
253 __cxa_vec_cleanup(void *array_address
,
254 std::size_t element_count
,
255 std::size_t element_size
,
256 __cxa_cdtor_type destructor
)
260 char *ptr
= static_cast <char *> (array_address
);
261 std::size_t ix
= element_count
;
263 ptr
+= element_count
* element_size
;
280 // Destruct and release array.
282 __cxa_vec_delete(void *array_address
,
283 std::size_t element_size
,
284 std::size_t padding_size
,
285 __cxa_cdtor_type destructor
)
287 __cxa_vec_delete2(array_address
, element_size
, padding_size
,
289 &operator delete []);
293 __cxa_vec_delete2(void *array_address
,
294 std::size_t element_size
,
295 std::size_t padding_size
,
296 __cxa_cdtor_type destructor
,
297 void (*dealloc
) (void *))
302 char* base
= static_cast<char *>(array_address
);
306 std::size_t element_count
= reinterpret_cast<std::size_t *>(base
)[-1];
307 base
-= padding_size
;
310 __cxa_vec_dtor(array_address
, element_count
, element_size
,
316 uncatch_exception ue
;
319 __throw_exception_again
;
326 __cxa_vec_delete3(void *array_address
,
327 std::size_t element_size
,
328 std::size_t padding_size
,
329 __cxa_cdtor_type destructor
,
330 void (*dealloc
) (void *, std::size_t))
335 char* base
= static_cast <char *> (array_address
);
336 std::size_t size
= 0;
340 std::size_t element_count
= reinterpret_cast<std::size_t *> (base
)[-1];
341 base
-= padding_size
;
342 size
= element_count
* element_size
+ padding_size
;
345 __cxa_vec_dtor(array_address
, element_count
, element_size
,
351 uncatch_exception ue
;
354 __throw_exception_again
;
359 } // namespace __cxxabiv1
361 #if defined(__arm__) && defined(__ARM_EABI__)
363 // The ARM C++ ABI requires that the library provide these additional
364 // helper functions. There are placed in this file, despite being
365 // architecture-specifier, so that the compiler can inline the __cxa
366 // functions into these functions as appropriate.
371 __aeabi_vec_ctor_nocookie_nodtor (void *array_address
,
372 abi::__cxa_cdtor_type constructor
,
373 std::size_t element_size
,
374 std::size_t element_count
)
376 return abi::__cxa_vec_ctor (array_address
, element_count
, element_size
,
377 constructor
, /*destructor=*/NULL
);
381 __aeabi_vec_ctor_cookie_nodtor (void *array_address
,
382 abi::__cxa_cdtor_type constructor
,
383 std::size_t element_size
,
384 std::size_t element_count
)
386 if (array_address
== NULL
)
389 array_address
= reinterpret_cast<std::size_t *>(array_address
) + 2;
390 reinterpret_cast<std::size_t *>(array_address
)[-2] = element_size
;
391 reinterpret_cast<std::size_t *>(array_address
)[-1] = element_count
;
392 return abi::__cxa_vec_ctor (array_address
,
393 element_count
, element_size
,
394 constructor
, /*destructor=*/NULL
);
398 __aeabi_vec_cctor_nocookie_nodtor (void *dest_array
,
400 std::size_t element_size
,
401 std::size_t element_count
,
402 void *(*constructor
) (void *, void *))
404 return abi::__cxa_vec_cctor (dest_array
, src_array
,
405 element_count
, element_size
,
410 __aeabi_vec_new_cookie_noctor (std::size_t element_size
,
411 std::size_t element_count
)
413 return abi::__cxa_vec_new(element_count
, element_size
,
414 2 * sizeof (std::size_t),
415 /*constructor=*/NULL
, /*destructor=*/NULL
);
419 __aeabi_vec_new_nocookie (std::size_t element_size
,
420 std::size_t element_count
,
421 abi::__cxa_cdtor_type constructor
)
423 return abi::__cxa_vec_new (element_count
, element_size
, 0, constructor
,
428 __aeabi_vec_new_cookie_nodtor (std::size_t element_size
,
429 std::size_t element_count
,
430 abi::__cxa_cdtor_type constructor
)
432 return abi::__cxa_vec_new(element_count
, element_size
,
433 2 * sizeof (std::size_t),
438 __aeabi_vec_new_cookie(std::size_t element_size
,
439 std::size_t element_count
,
440 abi::__cxa_cdtor_type constructor
,
441 abi::__cxa_cdtor_type destructor
)
443 return abi::__cxa_vec_new (element_count
, element_size
,
444 2 * sizeof (std::size_t),
445 constructor
, destructor
);
450 __aeabi_vec_dtor (void *array_address
,
451 abi::__cxa_cdtor_type destructor
,
452 std::size_t element_size
,
453 std::size_t element_count
)
455 abi::__cxa_vec_dtor (array_address
, element_count
, element_size
,
457 return reinterpret_cast<std::size_t*> (array_address
) - 2;
461 __aeabi_vec_dtor_cookie (void *array_address
,
462 abi::__cxa_cdtor_type destructor
)
464 abi::__cxa_vec_dtor (array_address
,
465 reinterpret_cast<std::size_t *>(array_address
)[-1],
466 reinterpret_cast<std::size_t *>(array_address
)[-2],
468 return reinterpret_cast<std::size_t*> (array_address
) - 2;
473 __aeabi_vec_delete (void *array_address
,
474 abi::__cxa_cdtor_type destructor
)
476 abi::__cxa_vec_delete (array_address
,
477 reinterpret_cast<std::size_t *>(array_address
)[-2],
478 2 * sizeof (std::size_t),
483 __aeabi_vec_delete3 (void *array_address
,
484 abi::__cxa_cdtor_type destructor
,
485 void (*dealloc
) (void *, std::size_t))
487 abi::__cxa_vec_delete3 (array_address
,
488 reinterpret_cast<std::size_t *>(array_address
)[-2],
489 2 * sizeof (std::size_t),
490 destructor
, dealloc
);
494 __aeabi_vec_delete3_nodtor (void *array_address
,
495 void (*dealloc
) (void *, std::size_t))
497 abi::__cxa_vec_delete3 (array_address
,
498 reinterpret_cast<std::size_t *>(array_address
)[-2],
499 2 * sizeof (std::size_t),
500 /*destructor=*/NULL
, dealloc
);
502 } // namespace __aeabiv1
504 #endif // defined(__arm__) && defined(__ARM_EABI__)