Implemented dlfcn functions
This commit is contained in:
@@ -1,30 +1,56 @@
|
||||
#include <magenta/types.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <dlfcn.h>
|
||||
#include <fcntl.h>
|
||||
#include <mio/fs.h>
|
||||
|
||||
|
||||
__attribute__((weak)) void *dyld_load_object(mx_handle_t handle, int mode) { return NULL; }
|
||||
__attribute__((weak)) void *dyld_load_object(const char *path, mx_handle_t handle, int mode) { return NULL; }
|
||||
__attribute__((weak)) void *dyld_get_symbol(void *handle, const char *name) { return NULL; }
|
||||
__attribute__((weak)) int dyld_close_object(void *handle) { return 0; }
|
||||
__attribute__((weak)) char *dyld_get_error(void) { return NULL; }
|
||||
|
||||
static char dl_error[512] = {};
|
||||
|
||||
void *dlopen(const char *path, int mode)
|
||||
{
|
||||
dyld_load_object(MX_NULL_HANDLE, 0);
|
||||
/* TODO include error message from errno */
|
||||
|
||||
int fd = open(path, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
snprintf(dl_error, sizeof dl_error, "cannot open '%s'", path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mx_handle_t image_vmo = MX_NULL_HANDLE;
|
||||
int err = mio_map_file(fd, &image_vmo);
|
||||
close(fd);
|
||||
|
||||
if (err != 0) {
|
||||
snprintf(dl_error, sizeof dl_error, "cannot load '%s'", path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dl_error[0] = '\0';
|
||||
return dyld_load_object(path, image_vmo, mode);
|
||||
}
|
||||
|
||||
void *dlsym(void *handle, const char *name)
|
||||
{
|
||||
return NULL;
|
||||
return dyld_get_symbol(handle, name);
|
||||
}
|
||||
|
||||
int dlclose(void *handle)
|
||||
{
|
||||
return 0;
|
||||
return dyld_close_object(handle);
|
||||
}
|
||||
|
||||
char *dlerror(void)
|
||||
{
|
||||
return NULL;
|
||||
if (dl_error[0] != '\0') {
|
||||
return dl_error;
|
||||
}
|
||||
|
||||
return dyld_get_error();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user