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
258 // Size of concrete vstruct
263 uintptr_t downcast(::System::_i_Object *obj,
264 const unsigned long *new_guid);
268 // FIXME: use above typedef
269 static inline bool guids_equal(const unsigned long *guid1,
270 const unsigned long *guid2)
272 return (guid1[0] == guid2[0] &&
273 guid1[1] == guid2[1] &&
274 (sizeof(long) == 8 ||
275 (guid1[2] == guid2[2] &&
276 guid1[3] == guid2[3])));
280 struct ParamInfoBlock {
281 uint32_t buffer_size;
284 uint32_t objlist_len;
285 uint32_t num_segments;
318 struct InvokeMethod {
331 // Return the caller's PC. It'd be nice if GCC had a builtin for
332 // the current PC, so that a simple relocation could be used rather
333 // than a function call. OPT: put this in lowlevel-lib, so that
334 // architectures can provide a faster version.
336 unsigned long get_pc();
338 static inline bool in_kernel()
347 typedef void (*MethodEntry)(ParamInfoBlock *pib);
351 void *ptr; // pointer to the class interface
354 typedef Util::RadixTree<Object, ID, 6> ObjTable;
359 inline void *operator new(size_t len, ::System::RunTime::ORBMM *orbmm,
362 return orbmm->alloc(len, refs);
365 inline void *operator new[](size_t len, ::System::RunTime::ORBMM *orbmm,
368 return orbmm->alloc(len, refs);
371 inline void operator delete(void *ptr, ::System::RunTime::ORBMM *orbmm,
374 orbmm->release(ptr, refs);
377 inline void operator delete[](void *ptr, ::System::RunTime::ORBMM *orbmm,
380 orbmm->release(ptr, refs);
383 // This is a macro rather than an inline template function so that the
384 // caller shows up as file/line number in the debugging information rather
385 // than this header file, and so that a variable argument list can be
386 // passed to a fixed arg ctor.
388 // To throw an IDL exception of type Foo, do this:
389 // throw_idl(Foo, args, to, foo);
391 #ifndef POLINTOS_NO_THROW_IDL
392 #define throw_idl(T, args...) do { \
393 throw T(NULL, NULL, \
394 new(::System::RunTime::orbmm) \
395 ::System::Exceptions::NativeCodeExceptionOriginInfo \
396 (::System::RunTime::get_pc()), \
397 ::System::RunTime::Priv::in_kernel(), ##args); \
400 #define rethrow_idl(oldex, T, args...) do { \
401 throw T(new(::System::RunTime::orbmm) typeof(oldex)(oldex), NULL, \
402 new(::System::RunTime::orbmm) \
403 ::System::Exceptions::NativeCodeExceptionOriginInfo \
404 (::System::RunTime::get_pc()), \
405 ::System::RunTime::Priv::in_kernel(), ##args); \