diff options
Diffstat (limited to 'include/binder')
-rw-r--r-- | include/binder/IBinder.h | 2 | ||||
-rw-r--r-- | include/binder/IMemory.h | 3 | ||||
-rw-r--r-- | include/binder/IPCThreadState.h | 10 | ||||
-rw-r--r-- | include/binder/MemoryDealer.h | 215 | ||||
-rw-r--r-- | include/binder/MemoryHeapBase.h | 1 | ||||
-rw-r--r-- | include/binder/MemoryHeapPmem.h | 7 | ||||
-rw-r--r-- | include/binder/Parcel.h | 4 |
7 files changed, 26 insertions, 216 deletions
diff --git a/include/binder/IBinder.h b/include/binder/IBinder.h index 884b5c1..749a977 100644 --- a/include/binder/IBinder.h +++ b/include/binder/IBinder.h @@ -52,7 +52,7 @@ public: DUMP_TRANSACTION = B_PACK_CHARS('_','D','M','P'), INTERFACE_TRANSACTION = B_PACK_CHARS('_', 'N', 'T', 'F'), - // Corresponds to tfOneWay -- an asynchronous call. + // Corresponds to TF_ONE_WAY -- an asynchronous call. FLAG_ONEWAY = 0x00000001 }; diff --git a/include/binder/IMemory.h b/include/binder/IMemory.h index ae042cb..74d2cc7 100644 --- a/include/binder/IMemory.h +++ b/include/binder/IMemory.h @@ -36,8 +36,7 @@ public: // flags returned by getFlags() enum { - READ_ONLY = 0x00000001, - MAP_ONCE = 0x00000002 + READ_ONLY = 0x00000001 }; virtual int getHeapID() const = 0; diff --git a/include/binder/IPCThreadState.h b/include/binder/IPCThreadState.h index 78306b2..3ab985d 100644 --- a/include/binder/IPCThreadState.h +++ b/include/binder/IPCThreadState.h @@ -68,6 +68,13 @@ public: static void shutdown(); + // Call this to disable switching threads to background scheduling when + // receiving incoming IPC calls. This is specifically here for the + // Android system process, since it expects to have background apps calling + // in to it but doesn't want to acquire locks in its services while in + // the background. + static void disableBackgroundScheduling(bool disable); + private: IPCThreadState(); ~IPCThreadState(); @@ -93,9 +100,10 @@ private: void* cookie); const sp<ProcessState> mProcess; + const pid_t mMyThreadId; Vector<BBinder*> mPendingStrongDerefs; Vector<RefBase::weakref_type*> mPendingWeakDerefs; - + Parcel mIn; Parcel mOut; status_t mLastError; diff --git a/include/binder/MemoryDealer.h b/include/binder/MemoryDealer.h index 03ac70a..170f20d 100644 --- a/include/binder/MemoryDealer.h +++ b/include/binder/MemoryDealer.h @@ -22,232 +22,35 @@ #include <sys/types.h> #include <binder/IMemory.h> -#include <utils/threads.h> #include <binder/MemoryHeapBase.h> namespace android { // ---------------------------------------------------------------------------- -class String8; -/* - * interface for implementing a "heap". A heap basically provides - * the IMemoryHeap interface for cross-process sharing and the - * ability to map/unmap pages within the heap. - */ -class HeapInterface : public virtual BnMemoryHeap -{ -public: - // all values must be page-aligned - virtual sp<IMemory> mapMemory(size_t offset, size_t size) = 0; - - HeapInterface(); -protected: - virtual ~HeapInterface(); -}; - -// ---------------------------------------------------------------------------- - -/* - * interface for implementing an allocator. An allocator provides - * methods for allocating and freeing memory blocks and dumping - * its state. - */ -class AllocatorInterface : public RefBase -{ -public: - enum { - PAGE_ALIGNED = 0x00000001 - }; - - virtual size_t allocate(size_t size, uint32_t flags = 0) = 0; - virtual status_t deallocate(size_t offset) = 0; - virtual size_t size() const = 0; - virtual void dump(const char* what, uint32_t flags = 0) const = 0; - virtual void dump(String8& res, - const char* what, uint32_t flags = 0) const = 0; - - AllocatorInterface(); -protected: - virtual ~AllocatorInterface(); -}; - -// ---------------------------------------------------------------------------- - -/* - * concrete implementation of HeapInterface on top of mmap() - */ -class SharedHeap : public HeapInterface, public MemoryHeapBase -{ -public: - SharedHeap(); - SharedHeap(size_t size, uint32_t flags = 0, char const * name = NULL); - virtual ~SharedHeap(); - virtual sp<IMemory> mapMemory(size_t offset, size_t size); -}; - -// ---------------------------------------------------------------------------- - -/* - * A simple templatized doubly linked-list implementation - */ - -template <typename NODE> -class LinkedList -{ - NODE* mFirst; - NODE* mLast; - -public: - LinkedList() : mFirst(0), mLast(0) { } - bool isEmpty() const { return mFirst == 0; } - NODE const* head() const { return mFirst; } - NODE* head() { return mFirst; } - NODE const* tail() const { return mLast; } - NODE* tail() { return mLast; } - - void insertAfter(NODE* node, NODE* newNode) { - newNode->prev = node; - newNode->next = node->next; - if (node->next == 0) mLast = newNode; - else node->next->prev = newNode; - node->next = newNode; - } - - void insertBefore(NODE* node, NODE* newNode) { - newNode->prev = node->prev; - newNode->next = node; - if (node->prev == 0) mFirst = newNode; - else node->prev->next = newNode; - node->prev = newNode; - } - - void insertHead(NODE* newNode) { - if (mFirst == 0) { - mFirst = mLast = newNode; - newNode->prev = newNode->next = 0; - } else { - newNode->prev = 0; - newNode->next = mFirst; - mFirst->prev = newNode; - mFirst = newNode; - } - } - - void insertTail(NODE* newNode) { - if (mLast == 0) { - insertHead(newNode); - } else { - newNode->prev = mLast; - newNode->next = 0; - mLast->next = newNode; - mLast = newNode; - } - } - - NODE* remove(NODE* node) { - if (node->prev == 0) mFirst = node->next; - else node->prev->next = node->next; - if (node->next == 0) mLast = node->prev; - else node->next->prev = node->prev; - return node; - } -}; - - -/* - * concrete implementation of AllocatorInterface using a simple - * best-fit allocation scheme - */ -class SimpleBestFitAllocator : public AllocatorInterface -{ -public: - - SimpleBestFitAllocator(size_t size); - virtual ~SimpleBestFitAllocator(); - - virtual size_t allocate(size_t size, uint32_t flags = 0); - virtual status_t deallocate(size_t offset); - virtual size_t size() const; - virtual void dump(const char* what, uint32_t flags = 0) const; - virtual void dump(String8& res, - const char* what, uint32_t flags = 0) const; - -private: - - struct chunk_t { - chunk_t(size_t start, size_t size) - : start(start), size(size), free(1), prev(0), next(0) { - } - size_t start; - size_t size : 28; - int free : 4; - mutable chunk_t* prev; - mutable chunk_t* next; - }; - - ssize_t alloc(size_t size, uint32_t flags); - chunk_t* dealloc(size_t start); - void dump_l(const char* what, uint32_t flags = 0) const; - void dump_l(String8& res, const char* what, uint32_t flags = 0) const; - - static const int kMemoryAlign; - mutable Mutex mLock; - LinkedList<chunk_t> mList; - size_t mHeapSize; -}; +class SimpleBestFitAllocator; // ---------------------------------------------------------------------------- class MemoryDealer : public RefBase { public: + MemoryDealer(size_t size, const char* name = 0); - enum { - READ_ONLY = MemoryHeapBase::READ_ONLY, - PAGE_ALIGNED = AllocatorInterface::PAGE_ALIGNED - }; - - // creates a memory dealer with the SharedHeap and SimpleBestFitAllocator - MemoryDealer(size_t size, uint32_t flags = 0, const char* name = 0); - - // provide a custom heap but use the SimpleBestFitAllocator - MemoryDealer(const sp<HeapInterface>& heap); - - // provide both custom heap and allocotar - MemoryDealer( - const sp<HeapInterface>& heap, - const sp<AllocatorInterface>& allocator); - - virtual sp<IMemory> allocate(size_t size, uint32_t flags = 0); + virtual sp<IMemory> allocate(size_t size); virtual void deallocate(size_t offset); - virtual void dump(const char* what, uint32_t flags = 0) const; - + virtual void dump(const char* what) const; sp<IMemoryHeap> getMemoryHeap() const { return heap(); } - sp<AllocatorInterface> getAllocator() const { return allocator(); } protected: virtual ~MemoryDealer(); -private: - const sp<HeapInterface>& heap() const; - const sp<AllocatorInterface>& allocator() const; - - class Allocation : public BnMemory { - public: - Allocation(const sp<MemoryDealer>& dealer, - ssize_t offset, size_t size, const sp<IMemory>& memory); - virtual ~Allocation(); - virtual sp<IMemoryHeap> getMemory(ssize_t* offset, size_t* size) const; - private: - sp<MemoryDealer> mDealer; - ssize_t mOffset; - size_t mSize; - sp<IMemory> mMemory; - }; +private: + const sp<IMemoryHeap>& heap() const; + SimpleBestFitAllocator* allocator() const; - sp<HeapInterface> mHeap; - sp<AllocatorInterface> mAllocator; + sp<IMemoryHeap> mHeap; + SimpleBestFitAllocator* mAllocator; }; diff --git a/include/binder/MemoryHeapBase.h b/include/binder/MemoryHeapBase.h index d793c24..2f2e31b 100644 --- a/include/binder/MemoryHeapBase.h +++ b/include/binder/MemoryHeapBase.h @@ -32,7 +32,6 @@ class MemoryHeapBase : public virtual BnMemoryHeap public: enum { READ_ONLY = IMemoryHeap::READ_ONLY, - MAP_ONCE = IMemoryHeap::MAP_ONCE, // memory won't be mapped locally, but will be mapped in the remote // process. DONT_MAP_LOCALLY = 0x00000100, diff --git a/include/binder/MemoryHeapPmem.h b/include/binder/MemoryHeapPmem.h index dbf26ff..e1660c4 100644 --- a/include/binder/MemoryHeapPmem.h +++ b/include/binder/MemoryHeapPmem.h @@ -20,10 +20,10 @@ #include <stdlib.h> #include <stdint.h> -#include <binder/MemoryDealer.h> #include <binder/MemoryHeapBase.h> #include <binder/IMemory.h> #include <utils/SortedVector.h> +#include <utils/threads.h> namespace android { @@ -31,7 +31,7 @@ class MemoryHeapBase; // --------------------------------------------------------------------------- -class MemoryHeapPmem : public HeapInterface, public MemoryHeapBase +class MemoryHeapPmem : public MemoryHeapBase { public: class MemoryPmem : public BnMemory { @@ -46,8 +46,7 @@ public: sp<MemoryHeapPmem> mClientHeap; }; - MemoryHeapPmem(const sp<MemoryHeapBase>& pmemHeap, - uint32_t flags = IMemoryHeap::MAP_ONCE); + MemoryHeapPmem(const sp<MemoryHeapBase>& pmemHeap, uint32_t flags = 0); ~MemoryHeapPmem(); /* HeapInterface additions */ diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index ba6c711..66c34b2 100644 --- a/include/binder/Parcel.h +++ b/include/binder/Parcel.h @@ -30,6 +30,7 @@ class IBinder; class ProcessState; class String8; class TextOutput; +class Flattenable; struct flat_binder_object; // defined in support_p/binder_module.h @@ -81,6 +82,7 @@ public: status_t writeString16(const char16_t* str, size_t len); status_t writeStrongBinder(const sp<IBinder>& val); status_t writeWeakBinder(const wp<IBinder>& val); + status_t write(const Flattenable& val); // Place a native_handle into the parcel (the native_handle's file- // descriptors are dup'ed, so it is safe to delete the native_handle @@ -119,7 +121,7 @@ public: const char16_t* readString16Inplace(size_t* outLen) const; sp<IBinder> readStrongBinder() const; wp<IBinder> readWeakBinder() const; - + status_t read(Flattenable& val) const; // Retrieve native_handle from the parcel. This returns a copy of the // parcel's native_handle (the caller takes ownership). The caller |