libgralloc: use proper types and type casts

- Use proper types for pointers
- Resolve compiler errors
- handle proper type casts
- remove unused variables

Change-Id: I628ebe174485d30abadea4ca40b67f9aab1a0652
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index 878f17c..9f95667 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -428,7 +428,7 @@
             }
             size = alignedw*alignedh +
                     (ALIGN(alignedw/2, 16) * (alignedh/2))*2;
-            size = ALIGN(size, 4096);
+            size = ALIGN(size, (size_t)4096);
             break;
         case HAL_PIXEL_FORMAT_YCbCr_420_SP:
         case HAL_PIXEL_FORMAT_YCrCb_420_SP:
@@ -577,7 +577,7 @@
     private_handle_t* hnd = new private_handle_t(data.fd, data.size,
                                                  data.allocType, 0, format,
                                                  alignedw, alignedh);
-    hnd->base = (int) data.base;
+    hnd->base = (uintptr_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 01af2e1..0ff082f 100644
--- a/libgralloc/fb_priv.h
+++ b/libgralloc/fb_priv.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2008 The Android Open Source Project
- * Copyright (c) 2012, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@
     uint32_t fbFormat;
     uint32_t flags;
     uint32_t numBuffers;
-    uint32_t bufferMask;
+    size_t   bufferMask;
     pthread_mutex_t lock;
     private_handle_t *currentBuffer;
     struct fb_var_screeninfo info;
@@ -51,7 +51,6 @@
     float ydpi;
     float fps;
     uint32_t swapInterval;
-    uint32_t currentOffset;
 };
 
 
diff --git a/libgralloc/framebuffer.cpp b/libgralloc/framebuffer.cpp
index a7a58dc..d1f4207 100644
--- a/libgralloc/framebuffer.cpp
+++ b/libgralloc/framebuffer.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2008 The Android Open Source Project
- * Copyright (c) 2010-2012 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2010-2014 The Linux Foundation. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -72,7 +72,6 @@
     if (property_interval >= 0)
         interval = property_interval;
 
-    fb_context_t* ctx = (fb_context_t*)dev;
     private_module_t* m = reinterpret_cast<private_module_t*>(
         dev->common.module);
     if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval)
@@ -90,7 +89,7 @@
         (const_cast<native_handle_t*>(buffer));
     const size_t offset = hnd->base - m->framebuffer->base;
     m->info.activate = FB_ACTIVATE_VBL;
-    m->info.yoffset = offset / m->finfo.line_length;
+    m->info.yoffset = (int)(offset / m->finfo.line_length);
     if (ioctl(m->framebuffer->fd, FBIOPUT_VSCREENINFO, &m->info) == -1) {
         ALOGE("%s: FBIOPUT_VSCREENINFO for primary failed, str: %s",
                 __FUNCTION__, strerror(errno));
@@ -102,6 +101,9 @@
 static int fb_compositionComplete(struct framebuffer_device_t* dev)
 {
     // TODO: Properly implement composition complete callback
+    if(!dev) {
+        return -1;
+    }
     glFinish();
 
     return 0;
@@ -202,8 +204,8 @@
     }
 
     //adreno needs 4k aligned offsets. Max hole size is 4096-1
-    int  size = roundUpToPageSize(info.yres * info.xres *
-                                                       (info.bits_per_pixel/8));
+    size_t size = roundUpToPageSize(info.yres * info.xres *
+                                               (info.bits_per_pixel/8));
 
     /*
      * Request NUM_BUFFERS screens (at least 2 for page flipping)
@@ -224,13 +226,13 @@
 
     //consider the included hole by 4k alignment
     uint32_t line_length = (info.xres * info.bits_per_pixel / 8);
-    info.yres_virtual = (size * numberOfBuffers) / line_length;
+    info.yres_virtual = (uint32_t) ((size * numberOfBuffers) / line_length);
 
     uint32_t flags = PAGE_FLIP;
 
     if (info.yres_virtual < ((size * 2) / line_length) ) {
         // we need at least 2 for page-flipping
-        info.yres_virtual = size / line_length;
+        info.yres_virtual = (int)(size / line_length);
         flags &= ~PAGE_FLIP;
         ALOGW("page flipping not supported (yres_virtual=%d, requested=%d)",
               info.yres_virtual, info.yres*2);
@@ -244,12 +246,13 @@
     if (int(info.width) <= 0 || int(info.height) <= 0) {
         // the driver doesn't return that information
         // default to 160 dpi
-        info.width  = ((info.xres * 25.4f)/160.0f + 0.5f);
-        info.height = ((info.yres * 25.4f)/160.0f + 0.5f);
+        info.width  = (uint32_t)(((float)(info.xres) * 25.4f)/160.0f + 0.5f);
+        info.height = (uint32_t)(((float)(info.yres) * 25.4f)/160.0f + 0.5f);
     }
 
-    float xdpi = (info.xres * 25.4f) / info.width;
-    float ydpi = (info.yres * 25.4f) / info.height;
+    float xdpi = ((float)(info.xres) * 25.4f) / (float)info.width;
+    float ydpi = ((float)(info.yres) * 25.4f) / (float)info.height;
+
 #ifdef MSMFB_METADATA_GET
     struct msmfb_metadata metadata;
     memset(&metadata, 0 , sizeof(metadata));
@@ -259,7 +262,7 @@
         close(fd);
         return -errno;
     }
-    float fps  = metadata.data.panel_frame_rate;
+    float fps = (float)metadata.data.panel_frame_rate;
 #else
     //XXX: Remove reserved field usage on all baselines
     //The reserved[3] field is used to store FPS by the driver.
@@ -320,7 +323,6 @@
      * map the framebuffer
      */
 
-    int err;
     module->numBuffers = info.yres_virtual / info.yres;
     module->bufferMask = 0;
     //adreno needs page aligned offsets. Align the fbsize to pagesize.
@@ -336,9 +338,8 @@
         close(fd);
         return -errno;
     }
