Commit 2f24bb27 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Fix WRAP_GBM_FN

Due to C++ overloading rules, only some of the gbm_* wrapper
functions were getting called.  For example, if we were passing
a char* where a void* was expected, the wrapper would get called,
but if we passed exactly the arguments that function expects,
the wrapper would not get called.

To fix this, add macros that remap gbm_* to call_gbm_*.

BUG=1031269

Change-Id: I1814be43f4e5b0f746a6e4a068a95c229a71d20b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1981053
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728328}
parent 9c99c066
...@@ -32,23 +32,23 @@ namespace { ...@@ -32,23 +32,23 @@ namespace {
#define WRAP_GBM_FN(x) \ #define WRAP_GBM_FN(x) \
ALLOW_UNUSED_TYPE decltype(x)* get_##x() { return x; } ALLOW_UNUSED_TYPE decltype(x)* get_##x() { return x; }
#else #else
#define WRAP_GBM_FN(x) \ #define WRAP_GBM_FN(x) \
decltype(auto) get_##x() { \ decltype(auto) get_##x() { \
static auto* x##_ = \ static auto* x##_ = \
reinterpret_cast<decltype(::x)*>(dlsym(RTLD_DEFAULT, STRINGIZE(x))); \ reinterpret_cast<decltype(::x)*>(dlsym(RTLD_DEFAULT, STRINGIZE(x))); \
return x##_; \ return x##_; \
} \ } \
/* Functions that call dlsym-loaded functions must not be instrumented with \ /* Functions that call dlsym-loaded functions must not be instrumented */ \
* CFI_ICALL. */ \ /* with CFI_ICALL. */ \
template <typename... Args> \ template <typename... Args> \
NO_SANITIZE("cfi-icall") \ NO_SANITIZE("cfi-icall") \
decltype(auto) x(Args&&... args) { \ decltype(auto) call_##x(Args&&... args) { \
if (!get_##x()) { \ if (!get_##x()) { \
LOG(FATAL) << STRINGIZE(x) << "() is not available on this platform. " \ LOG(FATAL) << STRINGIZE(x) << "() is not available on this platform. " \
<< STRINGIZE(get_##x) \ << STRINGIZE(get_##x) \
<< "() should be used to determine availability."; \ << "() should be used to determine availability."; \
} \ } \
return get_##x()(std::forward<Args>(args)...); \ return get_##x()(std::forward<Args>(args)...); \
} }
#endif #endif
...@@ -56,6 +56,10 @@ namespace { ...@@ -56,6 +56,10 @@ namespace {
// is dropped. // is dropped.
WRAP_GBM_FN(gbm_bo_map) WRAP_GBM_FN(gbm_bo_map)
WRAP_GBM_FN(gbm_bo_unmap) WRAP_GBM_FN(gbm_bo_unmap)
#if !defined(MINIGBM)
#define gbm_bo_map call_gbm_bo_map
#define gbm_bo_unmap call_gbm_bo_unmap
#endif
// TODO(https://crbug.com/784010): Remove these once support for Ubuntu Trusty // TODO(https://crbug.com/784010): Remove these once support for Ubuntu Trusty
// and Debian Stretch are dropped. // and Debian Stretch are dropped.
...@@ -65,6 +69,14 @@ WRAP_GBM_FN(gbm_bo_get_modifier) ...@@ -65,6 +69,14 @@ WRAP_GBM_FN(gbm_bo_get_modifier)
WRAP_GBM_FN(gbm_bo_get_offset) WRAP_GBM_FN(gbm_bo_get_offset)
WRAP_GBM_FN(gbm_bo_get_plane_count) WRAP_GBM_FN(gbm_bo_get_plane_count)
WRAP_GBM_FN(gbm_bo_get_stride_for_plane) WRAP_GBM_FN(gbm_bo_get_stride_for_plane)
#if !defined(MINIGBM)
#define gbm_bo_create_with_modifiers call_gbm_bo_create_with_modifiers
#define gbm_bo_get_handle_for_plane call_gbm_bo_get_handle_for_plane
#define gbm_bo_get_modifier call_gbm_bo_get_modifier
#define gbm_bo_get_offset call_gbm_bo_get_offset
#define gbm_bo_get_plane_count call_gbm_bo_get_plane_count
#define gbm_bo_get_stride_for_plane call_gbm_bo_get_stride_for_plane
#endif
int GetPlaneFdForBo(gbm_bo* bo, size_t plane) { int GetPlaneFdForBo(gbm_bo* bo, size_t plane) {
#if defined(MINIGBM) #if defined(MINIGBM)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment