]> git.buserror.net Git - polintos/scott/priv.git/blobdiff - include/c++/orb.h
Some weak symbol usage, and some marshalling stuff.
[polintos/scott/priv.git] / include / c++ / orb.h
index 076f1ddea6e22aa4462ac40054ed6171bb08a7cb..1f1a3e6f6588586d69caec87fd0976ff6571c783 100644 (file)
@@ -4,6 +4,10 @@
 #include <stdint.h>
 #include <stddef.h>
 #include <string.h>
+#include <limits.h>
+
+#include <lowlevel/barriers.h>
+#include <lowlevel/bitops.h>
 
 namespace System {
        struct _i_Object;
@@ -125,6 +129,71 @@ namespace System {
                                return new_arr;
                        }
                };
+               
+               template<typename T>
+               struct GrowableArray : public MutableArray<T> {
+                       using MutableArray<T>::ptr;
+                       using MutableArray<T>::count;
+                       size_t bufsize;
+                       
+                       GrowableArray()
+                       {
+                               bufsize = 0;
+                       }
+                       
+                       GrowableArray(NullArray na) : MutableArray<T>(na)
+                       {
+                               bufsize = 0;
+                       }
+                       
+                       GrowableArray(T *PTR, size_t COUNT) : MutableArray<T>(PTR, COUNT)
+                       {
+                               bufsize = COUNT;
+                       }
+                       
+                       GrowableArray(T *PTR, size_t COUNT, size_t BUFSIZE) :
+                       MutableArray<T>(PTR, COUNT)
+                       {
+                               bufsize = BUFSIZE;
+                       }
+                       
+                       GrowableArray(MutableArray<T> &ma) : MutableArray<T>(ma)
+                       {
+                               bufsize = count;
+                       }
+                       
+                       void grow(size_t newsize)
+                       {
+                               if (newsize <= bufsize)
+                                       return;
+                               
+                               T *oldptr = ptr;
+                               T *newptr = new(orbmm) T[newsize];
+                               memcpy(newptr, ptr, count * sizeof(T));
+                               ptr = newptr;
+                               ll_smp_membar_store_after_store();
+                               bufsize = newsize;
+                               // FIXME: Should release imply membar?
+                               ll_smp_membar_any_after_store();
+                               orbmm->release(oldptr);
+                       }
+                       
+                       // Caller must sync against all writers.
+                       void append(T *newptr, size_t len, size_t max = ULONG_MAX)
+                       {
+                               if (count + len < count)
+                                       throw ArrayException();
+                               
+                               if (count + len > max)
+                                       throw ArrayException();
+                               
+                               if (count + len > bufsize)
+                                       grow(ll_get_order_round_up(count + len));
+                               
+                               memcpy(ptr + count, newptr, len * sizeof(T));
+                               count += len;
+                       }
+               };
 
                template<typename T> struct Array {
                        const T *ptr;
@@ -239,31 +308,20 @@ namespace System {
                        return ret;
                }
                
+               struct IFaceInfo;
+               typedef uint32_t ID;
+
                struct IFaceTable {
-                       const unsigned long *const guid;
+                       const IFaceInfo *info;
                        const ptrdiff_t offset;
                };
                
-               struct VStructInfo {
-                       // List of GUIDs of the struct and its superstructs,
-                       // starting with System.VStruct and ending with
-                       // the concrete struct.
-                       
-                       const unsigned long *const *const guids;
-
-                       // Length of inheritance chain; 1 for System.VStruct
-                       
-                       const int chainlen;
-                       
-                       // Size of concrete vstruct
-                       
-                       const int structlen;
+               union GUID {
+                       unsigned char c[16];
+                       unsigned long l[];
                };
-               
-               uintptr_t downcast(::System::_i_Object *obj,
-                                  const unsigned long *new_guid);
 
-               typedef u64 GUID[2];
+               uintptr_t downcast(::System::_i_Object *obj, const GUID *new_guid);
 
                // FIXME: use above typedef
                static inline bool guids_equal(const unsigned long *guid1,
@@ -276,12 +334,11 @@ namespace System {
                                  guid1[3] == guid2[3])));
                }
                
