Seemingly the 64-bit int is always aligned to 8 in LP64.
But this is not hold in LP32.
Consequently sizeof(gralloc_drm_handle_t) are different
between LP64 (which is 18 ints) and LP32 (which is 16 ints).
As a result, 32-bit apps will crash in 64-bit OS since the
checking handle->base.numInts != GRALLOC_GBM_HANDLE_NUM_INTS
is true.
Fix it by always aligning 64-bit int to 8. Besides, to avoid
additional padding, just exchange the order of data_owner
and modifier. It aligns modifier to 8 natually.
This makes gralloc_drm_handle_t fit in 16 ints perfectly.
(v2) gralloc_drm_handle.h patch now applied in gralloc_handle.h
and GRALLOC_HANDLE_VERSION updated to 4
Reported-by: Mauro Rossi <issor.oruam@gmail.com>
Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw>
Reviewed-by: Robert Foss <robert.foss@collabora.com>
In trying to integrate the new gralloc_handle.h with the
drm_hwcomposer, I started seeing the following compilation
errors:
In file included from external/drm_hwcomposer/platformdrmgeneric.cpp:28:
external/libdrm/android/gralloc_handle.h:108:9: error: cannot initialize return object of type 'native_handle_t *' (aka 'native_handle *') with an lvalue of type 'struct gralloc_handle_t *'
return handle;
^~~~~~
1 error generated.
This seems to be due to the gralloc_handle_create() definition
needs to return a native_handle_t * type, rather then a
gralloc_handle_t *, which is what the code actually returns.
After talking w/ Rob Herring, having the code return the
native handle should be the proper fix, so that is what
this patch changes.
Cc: Chih-Wei Huang <cwhuang@android-x86.org>
Cc: Stefan Schake <stschake@gmail.com>
Cc: Robert Foss <robert.foss@collabora.com>
Cc: Sean Paul <seanpaul@google.com>
Cc: Rob Herring <robh@kernel.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Reviewed-by: Robert Foss <robert.foss@collabora.com>
There's a number of problems with gralloc_handle_create starting with it
doesn't even compile. More importantly, it doesn't really create (i.e.
allocate) a handle. It allocates a native_handle_t, copies it to a
struct gralloc_handle_t on the stack and returns the struct (not a ptr).
So the caller still has to allocate a struct gralloc_handle_t to hold
the returned struct.
Rework gralloc_handle_create() to allocate a new handle and return the
pointer to the allocated handle. Callers should free the handle with
native_handle_close() and native_handle_delete(). In the interest of
making gralloc_handle_t opaque, return a native_handle_t ptr instead.
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Clients frequently need to convert a buffer_handle_t (aka
native_handle_t *) to a gralloc_handle_t ptr. This is a simple cast, but
add an inline function to do the conversion.
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Fix a typo where alloc_handle_t should be gralloc_handle_t. One still
remains in gralloc_handle_create, but a subsequent commit will fix that
along with other problems in gralloc_handle_create.
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Const members are problematic for dynamically allocating struct
gralloc_handle_t, so just drop the const modifier.
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Signed-off-by: Rob Herring <robh@kernel.org>
In order to lessen future alignment issues, lets switch to
fixed width integers where possible.
This excludes the data_owner since it is a pid_t which
in theory could be larger than 32 bits.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Rob Herring <robh@kernel.org>
The name member of gralloc_handle_t is no longer needed and has been removed.
The version field has also been bumped.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Rob Herring <robh@kernel.org>
The version variable will be used for versioning of this
struct and the corresponding accessor functions.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Rob Herring <robh@kernel.org>
This struct is used in mesa and drm_hwcomposer.
Versions of if have been implemented in several grallocs:
drm_gralloc, gbm_gralloc, minigbm and intel-minigbm.
Other than the 1:1 move of the struct a new generic name
has been chosen and variables have had comments added to them.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Rob Herring <robh@kernel.org>