]> git.buserror.net Git - polintos/scott/priv.git/commitdiff
Move arrays to Util namespace, add parametric allocator.
authorScott Wood <scott@thor.buserror.net>
Mon, 10 Dec 2007 04:06:38 +0000 (22:06 -0600)
committerScott Wood <scott@thor.buserror.net>
Mon, 10 Dec 2007 04:06:38 +0000 (22:06 -0600)
15 files changed:
idlcomp/languages/c++/main.cc
idlcomp/languages/c++/marshall.cc
idlcomp/tests/cpp-server.cc
idlcomp/vtable-sample.h
include/c++/orb.h
include/c++/util/array.h [new file with mode: 0644]
kernel/core/irq.cc
kernel/include/kern/console.h
kernel/include/kern/kernel.h
kernel/include/kern/mem.h
kernel/io/console/misc.cc
kernel/mem/addrspace.cc
kernel/mem/orbmm.cc
kernel/orb/invoke.cc
lib/c++/orb.cc

index 57f94556bb594a17bee0a493c64c88731ab98704..ab4289c596e5c3dee5e3af14e35d0c00e6ef9d47 100644 (file)
@@ -259,7 +259,7 @@ void cpp_output_type(ostream &file, Type *t, bool array, bool is_mutable)
        cpp_output_name(file, t);
 
        if (array)
-               file << ">";
+               file << ", ::System::RunTime::ORBMM>";
 
        file << ' ';
 }
@@ -293,7 +293,7 @@ void cpp_output_type(ostream &file, CompiledBasicType &t, bool is_mutable)
        }
        
        if (is_array(t))
-               file << '>';
+               file << ", ::System::RunTime::ORBMM>";
        
        file << ' ';
 }
index 6deb115ad7f2842a10c7a6accc6db0356456d7f2..bd1f4286f0f6a6ceb84278f60bf45f42449e7e35 100644 (file)
@@ -39,14 +39,14 @@ void CPPFile::output_marshall(Struct *sym, int pass)
                case trav_nsdecl:
                        extra_newline();
                        
-                       file << indent << "int _marshall(::System::RunTime::GrowableArray<uint8_t> &buf,\n"
-                            << indent << "              ::System::RunTime::GrowableArray< ::System::RunTime::ID> &objlist,\n"
-                            << indent << "              ::System::RunTime::GrowableArray< ::System::RunTime::NewObject> &newobjlist,\n"
+                       file << indent << "int _marshall(::System::RunTime::GrowableArray<uint8_t, ::System::RunTime::ORBMM> &buf,\n"
+                            << indent << "              ::System::RunTime::GrowableArray< ::System::RunTime::ID, ::System::RunTime::ORBMM> &objlist,\n"
+                            << indent << "              ::System::RunTime::GrowableArray< ::System::RunTime::NewObject, ::System::RunTime::ORBMM> &newobjlist,\n"
                             << indent << "              ::System::RunTime::ParamInfoBlock::Segment *segs,\n"
                             << indent << "              int nsegs);\n";
 
-                       file << indent << "void _unmarshall(::System::RunTime::Array<uint8_t> buf,\n"
-                            << indent << "                 ::System::RunTime::Array< ::System::_i_Object *> objlist,\n"
+                       file << indent << "void _unmarshall(::System::RunTime::Array<uint8_t, ::System::RunTime::ORBMM> buf,\n"
+                            << indent << "                 ::System::RunTime::Array< ::System::_i_Object *, ::System::RunTime::ORBMM> objlist,\n"
                             << indent << "                 ::System::RunTime::ParamInfoBlock::Segment *segs,\n"
                             << indent << "                 int nsegs);\n";
 
index 528ee1eefabcdb3af762604c2cdc6f8ea72c39a5..02d4924744a8d66cb406692487945e9cc5856a13 100644 (file)
@@ -5,7 +5,7 @@ using System::IO::File;
 using namespace System::IO::FileStream_ns;
 using System::RunTime::Array;
 using System::RunTime::MutableArray;
-
+using System::RunTime::ORBMM;
 
 namespace Stuff {
        using System::Notifiers::Notifier;
@@ -79,7 +79,7 @@ public:
                f.size(size);
        }
        
