1 // new abi support -*- C++ -*-
3 // Free Software Foundation, Inc.
4 // Written by Nathan Sidwell, Codesourcery LLC, <nathan@codesourcery.com>
6 // GNU CC is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
11 // GNU CC is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with GNU CC; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330,
19 // Boston, MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 #if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
35 // Exception handling hook, to mark current exception as not caught --
36 // generally because we're about to rethrow it after some cleanup.
37 extern "C" void __uncatch_exception (void);
42 /* allocate and construct array */
44 __cxa_vec_new (size_t element_count
,
47 void (*constructor
) (void *),
48 void (*destructor
) (void *))
50 return __cxa_vec_new2 (element_count
, element_size
, padding_size
,
51 constructor
, destructor
,
52 &operator new[], &operator delete []);
56 __cxa_vec_new2 (size_t element_count
,
59 void (*constructor
) (void *),
60 void (*destructor
) (void *),
61 void *(*alloc
) (size_t),
62 void (*dealloc
) (void *))
64 size_t size
= element_count
* element_size
+ padding_size
;
65 char *base
= static_cast <char *> (alloc (size
));
70 reinterpret_cast <size_t *> (base
)[-1] = element_count
;
74 __cxa_vec_ctor (base
, element_count
, element_size
,
75 constructor
, destructor
);
79 __uncatch_exception ();
80 dealloc (base
- padding_size
);
87 __cxa_vec_new3 (size_t element_count
,
90 void (*constructor
) (void *),
91 void (*destructor
) (void *),
92 void *(*alloc
) (size_t),
93 void (*dealloc
) (void *, size_t))
95 size_t size
= element_count
* element_size
+ padding_size
;
96 char *base
= static_cast <char *> (alloc (size
));
100 base
+= padding_size
;
101 reinterpret_cast <size_t *> (base
)[-1] = element_count
;
105 __cxa_vec_ctor (base
, element_count
, element_size
,
106 constructor
, destructor
);
110 __uncatch_exception ();
111 dealloc (base
- padding_size
, size
);
117 /* construct array */
119 __cxa_vec_ctor (void *array_address
,
120 size_t element_count
,
122 void (*constructor
) (void *),
123 void (*destructor
) (void *))
126 char *ptr
= static_cast <char *> (array_address
);
131 for (; ix
!= element_count
; ix
++, ptr
+= element_size
)
136 __uncatch_exception ();
137 __cxa_vec_dtor (array_address
, ix
, element_size
, destructor
);
142 /* construct an array by copying */
145 __cxa_vec_cctor (void *dest_array
,
147 size_t element_count
,
149 void (*constructor
) (void *, void *),
150 void (*destructor
) (void *))
153 char *dest_ptr
= static_cast <char *> (dest_array
);
154 char *src_ptr
= static_cast <char *> (src_array
);
159 for (; ix
!= element_count
;
160 ix
++, src_ptr
+= element_size
, dest_ptr
+= element_size
)
161 constructor (dest_ptr
, src_ptr
);
165 __uncatch_exception ();
166 __cxa_vec_dtor (dest_array
, ix
, element_size
, destructor
);
173 __cxa_vec_dtor (void *array_address
,
174 size_t element_count
,
176 void (*destructor
) (void *))
180 char *ptr
= static_cast <char *> (array_address
);
181 size_t ix
= element_count
;
182 bool unwinding
= std::uncaught_exception ();
184 ptr
+= element_count
* element_size
;
197 // [except.ctor]/3 If a destructor called during stack unwinding
198 // exits with an exception, terminate is called.
200 __uncatch_exception ();
201 __cxa_vec_dtor (array_address
, ix
, element_size
, destructor
);
207 /* destruct and release array */
209 __cxa_vec_delete (void *array_address
,
212 void (*destructor
) (void *))
214 __cxa_vec_delete2 (array_address
, element_size
, padding_size
,
216 &operator delete []);
220 __cxa_vec_delete2 (void *array_address
,
223 void (*destructor
) (void *),
224 void (*dealloc
) (void *))
226 char *base
= static_cast <char *> (array_address
);
230 size_t element_count
= reinterpret_cast <size_t *> (base
)[-1];
231 base
-= padding_size
;
234 __cxa_vec_dtor (array_address
, element_count
, element_size
,
239 __uncatch_exception ();
248 __cxa_vec_delete3 (void *array_address
,
251 void (*destructor
) (void *),
252 void (*dealloc
) (void *, size_t))
254 char *base
= static_cast <char *> (array_address
);
259 size_t element_count
= reinterpret_cast <size_t *> (base
)[-1];
260 base
-= padding_size
;
261 size
= element_count
* element_size
+ padding_size
;
264 __cxa_vec_dtor (array_address
, element_count
, element_size
,
269 __uncatch_exception ();
270 dealloc (base
, size
);
274 dealloc (base
, size
);
277 } // namespace __cxxabiv1
279 #endif // defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100