Package libhybris (#1402)

As discussed in #1039, I want to split feature/hybris branch into
smaller sensible pull requests.

This is the first one that simply adds android-headers and libhybris
packaging. libhybris allows apps compiled with glibc (musl in our case)
to load Android libraries that utilize bionic libc, which is used to
load proprietary userspace drivers.

The package isn't very useful on its own and requires core (non-UI/Java)
Android services to be running in some way - either in Halium-style LXC
container or in same root as main OS with modified init (Mer/Sailfish do
it this way). Both ways are tested to work in postmarketOS.

libhybris also includes some tests, not all of them are known to be
representative, but test_vibrator and test_egl_configs are usually good
indicators if system is set up correctly.
This commit is contained in:
NotKit 2018-04-10 23:13:42 +02:00 committed by Oliver Smith
parent 7a6cb98cc7
commit f6a67e0215
7 changed files with 2567 additions and 0 deletions

View File

@ -0,0 +1,29 @@
pkgname=android-headers-4.4
_pkgname=android-headers
pkgver=4.4_git20171022
_pkgver=4.4
pkgrel=0
arch="noarch"
url="https://github.com/ubports/android-headers"
license="Apache"
makedepends=""
depends=""
_rev=f636fa26a61b36bef284a7aeba95eb767344b8b4
source="$pkgname-$_rev.tar.gz::https://github.com/ubports/android-headers/archive/$_rev.tar.gz
android-headers.pc"
pkgdesc="Android headers used for building libhybris"
options="!check"
builddir="$srcdir/$_pkgname-$_rev"
package() {
cd "$builddir"
mkdir -p "${pkgdir}/usr/include"
cp -r "$builddir/19" "${pkgdir}/usr/include/android-$_pkgver"
install -Dm644 "$srcdir/android-headers.pc" "${pkgdir}/usr/lib/pkgconfig/android-headers-$_pkgver.pc"
}
sha512sums="c146753908ae0dd9aca0138a0a63e8578d65200d6d9b5154b846a0ac3309d9e33f6edddd92cd420e7b7dcaf73630546eb1bd45927cf8b4921f67dec7db7bb55c android-headers-4.4-f636fa26a61b36bef284a7aeba95eb767344b8b4.tar.gz
331f2670da9ce2690225694196265a55e2f41c35a1a12b71a75de3478b3b266c215be9bd451ab5ea13d4802e9f7d4e1bab8aa006d0df81fc264b2a132a022640 android-headers.pc"

View File

@ -0,0 +1,9 @@
Name: Android header files
Description: Header files needed to write applications for the Android platform
Version: 4.4
prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
Cflags: -I${includedir}/android-4.4

View File

@ -0,0 +1,39 @@
pkgname=android-headers-7.1
_pkgname=android-headers
pkgver=7.1_git20170630
_pkgver=7.1
pkgrel=0
arch="noarch"
url="https://github.com/Halium/android-headers"
license="Apache"
makedepends=""
depends=""
_rev=1f6591ba7d42b91c32acf5a65a2a4fae983d6865
source="$pkgname-$_rev.tar.gz::https://github.com/Halium/android-headers/archive/$_rev.tar.gz"
pkgdesc="Android headers used for building libhybris"
subpackages="$pkgname-caf:package_caf"
builddir="$srcdir/$_pkgname-$_rev"
package() {
cd "$builddir"
make PREFIX=/usr DESTDIR="${pkgdir}" install
mv ${pkgdir}/usr/include/android ${pkgdir}/usr/include/android-$_pkgver
sed -i "s~${includedir}/android~${includedir}/android-$_pkgver~g" ${pkgdir}/usr/lib/pkgconfig/android-headers.pc
mv "${pkgdir}/usr/lib/pkgconfig/android-headers.pc" "${pkgdir}/usr/lib/pkgconfig/android-headers-$_pkgver.pc"
}
package_caf() {
cd "$builddir"
sed -i 's~/\* CONFIG GOES HERE \*/~#define QCOM_BSP 1\n#define QTI_BSP 1~g' android-config.h
make PREFIX=/usr DESTDIR="${subpkgdir}" install
mv ${subpkgdir}/usr/include/android ${subpkgdir}/usr/include/android-$_pkgver-caf
sed -i "s~${includedir}/android~${includedir}/android-$_pkgver-caf~g" ${subpkgdir}/usr/lib/pkgconfig/android-headers.pc
mv "${subpkgdir}/usr/lib/pkgconfig/android-headers.pc" "${subpkgdir}/usr/lib/pkgconfig/android-headers-$_pkgver-caf.pc"
}
sha512sums="652641b469f7faf90c7adf03b14047f9eb24fdb190d9ab131d72f73b2d9357aad80cad48867ede66b0a737661cfb9e26fb4583b9fed15b8d6d667fe53ea14419 android-headers-7.1-1f6591ba7d42b91c32acf5a65a2a4fae983d6865.tar.gz"

View File

@ -0,0 +1,592 @@
From 98b46a48875cedf8af2445be63f196b6fe9b8648 Mon Sep 17 00:00:00 2001
From: NeKit <nekit1000@gmail.com>
Date: Wed, 1 Nov 2017 15:39:45 +0300
Subject: [PATCH 1/3] Make libhybris compile with musl
Hooks for some functions had to be disabled due to musl not having/exposing
them, which might lead to problems depending on how musl/bionic are
(in)compatible.
---
hybris/common/hooks.c | 44 ++++++++++++++++++++++
hybris/common/hooks_shm.c | 4 ++
hybris/common/jb/dlfcn.c | 4 ++
hybris/common/mm/bionic/libc/include/link.h | 1 +
.../common/mm/bionic/libc/private/libc_logging.h | 13 +++++++
hybris/common/mm/dlfcn.cpp | 4 ++
hybris/common/mm/hybris_compat.h | 11 ++++++
hybris/common/mm/linker.cpp | 11 ++++++
hybris/common/n/bionic/libc/include/dlfcn.h | 4 +-
hybris/common/n/bionic/libc/include/link.h | 1 +
hybris/common/n/bionic/libc/private/libc_logging.h | 15 +++++++-
hybris/common/n/dlfcn.cpp | 4 ++
hybris/common/n/hybris_compat.cpp | 8 ++++
hybris/common/n/hybris_compat.h | 22 +++++++++++
hybris/include/hybris/common/musl_compat.h | 10 +++++
hybris/properties/properties.c | 3 ++
hybris/tests/test_camera.c | 4 ++
17 files changed, 160 insertions(+), 3 deletions(-)
create mode 100644 hybris/include/hybris/common/musl_compat.h
diff --git a/hybris/common/hooks.c b/hybris/common/hooks.c
index 3b21d74..01e1f3e 100644
--- a/hybris/common/hooks.c
+++ b/hybris/common/hooks.c
@@ -73,6 +73,10 @@
#include <hybris/properties/properties.h>
#include <hybris/common/hooks.h>
+#ifndef __GLIBC__
+#include <hybris/common/musl_compat.h>
+#endif
+
#include <android-config.h>
#ifdef WANT_ARM_TRACING
@@ -504,6 +508,7 @@ static int _hybris_hook_pthread_attr_getstacksize(pthread_attr_t const *__attr,
return pthread_attr_getstacksize(realattr, stack_size);
}
+#ifdef __GLIBC__
static int _hybris_hook_pthread_attr_setstackaddr(pthread_attr_t *__attr, void *stack_addr)
{
pthread_attr_t *realattr = (pthread_attr_t *) *(uintptr_t *) __attr;
@@ -521,6 +526,7 @@ static int _hybris_hook_pthread_attr_getstackaddr(pthread_attr_t const *__attr,
return pthread_attr_getstackaddr(realattr, stack_addr);
}
+#endif
static int _hybris_hook_pthread_attr_setstack(pthread_attr_t *__attr, void *stack_base, size_t stack_size)
{
@@ -1107,6 +1113,7 @@ static int _hybris_hook_pthread_rwlockattr_getpshared(pthread_rwlockattr_t *__at
return pthread_rwlockattr_getpshared(realattr, pshared);
}
+#ifdef __GLIBC__
int _hybris_hook_pthread_rwlockattr_setkind_np(pthread_rwlockattr_t *attr, int pref)
{
pthread_rwlockattr_t *realattr = (pthread_rwlockattr_t *) *(uintptr_t *) attr;
@@ -1124,6 +1131,7 @@ int _hybris_hook_pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t *attr,
return pthread_rwlockattr_getkind_np(realattr, pref);
}
+#endif
/*
* pthread_rwlock_* functions
@@ -1443,10 +1451,14 @@ static int _hybris_hook_fgetpos(FILE *fp, bionic_fpos_t *pos)
{
TRACE_HOOK("fp %p pos %p", fp, pos);
+#ifdef __GLIBC__
fpos_t my_fpos;
int ret = fgetpos(_get_actual_fp(fp), &my_fpos);
*pos = my_fpos.__pos;
+#else
+ int ret = fgetpos(_get_actual_fp(fp), pos);
+#endif
return ret;
}
@@ -1532,12 +1544,16 @@ static int _hybris_hook_fsetpos(FILE *fp, const bionic_fpos_t *pos)
{
TRACE_HOOK("fp %p pos %p", fp, pos);
+#ifdef __GLIBC__
fpos_t my_fpos;
my_fpos.__pos = *pos;
memset(&my_fpos.__state, 0, sizeof(mbstate_t));
mbsinit(&my_fpos.__state);
return fsetpos(_get_actual_fp(fp), &my_fpos);
+#else
+ return fsetpos(_get_actual_fp(fp), pos);
+#endif
}
static long _hybris_hook_ftell(FILE *fp)
@@ -1815,6 +1831,7 @@ static int _hybris_hook_versionsort(struct bionic_dirent **a,
return strverscmp((*a)->d_name, (*b)->d_name);
}
+#ifdef __GLIBC__
static int _hybris_hook_scandirat(int fd, const char *dir,
struct bionic_dirent ***namelist,
int (*filter) (const struct bionic_dirent *),
@@ -1876,6 +1893,7 @@ static int _hybris_hook_scandir(const char *dir,
{
return _hybris_hook_scandirat(AT_FDCWD, dir, namelist, filter, compar);
}
+#endif
static inline void swap(void **a, void **b)
{
@@ -2125,6 +2143,7 @@ int _hybris_hook_open(const char *pathname, int flags, ...)
return open(target_path, flags, mode);
}
+#ifdef __GLIBC__
/**
* Wrap some GCC builtin functions, which don't have any address
*/
@@ -2150,6 +2169,7 @@ __THROW int _hybris_hook___snprintf_chk (char *__restrict __s, size_t __n, int _
return ret;
}
+#endif
static __thread void *tls_hooks[16];
@@ -2295,6 +2315,7 @@ static char* _hybris_hook_setlocale(int category, const char *locale)
return setlocale(category, locale);
}
+#ifdef __GLIBC__
static void* _hybris_hook_mmap(void *addr, size_t len, int prot,
int flags, int fd, off_t offset)
{
@@ -2310,6 +2331,7 @@ static int _hybris_hook_munmap(void *addr, size_t length)
return munmap(addr, length);
}
+#endif
extern size_t strlcat(char *dst, const char *src, size_t siz);
extern size_t strlcpy(char *dst, const char *src, size_t siz);
@@ -2463,7 +2485,9 @@ static struct _hook hooks_common[] = {
HOOK_DIRECT_NO_DEBUG(realloc),
HOOK_DIRECT_NO_DEBUG(memalign),
HOOK_DIRECT_NO_DEBUG(valloc),
+#ifdef __GLIBC__
HOOK_DIRECT_NO_DEBUG(pvalloc),
+#endif
HOOK_DIRECT(fread),
HOOK_DIRECT_NO_DEBUG(getxattr),
HOOK_DIRECT(mprotect),
@@ -2513,8 +2537,10 @@ static struct _hook hooks_common[] = {
HOOK_DIRECT_NO_DEBUG(bcopy),
HOOK_DIRECT_NO_DEBUG(bzero),
HOOK_DIRECT_NO_DEBUG(ffs),
+#ifdef __GLIBC__
HOOK_INDIRECT(__sprintf_chk),
HOOK_INDIRECT(__snprintf_chk),
+#endif
/* pthread.h */
HOOK_DIRECT_NO_DEBUG(getauxval),
HOOK_INDIRECT(gettid),
@@ -2573,8 +2599,10 @@ static struct _hook hooks_common[] = {
HOOK_INDIRECT(pthread_attr_getschedparam),
HOOK_INDIRECT(pthread_attr_setstacksize),
HOOK_INDIRECT(pthread_attr_getstacksize),
+#ifdef __GLIBC__
HOOK_INDIRECT(pthread_attr_setstackaddr),
HOOK_INDIRECT(pthread_attr_getstackaddr),
+#endif
HOOK_INDIRECT(pthread_attr_setstack),
HOOK_INDIRECT(pthread_attr_getstack),
HOOK_INDIRECT(pthread_attr_setguardsize),
@@ -2682,8 +2710,10 @@ static struct _hook hooks_common[] = {
HOOK_DIRECT_NO_DEBUG(seekdir),
HOOK_DIRECT_NO_DEBUG(telldir),
HOOK_DIRECT_NO_DEBUG(dirfd),
+#ifdef __GLIBC__
HOOK_INDIRECT(scandir),
HOOK_INDIRECT(scandirat),
+#endif
HOOK_INDIRECT(alphasort),
HOOK_INDIRECT(versionsort),
/* fcntl.h */
@@ -2707,7 +2737,9 @@ static struct _hook hooks_common[] = {
HOOK_DIRECT_NO_DEBUG(localtime_r),
HOOK_DIRECT_NO_DEBUG(gmtime),
HOOK_DIRECT_NO_DEBUG(abort),
+#ifdef __GLIBC__
HOOK_DIRECT_NO_DEBUG(writev),
+#endif
/* unistd.h */
HOOK_DIRECT_NO_DEBUG(access),
/* grp.h */
@@ -2736,13 +2768,17 @@ static struct _hook hooks_mm[] = {
HOOK_DIRECT(putenv),
HOOK_DIRECT(clearenv),
HOOK_DIRECT_NO_DEBUG(dprintf),
+#ifdef __GLIBC__
HOOK_DIRECT_NO_DEBUG(mallinfo),
+#endif
HOOK_DIRECT(malloc_usable_size),
HOOK_DIRECT(posix_memalign),
HOOK_DIRECT(mprotect),
HOOK_TO(__gnu_strerror_r, _hybris_hook__gnu_strerror_r),
+#ifdef __GLIBC__
HOOK_INDIRECT(pthread_rwlockattr_getkind_np),
HOOK_INDIRECT(pthread_rwlockattr_setkind_np),
+#endif
/* unistd.h */
HOOK_DIRECT(fork),
HOOK_DIRECT_NO_DEBUG(ttyname),
@@ -2764,15 +2800,21 @@ static struct _hook hooks_mm[] = {
HOOK_DIRECT(localeconv),
HOOK_DIRECT(setlocale),
/* sys/mman.h */
+#ifdef __GLIBC__
+ // mmap from musl considers offsets from gralloc to be invalid,
+ // so avoid hooking it
HOOK_DIRECT(mmap),
HOOK_DIRECT(munmap),
+#endif
/* wchar.h */
HOOK_DIRECT_NO_DEBUG(wmemchr),
HOOK_DIRECT_NO_DEBUG(wmemcmp),
HOOK_DIRECT_NO_DEBUG(wmemcpy),
HOOK_DIRECT_NO_DEBUG(wmemmove),
HOOK_DIRECT_NO_DEBUG(wmemset),
+#ifdef __GLIBC__
HOOK_DIRECT_NO_DEBUG(wmempcpy),
+#endif
HOOK_INDIRECT(fputws),
// It's enough to hook vfwprintf here as fwprintf will call it with a
// proper va_list in place so we don't have to handle this here.
@@ -2826,9 +2868,11 @@ static struct _hook hooks_mm[] = {
/* dirent.h */
HOOK_TO(readdir64, _hybris_hook_readdir),
HOOK_TO(readdir64_r, _hybris_hook_readdir_r),
+#ifdef __GLIBC__
HOOK_INDIRECT(scandir),
HOOK_INDIRECT(scandirat),
HOOK_TO(scandir64, _hybris_hook_scandir),
+#endif
};
diff --git a/hybris/common/hooks_shm.c b/hybris/common/hooks_shm.c
index c90cee5..27dfeef 100644
--- a/hybris/common/hooks_shm.c
+++ b/hybris/common/hooks_shm.c
@@ -33,6 +33,10 @@
#include <sys/shm.h>
#include <sys/mman.h>
+#ifndef __GLIBC__
+#include <hybris/common/musl_compat.h>
+#endif
+
/* Debug */
#include "logging.h"
#define LOGD(message, ...) HYBRIS_DEBUG_LOG(HOOKS, message, ##__VA_ARGS__)
diff --git a/hybris/common/jb/dlfcn.c b/hybris/common/jb/dlfcn.c
index 78500e4..6996527 100644
--- a/hybris/common/jb/dlfcn.c
+++ b/hybris/common/jb/dlfcn.c
@@ -23,6 +23,10 @@
#include "linker.h"
#include "linker_format.h"
+#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP {{PTHREAD_MUTEX_RECURSIVE}}
+#endif
+
/* This file hijacks the symbols stubbed out in libdl.so. */
#define DL_SUCCESS 0
diff --git a/hybris/common/mm/bionic/libc/include/link.h b/hybris/common/mm/bionic/libc/include/link.h
index cb8e139..10d105d 100644
--- a/hybris/common/mm/bionic/libc/include/link.h
+++ b/hybris/common/mm/bionic/libc/include/link.h
@@ -29,6 +29,7 @@
#define _LINK_H_
#include <sys/types.h>
+#include <sys/cdefs.h>
#include <elf.h>
__BEGIN_DECLS
diff --git a/hybris/common/mm/bionic/libc/private/libc_logging.h b/hybris/common/mm/bionic/libc/private/libc_logging.h
index 6beb47e..e526c03 100644
--- a/hybris/common/mm/bionic/libc/private/libc_logging.h
+++ b/hybris/common/mm/bionic/libc/private/libc_logging.h
@@ -33,6 +33,8 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
__BEGIN_DECLS
@@ -73,7 +75,18 @@ struct abort_msg_t {
// Formats a message to the log (priority 'fatal'), then aborts.
//
+#ifdef __GLIBC__
void __libc_fatal(const char* format, ...);
+#else
+void inline __libc_fatal(const char* format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+ abort();
+}
+#endif
//
// Formats a message to the log (priority 'fatal'), but doesn't abort.
diff --git a/hybris/common/mm/dlfcn.cpp b/hybris/common/mm/dlfcn.cpp
index 8a8213f..e9f6914 100644
--- a/hybris/common/mm/dlfcn.cpp
+++ b/hybris/common/mm/dlfcn.cpp
@@ -31,6 +31,10 @@
#include "hybris_compat.h"
+#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP {{PTHREAD_MUTEX_RECURSIVE}}
+#endif
+
#ifdef WANT_ARM_TRACING
#include "../wrappers.h"
#endif
diff --git a/hybris/common/mm/hybris_compat.h b/hybris/common/mm/hybris_compat.h
index 2e10383..de1d852 100644
--- a/hybris/common/mm/hybris_compat.h
+++ b/hybris/common/mm/hybris_compat.h
@@ -32,6 +32,9 @@
#include <string.h>
#include <memory.h>
+#ifndef __GLIBC__
+#include <hybris/common/musl_compat.h>
+#endif
extern "C" size_t strlcpy(char *dest, const char *src, size_t size);
extern "C" size_t strlcat(char *dst, const char *src, size_t size);
@@ -55,4 +58,12 @@ extern "C" size_t strlcat(char *dst, const char *src, size_t size);
#define DT_ANDROID_RELA (DT_LOOS + 4)
#define DT_ANDROID_RELASZ (DT_LOOS + 5)
+#if defined (__aarch64__)
+
+#ifndef R_AARCH64_IRELATIVE
+#define R_AARCH64_IRELATIVE 1032
+#endif
+
+#endif
+
#endif
diff --git a/hybris/common/mm/linker.cpp b/hybris/common/mm/linker.cpp
index 10a3853..8fe23b3 100644
--- a/hybris/common/mm/linker.cpp
+++ b/hybris/common/mm/linker.cpp
@@ -38,6 +38,9 @@
#include <sys/mman.h>
#include <sys/param.h>
#include <unistd.h>
+#ifndef __GLIBC__
+#include <libgen.h>
+#endif
#include <new>
#include <string>
@@ -1169,7 +1172,11 @@ static const char* fix_dt_needed(const char* dt_needed, const char* sopath) {
#if !defined(__LP64__)
// Work around incorrect DT_NEEDED entries for old apps: http://b/21364029
if (get_application_target_sdk_version() <= 22) {
+#ifdef __GLIBC__
const char* bname = basename(dt_needed);
+#else
+ const char* bname = (const char*) basename((char*)dt_needed);
+#endif
if (bname != dt_needed) {
DL_WARN("'%s' library has invalid DT_NEEDED entry '%s'", sopath, dt_needed);
}
@@ -2900,7 +2907,11 @@ bool soinfo::prelink_image() {
// the main executable and linker; they do not need to have dt_soname
if (soname_ == nullptr && this != somain && (flags_ & FLAG_LINKER) == 0 &&
get_application_target_sdk_version() <= 22) {
+#ifdef __GLIBC__
soname_ = basename(realpath_.c_str());
+#else
+ soname_ = (const char*) basename((char*) realpath_.c_str());
+#endif
DL_WARN("%s: is missing DT_SONAME will use basename as a replacement: \"%s\"",
get_realpath(), soname_);
}
diff --git a/hybris/common/n/bionic/libc/include/dlfcn.h b/hybris/common/n/bionic/libc/include/dlfcn.h
index c2e8980..692ce52 100644
--- a/hybris/common/n/bionic/libc/include/dlfcn.h
+++ b/hybris/common/n/bionic/libc/include/dlfcn.h
@@ -46,8 +46,8 @@ typedef struct {
extern void* dlopen(const char* filename, int flag);
extern int dlclose(void* handle);
extern const char* dlerror(void);
-extern void* dlsym(void* handle, const char* symbol) __nonnull((2));
-extern void* dlvsym(void* handle, const char* symbol, const char* version) __nonnull((2, 3));
+extern void* dlsym(void* handle, const char* symbol) __attribute__((nonnull((2))));
+extern void* dlvsym(void* handle, const char* symbol, const char* version) __attribute__((nonnull((2, 3))));
extern int dladdr(const void* addr, Dl_info *info);
enum {
diff --git a/hybris/common/n/bionic/libc/include/link.h b/hybris/common/n/bionic/libc/include/link.h
index cb8e139..10d105d 100644
--- a/hybris/common/n/bionic/libc/include/link.h
+++ b/hybris/common/n/bionic/libc/include/link.h
@@ -29,6 +29,7 @@
#define _LINK_H_
#include <sys/types.h>
+#include <sys/cdefs.h>
#include <elf.h>
__BEGIN_DECLS
diff --git a/hybris/common/n/bionic/libc/private/libc_logging.h b/hybris/common/n/bionic/libc/private/libc_logging.h
index a696cec..2da0238 100644
--- a/hybris/common/n/bionic/libc/private/libc_logging.h
+++ b/hybris/common/n/bionic/libc/private/libc_logging.h
@@ -33,6 +33,8 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
__BEGIN_DECLS
@@ -73,7 +75,18 @@ struct abort_msg_t {
// Formats a message to the log (priority 'fatal'), then aborts.
//
-void __libc_fatal(const char* format, ...);
+#ifdef __GLIBC__
+ void __libc_fatal(const char* format, ...);
+#else
+void inline __libc_fatal(const char* format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+ abort();
+}
+#endif
//
// Formats a message to the log (priority 'fatal'), but doesn't abort.
diff --git a/hybris/common/n/dlfcn.cpp b/hybris/common/n/dlfcn.cpp
index 056f271..91d52ed 100644
--- a/hybris/common/n/dlfcn.cpp
+++ b/hybris/common/n/dlfcn.cpp
@@ -30,6 +30,10 @@
#include "hybris_compat.h"
+#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP {{PTHREAD_MUTEX_RECURSIVE}}
+#endif
+
/* This file hijacks the symbols stubbed out in libdl.so. */
static pthread_mutex_t g_dl_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
diff --git a/hybris/common/n/hybris_compat.cpp b/hybris/common/n/hybris_compat.cpp
index cfe1e78..5238409 100644
--- a/hybris/common/n/hybris_compat.cpp
+++ b/hybris/common/n/hybris_compat.cpp
@@ -27,3 +27,11 @@
*/
#include "hybris_compat.h"
+
+#ifndef __GLIBC__
+const char *gnu_basename(const char *path)
+{
+ char *base = strrchr(path, '/');
+ return base ? base + 1 : path;
+}
+#endif
diff --git a/hybris/common/n/hybris_compat.h b/hybris/common/n/hybris_compat.h
index 2e10383..77a0919 100644
--- a/hybris/common/n/hybris_compat.h
+++ b/hybris/common/n/hybris_compat.h
@@ -32,6 +32,9 @@
#include <string.h>
#include <memory.h>
+#ifndef __GLIBC__
+#include <hybris/common/musl_compat.h>
+#endif
extern "C" size_t strlcpy(char *dest, const char *src, size_t size);
extern "C" size_t strlcat(char *dst, const char *src, size_t size);
@@ -55,4 +58,23 @@ extern "C" size_t strlcat(char *dst, const char *src, size_t size);
#define DT_ANDROID_RELA (DT_LOOS + 4)
#define DT_ANDROID_RELASZ (DT_LOOS + 5)
+#if defined (__aarch64__)
+
+#ifndef R_AARCH64_TLS_DTPREL32
+#define R_AARCH64_TLS_DTPREL32 1031
+#endif
+
+#ifndef R_AARCH64_IRELATIVE
+#define R_AARCH64_IRELATIVE 1032
+#endif
+
+#endif
+
+#ifndef __GLIBC__
+#ifndef basename
+const char *gnu_basename(const char *path);
+#define basename gnu_basename
+#endif
+#endif
+
#endif
diff --git a/hybris/include/hybris/common/musl_compat.h b/hybris/include/hybris/common/musl_compat.h
new file mode 100644
index 0000000..c5f86f2
--- /dev/null
+++ b/hybris/include/hybris/common/musl_compat.h
@@ -0,0 +1,10 @@
+#include <unistd.h>
+/* taken from glibc unistd.h and fixes musl */
+#ifndef TEMP_FAILURE_RETRY
+#define TEMP_FAILURE_RETRY(expression) \
+ (__extension__ \
+ ({ long int __result; \
+ do __result = (long int) (expression); \
+ while (__result == -1L && errno == EINTR); \
+ __result; }))
+#endif
diff --git a/hybris/properties/properties.c b/hybris/properties/properties.c
index 55cdda6..ae8bbbc 100644
--- a/hybris/properties/properties.c
+++ b/hybris/properties/properties.c
@@ -36,6 +36,9 @@
#include <poll.h>
#include <hybris/properties/properties.h>
+#ifndef __GLIBC__
+#include <hybris/common/musl_compat.h>
+#endif
#include "properties_p.h"
diff --git a/hybris/tests/test_camera.c b/hybris/tests/test_camera.c
index 693a6fb..8f4bc38 100644
--- a/hybris/tests/test_camera.c
+++ b/hybris/tests/test_camera.c
@@ -40,6 +40,10 @@
#include <sys/stat.h>
#include <sys/types.h>
+#ifndef __GLIBC__
+#include <hybris/common/musl_compat.h>
+#endif
+
int shot_counter = 1;
int32_t current_zoom_level = 1;
bool new_camera_frame_available = true;
--
2.15.1

View File

@ -0,0 +1,75 @@
From 91f4908067686c28e10894d4bd6042c0a452bf24 Mon Sep 17 00:00:00 2001
From: Richard Braakman <richard.braakman@jollamobile.com>
Date: Wed, 1 Nov 2017 23:35:31 +0300
Subject: [PATCH 2/3] [tests] Regression test for EGL-glibc TLS conflict bionic
and glibc have different layouts for TLS space. Since libEGL used a bionic
slot directly (in inlined code), libhybris's hooks didn't translate it
properly and libEGL ended up overwriting some unrelated thread-local values
in glibc.
The problem only showed up when linking with libGLESv2 (which
pulls in libEGL), not when linking with libEGL directly. That's
why the test was added to test_glesv2.c
---
hybris/tests/test_hwcomposer.cpp | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/hybris/tests/test_hwcomposer.cpp b/hybris/tests/test_hwcomposer.cpp
index 2253d50..b5d04a4 100644
--- a/hybris/tests/test_hwcomposer.cpp
+++ b/hybris/tests/test_hwcomposer.cpp
@@ -29,6 +29,23 @@
#include <malloc.h>
#include <sync/sync.h>
+/* Regression test: make sure that there's no conflict between
+ * the TLS (thread-local storage) slots used via libEGL/bionic
+ * and the TLS space allocated by the host toolchain. The array
+ * declared here should remain unchanged regardless of GL activity.
+ * Since this array is the first __thread storage declared in the main
+ * program, glibc will allocate it before any others.
+ */
+#define SLOT_FILLER (void *) 0x11122111 /* arbitrary non-zero value */
+#define S SLOT_FILLER
+__thread void *tls_space[64] = {
+ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
+ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
+ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
+ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
+};
+#undef S
+
const char vertex_src [] =
" \
attribute vec4 position; \
@@ -343,7 +360,7 @@ int main(int argc, char **argv)
glClearColor ( 1. , 1. , 1. , 1.); // background color
float phase = 0;
int i, oldretire = -1, oldrelease = -1, oldrelease2 = -1;
- for (i=0; i<1020*60; ++i) {
+ for (i=0; i<60*60; ++i) {
glClear(GL_COLOR_BUFFER_BIT);
glUniform1f ( phase_loc , phase ); // write the value of phase to the shaders phase
phase = fmodf ( phase + 0.5f , 2.f * 3.141f ); // and update the local variable
@@ -369,6 +386,18 @@ int main(int argc, char **argv)
printf("terminated\n");
android_dlclose(baz);
#endif
+
+ int bad_tls = 0;
+ for (i=0; i<64; ++i) {
+ if (tls_space[i] != SLOT_FILLER) {
+ printf("TLS array slot %d polluted: %p\n", i, tls_space[i]);
+ bad_tls++;
+ }
+ }
+ if (bad_tls)
+ return 1;
+
+ return 0;
}
// vim:ts=4:sw=4:noexpandtab
--
2.15.1

View File

@ -0,0 +1,151 @@
pkgname=libhybris
pkgver=1.0_git20180212
pkgrel=1
arch="armhf aarch64"
url="https://github.com/libhybris/libhybris"
license="Apache"
makedepends="autoconf automake libtool wayland-dev linux-headers bsd-compat-headers
libx11-dev libxcb-dev libxext-dev
android-headers-7.1 android-headers-7.1-caf android-headers-4.4"
depends_dev="bsd-compat-headers android-headers-7.1"
_rev=54dd4749706334882f9c404fca01a19f01325d07
source="$pkgname-$_rev.tar.gz::https://github.com/libhybris/libhybris/archive/$_rev.tar.gz
0001-Make-libhybris-compile-with-musl.patch
0002-tests-Regression-test-for-EGL-glibc-TLS-conflict.patch
0003-Implement-X11-EGL-platform-based-on-wayland-code.patch"
pkgdesc="libhybris allows to use bionic-based HW adaptations"
subpackages="$pkgname-dev $pkgname-egl $pkgname-gles $pkgname-libwayland-egl:_wayland
$pkgname-7.1:_specific $pkgname-7.1-caf:_specific $pkgname-4.4:_specific"
if [ "$CARCH" == "aarch64" ]; then
subpackages="$pkgname-dev $pkgname-egl $pkgname-gles $pkgname-libwayland-egl:_wayland
$pkgname-7.1:_specific $pkgname-7.1-caf:_specific"
fi
options="!check !strip !tracedeps"
builddir="$srcdir/$pkgname-$_rev"
_tmppkgdir="$srcdir/tmpinstall"
_main_headers_ver=7.1
_bins_specific="test_audio test_camera test_egl_configs test_gps
test_hwcomposer test_input test_lights test_media test_nfc
test_recorder test_sensors test_sf test_vibrator test_wifi"
_libs_specific="libcamera.so.1.0.0 libhardware.so.2.0.0
libhybris-common.so.1.0.0 libhybris-eglplatformcommon.so.1.0.0
libhybris-hwcomposerwindow.so.1.0.0 libis.so.1.0.0 libmedia.so.1
libmedia.so.1.0.0 libnfc_ndef_nxp.so.1.0.0 libnfc_nxp.so.1.0.0
libsf.so.1.0.0 libsync.so.2.0.0 libui.so.1.0.0 libvibrator.so.1.0.0
libwifi.so.1.0.0
libhybris/eglplatform_fbdev.so libhybris/eglplatform_hwcomposer.so
libhybris/eglplatform_null.so libhybris/eglplatform_wayland.so
libhybris/eglplatform_x11.so"
build() {
cd "$builddir/hybris"
NOCONFIGURE=1 ./autogen.sh
if [ "$CARCH" == "armhf" ]; then
_vers="7.1 7.1-caf 4.4"
_ldpath="/usr/libexec/droid-hybris/system/lib:/vendor/lib:/system/lib"
_arch="arm"
elif [ "$CARCH" == "aarch64" ]; then
_vers="7.1 7.1-caf"
_ldpath="/usr/libexec/droid-hybris/system/lib64:/vendor/lib64:/system/lib64"
_arch="arm64"
fi
for _headers_ver in $_vers; do
msg "building $pkgname-$_headers_ver"
./configure \
--prefix=/usr \
--enable-wayland \
--enable-trace \
--enable-debug \
--enable-experimental \
--with-android-headers=/usr/include/android-$_headers_ver \
--with-default-hybris-ld-library-path=$_ldpath \
--enable-arch=$_arch \
--enable-property-cache
make DESTDIR="${_tmppkgdir}/$pkgname-$_headers_ver" install
done
}
package() {
cd "$builddir/hybris"
# make DESTDIR="${pkgdir}" install
mkdir -p "${pkgdir}"
cp -a ${_tmppkgdir}/$pkgname-$_main_headers_ver/* "${pkgdir}"
for _bin in ${_bins_specific}; do
rm "${pkgdir}/usr/bin/${_bin}"
done
for _lib in ${_libs_specific}; do
rm "${pkgdir}/usr/lib/${_lib}"
done
}
_specific() {
for _bin in ${_bins_specific}; do
install -Dm755 "${_tmppkgdir}/${subpkgname}/usr/bin/${_bin}" \
"${subpkgdir}/usr/bin/${_bin}"
done
for _lib in ${_libs_specific}; do
install -Dm755 "${_tmppkgdir}/${subpkgname}/usr/lib/${_lib}" \
"${subpkgdir}/usr/lib/${_lib}"
done
}
egl() {
options="!tracedeps"
pkgdesc="libhybris libEGL runtime libraries"
install -d "$subpkgdir"/usr/lib
mv "$pkgdir"/usr/lib/libEGL.so.* \
"$subpkgdir"/usr/lib/
}
gles() {
options="!tracedeps"
pkgdesc="libhybris libGLESv2 runtime libraries"
install -d "$subpkgdir"/usr/lib
mv "$pkgdir"/usr/lib/libGLES*.so.* \
"$subpkgdir"/usr/lib/
}
_wayland() {
pkgdesc="libhybris libwayland-egl library"
mkdir -p "$subpkgdir"/usr/lib
mv "$pkgdir"/usr/lib/libwayland-egl.so.* "$subpkgdir"/usr/lib/ \
|| return 1
}
dev() {
default_dev
# Avoid conflicts with mesa-dev
rm -f "$subpkgdir"/usr/lib/lib*GL*.so
rm -f "$subpkgdir"/usr/lib/libwayland-egl.so
cd "$subpkgdir"/usr/lib/pkgconfig
rm -f egl.pc glesv*.pc wayland-egl.pc
cd "$subpkgdir"/usr/include
# Move libhybris-provided headers into hybris dir
mv CL EGL GLES GLES2 KHR VG hybris
# Symlink eglhybris.h
mkdir -p EGL
cd EGL
ln -s ../hybris/EGL/eglhybris.h .
}
sha512sums="798360130e540d9dd29ec937b3d01a1b146881c45ec6a2dd1a599a0164d46886b58927d38575993b525a06e99fcc2dd46f020e70f7e5c7cc43258b840ae183f8 libhybris-54dd4749706334882f9c404fca01a19f01325d07.tar.gz
9655816dc3d89f329801a74f4499c3752cbc96f7ba2e052765335a2cbd7e74cdf45064260ab27537bcd9d64673144eac6f89e31af4b4c6b4a4792ad7b398555d 0001-Make-libhybris-compile-with-musl.patch
1355a4403d1af8bdf75b9e4502cbfc093b9788224ce7c24a1f6a53dd7996d385d31a3362577a4293db6b6d0dd0ae4e88140b38c658ff0a288d9acfc2753859bb 0002-tests-Regression-test-for-EGL-glibc-TLS-conflict.patch
f7d7b460af5f13c37289d7eadfa5eb52248a4a5379a1da07b74231eb4fc9c1ccda6644bcd39bbae89bd068d7f3f6c5fe4e9ae6b41991c1f3b48d6b4d59d951d8 0003-Implement-X11-EGL-platform-based-on-wayland-code.patch"