-       void read(Array<uint8_t> *buf, uint64_t *len)
+       void read(Array<uint8_t, ORBMM> *buf, uint64_t *len)
        {
                if (!f) {
                        // throw exc
@@ -90,7 +90,7 @@ public:
                pos += *len;
        }
 
-       void read_foo(MutableArray<uint8_t> buf, uint64_t len, Notifier n)
+       void read_foo(MutableArray<uint8_t, ORBMM> buf, uint64_t len, Notifier n)
        {
                if (!f) {
                        // throw exc
@@ -101,7 +101,7 @@ public:
                pos += len;
        }
 
-       void write(Array<uint8_t> buf, uint64_t *len)
+       void write(Array<uint8_t, ORBMM> buf, uint64_t *len)
        {
                if (!f) {
                        // throw exc
@@ -112,7 +112,7 @@ public:
                pos += *len;
        }
 
-       void write_foo(Array<uint8_t> buf, uint64_t len, Notifier n)
+       void write_foo(Array<uint8_t, ORBMM> buf, uint64_t len, Notifier n)
        {
                printf("write_foo, this %p\n", this);
        
@@ -155,11 +155,11 @@ int main()
        }
        
        printf("fs is %p\n", (void *)fs);
-       fs.write_async(Array<uint8_t>(NULL, 0), 0, NULL);
+       fs.write_async(nullarray, 0, NULL);
        printf("fs is %p\n", (void *)fs);
        System::IO::OStream ostr = fs;
        printf("ostr is %p\n", (void *)ostr);
-       ostr.write_async(Array<uint8_t>(NULL, 0), 0, NULL);
+       ostr.write_async(nullarray, 0, NULL);
        System::Object obj = fs;
        System::IO::FileStream fs2 = System::IO::FileStream::downcast(obj);
        System::IO::OStream os2 = System::IO::OStream::downcast(obj);
index bffd75fa43c8b4d05c17dac5b564db8124414ce3..eff0f4c1b65af2cd93ca0d688711f76030385117 100644 (file)
@@ -187,10 +187,10 @@ namespace IO {
 
                        struct methods {
                                void (*read)(::System::IO::_i_IStream *_this, 
-                                            Array<char> *buf, uint64_t *len);
+                                            Array<char, ::System::RunTime::ORBMM> *buf, uint64_t *len);
                                
                                void (*read_async)(::System::IO::_i_IStream *_this,
-                                                  Array<unsigned char> *buf,
+                                                  Array<unsigned char, ::System::RunTime::ORBMM> *buf,
                                                   ::System::Notifier *notifier);
                        } methods;
                } info;
@@ -322,10 +322,10 @@ namespace IO {
 
                        struct methods {
                                void (*read)(::System::IO::_i_IStream *_this, 
-                                            Array<char> *buf, uint64_t *len);
+                                            Array<char, ::System::RunTime::ORBMM> *buf, uint64_t *len);
                                
                                void (*read_async)(::System::IO::_i_IStream *_this,
-                                                  Array<unsigned char> *buf,
+                                                  Array<unsigned char, ::System::RunTime::ORBMM> *buf,
                                                   ::System::Notifier *notifier);
 
                                void (*write)(::System::IO::_i_OStream *_this, unsigned char *buf,
index 1f1a3e6f6588586d69caec87fd0976ff6571c783..a2ead4d67fde25486c28f3412fcc0030265c00a1 100644 (file)
@@ -9,6 +9,8 @@
 #include <lowlevel/barriers.h>
 #include <lowlevel/bitops.h>
 
+#include <util/array.h>
+
 namespace System {
        struct _i_Object;
 
@@ -17,296 +19,19 @@ namespace System {
        }
 
        namespace RunTime {
+               using namespace ::Util::Arrays;
+               
                class ORBMM {
-                       void *priv;
+                       static void *priv;
                        
                public:
-                       class AllocGroup {
-                               friend class ORBMM;
-                       };
-                       
                        typedef ::System::Mem::Region Region;
                        
-                       ORBMM();
-                       
-                       void *alloc(size_t size, int refs = 1);
-                       void retain(void *ptr, int refs = 1);
-                       void release(void *ptr, int refs = 1);
-                       void add_region(Region region, bool unmap_orig, int refs = 1);
-               };
-               
-               extern ORBMM *orbmm;
-               
-               // FIXME: should be an IDL exception
-               struct ArrayException
-               {
-               };
-               
-               class NullArray {
-               };
-               
-               static const NullArray nullarray = {};
-               
-               template<typename T> struct MutableArray {
-                       T *ptr;
-                       size_t count;
-               
-                       bool valid_index(size_t index)
-                       {
-                               return index >= 0 && index < count;
-                       }
-                       
-                       T &operator[](size_t index)
-                       {
-#ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
-                               if (!valid_index(index))
-                                       throw ArrayException();
-#endif
-               
-                               return ptr[index];
-                       }
-                       
-                       MutableArray()
-                       {
-                               ptr = NULL;
-                               count = 0;
-                       }
-                       
-                       MutableArray(NullArray na)
-                       {
-                               ptr = NULL;
-                               count = 0;
-                       }
-                       
-                       MutableArray(T *PTR, size_t COUNT)
-                       {
-                               ptr = PTR;
-                               count = COUNT;
-                       }
-                       
-                       MutableArray &slice_nocheck(size_t first, size_t newcount)
-                       {
-                               MutableArray ret;
-                               ret.ptr = ptr + first;
-                               ret.count = newcount;
-                               return ret;
-                       }
-
-                       MutableArray &slice_nocheck(size_t first)
-                       {
-                               MutableArray ret;
-                               ret.ptr = ptr + first;
-                               ret.count = count - first;
-                               return ret;
-                       }
-
-                       MutableArray &slice(size_t first, size_t count)
-                       {
-#ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
-                               if (!valid_index(first) || !valid_index(first + count - 1))
-                                       throw ArrayException();
-#endif
-                               
-                               return slice_nocheck(first, count);
-                       }
-
-                       MutableArray &slice(size_t first)
-                       {
-#ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
-                               if (!valid_index(first))
-                                       throw ArrayException();
-#endif
-                               
-                               return slice_nocheck(first);
-                       }
-                       
-                       MutableArray copy()
-                       {
-                               MutableArray new_arr;
-                               new_arr.ptr = new(orbmm) T[count];
-                               new_arr.count = count;
-                               memcpy(new_arr.ptr, ptr, count);
-                               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;
-                       }
+                       static void *alloc(size_t size, int refs = 1);
+                       static void retain(void *ptr, int refs = 1);
+                       static void release(void *ptr, int refs = 1);
+                       static void add_region(Region region, bool unmap_orig, int refs = 1);
                };
-
-               template<typename T> struct Array {
-                       const T *ptr;
-                       size_t count;
-               
-                       bool valid_index(size_t index)
-                       {
-                               return index >= 0 && index < count;
-                       }
-                       
-                       const T &operator[](size_t index)
-                       {
-#ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
-                               if (!valid_index(index))
-                                       throw ArrayException();
-#endif
-               
-                               return ptr[index];
-                       }
-                       
-                       Array()
-                       {
-                               ptr = NULL;
-                               count = 0;
-                       }
-                       
-                       Array(NullArray na)
-                       {
-                               ptr = NULL;
-                               count = 0;
-                       }
-                       
-                       Array(const T *PTR, size_t COUNT)
-                       {
-                               ptr = PTR;
-                               count = COUNT;
-                       }
-                       
-                       Array(MutableArray<T> ma)
-                       {
-                               ptr = ma.ptr;
-                               count = ma.count;
-                       }
-                       
-                       MutableArray<T> constcast()
-                       {
-                               MutableArray<T> ma;
-                               ma.ptr = const_cast<T>(ptr);
-                               ma.count = count;
-                               return ma;
-                       }
-                       
-                       Array &slice_nocheck(size_t first, size_t newcount)
-                       {
-                               Array ret;
-                               ret.ptr = ptr + first;
-                               ret.count = newcount;
-                               return ret;
-                       }
-
-                       Array &slice_nocheck(size_t first)
-                       {
-                               Array ret;
-                               ret.ptr = ptr + first;
-                               ret.count = count - first;
-                               return ret;
-                       }
-
-                       Array &slice(size_t first, size_t count)
-                       {
-#ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
-                               if (!valid_index(first) || !valid_index(first + count - 1))
-                                       throw ArrayException();
-#endif
-                               
-                               return slice_nocheck(first, count);
-                       }
-
-                       Array &slice(size_t first)
-                       {
-#ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
-                               if (!valid_index(first))
-                                       throw ArrayException();
-#endif
-                               
-                               return slice_nocheck(first);
-                       }
-                       
-                       MutableArray<T> copy()
-                       {
-                               MutableArray<T> new_arr;
-                               new_arr.ptr = new(orbmm) T[count];
-                               new_arr.count = count;
-                               memcpy(new_arr.ptr, ptr, count);
-                               return new_arr;
-                       }
-               };
-
-               static inline Array<uint8_t> countarray(const char *ptr)
-               {
-                       Array<uint8_t> ret;
-                       ret.ptr = reinterpret_cast<const uint8_t *>(ptr);
-                       ret.count = strlen(ptr);
-                       return ret;
-               }
-
-               static inline MutableArray<uint8_t> countarray(char *ptr)
-               {
-                       MutableArray<uint8_t> ret;
-                       ret.ptr = reinterpret_cast<uint8_t *>(ptr);
-                       ret.count = strlen(ptr);
-                       return ret;
-               }
                
                struct IFaceInfo;
                typedef uint32_t ID;
@@ -386,7 +111,7 @@ namespace System {
 
                struct IFaceInfo {
                        const GUID *guid;
-                       void (*invoke)(Array<ID> objlist,
+                       void (*invoke)(Array<ID, ORBMM> objlist,
                                       ParamInfoBlock::Segment *segs,
                                       int nsegs);
                        ::System::_i_Object *(*wrapper)(ID id);
@@ -409,13 +134,13 @@ namespace System {
                        
                        const int chainlen;
 
-                       int (*marshall)(GrowableArray<uint8_t> &buf,
-                                       GrowableArray<ID> &objlist,
-                                       GrowableArray<NewObject> &newobjlist,
+                       int (*marshall)(GrowableArray<uint8_t, ORBMM> &buf,
+                                       GrowableArray<ID, ORBMM> &objlist,
+                                       GrowableArray<NewObject, ORBMM> &newobjlist,
                                        ParamInfoBlock::Segment *segs,
                                        int nsegs);
-                       void (*unmarshall)(Array<uint8_t> buf,
-                                          Array< ::System::_i_Object *> objlist,
+                       void (*unmarshall)(Array<uint8_t, ORBMM> buf,
+                                          Array< ::System::_i_Object *, ORBMM> objlist,
                                           ParamInfoBlock::Segment *segs,
                                           int nsegs);
                };
@@ -440,29 +165,16 @@ namespace System {
        };
 }
 
-inline void *operator new(size_t len, ::System::RunTime::ORBMM *orbmm,
+inline void *operator new(size_t len, ::System::RunTime::ORBMM orbmm,
                           int refs = 1)
 {
-       return orbmm->alloc(len, refs);
-}
-
-inline void *operator new[](size_t len, ::System::RunTime::ORBMM *orbmm,
-                            int refs = 1)
-{
-       return orbmm->alloc(len, refs);
+       return ::System::RunTime::ORBMM::alloc(len, refs);
 }
 
-// FIXME: This isn't safe on anything with a descructor.
-inline void operator delete(void *ptr, ::System::RunTime::ORBMM *orbmm,
+inline void *operator new[](size_t len, ::System::RunTime::ORBMM orbmm,
                             int refs = 1)
 {
-       orbmm->release(ptr, refs);
-}
-
-inline void operator delete[](void *ptr, ::System::RunTime::ORBMM *orbmm,
-                              int refs = 1)
-{
-       orbmm->release(ptr, refs);
+       return ::System::RunTime::ORBMM::alloc(len, refs);
 }
 
 // This is a macro rather than an inline template function so that the
@@ -476,15 +188,15 @@ inline void operator delete[](void *ptr, ::System::RunTime::ORBMM *orbmm,
 #ifndef POLINTOS_NO_THROW_IDL
 #define throw_idl(T, args...) do { \
        throw T(NULL, NULL, \
-               new(::System::RunTime::orbmm) \
+               new(::System::RunTime::ORBMM()) \
                   ::System::Exceptions::NativeCodeExceptionOriginInfo \
                   (::System::RunTime::Priv::get_pc()), \
                ::System::RunTime::Priv::in_kernel(), ##args); \
 } while (0)
 
 #define rethrow_idl(oldex, T, args...) do { \
-       throw T(new(::System::RunTime::orbmm) typeof(oldex)(oldex), NULL, \
-               new(::System::RunTime::orbmm) \
+       throw T(new(::System::RunTime::ORBMM()) typeof(oldex)(oldex), NULL, \
+               new(::System::RunTime::ORBMM()) \
                   ::System::Exceptions::NativeCodeExceptionOriginInfo \
                   (::System::RunTime::Priv::get_pc()), \
                ::System::RunTime::Priv::in_kernel(), ##args); \
diff --git a/include/c++/util/array.h b/include/c++/util/array.h
new file mode 100644 (file)
index 0000000..80ba1c7
--- /dev/null
@@ -0,0 +1,305 @@
+// util/array.h -- Dynamically sized arrays
+//
+// This software is copyright (c) 2007 Scott Wood <scott@buserror.net>.
+// 
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors or contributors be held liable for any damages
+// arising from the use of this software.
+// 
+// Permission is hereby granted to everyone, free of charge, to use, copy,
+// modify, prepare derivative works of, publish, distribute, perform,
+// sublicense, and/or sell copies of the Software, provided that the above
+// copyright notice and disclaimer of warranty be included in all copies or
+// substantial portions of this software.
+
+#ifndef _UTIL_ARRAY_H
+#define _UTIL_ARRAY_H
+
+namespace System {
+namespace RunTime {
+       class ORBMM;
+}}
+
+namespace Util {
+       namespace Arrays {
+               struct ArrayException
+               {
+               };
+               
+               class NullArray {
+               };
+               
+               static const NullArray nullarray = {};
+               
+               template<typename T, typename Alloc = ::System::RunTime::ORBMM> struct MutableArray {
+                       T *ptr;
+                       size_t count;
+               
+                       bool valid_index(size_t index)
+                       {
+                               return index >= 0 && index < count;
+                       }
+                       
+                       T &operator[](size_t index)
+                       {
+#ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
+                               if (!valid_index(index))
+                                       throw ArrayException();
+#endif
+               
+                               return ptr[index];
+                       }
+                       
+                       MutableArray()
+                       {
+                               ptr = NULL;
+                               count = 0;
+                       }
+                       
+                       MutableArray(NullArray na)
+                       {
+                               ptr = NULL;
+                               count = 0;
+                       }
+                       
+                       MutableArray(T *PTR, size_t COUNT)
+                       {
+                               ptr = PTR;
+                               count = COUNT;
+                       }
+                       
+                       MutableArray &slice_nocheck(size_t first, size_t newcount)
+                       {
+                               MutableArray ret;
+                               ret.ptr = ptr + first;
+                               ret.count = newcount;
+                               return ret;
+                       }
+       
+                       MutableArray &slice_nocheck(size_t first)
+                       {
+                               MutableArray ret;
+                               ret.ptr = ptr + first;
+                               ret.count = count - first;
+                               return ret;
+                       }
+       
+                       MutableArray &slice(size_t first, size_t count)
+                       {
+#ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
+                               if (!valid_index(first) || !valid_index(first + count - 1))
+                                       throw ArrayException();
+#endif
+                               
+                               return slice_nocheck(first, count);
+                       }
+       
+                       MutableArray &slice(size_t first)
+                       {
+#ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
+                               if (!valid_index(first))
+                                       throw ArrayException();
+#endif
+                               
+                               return slice_nocheck(first);
+                       }
+                       
+                       MutableArray copy()
+                       {
+                               MutableArray new_arr;
+                               new_arr.ptr = new(Alloc()) T[count];
+                               new_arr.count = count;
+                               memcpy(new_arr.ptr, ptr, count);
+                               return new_arr;
+                       }
+               };
+               
+               template<typename T, typename Alloc = ::System::RunTime::ORBMM>
+               struct GrowableArray : public MutableArray<T, Alloc> {
+                       using MutableArray<T, Alloc>::ptr;
+                       using MutableArray<T, Alloc>::count;
+                       size_t bufsize;
+                       
+                       GrowableArray()
+                       {
+                               bufsize = 0;
+                       }
+                       
+                       GrowableArray(NullArray na) : MutableArray<T, Alloc>(na)
+                       {
+                               bufsize = 0;
+                       }
+                       
+                       GrowableArray(T *PTR, size_t COUNT) : MutableArray<T, Alloc>(PTR, COUNT)
+                       {
+                               bufsize = COUNT;
+                       }
+                       
+                       GrowableArray(T *PTR, size_t COUNT, size_t BUFSIZE) :
+                       MutableArray<T, Alloc>(PTR, COUNT)
+                       {
+                               bufsize = BUFSIZE;
+                       }
+                       
+                       GrowableArray(MutableArray<T, Alloc> &ma) : MutableArray<T, Alloc>(ma)
+                       {
+                               bufsize = count;
+                       }
+                       
+                       void grow(size_t newsize)
+                       {
+                               if (newsize <= bufsize)
+                                       return;
+                               
+                               T *oldptr = ptr;
+                               T *newptr = new(Alloc()) T[newsize];
+       
+                               memcpy(newptr, ptr, count * sizeof(T));
+       
+                               ptr = newptr;
+                               ll_smp_membar_store_after_store();
+                               bufsize = newsize;
+                               ll_smp_membar_any_after_store();
+       
+                               Alloc::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, typename Alloc = ::System::RunTime::ORBMM> struct Array {
+                       const T *ptr;
+                       size_t count;
+               
+                       bool valid_index(size_t index)
+                       {
+                               return index >= 0 && index < count;
+                       }
+                       
+                       const T &operator[](size_t index)
+                       {
+#ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
+                               if (!valid_index(index))
+                                       throw ArrayException();
+#endif
+               
+                               return ptr[index];
+                       }
+                       
+                       Array()
+                       {
+                               ptr = NULL;
+                               count = 0;
+                       }
+                       
+                       Array(NullArray na)
+                       {
+                               ptr = NULL;
+                               count = 0;
+                       }
+
+                       Array(const T *PTR, size_t COUNT)
+                       {
+                               ptr = PTR;
+                               count = COUNT;
+                       }
+                       
+                       Array(MutableArray<T, Alloc> ma)
+                       {
+                               ptr = ma.ptr;
+                               count = ma.count;
+                       }
+                       
+                       MutableArray<T, Alloc> constcast()
+                       {
+                               MutableArray<T, Alloc> ma;
+                               ma.ptr = const_cast<T>(ptr);
+                               ma.count = count;
+                               return ma;
+                       }
+                       
+                       Array &slice_nocheck(size_t first, size_t newcount)
+                       {
+                               Array ret;
+                               ret.ptr = ptr + first;
+                               ret.count = newcount;
+                               return ret;
+                       }
+       
+                       Array &slice_nocheck(size_t first)
+                       {
+                               Array ret;
+                               ret.ptr = ptr + first;
+                               ret.count = count - first;
+                               return ret;
+                       }
+       
+                       Array &slice(size_t first, size_t count)
+                       {
+#ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
+                               if (!valid_index(first) || !valid_index(first + count - 1))
+                                       throw ArrayException();
+#endif
+                               
+                               return slice_nocheck(first, count);
+                       }
+       
+                       Array &slice(size_t first)
+                       {
+#ifndef POLINTOS_NO_ARRAY_BOUNDS_CHECK
+                               if (!valid_index(first))
+                                       throw ArrayException();
+#endif
+                               
+                               return slice_nocheck(first);
+                       }
+                       
+                       MutableArray<T, Alloc> copy()
+                       {
+                               MutableArray<T, Alloc> new_arr;
+                               new_arr.ptr = new(Alloc()) T[count];
+                               new_arr.count = count;
+                               memcpy(new_arr.ptr, ptr, count);
+                               return new_arr;
+                       }
+               };
+       
+               template<typename Alloc>
+               static inline Array<uint8_t, Alloc>
+               countarray(const char *ptr)
+               {
+                       Array<uint8_t, Alloc> ret;
+                       ret.ptr = reinterpret_cast<const uint8_t *>(ptr);
+                       ret.count = strlen(ptr);
+                       return ret;
+               }
+       
+               template<typename Alloc>
+               static inline MutableArray<uint8_t, Alloc>
+               countarray(char *ptr)
+               {
+                       MutableArray<uint8_t, Alloc> ret;
+                       ret.ptr = reinterpret_cast<uint8_t *>(ptr);
+                       ret.count = strlen(ptr);
+                       return ret;
+               }
+       }
+       
+       using namespace Arrays;
+}
+
+#endif
index 577f63b149dbeef54c6b8aacaa2856594fbae68b..b9e84e6fed9a1b665e851c6e136b583b8ef7becd 100644 (file)
@@ -27,7 +27,7 @@ namespace IRQ {
                
                while (list) {
                        if (list == irq)
-                               throw_idl(ResourceBusy, -1, countarray("IRQ in use"));
+                               throw_idl(ResourceBusy, -1, countarray<ORBMM>("IRQ in use"));
                        
                        insert = &list->next;
                        list = *insert;
index 9da6977cf27ff4d428793a18ffe66ab5a348224a..174d4c6eba492ea397ec004467e3d7afa5a6f6a6 100644 (file)
@@ -11,7 +11,7 @@ namespace Console {
                {
                }
        
-               virtual void write(Array<octet> buf, u64 *len) = 0;
+               virtual void write(Array<octet, ORBMM> buf, u64 *len) = 0;
                void write(const char *data, size_t len);
        };
        
index f90d701dee6d3f06ebb045197be7801637cdb3e5..5d6e8b6d56cab66ef057c76659a0e7220a5ab2e4 100644 (file)
@@ -15,7 +15,7 @@
 using System::RunTime::countarray;
 using System::RunTime::Array;
 using System::RunTime::nullarray;
-using System::RunTime::orbmm;
+using System::RunTime::ORBMM;
 using System::Object;
 using System::Objects::Factory;
 using namespace System::Exceptions::Std;
index a143dfb7dcaa209f23085e13bf72f914697db246..eeb4e6e7975f9434c9d72ddb0814e2dfd9914ce1 100644 (file)
@@ -348,8 +348,6 @@ namespace Mem {
 
        extern Factory addr_space_factory, proc_addr_space_factory;
 
-       using ::System::RunTime::orbmm;
-       
        static inline bool page_aligned(u64 addr)
        {
                return !(addr & (u64)(Arch::page_size - 1));
index 7da03244e01d4bfbafd0f560fdf15fbde6e45315..fe91d18aa3ec26d8399dbc91875b8187a86b1c77 100644 (file)
@@ -21,7 +21,7 @@ namespace Console {
        void Console::write(const char *data, size_t len)
        {
                u64 len64 = len;
-               write(Array<octet>((octet *)data, len), &len64);
+               write(Array<octet, ORBMM>((octet *)data, len), &len64);
        }
        
        // All consoles will set this to themselves; the last console
index 78cbe5e6b573aa5c2429fcbd70ee5392cf478d9b..3280adde37e39109d696237810f4ee9cf7bc285e 100644 (file)
@@ -567,7 +567,7 @@ namespace Mem {
                
                if (mflags.Replace)
                        throw_idl(InvalidArgument, 3,
-                                 countarray("Replace unimplemented"));
+                                 countarray<ORBMM>("Replace unimplemented"));
                
                Mappable *cma = Mappable::classptr(ma);
                if (!cma) {
@@ -583,10 +583,10 @@ namespace Mem {
                        mflags.Fixed = 1;
                
                if (!page_aligned(region.start))
-                       throw_idl(InvalidArgument, 1, countarray("unaligned start"));
+                       throw_idl(InvalidArgument, 1, countarray<ORBMM>("unaligned start"));
                
                if (!page_aligned(region.end + 1))
-                       throw_idl(InvalidArgument, 1, countarray("unaligned end"));
+                       throw_idl(InvalidArgument, 1, countarray<ORBMM>("unaligned end"));
                
                Lock::AutoLock autolock(lock);
                Region vregion;
@@ -599,11 +599,11 @@ namespace Mem {
                        if (is_process) {
                                if (!valid_addr(vregion.start))
                                        throw_idl(InvalidArgument, 2,
-                                                 countarray("invalid virtual start"));
+                                                 countarray<ORBMM>("invalid virtual start"));
                                
                                if (!valid_addr(vregion.end))
                                        throw_idl(InvalidArgument, 2,
-                                                 countarray("invalid virtual end"));
+                                                 countarray<ORBMM>("invalid virtual end"));
                        }
                        
                        if (check_overlap(vregion, prev))
@@ -612,10 +612,10 @@ namespace Mem {
                
                if (*vstart == System::Mem::AddrSpace_ns::unspecified_start) {
                        if (fixed)
-                               throw_idl(ResourceBusy, 2, countarray("varea overlap"));
+                               throw_idl(ResourceBusy, 2, countarray<ORBMM>("varea overlap"));
                        
                        if (!get_free_region(region.end - region.start + 1, vregion, prev))
-                               throw_idl(OutOfSpace, countarray("out of vspace"));
+                               throw_idl(OutOfSpace, countarray<ORBMM>("out of vspace"));
                        
                        *vstart = vregion.start;
                }
index deb868932636f40790ffabf304239fd22ac88425..91187389af46184d0c4094628df4056453804344 100644 (file)
@@ -20,11 +20,6 @@ namespace RunTime {
        ORBMM orbmm_real;
        ORBMM *orbmm = &orbmm_real;
        
-       ORBMM::ORBMM()
-       {
-               priv = NULL;
-       }
-
        void *ORBMM::alloc(size_t size, int refs)
        {
                return reinterpret_cast<void *>(new u8[size]);
index 7fffb61ef2fde1bb1b8c00e17abea2aec434bcf5..ced7ad8469db3508d6cbf4706d4f6a46e59b3c96 100644 (file)
@@ -116,7 +116,7 @@ namespace ORB {
                        size_t len = round_up(spib->segments[i].len, 3);
 
                        if (len + copied > bufsize || len + copied < copied)
-                               throw_idl(InvalidArgument, 0, countarray("copy_data: bad size"));
+                               throw_idl(InvalidArgument, 0, countarray<ORBMM>("copy_data: bad size"));
                        
                        dpib->segments[i].ptr = vaddr;
                        dpib->segments[i].len = len;
@@ -161,13 +161,13 @@ namespace ORB {
                printf("objlist len %u\n", pib.objlist_len);
                
                if (pib.objlist_len == 0)
-                       throw_idl(InvalidArgument, 0, countarray("no objects"));
+                       throw_idl(InvalidArgument, 0, countarray<ORBMM>("no objects"));
                
                // FIXME: declare constants somewhere
                if (pib.num_segments > 64)
-                       throw_idl(InvalidArgument, 0, countarray("too many segments"));
+                       throw_idl(InvalidArgument, 0, countarray<ORBMM>("too many segments"));
                if (pib.objlist_len > 4096)
-                       throw_idl(InvalidArgument, 0, countarray("too many objects"));
+                       throw_idl(InvalidArgument, 0, countarray<ORBMM>("too many objects"));
                
                printf("&pib.objlist[0] %p\n", &pib.objlist[0]);
                
@@ -190,8 +190,8 @@ namespace ORB {
                        buflen += sizeof(ParamInfoBlock);
                        buflen += pib.num_segments * sizeof(ParamInfoBlock::Segment);
                        
-                       u8 *args = new(orbmm) u8[buflen];
-                       u8 *copy = new(orbmm) u8[pib.copy_size];
+                       u8 *args = new(ORBMM()) u8[buflen];
+                       u8 *copy = new(ORBMM()) u8[pib.copy_size];
                        ParamInfoBlock *dpib = reinterpret_cast<ParamInfoBlock *>
                                               (args + piboff);
                        dpib->objlist = reinterpret_cast<ID *>(args + datalen);
index 636ee9a9a8694930f973912c476b4c369f15d944..64df51756c86939a8106b11d8bad6137533bd617 100644 (file)
@@ -66,7 +66,7 @@ namespace RunTime {
                        return reinterpret_cast<unsigned long>(__builtin_return_address(0));
                }
 
-               void exception_to_array(::System::VStruct *ex, Array<uint8_t> *ar)
+               void exception_to_array(::System::VStruct *ex, Array<uint8_t, ORBMM> *ar)
                {
                        // FIXME: marshall struct
                }
@@ -95,7 +95,7 @@ namespace RunTime {
 extern "C" void abort();
 
 extern "C" void handle_message(::System::RunTime::ParamInfoBlock *pib,
-                               ::System::RunTime::Array<uint8_t> *ex_arr)
+                               ::System::RunTime::Array<uint8_t, ::System::RunTime::ORBMM> *ex_arr)
 {
        try {
                ::System::RunTime::Priv::handle_message(pib);