brief intro to libhybris

by groleo

One of libhybris’s use cases is to implement a GNU/Linux graphic stack, using Android proprietary drivers.
By graphic stack I mean the API for EGL, Wayland-egl and GLES{v1,v2} (yellow boxes).

g145391

Most of functions in the *GL libraries will call in android_dlopen/android_dlsym, for example:

EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,
    EGLint config_size, EGLint *num_config)
{
    EGL_DLSYM(&_eglGetConfigs, "eglGetConfigs");
     return (*_eglGetConfigs)(dpy, configs, config_size, num_config);
}

android_dlopen/android_dlsym come from mostly-unmodified android linker code, so it will load and relocate the android libraries just as on a real devices.
While the library relocation takes place, any reference to a bionic symbol is redirected(hooked) toward an adaptation function.
That’s because some “struct”s or “enum”s are defined differently in bionic than in glibc or the function behaviour is different:

static void *my_memcpy(void *dst, const void *src, size_t len)                                                                                                                           
{                                                                                                                                                                           
    if (src == NULL || dst == NULL)                                                                                                                                                      
         return NULL;                                                                                                                                                                     
     return memcpy(dst, src, len);                                                                                                                                                        
} 

For more details, I strongly recommend reading Carstens’ blog

Advertisements