24 typedef ::System::Mem::Region Region;
28 void *alloc(size_t size, int refs = 1);
29 void retain(void *ptr, int refs = 1);
30 void release(void *ptr, int refs = 1);
31 void add_region(Region region, bool unmap_orig, int refs = 1);
36 // FIXME: should be an IDL exception
44 static const NullArray nullarray = {};
46 template<typename T> struct MutableArray {
50 bool valid_index(size_t index)
52 return index >= 0 && index < count;
55 T &operator[](size_t index)
57 #ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
58 if (!valid_index(index))
59 throw ArrayException();
71 MutableArray(NullArray na)
77 MutableArray(T *PTR, size_t COUNT)
83 MutableArray &slice_nocheck(size_t first, size_t newcount)
86 ret.ptr = ptr + first;
91 MutableArray &slice_nocheck(size_t first)
94 ret.ptr = ptr + first;
95 ret.count = count - first;
99 MutableArray &slice(size_t first, size_t count)
101 #ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
102 if (!valid_index(first) || !valid_index(first + count - 1))
103 throw ArrayException();
106 return slice_nocheck(first, count);
109 MutableArray &slice(size_t first)
111 #ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
112 if (!valid_index(first))
113 throw ArrayException();
116 return slice_nocheck(first);
121 MutableArray new_arr;
122 new_arr.ptr = new(orbmm) T[count];
123 new_arr.count = count;
124 memcpy(new_arr.ptr, ptr, count);
129 template<typename T> struct Array {
133 bool valid_index(size_t index)
135 return index >= 0 && index < count;
138 const T &operator[](size_t index)
140 #ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
141 if (!valid_index(index))
142 throw ArrayException();
160 Array(const T *PTR, size_t COUNT)
166 Array(MutableArray<T> ma)
172 MutableArray<T> constcast()
175 ma.ptr = const_cast<T>(ptr);
180 Array &slice_nocheck(size_t first, size_t newcount)
183 ret.ptr = ptr + first;
184 ret.count = newcount;
188 Array &slice_nocheck(size_t first)
191 ret.ptr = ptr + first;
192 ret.count = count - first;
196 Array &slice(size_t first, size_t count)
198 #ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
199 if (!valid_index(first) || !valid_index(first + count - 1))
200 throw ArrayException();
203 return slice_nocheck(first, count);
206 Array &slice(size_t first)
208 #ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
209 if (!valid_index(first))
210 throw ArrayException();
213 return slice_nocheck(first);
216 MutableArray<T> copy()
218 MutableArray<T> new_arr;
219 new_arr.ptr = new(orbmm) T[count];
220 new_arr.count = count;
221 memcpy(new_arr.ptr, ptr, count);
226 static inline Array<uint8_t> countarray(const char *ptr)
229 ret.ptr = reinterpret_cast<const uint8_t *>(ptr);
230 ret.count = strlen(ptr);
234 static inline MutableArray<uint8_t> countarray(char *ptr)
236 MutableArray<uint8_t> ret;
237 ret.ptr = reinterpret_cast<uint8_t *>(ptr);
238 ret.count = strlen(ptr);
243 const unsigned long *const guid;
244 const ptrdiff_t offset;
248 // List of GUIDs of the struct and its superstructs,
249 // starting with System.VStruct and ending with
250 // the concrete struct.
252 const unsigned long *const *const guids;
254 // Length of inheritance chain; 1 for System.VStruct
259 uintptr_t downcast(::System::_i_Object *obj,
260 const unsigned long *new_guid);
262 static inline bool guids_equal(const unsigned long *guid1,
263 const unsigned long *guid2)
265 return (guid1[0] == guid2[0] &&
266 guid1[1] == guid2[1] &&
267 (sizeof(long) == 8 ||
268 (guid1[2] == guid2[2] &&
269 guid1[3] == guid2[3])));
272 // Return the caller's PC. It'd be nice if GCC had a builtin for
273 // the current PC, so that a simple relocation could be used rather
274 // than a function call. OPT: put this in lowlevel-lib, so that
275 // architectures can provide a faster version.
277 unsigned long get_pc();
279 struct ParamInfoBlock {
280 uintptr_t buffer_size;
282 uintptr_t *objlist_ptr;
283 uintptr_t objlist_len;
284 uintptr_t num_segments;
307 inline void *operator new(size_t len, ::System::RunTime::ORBMM *orbmm,
310 return orbmm->alloc(len, refs);
313 inline void *operator new[](size_t len, ::System::RunTime::ORBMM *orbmm,
316 return orbmm->alloc(len, refs);
319 inline void operator delete(void *ptr, ::System::RunTime::ORBMM *orbmm,
322 orbmm->release(ptr, refs);
325 inline void operator delete[](void *ptr, ::System::RunTime::ORBMM *orbmm,
328 orbmm->release(ptr, refs);
331 // This is a macro rather than an inline template function so that the
332 // caller shows up as file/line number in the debugging information rather
333 // than this header file, and so that a variable argument list can be
334 // passed to a fixed arg ctor.
336 // To throw an IDL exception of type Foo, do this:
337 // throw_idl(Foo, args, to, foo);
339 #ifndef POLINTOS_NO_THROW_IDL
340 #define throw_idl(T, args...) do { \
341 throw T(NULL, NULL, \
342 new(::System::RunTime::orbmm) \
343 ::System::Exceptions::NativeCodeExceptionOriginInfo \
344 (::System::RunTime::get_pc()), \
345 ::System::Priv::in_kernel(), ##args); \
348 #define rethrow_idl(oldex, T, args...) do { \
349 throw T(new(::System::RunTime::orbmm) typeof(oldex)(oldex), NULL, \
350 new(::System::RunTime::orbmm) \
351 ::System::Exceptions::NativeCodeExceptionOriginInfo \
352 (::System::RunTime::get_pc()), \
353 ::System::Priv::in_kernel(), ##args); \