-    module->framebuffer->base = intptr_t(vaddr);
+    module->framebuffer->base = uintptr_t(vaddr);
     memset(vaddr, 0, fbSize);
-    module->currentOffset = 0;
     //Enable vsync
     int enable = 1;
     ioctl(module->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL,
diff --git a/libgralloc/gpu.cpp b/libgralloc/gpu.cpp
index b6253cd..a256db8 100644
--- a/libgralloc/gpu.cpp
+++ b/libgralloc/gpu.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2010 The Android Open Source Project
- * Copyright (c) 2011-2013 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2014 The Linux Foundation. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -70,13 +70,13 @@
     /* force 1MB alignment selectively for secure buffers, MDP5 onwards */
 #ifdef MDSS_TARGET
     if (usage & GRALLOC_USAGE_PROTECTED) {
-        data.align = ALIGN(data.align, SZ_1M);
+        data.align = ALIGN((int) data.align, SZ_1M);
         size = ALIGN(size, data.align);
     }
 #endif
 
     data.size = size;
-    data.pHandle = (unsigned int) pHandle;
+    data.pHandle = (uintptr_t) pHandle;
     err = mAllocCtrl->allocate(data, usage);
 
     if (!err) {
@@ -148,13 +148,13 @@
         }
 
         flags |= data.allocType;
-        int eBaseAddr = int(eData.base) + eData.offset;
+        uintptr_t eBaseAddr = (uintptr_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 = int(data.base) + data.offset;
+        hnd->base = (uintptr_t)(data.base) + data.offset;
         hnd->gpuaddr = 0;
 
         *pHandle = hnd;
@@ -182,7 +182,7 @@
     }
 }
 
-int gpu_context_t::gralloc_alloc_framebuffer_locked(size_t size, int usage,
+int gpu_context_t::gralloc_alloc_framebuffer_locked(int usage,
                                                     buffer_handle_t* pHandle)
 {
     private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
@@ -197,7 +197,7 @@
         return -EINVAL;
     }
 
-    const uint32_t bufferMask = m->bufferMask;
+    const size_t bufferMask = m->bufferMask;
     const uint32_t numBuffers = m->numBuffers;
     size_t bufferSize = m->finfo.line_length * m->info.yres;
 
@@ -219,7 +219,7 @@
     }
 
     // create a "fake" handle for it
-    intptr_t vaddr = intptr_t(m->framebuffer->base);
+    uintptr_t vaddr = uintptr_t(m->framebuffer->base);
     private_handle_t* hnd = new private_handle_t(
         dup(m->framebuffer->fd), bufferSize,
         private_handle_t::PRIV_FLAGS_USES_PMEM |
@@ -236,18 +236,18 @@
         vaddr += bufferSize;
     }
     hnd->base = vaddr;
-    hnd->offset = vaddr - intptr_t(m->framebuffer->base);
+    hnd->offset = vaddr - uintptr_t(m->framebuffer->base);
     *pHandle = hnd;
     return 0;
 }
 
 
