24 typedef ::System::Mem::Region Region;
28 void *alloc(size_t size, AllocGroup *group = NULL);
30 void retain(Region region);
31 void release(Region region);
32 void super_retain(Region region);
33 void super_release(Region region);
34 AllocGroup *create_group();
35 void destroy_group(AllocGroup *group);
36 void *add_region(Region region);
41 // FIXME: should be an IDL exception
49 static const NullArray nullarray = {};
51 template<typename T> struct MutableArray {
55 bool valid_index(size_t index)
57 return index >= 0 && index < count;
60 T &operator[](size_t index)
62 #ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
63 if (!valid_index(index))
64 throw ArrayException();
76 MutableArray(NullArray na)
82 MutableArray(T *PTR, size_t COUNT)
88 MutableArray &slice_nocheck(size_t first, size_t newcount)
91 ret.ptr = ptr + first;
96 MutableArray &slice_nocheck(size_t first)
99 ret.ptr = ptr + first;
100 ret.count = count - first;
104 MutableArray &slice(size_t first, size_t count)
106 #ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
107 if (!valid_index(first) || !valid_index(first + count - 1))
108 throw ArrayException();
111 return slice_nocheck(first, count);
114 MutableArray &slice(size_t first)
116 #ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
117 if (!valid_index(first))
118 throw ArrayException();
121 return slice_nocheck(first);
126 MutableArray new_arr;
127 new_arr.ptr = new(orbmm) T[count];
128 new_arr.count = count;
129 memcpy(new_arr.ptr, ptr, count);
134 template<typename T> struct Array {
138 bool valid_index(size_t index)
140 return index >= 0 && index < count;
143 const T &operator[](size_t index)
145 #ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
146 if (!valid_index(index))
147 throw ArrayException();
165 Array(const T *PTR, size_t COUNT)
171 Array(MutableArray<T> ma)
177 MutableArray<T> constcast()
180 ma.ptr = const_cast<T>(ptr);
185 Array &slice_nocheck(size_t first, size_t newcount)
188 ret.ptr = ptr + first;
189 ret.count = newcount;
193 Array &slice_nocheck(size_t first)
196 ret.ptr = ptr + first;
197 ret.count = count - first;
201 Array &slice(size_t first, size_t count)
203 #ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
204 if (!valid_index(first) || !valid_index(first + count - 1))
205 throw ArrayException();
208 return slice_nocheck(first, count);
211 Array &slice(size_t first)
213 #ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
214 if (!valid_index(first))
215 throw ArrayException();
218 return slice_nocheck(first);
221 MutableArray<T> copy()
223 MutableArray<T> new_arr;
224 new_arr.ptr = new(orbmm) T[count];
225 new_arr.count = count;
226 memcpy(new_arr.ptr, ptr, count);
231 static inline Array<uint8_t> countarray(const char *ptr)
234 ret.ptr = reinterpret_cast<const uint8_t *>(ptr);
235 ret.count = strlen(ptr);
239 static inline MutableArray<uint8_t> countarray(char *ptr)
241 MutableArray<uint8_t> ret;
242 ret.ptr = reinterpret_cast<uint8_t *>(ptr);
243 ret.count = strlen(ptr);
248 const unsigned long *const guid;
249 const ptrdiff_t offset;
253 // List of GUIDs of the struct and its superstructs,
254 // starting with System.VStruct and ending with
255 // the concrete struct.
257 const unsigned long *const *const guids;
259 // Length of inheritance chain; 1 for System.VStruct
264 uintptr_t downcast(::System::_i_Object *obj,
265 const unsigned long *new_guid);
267 static inline bool guids_equal(const unsigned long *guid1,
268 const unsigned long *guid2)
270 return (guid1[0] == guid2[0] &&
271 guid1[1] == guid2[1] &&
272 (sizeof(long) == 8 ||
273 (guid1[2] == guid2[2] &&
274 guid1[3] == guid2[3])));
277 // Return the caller's PC. It'd be nice if GCC had a builtin for
278 // the current PC, so that a simple relocation could be used rather
279 // than a function call. OPT: put this in lowlevel-lib, so that
280 // architectures can provide a faster version.
282 unsigned long get_pc();
284 struct ParamInfoBlock {
285 uintptr_t buffer_size;
287 uintptr_t objlist_len;
289 uintptr_t ptrlist_len;
290 uintptr_t num_segments;
301 inline void *operator new(size_t len, ::System::RunTime::ORBMM *orbmm,
302 ::System::RunTime::ORBMM::AllocGroup *group = NULL)
304 return orbmm->alloc(len, group);
307 inline void *operator new[](size_t len, ::System::RunTime::ORBMM *orbmm,
308 ::System::RunTime::ORBMM::AllocGroup *group = NULL)
310 return orbmm->alloc(len, group);
313 // This is a macro rather than an inline template function so that the
314 // caller shows up as file/line number in the debugging information rather
315 // than this header file, and so that a variable argument list can be
316 // passed to a fixed arg ctor.
318 // To throw an IDL exception of type Foo, do this:
319 // throw_idl(Foo, args, to, foo);
321 #ifndef POLINTOS_NO_THROW_IDL
322 #define throw_idl(T, args...) do { \
323 throw T(NULL, NULL, \
324 new(::System::RunTime::orbmm) \
325 ::System::Exceptions::NativeCodeExceptionOriginInfo \
326 (::System::RunTime::get_pc()), \
327 _KERNEL ? 1 : 0, ##args); \
330 #define rethrow_idl(oldex, T, args...) do { \
331 throw T(new(::System::RunTime::orbmm) typeof(oldex)(oldex), NULL, \
332 new(::System::RunTime::orbmm) \
333 ::System::Exceptions::NativeCodeExceptionOriginInfo \
334 (::System::RunTime::get_pc()), \
335 _KERNEL ? 1 : 0, ##args); \