Commit 6765e70b authored by Kari Hormi's avatar Kari Hormi

Fix DeviceLauncher to measure falling edge values properly and load

libEGL.so instead of using RTLD_NEXT in Boottime-EGL.

Using RTLD_NEXT would cause the program to crash for reasons yet
unknown. This fix replaces the usage of RTLD_NEXT by loading libEGL.so
and executing the needed functions from there. This is "the correct" way
to do hooking, but unfortunately now requires libEGL.so from /usr/lib
instead of loading the next symbol dynamically.

The other fix is to DeviceLauncher. Apparently, something has changed in
the way the GPIO pin in the target device goes up/down which broke the
way DeviceLauncher worked. This is now fixed, although the solution
might need refining in the future.
parent 17626301
Pipeline #4294 failed with stages
#define _GNU_SOURCE
#include <iostream>
#include <fstream>
#include <dlfcn.h>
......@@ -10,14 +8,27 @@
EGLBoolean eglBindAPI(EGLenum api)
{
EGLBoolean (*original_eglBindAPI)(EGLenum api);
original_eglBindAPI = (EGLBoolean (*)(EGLenum)) dlsym(RTLD_NEXT, "eglBindAPI");
EGLBoolean ok = (*original_eglBindAPI)(api);
EGLBoolean ok;
void *eglLib = dlopen("libEGL.so", RTLD_LAZY);
char *error = dlerror();
if ( error != nullptr ) {
std::cerr << "Could not open libEGL.so: " << error;
ok = EGL_FALSE;
} else {
original_eglBindAPI = reinterpret_cast<EGLBoolean (*)(EGLenum)>(dlsym(eglLib, "eglBindAPI"));
ok = (*original_eglBindAPI)(api);
}
if (!BoottimeEGL::firstBindAPI && !BoottimeEGL::singleShotted) {
BoottimeEGL::firstBindAPI = true;
BoottimeEGL::singleShotted = true;
}
if ( dlclose(eglLib) != 0 )
std::cerr << "Could not close libEGL.so: " << dlerror();
return ok;
}
......@@ -25,8 +36,18 @@ EGLBoolean eglBindAPI(EGLenum api)
EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
{
EGLBoolean (*original_eglSwapBuffers)(EGLDisplay, EGLSurface);
original_eglSwapBuffers = (EGLBoolean (*)(EGLDisplay, EGLSurface)) dlsym(RTLD_NEXT, "eglSwapBuffers");
EGLBoolean ok = (*original_eglSwapBuffers)(dpy, surface);
EGLBoolean ok;
void *eglLib = dlopen("libEGL.so", RTLD_LAZY);
char *error = dlerror();
if ( error != nullptr ) {
std::cerr << "Could not open libEGL.so: " << error;
ok = EGL_FALSE;
} else {
original_eglSwapBuffers = reinterpret_cast<EGLBoolean (*)(EGLDisplay, EGLSurface)>(dlsym(eglLib, "eglSwapBuffers"));
ok = (*original_eglSwapBuffers)(dpy, surface);
}
if (BoottimeEGL::firstBindAPI) {
BoottimeEGL::firstBindAPI = false;
......@@ -47,8 +68,10 @@ EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
gpiovalue.close();
}
}
}
if ( dlclose(eglLib) != 0 )
std::cerr << "Could not close libEGL.so: " << dlerror();
return ok;
}
......@@ -98,9 +98,7 @@ int main(int argc, char *argv[])
lseek(fds.fd, 0, SEEK_SET);
read(fds.fd, &buffer, 3);
bool deviceOn = false;
usleep(100000);
usleep(1000000);
while (true) {
int ret = poll(&fds, 1, -1);
......@@ -110,13 +108,10 @@ int main(int argc, char *argv[])
char* end;
long bufferValue = strtol(buffer, &end, 10);
//std::cout << bufferValue << std::endl;
if (bufferValue == 0 && deviceOn) {
if (bufferValue == 0) {
firstFrame = std::chrono::high_resolution_clock::now();
break;
} else if (bufferValue == 1 && !deviceOn) {
deviceOn = true;
}
}
}
......
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