2009-03-04 03:31:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANDROID_MEMORY_HEAP_BASE_H
|
|
|
|
#define ANDROID_MEMORY_HEAP_BASE_H
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2009-05-20 02:08:10 +00:00
|
|
|
#include <binder/IMemory.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2011-06-22 20:58:59 +00:00
|
|
|
class MemoryHeapBase : public virtual BnMemoryHeap
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
READ_ONLY = IMemoryHeap::READ_ONLY,
|
|
|
|
// memory won't be mapped locally, but will be mapped in the remote
|
|
|
|
// process.
|
2009-10-30 05:55:00 +00:00
|
|
|
DONT_MAP_LOCALLY = 0x00000100,
|
|
|
|
NO_CACHING = 0x00000200
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
2011-06-22 20:58:59 +00:00
|
|
|
/*
|
2009-03-04 03:31:44 +00:00
|
|
|
* maps the memory referenced by fd. but DOESN'T take ownership
|
|
|
|
* of the filedescriptor (it makes a copy with dup()
|
|
|
|
*/
|
2009-08-17 20:28:30 +00:00
|
|
|
MemoryHeapBase(int fd, size_t size, uint32_t flags = 0, uint32_t offset = 0);
|
2011-06-22 20:58:59 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
/*
|
|
|
|
* maps memory from the given device
|
|
|
|
*/
|
|
|
|
MemoryHeapBase(const char* device, size_t size = 0, uint32_t flags = 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* maps memory from ashmem, with the given name for debugging
|
|
|
|
*/
|
|
|
|
MemoryHeapBase(size_t size, uint32_t flags = 0, char const* name = NULL);
|
|
|
|
|
|
|
|
virtual ~MemoryHeapBase();
|
|
|
|
|
|
|
|
/* implement IMemoryHeap interface */
|
|
|
|
virtual int getHeapID() const;
|
2012-09-25 22:28:44 +00:00
|
|
|
|
|
|
|
/* virtual address of the heap. returns MAP_FAILED in case of error */
|
2009-03-04 03:31:44 +00:00
|
|
|
virtual void* getBase() const;
|
2012-09-25 22:28:44 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
virtual size_t getSize() const;
|
|
|
|
virtual uint32_t getFlags() const;
|
2012-09-25 22:28:44 +00:00
|
|
|
virtual uint32_t getOffset() const;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
const char* getDevice() const;
|
2011-06-22 20:58:59 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
/* this closes this heap -- use carefully */
|
|
|
|
void dispose();
|
|
|
|
|
|
|
|
/* this is only needed as a workaround, use only if you know
|
|
|
|
* what you are doing */
|
|
|
|
status_t setDevice(const char* device) {
|
|
|
|
if (mDevice == 0)
|
|
|
|
mDevice = device;
|
|
|
|
return mDevice ? NO_ERROR : ALREADY_EXISTS;
|
|
|
|
}
|
2011-06-22 20:58:59 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
protected:
|
|
|
|
MemoryHeapBase();
|
|
|
|
// init() takes ownership of fd
|
|
|
|
status_t init(int fd, void *base, int size,
|
2011-06-22 20:58:59 +00:00
|
|
|
int flags = 0, const char* device = NULL);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
private:
|
2009-08-17 20:28:30 +00:00
|
|
|
status_t mapfd(int fd, size_t size, uint32_t offset = 0);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
int mFD;
|
|
|
|
size_t mSize;
|
|
|
|
void* mBase;
|
|
|
|
uint32_t mFlags;
|
|
|
|
const char* mDevice;
|
|
|
|
bool mNeedUnmap;
|
2011-06-22 20:58:59 +00:00
|
|
|
uint32_t mOffset;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|
|
|
|
|
|
|
|
#endif // ANDROID_MEMORY_HEAP_BASE_H
|