-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <errno.h> | ||
#include <string.h> | ||
|
||
#include "dyld.h" | ||
#include "module.h" | ||
#include "load_context.h" | ||
#include "util.h" | ||
#include "fileio.h" | ||
#include "xlog.h" | ||
|
||
void | ||
dyld_init(struct dyld *d) | ||
{ | ||
memset(d, 0, sizeof(*d)); | ||
} | ||
|
||
int | ||
dyld_load_needed_objects(struct dyld *d, struct dyld_object *obj) | ||
{ | ||
struct dylink_needs *needs = &obj->module->dylink->needs; | ||
uint32_t i; | ||
int ret = 0; | ||
for (i = 0; i < needs->count; i++) { | ||
const struct name *name = &needs->names[i]; | ||
char filename[MAX_PATH]; | ||
snprintf(filename, sizeof(filename), "%.*s", CSTR(name)); | ||
ret = dyld_load_object_from_file(d, filename); | ||
if (ret != 0) { | ||
goto fail; | ||
} | ||
} | ||
fail: | ||
return ret; | ||
} | ||
|
||
int | ||
dyld_load_object_from_file(struct dyld *d, const char *name) | ||
{ | ||
struct dyld_object *obj; | ||
int ret; | ||
obj = zalloc(sizeof(*obj)); | ||
if (obj == NULL) { | ||
ret = ENOMEM; | ||
goto fail; | ||
} | ||
ret = map_file(name, &obj->bin, &obj->binsz); | ||
if (ret != 0) { | ||
goto fail; | ||
} | ||
struct load_context lctx; | ||
load_context_init(&lctx); | ||
ret = module_create(&obj->module, obj->bin, obj->bin + obj->binsz, &lctx); | ||
load_context_clear(&lctx); | ||
if (ret != 0) { | ||
goto fail; | ||
} | ||
if (obj->module->dylink == NULL) { | ||
xlog_error("module %s doesn't have dylink.0", name); | ||
ret = EINVAL; | ||
goto fail; | ||
} | ||
ret = dyld_load_needed_objects(d, obj); | ||
fail: | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
struct dyld_plt { | ||
struct finst *finst; | ||
struct tableinst *tableinst; | ||
uint32_t idx_in_table; | ||
}; | ||
|
||
struct dyld_object { | ||
uint32_t memory_base; | ||
uint32_t table_base; | ||
|
||
const uint8_t *bin; | ||
size_t binsz; | ||
struct module *module; | ||
struct instance *instance; | ||
|
||
struct dyld_object *next; | ||
}; | ||
|
||
struct dyld { | ||
uint32_t memory_base; | ||
uint32_t table_base; | ||
struct meminst *meminst; | ||
struct tableinst *tableinst; | ||
struct dyld_object *objs; | ||
}; | ||
|
||
int dyld_resolve_symbol(dyld_object *refobj, enum importtype type, | ||
const struct name *name, void **resultp); |