1 // New abi Support -*- C++ -*-
3 // Copyright (C) 2000, 2001 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
));
90 reinterpret_cast <std::size_t *> (base
)[-1] = element_count
;
94 __cxa_vec_ctor(base
, element_count
, element_size
,
95 constructor
, destructor
);
100 uncatch_exception ue
;
101 dealloc(base
- padding_size
);
103 __throw_exception_again
;
109 __cxa_vec_new3(std::size_t element_count
,
110 std::size_t element_size
,
111 std::size_t padding_size
,
112 void (*constructor
) (void *),
113 void (*destructor
) (void *),
114 void *(*alloc
) (std::size_t),
115 void (*dealloc
) (void *, std::size_t))
117 std::size_t size
= element_count
* element_size
+ padding_size
;
118 char *base
= static_cast<char *>(alloc (size
));
122 base
+= padding_size
;
123 reinterpret_cast<std::size_t *>(base
)[-1] = element_count
;
127 __cxa_vec_ctor(base
, element_count
, element_size
,
128 constructor
, destructor
);
133 uncatch_exception ue
;
134 dealloc(base
- padding_size
, size
);
136 __throw_exception_again
;
143 __cxa_vec_ctor(void *array_address
,
144 std::size_t element_count
,
145 std::size_t element_size
,
146 void (*constructor
) (void *),
147 void (*destructor
) (void *))
150 char *ptr
= static_cast<char *>(array_address
);
155 for (; ix
!= element_count
; ix
++, ptr
+= element_size
)
161 uncatch_exception ue
;
162 __cxa_vec_cleanup(array_address
, ix
, element_size
, destructor
);
164 __throw_exception_again
;
168 // Construct an array by copying.
170 __cxa_vec_cctor(void *dest_array
,
172 std::size_t element_count
,
173 std::size_t element_size
,
174 void (*constructor
) (void *, void *),
175 void (*destructor
) (void *))
178 char *dest_ptr
= static_cast<char *>(dest_array
);
179 char *src_ptr
= static_cast<char *>(src_array
);
184 for (; ix
!= element_count
;
185 ix
++, src_ptr
+= element_size
, dest_ptr
+= element_size
)
186 constructor(dest_ptr
, src_ptr
);
191 uncatch_exception ue
;
192 __cxa_vec_cleanup(dest_array
, ix
, element_size
, destructor
);
194 __throw_exception_again
;
200 __cxa_vec_dtor(void *array_address
,
201 std::size_t element_count
,
202 std::size_t element_size
,
203 void (*destructor
) (void *))
207 char *ptr
= static_cast<char *>(array_address
);
208 std::size_t ix
= element_count
;
210 ptr
+= element_count
* element_size
;
223 uncatch_exception ue
;
224 __cxa_vec_cleanup(array_address
, ix
, element_size
, destructor
);
226 __throw_exception_again
;
231 // Destruct array as a result of throwing an exception.
232 // [except.ctor]/3 If a destructor called during stack unwinding
233 // exits with an exception, terminate is called.
235 __cxa_vec_cleanup(void *array_address
,
236 std::size_t element_count
,
237 std::size_t element_size
,
238 void (*destructor
) (void *))
242 char *ptr
= static_cast <char *> (array_address
);
243 std::size_t ix
= element_count
;
245 ptr
+= element_count
* element_size
;
262 // Destruct and release array.
264 __cxa_vec_delete(void *array_address
,
265 std::size_t element_size
,
266 std::size_t padding_size
,
267 void (*destructor
) (void *))
269 __cxa_vec_delete2(array_address
, element_size
, padding_size
,
271 &operator delete []);
275 __cxa_vec_delete2(void *array_address
,
276 std::size_t element_size
,
277 std::size_t padding_size
,
278 void (*destructor
) (void *),
279 void (*dealloc
) (void *))
281 char *base
= static_cast<char *>(array_address
);
285 std::size_t element_count
= reinterpret_cast<std::size_t *>(base
)[-1];
286 base
-= padding_size
;
289 __cxa_vec_dtor(array_address
, element_count
, element_size
,
295 uncatch_exception ue
;
298 __throw_exception_again
;
305 __cxa_vec_delete3(void *array_address
,
306 std::size_t element_size
,
307 std::size_t padding_size
,
308 void (*destructor
) (void *),
309 void (*dealloc
) (void *, std::size_t))
311 char *base
= static_cast <char *> (array_address
);
312 std::size_t size
= 0;
316 std::size_t element_count
= reinterpret_cast<std::size_t *> (base
)[-1];
317 base
-= padding_size
;
318 size
= element_count
* element_size
+ padding_size
;
321 __cxa_vec_dtor(array_address
, element_count
, element_size
,
327 uncatch_exception ue
;
330 __throw_exception_again
;
335 } // namespace __cxxabiv1