Ejemplo n.º 1
0
static void *android_dlopen_wrap(const char *filename, int flag)
{
    void *ret = get_builtin_lib_handle(filename);
    if (ret)
        return ret;

    return android_dlopen(filename, flag);
}
Ejemplo n.º 2
0
static void init_servo()
{
    LOGI("initializing native application for Servo");

    setenv("RUST_LOG", "servo,gfx,msg,util,layers,js,glut,std,rt,extra", 1);

//    setenv("SERVO_URL", "/mnt/sdcard/html/demo.html", 1);
//    setenv("RUST_THREADS", "1", 1);
    
//    char* size_stack = getenv("RUST_MIN_STACK");
//    char* rust_log = getenv("RUST_LOG");
//    char* servo_url = getenv("SERVO_URL");

//    LOGI("Stack Size is : %s", size_stack);
//    LOGI("RUST_LOG flag is : %s", rust_log);
//    LOGI("loading url is : %s", servo_url);
    

    LOGI("load servo library");
    void* libservo = android_dlopen("/data/data/com.example.ServoAndroid/lib/libservo.so");
    if (libservo == NULL) {
        LOGW("failed to load servo lib: %s", dlerror());
        return;
    }

    REGISTER_FUNCTION(libservo, glutMainLoopEvent);
    REGISTER_FUNCTION(libservo, glutInit);
    REGISTER_FUNCTION(libservo, glutInitDisplayMode);
    REGISTER_FUNCTION(libservo, glutCreateWindow);
    REGISTER_FUNCTION(libservo, glutDestroyWindow);
    REGISTER_FUNCTION(libservo, glutPostRedisplay);
    REGISTER_FUNCTION(libservo, glutSwapBuffers);
    REGISTER_FUNCTION(libservo, glutGetWindow);
    REGISTER_FUNCTION(libservo, glutSetWindow);
    REGISTER_FUNCTION(libservo, glutReshapeWindow);
    REGISTER_FUNCTION(libservo, glutDisplayFunc);
    REGISTER_FUNCTION(libservo, glutReshapeFunc);
    REGISTER_FUNCTION(libservo, glutTimerFunc);
    REGISTER_FUNCTION(libservo, glutGet);
    REGISTER_FUNCTION(libservo, glutKeyboardFunc);
    REGISTER_FUNCTION(libservo, glutMouseFunc);
    REGISTER_FUNCTION(libservo, glutMouseWheelFunc);
    REGISTER_FUNCTION(libservo, glutSetWindowTitle);
    REGISTER_FUNCTION(libservo, glutIdleFunc);
    REGISTER_FUNCTION(libservo, glutInitWindowSize);
    REGISTER_FUNCTION(libservo, glutGetModifiers);

    void (*main)(int, char**);
    *(void**)(&main) = dlsym(libservo, "android_start");
    if (main) {
        LOGI("go into android_start()");
        static char* argv[] = {"servo", "/mnt/sdcard/html/about-mozilla.html"};
        (*main)(2, argv);
        return;
    }
    LOGW("could not find android_start() in the libServo shared library");
}
Ejemplo n.º 3
0
static inline void __load_library() {
  if (!__handle) {
    __handle = android_dlopen(LIB_DROID_MEDIA_PATH, RTLD_NOW);
    if (!__handle) {
      // calling abort() is bad but it does not matter anyway as we will crash.
      abort();
    }
  }
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
    void *foo = android_dlopen(argv[1], RTLD_LAZY);
    void* (*hello)(char a, char b);
    assert(foo != NULL);
    hello = android_dlsym(foo, "hello");
    assert(hello != NULL);
    (*hello)('z', 'd');
    printf("full stop\n");    
exit(0); 
}  
Ejemplo n.º 5
0
static void  __attribute__((constructor)) _init_androidglesv2()  {
	_libglesv2 = (void *) android_dlopen(getenv("LIBGLESV2") ? getenv("LIBGLESV2") : "libGLESv2.so", RTLD_NOW);
	GLES2_LOAD(glBlendColor);
	GLES2_LOAD(glClearColor);
	GLES2_LOAD(glClearDepthf);
	GLES2_LOAD(glDepthRangef);
	GLES2_LOAD(glLineWidth);
	GLES2_LOAD(glPolygonOffset);
	GLES2_LOAD(glSampleCoverage);
	GLES2_LOAD(glTexParameterf);
	GLES2_LOAD(glUniform1f);
	GLES2_LOAD(glUniform2f);
	GLES2_LOAD(glUniform3f);
	GLES2_LOAD(glUniform4f);
	GLES2_LOAD(glVertexAttrib1f);
	GLES2_LOAD(glVertexAttrib2f);
	GLES2_LOAD(glVertexAttrib3f);
	GLES2_LOAD(glVertexAttrib4f);
	GLES2_LOAD(glEGLImageTargetTexture2DOES);
}
Ejemplo n.º 6
0
static void _init_androidegl()
{
	_libegl = (void *) android_dlopen(getenv("LIBEGL") ? getenv("LIBEGL") : "libEGL.so", RTLD_LAZY);
	_libgles = (void *) android_dlopen(getenv("LIBGLESV2") ? getenv("LIBGLESV2") : "libGLESv2.so", RTLD_LAZY);
}
Ejemplo n.º 7
0
static void _init_lib_hardware()
{
	_libhardware = (void *) android_dlopen("/system/lib/libhardware.so", RTLD_LAZY);
}
Ejemplo n.º 8
0
void *
android_dlopen(const char *library)
{
    //added by aydin.kim - parse ld_library_path
    char *libraries[256];
    int i1 = 0, icnt = 0;

    char ld_library_path[1024];
    char* library_path = getenv("LD_LIBRARY_PATH");
    strcpy(ld_library_path, library_path);

    //    LOGI("LD_LIBRARY_PATH is : %s", ld_library_path);
    libraries[i1] = strtok(ld_library_path, ":");
    //LOGI("library : %s", libraries[i1]);
    while(libraries[i1]) {
        libraries[++i1] = strtok(NULL, ":");
        //LOGI("library : %s", libraries[i1]);
    }
    icnt = i1;

    library_locations = (const char**)malloc((icnt+2) * sizeof(char *));
    for(int j = 0; j < icnt+2; j++)
        library_locations[j] = NULL;
    if(library_locations == NULL) {
        SET_ERROR("Cannot allocate library locations");
        return 0;
    }
    library_locations[0] = "/data/data/com.example.ServoAndroid/lib";
    //    LOGI("added library path : %s", library_locations[0]);
    for(int i = 0; i < icnt; i++ ) {
        library_locations[i+1] = strdup(libraries[i]);
        //        LOGI("added library path : %s", library_locations[i+1]);
    }

    /*
     * We should *not* try to just dlopen() the bare library name
     * first, as the stupid dynamic linker remembers for each library
     * basename if loading it has failed. Thus if you try loading it
     * once, and it fails because of missing needed libraries, and
     * your load those, and then try again, it fails with an
     * infuriating message "failed to load previously" in the log.
     *
     * We *must* first dlopen() all needed libraries, recursively. It
     * shouldn't matter if we dlopen() a library that already is
     * loaded, dlopen() just returns the same value then.
     */

    struct loadedLib {
        const char *name;
        void *handle;
        struct loadedLib *next;
    };
    static struct loadedLib *loaded_libraries = NULL;

    struct loadedLib *rover;
    struct loadedLib *new_loaded_lib;

    struct stat st;
    void *p;
    char *full_name = NULL;
    char **needed;
    int i;
    int found;

    struct timeval tv0, tv1, tvdiff;

    rover = loaded_libraries;
    while (rover != NULL &&
           strcmp(rover->name, library) != 0)
        rover = rover->next;

    if (rover != NULL)
        return rover->handle;

    /* LOGI("android_dlopen(%s)", library); */

    found = 0;
    if (library[0] == '/') {
        full_name = strdup(library);

        if (stat(full_name, &st) == 0 &&
            S_ISREG(st.st_mode)) {
            found = 1;
        } else {
            free(full_name);
            full_name = NULL;
        }
    } else {
        for (i = 0; !found && library_locations[i] != NULL; i++) {
            full_name = (char*)malloc(strlen(library_locations[i]) + 1 + strlen(library) + 1);
            strcpy(full_name, library_locations[i]);
            strcat(full_name, "/");
            strcat(full_name, library);

            if (stat(full_name, &st) == 0 &&
                S_ISREG(st.st_mode)) {
                found = 1;
            } else {
                free(full_name);
                full_name = NULL;
            }
        }
    }

    if (!found) {
        SET_ERROR("Library %s not found", library);
        assert(full_name == NULL); // full_name was freed above if !found
        return NULL;
    }

    needed = android_dlneeds(full_name);
    if (needed == NULL) {
        free(full_name);
        return NULL;
    }

    for (i = 0; needed[i] != NULL; i++) {
        if (android_dlopen(needed[i]) == NULL) {
            free_ptrarray((void **) needed);
            free(full_name);
            return NULL;
        }
    }
    free_ptrarray((void **) needed);

    gettimeofday(&tv0, NULL);
    p = dlopen(full_name, RTLD_LOCAL);
    gettimeofday(&tv1, NULL);
    timersub(&tv1, &tv0, &tvdiff);
    LOGI("dlopen(%s) = %p, %ld.%03lds",
         full_name, p,
         (long) tvdiff.tv_sec, (long) tvdiff.tv_usec / 1000);
    if (p == NULL)
        SET_ERROR("Error from dlopen(%s): %s", full_name, dlerror());
    free(full_name);
    full_name = NULL;

    new_loaded_lib = (struct loadedLib*)malloc(sizeof(*new_loaded_lib));
    new_loaded_lib->name = strdup(library);
    new_loaded_lib->handle = p;

    new_loaded_lib->next = loaded_libraries;
    loaded_libraries = new_loaded_lib;

    return p;
}
Ejemplo n.º 9
0
static void _init_androidglesv2()
{
 _libglesv2 = (void *) android_dlopen("/system/lib/libGLESv2.so", RTLD_LAZY);
}
Ejemplo n.º 10
0
static void _init_androidc()
{
    _libc = (void *) android_dlopen("/system/lib/libc.so", RTLD_LAZY);
}
Ejemplo n.º 11
0
void *
android_dlopen(const char *library)
{
    /*
     * We should *not* try to just dlopen() the bare library name
     * first, as the stupid dynamic linker remembers for each library
     * basename if loading it has failed. Thus if you try loading it
     * once, and it fails because of missing needed libraries, and
     * your load those, and then try again, it fails with an
     * infuriating message "failed to load previously" in the log.
     *
     * We *must* first dlopen() all needed libraries, recursively. It
     * shouldn't matter if we dlopen() a library that already is
     * loaded, dlopen() just returns the same value then.
     */

    struct loadedLib {
        const char *name;
        void *handle;
        struct loadedLib *next;
    };
    static struct loadedLib *loaded_libraries = NULL;

    struct loadedLib *rover;
    struct loadedLib *new_loaded_lib;

    struct stat st;
    void *p;
    char *full_name;
    char **needed;
    int i;
    int found;

    struct timeval tv0, tv1, tvdiff;

    rover = loaded_libraries;
    while (rover != NULL &&
           strcmp(rover->name, library) != 0)
        rover = rover->next;

    if (rover != NULL)
        return rover->handle;

    /* LOGI("android_dlopen(%s)", library); */

    found = 0;
    if (library[0] == '/') {
        full_name = strdup(library);

        if (stat(full_name, &st) == 0 &&
            S_ISREG(st.st_mode))
            found = 1;
        else
            free(full_name);
    } else {
        for (i = 0; !found && library_locations[i] != NULL; i++) {
            full_name = (char*)malloc(strlen(library_locations[i]) + 1 + strlen(library) + 1);
            strcpy(full_name, library_locations[i]);
            strcat(full_name, "/");
            strcat(full_name, library);

            if (stat(full_name, &st) == 0 &&
                S_ISREG(st.st_mode))
                found = 1;
            else
                free(full_name);
        }
    }

    if (!found) {
        SET_ERROR("Library %s not found", library);
        return NULL;
    }

    needed = android_dlneeds(full_name);
    if (needed == NULL) {
        free(full_name);
        return NULL;
    }

    for (i = 0; needed[i] != NULL; i++) {
        if (android_dlopen(needed[i]) == NULL) {
            free_ptrarray((void **) needed);
            free(full_name);
            return NULL;
        }
    }
    free_ptrarray((void **) needed);

    gettimeofday(&tv0, NULL);
    p = dlopen(full_name, RTLD_LOCAL);
    gettimeofday(&tv1, NULL);
    timersub(&tv1, &tv0, &tvdiff);
    LOGI("dlopen(%s) = %p, %ld.%03lds",
         full_name, p,
         (long) tvdiff.tv_sec, (long) tvdiff.tv_usec / 1000);
    free(full_name);
    if (p == NULL)
        SET_ERROR("Error from dlopen(%s): %s", full_name, dlerror());

    new_loaded_lib = (struct loadedLib*)malloc(sizeof(*new_loaded_lib));
    new_loaded_lib->name = strdup(library);
    new_loaded_lib->handle = p;

    new_loaded_lib->next = loaded_libraries;
    loaded_libraries = new_loaded_lib;

    return p;
}
Ejemplo n.º 12
0
static void _init_androidglesv2()
{
	_libglesv2 = (void *) android_dlopen(getenv("LIBGLESV2") ? getenv("libGLESv2") : "/system/lib/libGLESv2.so", RTLD_LAZY);
}
Ejemplo n.º 13
0
Archivo: dlfcn.c Proyecto: 8l/libhybris
void *hybris_dlopen(const char *filename, int flag)
{
    return android_dlopen(filename,flag);
}
Ejemplo n.º 14
0
static void _init_androidui()
{
       _libui = (void *) android_dlopen("/system/lib/libui.so", RTLD_LAZY);
}