1 // FIXME: This is out-of-date and incomplete.
12 static const unsigned char guid[];
15 // The concrete field is used by the ORB to locate the
16 // object ID (stored one word before the concrete pointer).
17 // The concrete field is zero except where multiple
18 // inheritance causes there to be multiple table pointers in
19 // the object. When that happens, the concrete field is the
20 // number of bytes (either 0 or negative) to add to the
21 // pointer to yield a pointer to the most derived interface
22 // (of which there can be only one).
26 // This is a pointer to the most derived interface's
27 // interface table, for use by a downcast method that does
28 // not know the real type yet.
30 ::System::RunTime::IFaceTable *concrete_IFaceTable;
32 // A list of interfaces follows. Each entry in the list
33 // consists of a pointer to the GUID for the entry's
34 // interface, followed by an offset to add to a pointer of
35 // this interface to obtain a pointer to this entry's
36 // interface. This list is scanned during downcast()
37 // operations. The entries are used directly (no scanning)
38 // for upcast operations, and the first entry (which must be
39 // the for this interface) is used by the ORB to verify the
40 // GUID of objects passed.
42 // The offsets must be dynamic, because an interface can
43 // only have one pointer regardless of how many times it is
44 // inherited by an interface's parents, and thus the pointer
45 // adjustment will not be the same for all pointers of the
46 // same inner interface.
48 // For now, this table is ordered by the for_all_supers
49 // traversal, but eventually it'd be nice to sort it
50 // by GUID pointer (and yes, that change will break ABI
53 ::System::RunTime::IFaceTable System_IDLIDL_Object;
55 // This is a NULL pointer to mark the end of the GUID
59 // Finally, the method pointers are provided.
60 // There are currently no methods in System::Object.
66 const info_type *info;
78 Object(_i_Object *other)
83 operator _i_Object *()
91 template<typename T> struct Array {
95 bool valid_index(size_t index)
97 return index >= 0 && index < count;
100 T &operator[](size_t index)
102 #ifndef NO_ARRAY_BOUNDS_CHECK
103 if (!valid_index(index))
104 throw SomeException();
111 uintptr_t downcast(::System::_i_Object *obj, unsigned char *new_guid)
113 IFaceTable *tbl = obj->info->concrete_IFaceTable;
114 int index = 0, found_index = -1;
116 while (tbl->guid != new_guid) {
123 uintptr_t ptr = (uintptr_t)obj;
125 ptr += obj->info->concrete;
132 struct NotifierInfo {
138 struct NotifierInfo : public ::System::NotifierInfo {
141 // Yuck. Hack to work around broken enum-scoping and
142 // undefined enum-width.
144 static const uint32_t Success = 0;
145 static const uint32_t NoMoreData = 1;
146 static const uint32_t NoMoreSpace = 2;
147 static const uint32_t IOError = 3;
148 static const uint32_t BadHandle = 4;
149 static const uint32_t PipeClosed = 5;
151 // Double yuck... Is there any sane way to avoid exposing
152 // a leading underscore to the user, without potential conflicts
153 // with enum values? Perhaps "enumval" could be made a reserved
159 // Note the absence of "virtual"... We don't want to use the
160 // compiler's virtual table implementation, as we can't rely on it
161 // to be compatible with any other language or compiler (or even
162 // other versions of itself), and we also need the object ID to be
163 // at a specific offset from the pointer. We manage all virtual
164 // table operations (including RTTI) ourselves. Note that it is
165 // an error if the compiler emits a virtual table (or anything
166 // else not asked for) for any reason.
168 // Unfortunately, this could deprive some compilers of optimization
169 // information (such as for inlining when the concrete type is known
170 // and the implementation is present in the same compilation unit).
171 // A compiler which explicitly supports our standard vtable layout
172 // could use alternate stub code that makes use of such support.
175 static const unsigned char guid[];
178 // The info struct from the closest superinterface
179 // which shares this pointer is included first.
180 ::System::_i_Object::info_type parent;
183 IFaceTable System_IDLIDL_IO_IDLIDL_IStream;
184 IFaceTable System_IDLIDL_Object;
189 void (*read)(::System::IO::_i_IStream *_this,
190 Array<char> *buf, uint64_t *len);
192 void (*read_async)(::System::IO::_i_IStream *_this,
193 Array<unsigned char> *buf,
194 ::System::Notifier *notifier);
203 void read(unsigned char &*buf, size_t &_count_buf, uint64_t &len)
205 _ptr->info->methods.read(this, buf, _count_buf, len);
208 void read_async(unsigned char *buf, size_t _count_buf,
209 ::System::Notifier *notifier)
211 _ptr->info->methods.read_async(this, buf, _count_buf, notifier);
219 IStream(_i_IStream *other)
224 operator _i_IStream *()
229 // Returns NULL if the downcast fails. Upcasts never fail.
230 // "downcast" is (will be) a reserved word in IDL, or at least
231 // in the C++ binding.
233 static IStream downcast(::System::Object oldptr)
235 return IStream(reinterpret_cast<_i_IStream *>
236 (::System::RunTime::downcast(oldptr, _i_IStream::guid)));
239 operator ::System::Object()
241 uintptr_t ptr = reinterpret_cast<uintptr_t>(this);
242 ptr += _ptr->info->System_IDLIDL_Object.offset;
243 return ::System::Object(reinterpret_cast<::System::_i_Object *>(ptr));
248 static const unsigned char guid[];
251 ::System::Object::info parent;
254 unsigned char *System_IDLIDL_IO_IDLIDL_OStream;
255 unsigned char *System_IDLIDL_Object;
260 int32_t System_IDLIDL_IO_IDLIDL_OStream;
261 int32_t System_IDLIDL_Object;
265 void (*write)(::System::IO::_i_OStream *_this, unsigned char *buf,
266 size_t *_count_buf, uint64_t *len);
268 void (*write_async)(::System::IO::_i_OStream *this, unsigned char *buf,
269 size_t count_buf, ::System::Notifier *notifier);
273 const info_type info;
275 void write(unsigned char *buf, size_t _count_buf, uint64_t &len)
277 info->methods.write(this, buf, _count_buf, len);
280 void write_async(unsigned char *buf, size_t _count_buf,
281 ::System::Notifier *notifier)
283 info->methods.write_async(this, buf, _count_buf, notifier);
286 static ::System::IO::OStream *downcast(::System::Object *obj)
288 return (::System::IO::OStream *)
289 ::System::RunTime::downcast(obj, ::System::IO::OStream::guid);
292 ::System::Object *upcast(::System::Object *type)
294 uintptr_t ptr = (uintptr_t)this;
295 ptr += info->casts.System_IDLIDL_Object;
296 return (::System::Object *)ptr;
302 static const unsigned char guid[];
305 // Share a pointer with the left-most superinterface
306 ::System::IO::_i_IStream::info parent;
309 unsigned char *System_IDLIDL_IO_IDLIDL_IOStream;
310 unsigned char *System_IDLIDL_IO_IDLIDL_IStream;
311 unsigned char *System_IDLIDL_IO_IDLIDL_OStream;
312 unsigned char *System_IDLIDL_Object;
317 int32_t System_IDLIDL_IO_IDLIDL_IOStream;
318 int32_t System_IDLIDL_IO_IDLIDL_IStream;
319 int32_t System_IDLIDL_IO_IDLIDL_OStream;
320 int32_t System_IDLIDL_Object;
324 void (*read)(::System::IO::_i_IStream *_this,
325 Array<char> *buf, uint64_t *len);
327 void (*read_async)(::System::IO::_i_IStream *_this,
328 Array<unsigned char> *buf,
329 ::System::Notifier *notifier);
331 void (*write)(::System::IO::_i_OStream *_this, unsigned char *buf,
332 size_t *_count_buf, uint64_t *len);
334 void (*write_async)(::System::IO::_i_OStream *this, unsigned char *buf,
335 size_t count_buf, ::System::Notifier *notifier);
339 const info_type *info;
341 ::System::_i_OStream::info *info_System_IDLIDL_OStream;
348 void read(unsigned char &*buf, size_t &_count_buf, uint64_t &len)
350 info->parent.methods.read(this, buf, _count_buf, len);
353 void read_async(unsigned char *buf, size_t _count_buf,
354 ::System::Notifier *notifier)
356 info->parent.methods.read_async(this, buf, _count_buf, notifier);
359 void write(unsigned char *buf, size_t _count_buf, uint64_t &len)
361 ::System::OStream *thisptr = upcast((::System::Ostream *)NULL);
362 info_System_IDLIDL_OStream.methods.write(this, buf, _count_buf, len);
365 void write_async(unsigned char *buf, size_t _count_buf,
366 ::System::Notifier *notifier)
368 info_System_IDLIDL_OStream.methods.write_async
369 (this, buf, _count_buf, notifier);
372 static ::System::IO::OStream *downcast(::System::Object *obj)
374 return (::System::IO::OStream *)
375 ::System::RunTime::downcast(obj, ::System::IO::OStream::guid);
378 ::System::Object *upcast(::System::Object *type)
380 uintptr_t ptr = (uintptr_t)this;
381 ptr += info->casts.System_IDLIDL_Object;
382 return (::System::Object *)ptr;
391 struct OStream : public ::System::Object {
392 void write(unsigned char *buf, size_t _count_buf, uint64_t &len) = 0;
395 struct IOStream : public IStream, OStream {
398 struct FStream : public IOStream {
399 void set_file(File *f) = 0;
400 void get_file(File &*f) = 0;
413 class PhysAddrSpace {
425 _inproc_MapHandle(void **vtable) : _vtable(vtable)
430 void unmap(Region *regions, size_t count)
435 class _remote_MapHandle : public MapHandle {
437 void unmap(Region *regions, size_t count)
443 // If implemented here, user supplies:
444 class RealMapHandle : public MapHandle {
445 void unmap(Region *regions, size_t count) {
450 // This goes in a footer included in a non-header after the user's
451 // header, or perhaps in an idlc-generated .cc file (which would
452 // then need to know where the user's headers are located).
453 void _entries_RealMapHandle() {
454 // -Wno-pmf-conversions please...
455 typedef void (*unmap)(RealMapHandle *, Region *, size_t);
458 asm volatile(".global _entry_RealMapHandle\n"
459 "_entry_RealMapHandle:"
462 "jmpl %0;" : : "i" ((unmap)&RealMapHandle::MapHandle));
465 // Need to make sure that the branch is within range, or
467 asm volatile(".global _entry_RealMapHandle\n"
468 "_entry_RealMapHandle:"
471 "br %0;" : : "i" ((unmap)&RealMapHandle::MapHandle));
474 // FIXME: probably use sections here instead of a global
475 // constructor. This way, initialization can be ordered,
476 // and it'd be easier to extract a list of implemented
477 // classes from the binary.
479 class _init_RealMapHandle() {
481 _init_RealMapHandle()
486 ~_init_RealMapHandle()
488 // deregister -- or don't bother because it's
489 // the end of the program and it'll be unregistered
490 // automatically anyway?
494 _init_RealMapHandle _initinstance_RealMapHandle;
496 // If not implemented here...
498 class RealMapHandle : public MapHandle {
499 void unmap(Region *regions, size_t count) {
509 uint64_t get_size() = 0;
510 void get_size(uint64_t &size) = 0;
512 uint64_t get_block_size() = 0;
513 void get_block_size(uint64_t &block_size) = 0;