gralloc: Remove opaque types
Remove opaque types like size_t, uintptr_t, intptr_t to support
32bit and 64bit processes together.
When a 64bit process creates a handle and a 32bit process validates
the incoming ints against expected ints, opaque types lead to
different and mismatching values.
Always use unit64_t for base address for 32bit and 64bit SF.
Use unsigned int for offset and size, since ION uses that.
Change-Id: I7db5544556a8924f98010b965f837592e9f0b4ca
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index 1702336..6af0eea 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -394,9 +394,9 @@
}
// helper function
-size_t getSize(int format, int width, int height, const int alignedw,
+unsigned int getSize(int format, int width, int height, const int alignedw,
const int alignedh) {
- size_t size = 0;
+ unsigned int size = 0;
switch (format) {
case HAL_PIXEL_FORMAT_RGBA_8888:
@@ -433,7 +433,7 @@
}
size = alignedw*alignedh +
(ALIGN(alignedw/2, 16) * (alignedh/2))*2;
- size = ALIGN(size, (size_t)4096);
+ size = ALIGN(size, (unsigned int)4096);
break;
case HAL_PIXEL_FORMAT_YCbCr_420_SP:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
@@ -501,10 +501,10 @@
return size;
}
-size_t getBufferSizeAndDimensions(int width, int height, int format,
+unsigned int getBufferSizeAndDimensions(int width, int height, int format,
int& alignedw, int &alignedh)
{
- size_t size;
+ unsigned int size;
AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
height,
@@ -519,10 +519,10 @@
}
-size_t getBufferSizeAndDimensions(int width, int height, int format, int usage,
- int& alignedw, int &alignedh)
+unsigned int getBufferSizeAndDimensions(int width, int height, int format,
+ int usage, int& alignedw, int &alignedh)
{
- size_t size;
+ unsigned int size;
int tileEnabled = isMacroTileEnabled(format, usage);
AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
@@ -539,7 +539,7 @@
void getBufferAttributes(int width, int height, int format, int usage,
- int& alignedw, int &alignedh, int& tileEnabled, size_t& size)
+ int& alignedw, int &alignedh, int& tileEnabled, unsigned int& size)
{
tileEnabled = isMacroTileEnabled(format, usage);
@@ -555,7 +555,7 @@
int getYUVPlaneInfo(private_handle_t* hnd, struct android_ycbcr* ycbcr)
{
int err = 0;
- size_t ystride, cstride;
+ unsigned int ystride, cstride;
memset(ycbcr->reserved, 0, sizeof(ycbcr->reserved));
// Get the chroma offsets from the handle width/height. We take advantage
@@ -647,7 +647,7 @@
private_handle_t* hnd = new private_handle_t(data.fd, data.size,
data.allocType, 0, format,
alignedw, alignedh);
- hnd->base = (uintptr_t) data.base;
+ hnd->base = (uint64_t) data.base;
hnd->offset = data.offset;
hnd->gpuaddr = 0;
*pHnd = hnd;
diff --git a/libgralloc/fb_priv.h b/libgralloc/fb_priv.h
index 0ff082f..191aa2a 100644
--- a/libgralloc/fb_priv.h
+++ b/libgralloc/fb_priv.h
@@ -41,7 +41,7 @@
uint32_t fbFormat;
uint32_t flags;
uint32_t numBuffers;
- size_t bufferMask;
+ uint32_t bufferMask;
pthread_mutex_t lock;
private_handle_t *currentBuffer;
struct fb_var_screeninfo info;
diff --git a/libgralloc/framebuffer.cpp b/libgralloc/framebuffer.cpp
index d1f4207..ca11bea 100644
--- a/libgralloc/framebuffer.cpp
+++ b/libgralloc/framebuffer.cpp
@@ -87,7 +87,8 @@
reinterpret_cast<private_module_t*>(dev->common.module);
private_handle_t *hnd = static_cast<private_handle_t*>
(const_cast<native_handle_t*>(buffer));
- const size_t offset = hnd->base - m->framebuffer->base;
+ const unsigned int offset = (unsigned int) (hnd->base -
+ m->framebuffer->base);
m->info.activate = FB_ACTIVATE_VBL;
m->info.yoffset = (int)(offset / m->finfo.line_length);
if (ioctl(m->framebuffer->fd, FBIOPUT_VSCREENINFO, &m->info) == -1) {
@@ -204,7 +205,7 @@
}
//adreno needs 4k aligned offsets. Max hole size is 4096-1
- size_t size = roundUpToPageSize(info.yres * info.xres *
+ unsigned int size = roundUpToPageSize(info.yres * info.xres *
(info.bits_per_pixel/8));
/*
@@ -326,7 +327,7 @@
module->numBuffers = info.yres_virtual / info.yres;
module->bufferMask = 0;
//adreno needs page aligned offsets. Align the fbsize to pagesize.
- size_t fbSize = roundUpToPageSize(finfo.line_length * info.yres)*
+ unsigned int fbSize = roundUpToPageSize(finfo.line_length * info.yres)*
module->numBuffers;
module->framebuffer = new private_handle_t(fd, fbSize,
private_handle_t::PRIV_FLAGS_USES_ION,
@@ -338,7 +339,7 @@
close(fd);
return -errno;
}
- module->framebuffer->base = uintptr_t(vaddr);
+ module->framebuffer->base = uint64_t(vaddr);
memset(vaddr, 0, fbSize);
//Enable vsync
int enable = 1;
diff --git a/libgralloc/gpu.cpp b/libgralloc/gpu.cpp
index 7a1efa4..0cba07a 100644
--- a/libgralloc/gpu.cpp
+++ b/libgralloc/gpu.cpp
@@ -51,7 +51,7 @@
}
-int gpu_context_t::gralloc_alloc_buffer(size_t size, int usage,
+int gpu_context_t::gralloc_alloc_buffer(unsigned int size, int usage,
buffer_handle_t* pHandle, int bufferType,
int format, int width, int height)
{
@@ -152,13 +152,13 @@
}
flags |= data.allocType;
- uintptr_t eBaseAddr = (uintptr_t)(eData.base) + eData.offset;
+ uint64_t eBaseAddr = (uint64_t)(eData.base) + eData.offset;
private_handle_t *hnd = new private_handle_t(data.fd, size, flags,
bufferType, format, width, height, eData.fd, eData.offset,
eBaseAddr);
hnd->offset = data.offset;
- hnd->base = (uintptr_t)(data.base) + data.offset;
+ hnd->base = (uint64_t)(data.base) + data.offset;
hnd->gpuaddr = 0;
setMetaData(hnd, UPDATE_COLOR_SPACE, (void*) &colorSpace);
@@ -199,9 +199,9 @@
return -EINVAL;
}
- const size_t bufferMask = m->bufferMask;
+ const unsigned int bufferMask = m->bufferMask;
const uint32_t numBuffers = m->numBuffers;
- size_t bufferSize = m->finfo.line_length * m->info.yres;
+ unsigned int bufferSize = m->finfo.line_length * m->info.yres;
//adreno needs FB size to be page aligned
bufferSize = roundUpToPageSize(bufferSize);
@@ -221,7 +221,7 @@
}
// create a "fake" handle for it
- uintptr_t vaddr = uintptr_t(m->framebuffer->base);
+ uint64_t vaddr = uint64_t(m->framebuffer->base);
private_handle_t* hnd = new private_handle_t(
dup(m->framebuffer->fd), bufferSize,
private_handle_t::PRIV_FLAGS_USES_PMEM |
@@ -238,7 +238,7 @@
vaddr += bufferSize;
}
hnd->base = vaddr;
- hnd->offset = vaddr - uintptr_t(m->framebuffer->base);
+ hnd->offset = (unsigned int)(vaddr - m->framebuffer->base);
*pHandle = hnd;
return 0;
}
@@ -256,11 +256,11 @@
int gpu_context_t::alloc_impl(int w, int h, int format, int usage,
buffer_handle_t* pHandle, int* pStride,
- size_t bufferSize) {
+ unsigned int bufferSize) {
if (!pHandle || !pStride)
return -EINVAL;
- size_t size;
+ unsigned int size;
int alignedw, alignedh;
int grallocFormat = format;
int bufferType;
@@ -287,7 +287,7 @@
size = getBufferSizeAndDimensions(w, h, grallocFormat, usage, alignedw,
alignedh);
- if ((ssize_t)size <= 0)
+ if ((unsigned int)size <= 0)
return -EINVAL;
size = (bufferSize >= size)? bufferSize : size;
@@ -319,19 +319,20 @@
int gpu_context_t::free_impl(private_handle_t const* hnd) {
private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
- const size_t bufferSize = m->finfo.line_length * m->info.yres;
- size_t index = (hnd->base - m->framebuffer->base) / bufferSize;
+ const unsigned int bufferSize = m->finfo.line_length * m->info.yres;
+ unsigned int index = (unsigned int) ((hnd->base - m->framebuffer->base)
+ / bufferSize);
m->bufferMask &= ~(1LU<<index);
} else {
terminateBuffer(&m->base, const_cast<private_handle_t*>(hnd));
IMemAlloc* memalloc = mAllocCtrl->getAllocator(hnd->flags);
- int err = memalloc->free_buffer((void*)hnd->base, (size_t) hnd->size,
+ int err = memalloc->free_buffer((void*)hnd->base, hnd->size,
hnd->offset, hnd->fd);
if(err)
return err;
// free the metadata space
- size_t size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
+ unsigned int size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
err = memalloc->free_buffer((void*)hnd->base_metadata,
size, hnd->offset_metadata,
hnd->fd_metadata);
diff --git a/libgralloc/gpu.h b/libgralloc/gpu.h
index 5837588..2248d30 100644
--- a/libgralloc/gpu.h
+++ b/libgralloc/gpu.h
@@ -35,7 +35,7 @@
gpu_context_t(const private_module_t* module,
IAllocController* alloc_ctrl);
- int gralloc_alloc_buffer(size_t size, int usage,
+ int gralloc_alloc_buffer(unsigned int size, int usage,
buffer_handle_t* pHandle,
int bufferType, int format,
int width, int height);
@@ -44,7 +44,7 @@
int alloc_impl(int w, int h, int format, int usage,
buffer_handle_t* pHandle, int* pStride,
- size_t bufferSize = 0);
+ unsigned int bufferSize = 0);
static int gralloc_alloc(alloc_device_t* dev, int w, int h,
int format, int usage,
diff --git a/libgralloc/gr.h b/libgralloc/gr.h
index 32f3256..797d57e 100644
--- a/libgralloc/gr.h
+++ b/libgralloc/gr.h
@@ -33,7 +33,7 @@
struct private_module_t;
struct private_handle_t;
-inline size_t roundUpToPageSize(size_t x) {
+inline unsigned int roundUpToPageSize(unsigned int x) {
return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
}
@@ -47,16 +47,16 @@
int mapFrameBufferLocked(struct private_module_t* module);
int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd);
-size_t getBufferSizeAndDimensions(int width, int height, int format, int usage,
- int& alignedw, int &alignedh);
-size_t getBufferSizeAndDimensions(int width, int height, int format,
- int& alignedw, int &alignedh);
+unsigned int getBufferSizeAndDimensions(int width, int height, int format,
+ int usage, int& alignedw, int &alignedh);
+unsigned int getBufferSizeAndDimensions(int width, int height, int format,
+ int& alignedw, int &alignedh);
// Attributes include aligned width, aligned height, tileEnabled and size of the buffer
void getBufferAttributes(int width, int height, int format, int usage,
int& alignedw, int &alignedh,
- int& tileEnabled, size_t &size);
+ int& tileEnabled, unsigned int &size);
bool isMacroTileEnabled(int format, int usage);
diff --git a/libgralloc/gralloc_priv.h b/libgralloc/gralloc_priv.h
index 8704354..7a4fc15 100644
--- a/libgralloc/gralloc_priv.h
+++ b/libgralloc/gralloc_priv.h
@@ -211,28 +211,29 @@
// ints
int magic;
int flags;
- size_t size;
- size_t offset;
+ unsigned int size;
+ unsigned int offset;
int bufferType;
- uintptr_t base;
- size_t offset_metadata;
+ uint64_t base __attribute__((aligned(8)));
+ unsigned int offset_metadata;
// The gpu address mapped into the mmu.
- uintptr_t gpuaddr;
+ uint64_t gpuaddr __attribute__((aligned(8)));
int format;
int width;
int height;
- uintptr_t base_metadata;
+ uint64_t base_metadata __attribute__((aligned(8)));
#ifdef __cplusplus
- //TODO64: Revisit this on 64-bit
- static const int sNumInts = (6 + (3 * (sizeof(size_t)/sizeof(int))) +
- (3 * (sizeof(uintptr_t)/sizeof(int))));
static const int sNumFds = 2;
+ static inline int sNumInts() {
+ return ((sizeof(private_handle_t) - sizeof(native_handle_t)) /
+ sizeof(int)) - sNumFds;
+ }
static const int sMagic = 'gmsm';
- private_handle_t(int fd, size_t size, int flags, int bufferType,
+ private_handle_t(int fd, unsigned int size, int flags, int bufferType,
int format, int width, int height, int eFd = -1,
- size_t eOffset = 0, uintptr_t eBase = 0) :
+ unsigned int eOffset = 0, uint64_t eBase = 0) :
fd(fd), fd_metadata(eFd), magic(sMagic),
flags(flags), size(size), offset(0), bufferType(bufferType),
base(0), offset_metadata(eOffset), gpuaddr(0),
@@ -240,7 +241,7 @@
base_metadata(eBase)
{
version = (int) sizeof(native_handle);
- numInts = sNumInts;
+ numInts = sNumInts();
numFds = sNumFds;
}
~private_handle_t() {
@@ -254,15 +255,15 @@
static int validate(const native_handle* h) {
const private_handle_t* hnd = (const private_handle_t*)h;
if (!h || h->version != sizeof(native_handle) ||
- h->numInts != sNumInts || h->numFds != sNumFds ||
+ h->numInts != sNumInts() || h->numFds != sNumFds ||
hnd->magic != sMagic)
{
ALOGD("Invalid gralloc handle (at %p): "
- "ver(%d/%zu) ints(%d/%d) fds(%d/%d)"
+ "ver(%d/%u) ints(%d/%d) fds(%d/%d)"
"magic(%c%c%c%c/%c%c%c%c)",
h,
h ? h->version : -1, sizeof(native_handle),
- h ? h->numInts : -1, sNumInts,
+ h ? h->numInts : -1, sNumInts(),
h ? h->numFds : -1, sNumFds,
hnd ? (((hnd->magic >> 24) & 0xFF)?
((hnd->magic >> 24) & 0xFF) : '-') : '?',
diff --git a/libgralloc/ionalloc.cpp b/libgralloc/ionalloc.cpp
index e657610..e6d34f8 100644
--- a/libgralloc/ionalloc.cpp
+++ b/libgralloc/ionalloc.cpp
@@ -118,16 +118,17 @@
data.base = base;
data.fd = fd_data.fd;
ioctl(mIonFd, ION_IOC_FREE, &handle_data);
- ALOGD_IF(DEBUG, "ion: Allocated buffer base:%p size:%zu fd:%d",
+ ALOGD_IF(DEBUG, "ion: Allocated buffer base:%p size:%u fd:%d",
data.base, ionAllocData.len, data.fd);
return 0;
}
-int IonAlloc::free_buffer(void* base, size_t size, size_t offset, int fd)
+int IonAlloc::free_buffer(void* base, unsigned int size, unsigned int offset,
+ int fd)
{
Locker::Autolock _l(mLock);
- ALOGD_IF(DEBUG, "ion: Freeing buffer base:%p size:%zu fd:%d",
+ ALOGD_IF(DEBUG, "ion: Freeing buffer base:%p size:%u fd:%d",
base, size, fd);
int err = 0;
err = open_device();
@@ -140,7 +141,8 @@
return err;
}
-int IonAlloc::map_buffer(void **pBase, size_t size, size_t offset, int fd)
+int IonAlloc::map_buffer(void **pBase, unsigned int size, unsigned int offset,
+ int fd)
{
int err = 0;
void *base = 0;
@@ -158,15 +160,16 @@
ALOGE("ion: Failed to map memory in the client: %s",
strerror(errno));
} else {
- ALOGD_IF(DEBUG, "ion: Mapped buffer base:%p size:%zu offset:%d fd:%d",
+ ALOGD_IF(DEBUG, "ion: Mapped buffer base:%p size:%u offset:%u fd:%d",
base, size, offset, fd);
}
return err;
}
-int IonAlloc::unmap_buffer(void *base, size_t size, size_t /*offset*/)
+int IonAlloc::unmap_buffer(void *base, unsigned int size,
+ unsigned int /*offset*/)
{
- ALOGD_IF(DEBUG, "ion: Unmapping buffer base:%p size:%zu", base, size);
+ ALOGD_IF(DEBUG, "ion: Unmapping buffer base:%p size:%u", base, size);
int err = 0;
if(munmap(base, size)) {
err = -errno;
@@ -176,7 +179,8 @@
return err;
}
-int IonAlloc::clean_buffer(void *base, size_t size, size_t offset, int fd, int op)
+int IonAlloc::clean_buffer(void *base, unsigned int size, unsigned int offset,
+ int fd, int op)
{
struct ion_flush_data flush_data;
struct ion_fd_data fd_data;
@@ -198,9 +202,9 @@
handle_data.handle = fd_data.handle;
flush_data.handle = fd_data.handle;
flush_data.vaddr = base;
- // offset and length are uint32_t
- flush_data.offset = (uint32_t) offset;
- flush_data.length = (uint32_t) size;
+ // offset and length are unsigned int
+ flush_data.offset = offset;
+ flush_data.length = size;
struct ion_custom_data d;
switch(op) {
diff --git a/libgralloc/ionalloc.h b/libgralloc/ionalloc.h
index 683c9af..635bda5 100644
--- a/libgralloc/ionalloc.h
+++ b/libgralloc/ionalloc.h
@@ -41,17 +41,17 @@
public:
virtual int alloc_buffer(alloc_data& data);
- virtual int free_buffer(void *base, size_t size,
- size_t offset, int fd);
+ virtual int free_buffer(void *base, unsigned int size,
+ unsigned int offset, int fd);
- virtual int map_buffer(void **pBase, size_t size,
- size_t offset, int fd);
+ virtual int map_buffer(void **pBase, unsigned int size,
+ unsigned int offset, int fd);
- virtual int unmap_buffer(void *base, size_t size,
- size_t offset);
+ virtual int unmap_buffer(void *base, unsigned int size,
+ unsigned int offset);
- virtual int clean_buffer(void*base, size_t size,
- size_t offset, int fd, int op);
+ virtual int clean_buffer(void*base, unsigned int size,
+ unsigned int offset, int fd, int op);
IonAlloc() { mIonFd = FD_INIT; }
diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp
index 189d205..0ee69c8 100644
--- a/libgralloc/mapper.cpp
+++ b/libgralloc/mapper.cpp
@@ -62,7 +62,7 @@
void *mappedAddress;
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) &&
!(hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER)) {
- size_t size = hnd->size;
+ unsigned int size = hnd->size;
IMemAlloc* memalloc = getAllocator(hnd->flags) ;
int err = memalloc->map_buffer(&mappedAddress, size,
hnd->offset, hnd->fd);
@@ -73,7 +73,7 @@
return -errno;
}
- hnd->base = intptr_t(mappedAddress) + hnd->offset;
+ hnd->base = uint64_t(mappedAddress) + hnd->offset;
mappedAddress = MAP_FAILED;
size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
err = memalloc->map_buffer(&mappedAddress, size,
@@ -84,7 +84,7 @@
hnd->base_metadata = 0;
return -errno;
}
- hnd->base_metadata = intptr_t(mappedAddress) + hnd->offset_metadata;
+ hnd->base_metadata = uint64_t(mappedAddress) + hnd->offset_metadata;
}
return 0;
}
@@ -99,7 +99,7 @@
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
int err = -EINVAL;
void* base = (void*)hnd->base;
- size_t size = hnd->size;
+ unsigned int size = hnd->size;
IMemAlloc* memalloc = getAllocator(hnd->flags) ;
if(memalloc != NULL) {
err = memalloc->unmap_buffer(base, size, hnd->offset);
@@ -307,8 +307,8 @@
case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER:
{
int fd = va_arg(args, int);
- size_t size = va_arg(args, size_t);
- size_t offset = va_arg(args, size_t);
+ unsigned int size = va_arg(args, unsigned int);
+ unsigned int offset = va_arg(args, unsigned int);
void* base = va_arg(args, void*);
int width = va_arg(args, int);
int height = va_arg(args, int);
@@ -316,13 +316,13 @@
native_handle_t** handle = va_arg(args, native_handle_t**);
private_handle_t* hnd = (private_handle_t*)native_handle_create(
- private_handle_t::sNumFds, private_handle_t::sNumInts);
+ private_handle_t::sNumFds, private_handle_t::sNumInts());
hnd->magic = private_handle_t::sMagic;
hnd->fd = fd;
hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
hnd->size = size;
hnd->offset = offset;
- hnd->base = intptr_t(base) + offset;
+ hnd->base = uint64_t(base) + offset;
hnd->gpuaddr = 0;
hnd->width = width;
hnd->height = height;
diff --git a/libgralloc/memalloc.h b/libgralloc/memalloc.h
index fcd7913..2bc1ddf 100644
--- a/libgralloc/memalloc.h
+++ b/libgralloc/memalloc.h
@@ -43,9 +43,9 @@
struct alloc_data {
void *base;
int fd;
- size_t offset;
- size_t size;
- size_t align;
+ unsigned int offset;
+ unsigned int size;
+ unsigned int align;
uintptr_t pHandle;
bool uncached;
unsigned int flags;
@@ -61,20 +61,20 @@
virtual int alloc_buffer(alloc_data& data) = 0;
// Free buffer
- virtual int free_buffer(void *base, size_t size,
- size_t offset, int fd) = 0;
+ virtual int free_buffer(void *base, unsigned int size,
+ unsigned int offset, int fd) = 0;
// Map buffer
- virtual int map_buffer(void **pBase, size_t size,
- size_t offset, int fd) = 0;
+ virtual int map_buffer(void **pBase, unsigned int size,
+ unsigned int offset, int fd) = 0;
// Unmap buffer
- virtual int unmap_buffer(void *base, size_t size,
- size_t offset) = 0;
+ virtual int unmap_buffer(void *base, unsigned int size,
+ unsigned int offset) = 0;
// Clean and invalidate
- virtual int clean_buffer(void *base, size_t size,
- size_t offset, int fd, int op) = 0;
+ virtual int clean_buffer(void *base, unsigned int size,
+ unsigned int offset, int fd, int op) = 0;
// Destructor
virtual ~IMemAlloc() {};