Skip to content

Commit

Permalink
Merge branch 'prop-fallback' into xenial_-_edge
Browse files Browse the repository at this point in the history
  • Loading branch information
mariogrip committed Jan 19, 2020
2 parents f7bf04a + 6dd776e commit ca37725
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 169 deletions.
12 changes: 6 additions & 6 deletions hybris/common/mm/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3231,10 +3231,10 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
}

// Use LD_LIBRARY_PATH and LD_PRELOAD (but only if we aren't setuid/setgid).
if (DEFAULT_HYBRIS_LD_LIBRARY_PATH)
parse_LD_LIBRARY_PATH(DEFAULT_HYBRIS_LD_LIBRARY_PATH);
else
if (ldpath_env)
parse_LD_LIBRARY_PATH(ldpath_env);
else
parse_LD_LIBRARY_PATH(DEFAULT_HYBRIS_LD_LIBRARY_PATH);
parse_LD_PRELOAD(ldpreload_env);

somain = si;
Expand Down Expand Up @@ -3384,10 +3384,10 @@ extern "C" void android_linker_init(int sdk_version, void* (*get_hooked_symbol)(
ldpreload_env = getenv("HYBRIS_LD_PRELOAD");
}

if (DEFAULT_HYBRIS_LD_LIBRARY_PATH)
parse_LD_LIBRARY_PATH(DEFAULT_HYBRIS_LD_LIBRARY_PATH);
else
if (ldpath_env)
parse_LD_LIBRARY_PATH(ldpath_env);
else
parse_LD_LIBRARY_PATH(DEFAULT_HYBRIS_LD_LIBRARY_PATH);
parse_LD_PRELOAD(ldpreload_env);

if (sdk_version > 0)
Expand Down
12 changes: 6 additions & 6 deletions hybris/common/n/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4561,10 +4561,10 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
#endif

// Use LD_LIBRARY_PATH and LD_PRELOAD (but only if we aren't setuid/setgid).
if (DEFAULT_HYBRIS_LD_LIBRARY_PATH)
parse_LD_LIBRARY_PATH(DEFAULT_HYBRIS_LD_LIBRARY_PATH);
else
if (ldpath_env)
parse_LD_LIBRARY_PATH(ldpath_env);
else
parse_LD_LIBRARY_PATH(DEFAULT_HYBRIS_LD_LIBRARY_PATH);
parse_LD_PRELOAD(ldpreload_env);
parse_LD_SHIM_LIBS(ldshim_libs_env);

Expand Down Expand Up @@ -4719,10 +4719,10 @@ extern "C" void android_linker_init(int sdk_version, void* (*get_hooked_symbol)(
ldpreload_env = getenv("HYBRIS_LD_PRELOAD");
}

if (DEFAULT_HYBRIS_LD_LIBRARY_PATH)
parse_LD_LIBRARY_PATH(DEFAULT_HYBRIS_LD_LIBRARY_PATH);
else
if (ldpath_env)
parse_LD_LIBRARY_PATH(ldpath_env);
else
parse_LD_LIBRARY_PATH(DEFAULT_HYBRIS_LD_LIBRARY_PATH);
parse_LD_PRELOAD(ldpreload_env);

if (sdk_version > 0)
Expand Down
5 changes: 5 additions & 0 deletions hybris/common/o/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ o_la_CPPFLAGS = \
-DDEFAULT_HYBRIS_LD_LIBRARY_PATH="\"@DEFAULT_HYBRIS_LD_LIBRARY_PATH@\"" \
$(ARCH_FLAGS) \
$(ANDROID_HEADERS_CFLAGS)

if HAS_ANDROID_9_0_0
o_la_CPPFLAGS += -DHAS_ANDROID_9_0_0
endif

o_la_LDFLAGS = \
-lsupc++ \
-module \
Expand Down
22 changes: 22 additions & 0 deletions hybris/common/o/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,34 @@ static const char* const kVendorLibDir = "/vendor/lib64";
static const char* const kVendorLibEglDir = "/vendor/lib64/egl";
static const char* const kOdmLibDir = "/odm/lib64";
static const char* const kOdmLibEglDir = "/odm/lib64/egl";
#ifdef HAS_ANDROID_9_0_0
static const char* const kSystemLibVndk28Dir = "/system/lib64/vndk-28";
#endif
static const char* const kAsanSystemLibDir = "/data/asan/system/lib64";
static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib64";
static const char* const kAsanVendorLibEglDir = "/data/asan/vendor/lib64/egl";
static const char* const kAsanOdmLibDir = "/data/asan/odm/lib64";
static const char* const kAsanOdmLibEglDir = "/data/asan/odm/lib64/egl";
#ifdef HAS_ANDROID_9_0_0
static const char* const kAsanSystemLibVndk28Dir = "/data/asan/system/lib64/vndk-28";
#endif
#else
static const char* const kSystemLibDir = "/system/lib";
static const char* const kVendorLibDir = "/vendor/lib";
static const char* const kVendorLibEglDir = "/vendor/lib/egl";
static const char* const kOdmLibDir = "/odm/lib";
static const char* const kOdmLibEglDir = "/odm/lib/egl";
#ifdef HAS_ANDROID_9_0_0
static const char* const kSystemLibVndk28Dir = "/system/lib/vndk-28";
#endif
static const char* const kAsanSystemLibDir = "/data/asan/system/lib";
static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib";
static const char* const kAsanVendorLibEglDir = "/data/asan/vendor/lib/egl";
static const char* const kAsanOdmLibDir = "/data/asan/odm/lib";
static const char* const kAsanOdmLibEglDir = "/data/asan/odm/lib/egl";
#ifdef HAS_ANDROID_9_0_0
static const char* const kAsanSystemLibVndk28Dir = "/data/asan/system/lib/vndk-28";
#endif
#endif

static const char* const kAsanLibDirPrefix = "/data/asan";
Expand All @@ -135,8 +147,13 @@ static const char* const kDefaultLdPaths[] = {
kOdmLibDir,
kVendorLibDir,

// libhybris support:
kOdmLibEglDir,
kVendorLibEglDir,

#ifdef HAS_ANDROID_9_0_0
kSystemLibVndk28Dir,
#endif
nullptr
};

Expand All @@ -153,6 +170,11 @@ static const char* const kAsanDefaultLdPaths[] = {
kOdmLibEglDir,
kAsanVendorLibEglDir,
kVendorLibEglDir,

#ifdef HAS_ANDROID_9_0_0
kAsanSystemLibVndk28Dir,
kSystemLibVndk28Dir,
#endif
nullptr
};

Expand Down
12 changes: 6 additions & 6 deletions hybris/common/o/linker_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args) {
}

// Use LD_LIBRARY_PATH and LD_PRELOAD (but only if we aren't setuid/setgid).
if (DEFAULT_HYBRIS_LD_LIBRARY_PATH)
parse_LD_LIBRARY_PATH(DEFAULT_HYBRIS_LD_LIBRARY_PATH);
else
if (ldpath_env)
parse_LD_LIBRARY_PATH(ldpath_env);
else
parse_LD_LIBRARY_PATH(DEFAULT_HYBRIS_LD_LIBRARY_PATH);
parse_LD_PRELOAD(ldpreload_env);

somain = si;
Expand Down Expand Up @@ -516,10 +516,10 @@ extern "C" void android_linker_init(int sdk_version, void* (*get_hooked_symbol)(
ldpreload_env = getenv("HYBRIS_LD_PRELOAD");
}

if (DEFAULT_HYBRIS_LD_LIBRARY_PATH)
parse_LD_LIBRARY_PATH(DEFAULT_HYBRIS_LD_LIBRARY_PATH);
else
if (ldpath_env)
parse_LD_LIBRARY_PATH(ldpath_env);
else
parse_LD_LIBRARY_PATH(DEFAULT_HYBRIS_LD_LIBRARY_PATH);
parse_LD_PRELOAD(ldpreload_env);

if (sdk_version > 0)
Expand Down
1 change: 1 addition & 0 deletions hybris/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ AC_SUBST(ANDROID_VERSION_PATCH, [$android_headers_patch])
AC_MSG_NOTICE("Android headers version is $android_headers_major.$android_headers_minor.$android_headers_patch")

# Add automake tests for version/API needs here that you need in code, including test .am's
AM_CONDITIONAL([HAS_ANDROID_9_0_0], [test $android_headers_major -ge 9 -a $android_headers_minor -ge 0 ])
AM_CONDITIONAL([HAS_ANDROID_8_0_0], [test $android_headers_major -ge 8 -a $android_headers_minor -ge 0 ])
AM_CONDITIONAL([HAS_ANDROID_7_0_0], [test $android_headers_major -ge 7 -a $android_headers_minor -ge 0 ])
AM_CONDITIONAL([HAS_ANDROID_6_0_0], [test $android_headers_major -ge 6 -a $android_headers_minor -ge 0 ])
Expand Down
4 changes: 2 additions & 2 deletions hybris/egl/platforms/common/eglplatformcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ extern "C" const char *eglplatformcommon_eglQueryString(EGLDisplay dpy, EGLint n
if (name == EGL_EXTENSIONS)
{
const char *ret = (*real_eglQueryString)(dpy, name);
static char eglextensionsbuf[1024];
snprintf(eglextensionsbuf, 1022, "%sEGL_HYBRIS_native_buffer2 EGL_HYBRIS_WL_acquire_native_buffer %s", ret ? ret : "",
static char eglextensionsbuf[2048];
snprintf(eglextensionsbuf, 2046, "%sEGL_HYBRIS_native_buffer2 EGL_HYBRIS_WL_acquire_native_buffer %s", ret ? ret : "",
#ifdef WANT_WAYLAND
"EGL_WL_bind_wayland_display "
#else
Expand Down
4 changes: 2 additions & 2 deletions hybris/egl/platforms/wayland/eglplatform_wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ extern "C" const char *waylandws_eglQueryString(EGLDisplay dpy, EGLint name, con
const char *ret = eglplatformcommon_eglQueryString(dpy, name, real_eglQueryString);
if (ret && name == EGL_EXTENSIONS)
{
static char eglextensionsbuf[1024];
snprintf(eglextensionsbuf, 1022, "%s %s", ret,
static char eglextensionsbuf[2048];
snprintf(eglextensionsbuf, 2046, "%s %s", ret,
"EGL_EXT_swap_buffers_with_damage EGL_WL_create_wayland_buffer_from_image"
);
ret = eglextensionsbuf;
Expand Down
61 changes: 61 additions & 0 deletions hybris/include/EGL/egl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,25 @@ extern "C" {

/* EGL Types */
/* EGLint is defined in eglplatform.h */
typedef intptr_t EGLAttrib;
typedef khronos_utime_nanoseconds_t EGLTime;
typedef unsigned int EGLBoolean;
typedef unsigned int EGLenum;
typedef void *EGLConfig;
typedef void *EGLContext;
typedef void *EGLDisplay;
typedef void *EGLSurface;
typedef void *EGLClientBuffer;
typedef void *EGLSync;
typedef void *EGLImage;

/* EGL Versioning */
#define EGL_VERSION_1_0 1
#define EGL_VERSION_1_1 1
#define EGL_VERSION_1_2 1
#define EGL_VERSION_1_3 1
#define EGL_VERSION_1_4 1
#define EGL_VERSION_1_5 1

/* EGL Enumerants. Bitmasks and other exceptional cases aside, most
* enums are assigned unique values starting at 0x3000.
Expand Down Expand Up @@ -242,6 +247,50 @@ typedef void *EGLClientBuffer;
* a bug in Khronos Bugzilla against task "Registry".
*/

/* EGL 1.5 tokens */
#define EGL_CONTEXT_MAJOR_VERSION 0x3098
#define EGL_CONTEXT_MINOR_VERSION 0x30FB
#define EGL_CONTEXT_OPENGL_PROFILE_MASK 0x30FD
#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY 0x31BD
#define EGL_NO_RESET_NOTIFICATION 0x31BE
#define EGL_LOSE_CONTEXT_ON_RESET 0x31BF
#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT 0x00000001
#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT 0x00000002
#define EGL_CONTEXT_OPENGL_DEBUG 0x31B0
#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE 0x31B1
#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS 0x31B2
#define EGL_OPENGL_ES3_BIT 0x00000040
#define EGL_CL_EVENT_HANDLE 0x309C
#define EGL_SYNC_CL_EVENT 0x30FE
#define EGL_SYNC_CL_EVENT_COMPLETE 0x30FF
#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE 0x30F0
#define EGL_SYNC_TYPE 0x30F7
#define EGL_SYNC_STATUS 0x30F1
#define EGL_SYNC_CONDITION 0x30F8
#define EGL_SIGNALED 0x30F2
#define EGL_UNSIGNALED 0x30F3
#define EGL_SYNC_FLUSH_COMMANDS_BIT 0x0001
#define EGL_FOREVER 0xFFFFFFFFFFFFFFFFull
#define EGL_TIMEOUT_EXPIRED 0x30F5
#define EGL_CONDITION_SATISFIED 0x30F6
#define EGL_NO_SYNC EGL_CAST(EGLSync,0)
#define EGL_SYNC_FENCE 0x30F9
#define EGL_GL_COLORSPACE 0x309D
#define EGL_GL_COLORSPACE_SRGB 0x3089
#define EGL_GL_COLORSPACE_LINEAR 0x308A
#define EGL_GL_RENDERBUFFER 0x30B9
#define EGL_GL_TEXTURE_2D 0x30B1
#define EGL_GL_TEXTURE_LEVEL 0x30BC
#define EGL_GL_TEXTURE_3D 0x30B2
#define EGL_GL_TEXTURE_ZOFFSET 0x30BD
#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x30B3
#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x30B4
#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x30B5
#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x30B6
#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x30B7
#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x30B8
#define EGL_IMAGE_PRESERVED 0x30D2
#define EGL_NO_IMAGE EGL_CAST(EGLImage,0)


/* EGL Functions */
Expand Down Expand Up @@ -313,6 +362,18 @@ EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, EGLSurface surface,
EGLNativePixmapType target);

/* EGL 1.5 */
EGLAPI EGLSync EGLAPIENTRY eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list);
EGLAPI EGLBoolean EGLAPIENTRY eglDestroySync(EGLDisplay dpy, EGLSync sync);
EGLAPI EGLint EGLAPIENTRY eglClientWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout);
EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value);
EGLAPI EGLImage EGLAPIENTRY eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImage(EGLDisplay dpy, EGLImage image);
EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplay(EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list);
EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLAttrib *attrib_list);
EGLAPI EGLBoolean EGLAPIENTRY eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags);

/* This is a generic function pointer type, whose name indicates it must
* be cast to the proper type *and calling convention* before use.
*/
Expand Down
28 changes: 22 additions & 6 deletions hybris/properties/hybris_properties.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018 Jolla Ltd. <[email protected]>
* Copyright (c) 2020 UBports foundation <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,12 +23,18 @@
#include <hybris/common/binding.h>

static void *libcutils = NULL;
static int own_impl = 0;

// These may point to the libhybris implementation or to the bionic implementation, depending on the linker being used.
static int (*bionic_property_list)(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie) = NULL;
static int (*bionic_property_get)(const char *key, char *value, const char *default_value) = NULL;
static int (*bionic_property_set)(const char *key, const char *value) = NULL;

// Private implementations as fallback
extern int my_property_list(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie);
extern int my_property_get(const char *key, char *value, const char *default_value);
extern int my_property_set(const char *key, const char *value);

static void unload_libcutils(void)
{
if (libcutils) {
Expand All @@ -43,16 +50,16 @@ static void unload_libcutils(void)

static void ensure_bionic_properties_initialized(void)
{
if (!libcutils) {
if (!libcutils && !own_impl) {
libcutils = android_dlopen("libcutils.so", RTLD_LAZY);
if (libcutils) {
PROPERTY_DLSYM(property_get);
PROPERTY_DLSYM(property_set);
PROPERTY_DLSYM(property_list);
atexit(unload_libcutils);
} else {
fprintf(stderr, "failed to load bionic libc.so\n");
abort();
own_impl = 1;
fprintf(stderr, "failed to load bionic libc.so, falling back own property implementation\n");
}
}
}
Expand All @@ -61,20 +68,29 @@ int property_list(void (*propfn)(const char *key, const char *value, void *cooki
{
ensure_bionic_properties_initialized();

return bionic_property_list(propfn, cookie);
if (!own_impl)
return bionic_property_list(propfn, cookie);
else
return my_property_list(propfn, cookie);
}

int property_get(const char *key, char *value, const char *default_value)
{
ensure_bionic_properties_initialized();

return bionic_property_get(key, value, default_value);
if (!own_impl)
return bionic_property_get(key, value, default_value);
else
return my_property_get(key, value, default_value);
}

int property_set(const char *key, const char *value)
{
ensure_bionic_properties_initialized();

return bionic_property_set(key, value);
if (!own_impl)
return bionic_property_set(key, value);
else
return my_property_set(key, value);
}

Loading

0 comments on commit ca37725

Please sign in to comment.