-               typedef uint32_t ID;
                struct ParamInfoBlock {
                        uint32_t buffer_size;
                        uint32_t copy_size;
-                       ID *objlist;
-                       uint32_t objlist_len;
+                       ID *objlist, *newobj;
+                       uint32_t objlist_len, newobj_len;
                        uint32_t num_segments;
 
                        struct Segment {
@@ -326,7 +383,43 @@ namespace System {
                        Segment0 seg0;
                        InvokeMethod invoke;
                };
-       
+
+               struct IFaceInfo {
+                       const GUID *guid;
+                       void (*invoke)(Array<ID> objlist,
+                                      ParamInfoBlock::Segment *segs,
+                                      int nsegs);
+                       ::System::_i_Object *(*wrapper)(ID id);
+               };
+               
+               struct NewObject {
+                       uint32_t guid_hash[5]; // SHA-1 hash of Interface GUIDs
+                       uint32_t id;
+                       uint32_t reserved[3]; // must be zero
+               };
+
+               struct VStructInfo {
+                       // List of GUIDs of the struct and its superstructs,
+                       // starting with System.VStruct and ending with
+                       // the concrete struct.
+                       
+                       const unsigned long *const *const guids;
+
+                       // Length of inheritance chain; 1 for System.VStruct
+                       
+                       const int chainlen;
+
+                       int (*marshall)(GrowableArray<uint8_t> &buf,
+                                       GrowableArray<ID> &objlist,
+                                       GrowableArray<NewObject> &newobjlist,
+                                       ParamInfoBlock::Segment *segs,
+                                       int nsegs);
+                       void (*unmarshall)(Array<uint8_t> buf,
+                                          Array< ::System::_i_Object *> objlist,
+                                          ParamInfoBlock::Segment *segs,
+                                          int nsegs);
+               };
+               
                namespace Priv {
                        // Return the caller's PC.  It'd be nice if GCC had a builtin for
                        // the current PC, so that a simple relocation could be used rather
@@ -343,15 +436,6 @@ namespace System {
                                return false;
 #endif
                        }
-
-                       typedef void (*MethodEntry)(ParamInfoBlock *pib);
-
-                       struct Object {
-                               MethodEntry entry;
-                               void *ptr; // pointer to the class interface
-                       };
-
-                       typedef Util::RadixTree<Object, ID, 6> ObjTable;
                }
        };
 }
@@ -368,6 +452,7 @@ inline void *operator new[](size_t len, ::System::RunTime::ORBMM *orbmm,
        return orbmm->alloc(len, refs);
 }
 
+// FIXME: This isn't safe on anything with a descructor.
 inline void operator delete(void *ptr, ::System::RunTime::ORBMM *orbmm,
                             int refs = 1)
 {
@@ -393,7 +478,7 @@ inline void operator delete[](void *ptr, ::System::RunTime::ORBMM *orbmm,
        throw T(NULL, NULL, \
                new(::System::RunTime::orbmm) \
                   ::System::Exceptions::NativeCodeExceptionOriginInfo \
-                  (::System::RunTime::get_pc()), \
+                  (::System::RunTime::Priv::get_pc()), \
                ::System::RunTime::Priv::in_kernel(), ##args); \
 } while (0)
 
@@ -401,7 +486,7 @@ inline void operator delete[](void *ptr, ::System::RunTime::ORBMM *orbmm,
        throw T(new(::System::RunTime::orbmm) typeof(oldex)(oldex), NULL, \
                new(::System::RunTime::orbmm) \
                   ::System::Exceptions::NativeCodeExceptionOriginInfo \
-                  (::System::RunTime::get_pc()), \
+                  (::System::RunTime::Priv::get_pc()), \
                ::System::RunTime::Priv::in_kernel(), ##args); \
 } while (0)
 #endif