-int gpu_context_t::gralloc_alloc_framebuffer(size_t size, int usage,
+int gpu_context_t::gralloc_alloc_framebuffer(int usage,
                                              buffer_handle_t* pHandle)
 {
     private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
     pthread_mutex_lock(&m->lock);
-    int err = gralloc_alloc_framebuffer_locked(size, usage, pHandle);
+    int err = gralloc_alloc_framebuffer_locked(usage, pHandle);
     pthread_mutex_unlock(&m->lock);
     return err;
 }
@@ -299,7 +299,7 @@
 
     int err = 0;
     if(useFbMem) {
-        err = gralloc_alloc_framebuffer(size, usage, pHandle);
+        err = gralloc_alloc_framebuffer(usage, pHandle);
     } else {
         err = gralloc_alloc_buffer(size, usage, pHandle, bufferType,
                                    grallocFormat, alignedw, alignedh);
@@ -317,8 +317,8 @@
     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;
-        int index = (hnd->base - m->framebuffer->base) / bufferSize;
-        m->bufferMask &= ~(1<<index);
+        size_t index = (hnd->base - m->framebuffer->base) / bufferSize;
+        m->bufferMask &= ~(1LU<<index);
     } else {
 
         terminateBuffer(&m->base, const_cast<private_handle_t*>(hnd));
@@ -328,9 +328,9 @@
         if(err)
             return err;
         // free the metadata space
-        unsigned long size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
+        size_t size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
         err = memalloc->free_buffer((void*)hnd->base_metadata,
-                                    (size_t) size, hnd->offset_metadata,
+                                    size, hnd->offset_metadata,
                                     hnd->fd_metadata);
         if (err)
             return err;
diff --git a/libgralloc/gpu.h b/libgralloc/gpu.h
index 8712c6c..a34ff7e 100644
--- a/libgralloc/gpu.h
+++ b/libgralloc/gpu.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2008 The Android Open Source Project
- * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -51,10 +51,10 @@
                              int format, int usage,
                              buffer_handle_t* pHandle,
                              int* pStride);
-    int gralloc_alloc_framebuffer_locked(size_t size, int usage,
+    int gralloc_alloc_framebuffer_locked(int usage,
                                          buffer_handle_t* pHandle);
 
-    int gralloc_alloc_framebuffer(size_t size, int usage,
+    int gralloc_alloc_framebuffer(int usage,
                                   buffer_handle_t* pHandle);
 
     static int gralloc_free(alloc_device_t* dev, buffer_handle_t handle);
diff --git a/libgralloc/gr.h b/libgralloc/gr.h
index 20b2994..52e9cc4 100644
--- a/libgralloc/gr.h
+++ b/libgralloc/gr.h
@@ -42,7 +42,8 @@
     return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
 }
 
-inline size_t ALIGN(size_t x, size_t align) {
+template <class Type>
+inline Type ALIGN(Type x, Type align) {
     return (x + align-1) & ~(align-1);
 }
 
diff --git a/libgralloc/gralloc_priv.h b/libgralloc/gralloc_priv.h
index 89f1a88..9f7c10b 100644
--- a/libgralloc/gralloc_priv.h
+++ b/libgralloc/gralloc_priv.h
@@ -209,33 +209,35 @@
         // ints
         int     magic;
         int     flags;
-        int     size;
-        int     offset;
+        size_t  size;
+        size_t  offset;
         int     bufferType;
-        int     base;
-        int     offset_metadata;
+        uintptr_t base;
+        size_t  offset_metadata;
         // The gpu address mapped into the mmu.
-        int     gpuaddr;
+        uintptr_t gpuaddr;
         int     format;
         int     width;
         int     height;
-        int     base_metadata;
+        uintptr_t base_metadata;
 
 #ifdef __cplusplus
-        static const int sNumInts = 12;
+        //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 const int sMagic = 'gmsm';
 
-        private_handle_t(int fd, int size, int flags, int bufferType,
-                         int format,int width, int height, int eFd = -1,
-                         int eOffset = 0, int eBase = 0) :
+        private_handle_t(int fd, size_t size, int flags, int bufferType,
+                         int format, int width, int height, int eFd = -1,
+                         size_t eOffset = 0, uintptr_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),
             format(format), width(width), height(height),
             base_metadata(eBase)
         {
-            version = sizeof(native_handle);
+            version = (int) sizeof(native_handle);
             numInts = sNumInts;
             numFds = sNumFds;
         }
@@ -254,7 +256,8 @@
                 hnd->magic != sMagic)
             {
                 ALOGD("Invalid gralloc handle (at %p): "
-                      "ver(%d/%d) ints(%d/%d) fds(%d/%d) magic(%c%c%c%c/%c%c%c%c)",
+                      "ver(%d/%zu) 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,
diff --git a/libgralloc/ionalloc.cpp b/libgralloc/ionalloc.cpp
index bb6c2c8..3acf06e 100644
--- a/libgralloc/ionalloc.cpp
+++ b/libgralloc/ionalloc.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -114,16 +114,16 @@
     data.base = base;
     data.fd = fd_data.fd;
     ioctl(mIonFd, ION_IOC_FREE, &handle_data);
-    ALOGD_IF(DEBUG, "ion: Allocated buffer base:%p size:%d fd:%d",
+    ALOGD_IF(DEBUG, "ion: Allocated buffer base:%p size:%zu fd:%d",
           data.base, ionAllocData.len, data.fd);
     return 0;
 }
 
 
-int IonAlloc::free_buffer(void* base, size_t size, int offset, int fd)
+int IonAlloc::free_buffer(void* base, size_t size, size_t offset, int fd)
 {
     Locker::Autolock _l(mLock);
-    ALOGD_IF(DEBUG, "ion: Freeing buffer base:%p size:%d fd:%d",
+    ALOGD_IF(DEBUG, "ion: Freeing buffer base:%p size:%zu fd:%d",
           base, size, fd);
     int err = 0;
     err = open_device();
@@ -136,7 +136,7 @@
     return err;
 }
 
-int IonAlloc::map_buffer(void **pBase, size_t size, int offset, int fd)
+int IonAlloc::map_buffer(void **pBase, size_t size, size_t offset, int fd)
 {
     int err = 0;
     void *base = 0;
@@ -154,15 +154,15 @@
         ALOGE("ion: Failed to map memory in the client: %s",
               strerror(errno));
     } else {
-        ALOGD_IF(DEBUG, "ion: Mapped buffer base:%p size:%d offset:%d fd:%d",
+        ALOGD_IF(DEBUG, "ion: Mapped buffer base:%p size:%zu offset:%d fd:%d",
               base, size, offset, fd);
     }
     return err;
 }
 
-int IonAlloc::unmap_buffer(void *base, size_t size, int offset)
+int IonAlloc::unmap_buffer(void *base, size_t size, size_t /*offset*/)
 {
-    ALOGD_IF(DEBUG, "ion: Unmapping buffer  base:%p size:%d", base, size);
+    ALOGD_IF(DEBUG, "ion: Unmapping buffer  base:%p size:%zu", base, size);
     int err = 0;
     if(munmap(base, size)) {
         err = -errno;
@@ -172,12 +172,11 @@
     return err;
 
 }
-int IonAlloc::clean_buffer(void *base, size_t size, int offset, int fd, int op)
+int IonAlloc::clean_buffer(void *base, size_t size, size_t offset, int fd, int op)
 {
     struct ion_flush_data flush_data;
     struct ion_fd_data fd_data;
     struct ion_handle_data handle_data;
-    ion_user_handle_t handle;
     int err = 0;
 
     err = open_device();
@@ -195,8 +194,9 @@
     handle_data.handle = fd_data.handle;
     flush_data.handle  = fd_data.handle;
     flush_data.vaddr   = base;
-    flush_data.offset  = offset;
-    flush_data.length  = size;
+    // offset and length are uint32_t
+    flush_data.offset  = (uint32_t) offset;
+    flush_data.length  = (uint32_t) size;
 
     struct ion_custom_data d;
     switch(op) {
diff --git a/libgralloc/ionalloc.h b/libgralloc/ionalloc.h
index 174f44b..683c9af 100644
--- a/libgralloc/ionalloc.h
+++ b/libgralloc/ionalloc.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -42,16 +42,16 @@
     virtual int alloc_buffer(alloc_data& data);
 
     virtual int free_buffer(void *base, size_t size,
-                            int offset, int fd);
+                            size_t offset, int fd);
 
     virtual int map_buffer(void **pBase, size_t size,
-                           int offset, int fd);
+                           size_t offset, int fd);
 
     virtual int unmap_buffer(void *base, size_t size,
-                             int offset);
+                             size_t offset);
 
     virtual int clean_buffer(void*base, size_t size,
-                             int offset, int fd, int op);
+                             size_t offset, int fd, int op);
 
     IonAlloc() { mIonFd = FD_INIT; }
 
diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp
index df9f7e4..c3ae070 100644
--- a/libgralloc/mapper.cpp
+++ b/libgralloc/mapper.cpp
@@ -59,6 +59,9 @@
                        buffer_handle_t handle,
                        void** vaddr)
 {
+    if(!module)
+        return -EINVAL;
+
     private_handle_t* hnd = (private_handle_t*)handle;
     void *mappedAddress;
     if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) &&
@@ -96,6 +99,9 @@
 static int gralloc_unmap(gralloc_module_t const* module,
                          buffer_handle_t handle)
 {
+    if(!module)
+        return -EINVAL;
+
     private_handle_t* hnd = (private_handle_t*)handle;
     if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
         int err = -EINVAL;
@@ -131,7 +137,7 @@
 int gralloc_register_buffer(gralloc_module_t const* module,
                             buffer_handle_t handle)
 {
-    if (private_handle_t::validate(handle) < 0)
+    if (!module || private_handle_t::validate(handle) < 0)
         return -EINVAL;
 
     // In this implementation, we don't need to do anything here
@@ -159,7 +165,7 @@
 int gralloc_unregister_buffer(gralloc_module_t const* module,
                               buffer_handle_t handle)
 {
-    if (private_handle_t::validate(handle) < 0)
+    if (!module || private_handle_t::validate(handle) < 0)
         return -EINVAL;
 
     /*
@@ -181,6 +187,9 @@
 int terminateBuffer(gralloc_module_t const* module,
                     private_handle_t* hnd)
 {
+    if(!module)
+        return -EINVAL;
+
     /*
      * If the buffer has been mapped during a lock operation, it's time
      * to un-map it. It's an error to be here with a locked buffer.
@@ -205,10 +214,10 @@
 
 int gralloc_lock(gralloc_module_t const* module,
                  buffer_handle_t handle, int usage,
-                 int l, int t, int w, int h,
+                 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
                  void** vaddr)
 {
-    if (private_handle_t::validate(handle) < 0)
+    if (!module || private_handle_t::validate(handle) < 0)
         return -EINVAL;
 
     int err = 0;
@@ -243,8 +252,9 @@
 int gralloc_unlock(gralloc_module_t const* module,
                    buffer_handle_t handle)
 {
-    if (private_handle_t::validate(handle) < 0)
+    if (!module || private_handle_t::validate(handle) < 0)
         return -EINVAL;
+
     int err = 0;
     private_handle_t* hnd = (private_handle_t*)handle;
 
@@ -276,6 +286,9 @@
 {
     int res = -EINVAL;
     va_list args;
+    if(!module)
+        return res;
+
     va_start(args, operation);
     switch (operation) {
         case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER:
@@ -289,7 +302,6 @@
                 int format = va_arg(args, int);
 
                 native_handle_t** handle = va_arg(args, native_handle_t**);
-                int memoryFlags = va_arg(args, int);
                 private_handle_t* hnd = (private_handle_t*)native_handle_create(
                     private_handle_t::sNumFds, private_handle_t::sNumInts);
                 hnd->magic = private_handle_t::sMagic;
diff --git a/libgralloc/memalloc.h b/libgralloc/memalloc.h
index 664bfa2..fcd7913 100644
--- a/libgralloc/memalloc.h
+++ b/libgralloc/memalloc.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -43,10 +43,10 @@
 struct alloc_data {
     void           *base;
     int            fd;
-    int            offset;
+    size_t         offset;
     size_t         size;
     size_t         align;
-    unsigned int   pHandle;
+    uintptr_t      pHandle;
     bool           uncached;
     unsigned int   flags;
     int            allocType;
@@ -62,19 +62,19 @@
 
     // Free buffer
     virtual int free_buffer(void *base, size_t size,
-                            int offset, int fd) = 0;
+                            size_t offset, int fd) = 0;
 
     // Map buffer
     virtual int map_buffer(void **pBase, size_t size,
-                           int offset, int fd) = 0;
+                           size_t offset, int fd) = 0;
 
     // Unmap buffer
     virtual int unmap_buffer(void *base, size_t size,
-                             int offset) = 0;
+                             size_t offset) = 0;
 
     // Clean and invalidate
     virtual int clean_buffer(void *base, size_t size,
-                             int offset, int fd, int op) = 0;
+                             size_t offset, int fd, int op) = 0;
 
     // Destructor
     virtual ~IMemAlloc() {};