#include #include #include #include #include #include #include __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) { /* 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 dyld_get_symbol(handle, name); } int dlclose(void *handle) { return dyld_close_object(handle); } char *dlerror(void) { if (dl_error[0] != '\0') { return dl_error; } return dyld_get_error(); }