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 typedef uint64_t GUID[2];
264 // FIXME: use above typedef
265 static inline bool guids_equal(const unsigned long *guid1,
266 const unsigned long *guid2)
268 return (guid1[0] == guid2[0] &&
269 guid1[1] == guid2[1] &&
270 (sizeof(long) == 8 ||
271 (guid1[2] == guid2[2] &&
272 guid1[3] == guid2[3])));
276 struct ParamInfoBlock {
277 uint32_t buffer_size;
280 uint32_t objlist_len;
281 uint32_t num_segments;
314 struct InvokeMethod {
327 // Return the caller's PC. It'd be nice if GCC had a builtin for
328 // the current PC, so that a simple relocation could be used rather
329 // than a function call. OPT: put this in lowlevel-lib, so that
330 // architectures can provide a faster version.
332 unsigned long get_pc();
334 static inline bool in_kernel()
346 inline void *operator new(size_t len, ::System::RunTime::ORBMM *orbmm,
349 return orbmm->alloc(len, refs);
352 inline void *operator new[](size_t len, ::System::RunTime::ORBMM *orbmm,
355 return orbmm->alloc(len, refs);
358 inline void operator delete(void *ptr, ::System::RunTime::ORBMM *orbmm,
361 orbmm->release(ptr, refs);
364 inline void operator delete[](void *ptr, ::System::RunTime::ORBMM *orbmm,
367 orbmm->release(ptr, refs);
370 // This is a macro rather than an inline template function so that the
371 // caller shows up as file/line number in the debugging information rather
372 // than this header file, and so that a variable argument list can be
373 // passed to a fixed arg ctor.
375 // To throw an IDL exception of type Foo, do this:
376 // throw_idl(Foo, args, to, foo);
378 #ifndef POLINTOS_NO_THROW_IDL
379 #define throw_idl(T, args...) do { \
380 throw T(NULL, NULL, \
381 new(::System::RunTime::orbmm) \
382 ::System::Exceptions::NativeCodeExceptionOriginInfo \
383 (::System::RunTime::Priv::get_pc()), \
384 ::System::RunTime::Priv::in_kernel(), ##args); \
387 #define rethrow_idl(oldex, T, args...) do { \
388 throw T(new(::System::RunTime::orbmm) typeof(oldex)(oldex), NULL, \
389 new(::System::RunTime::orbmm) \
390 ::System::Exceptions::NativeCodeExceptionOriginInfo \
391 (::System::RunTime::Priv::get_pc()), \
392 ::System::RunTime::Priv::in_kernel(), ##args); \