Changeset View
Changeset View
Standalone View
Standalone View
libexec/rtld-elf/rtld.c
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | |||||
static void objlist_remove(Objlist *, Obj_Entry *); | static void objlist_remove(Objlist *, Obj_Entry *); | ||||
static int open_binary_fd(const char *argv0, bool search_in_path, | static int open_binary_fd(const char *argv0, bool search_in_path, | ||||
const char **binpath_res); | const char **binpath_res); | ||||
static int parse_args(char* argv[], int argc, bool *use_pathp, int *fdp, | static int parse_args(char* argv[], int argc, bool *use_pathp, int *fdp, | ||||
const char **argv0); | const char **argv0); | ||||
static int parse_integer(const char *); | static int parse_integer(const char *); | ||||
static void *path_enumerate(const char *, path_enum_proc, const char *, void *); | static void *path_enumerate(const char *, path_enum_proc, const char *, void *); | ||||
static void print_usage(const char *argv0); | static void print_usage(const char *argv0); | ||||
#if defined(SHLIBRANDOM) | |||||
static void randomize_neededs(Obj_Entry *, int); | |||||
#endif | |||||
static void release_object(Obj_Entry *); | static void release_object(Obj_Entry *); | ||||
static int relocate_object_dag(Obj_Entry *root, bool bind_now, | static int relocate_object_dag(Obj_Entry *root, bool bind_now, | ||||
Obj_Entry *rtldobj, int flags, RtldLockState *lockstate); | Obj_Entry *rtldobj, int flags, RtldLockState *lockstate); | ||||
static int relocate_object(Obj_Entry *obj, bool bind_now, Obj_Entry *rtldobj, | static int relocate_object(Obj_Entry *obj, bool bind_now, Obj_Entry *rtldobj, | ||||
int flags, RtldLockState *lockstate); | int flags, RtldLockState *lockstate); | ||||
static int relocate_objects(Obj_Entry *, bool, Obj_Entry *, int, | static int relocate_objects(Obj_Entry *, bool, Obj_Entry *, int, | ||||
RtldLockState *); | RtldLockState *); | ||||
static int resolve_object_ifunc(Obj_Entry *, bool, int, RtldLockState *); | static int resolve_object_ifunc(Obj_Entry *, bool, int, RtldLockState *); | ||||
▲ Show 20 Lines • Show All 2,291 Lines • ▼ Show 20 Lines | process_needed(Obj_Entry *obj, Needed_Entry *needed, int flags) | ||||
obj1 = needed->obj = load_object(obj->strtab + needed->name, -1, obj, | obj1 = needed->obj = load_object(obj->strtab + needed->name, -1, obj, | ||||
flags & ~RTLD_LO_NOLOAD); | flags & ~RTLD_LO_NOLOAD); | ||||
if (obj1 == NULL && !ld_tracing && (flags & RTLD_LO_FILTEES) == 0) | if (obj1 == NULL && !ld_tracing && (flags & RTLD_LO_FILTEES) == 0) | ||||
return (-1); | return (-1); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
#if defined(SHLIBRANDOM) | |||||
static void | |||||
randomize_neededs(Obj_Entry *obj, int flags) | |||||
{ | |||||
Needed_Entry **needs=NULL, *need=NULL; | |||||
unsigned int i, j, nneed; | |||||
size_t sz = sizeof(unsigned int); | |||||
int mib[2]; | |||||
if (!(obj->needed) || (flags & RTLD_LO_FILTEES)) | |||||
return; | |||||
mib[0] = CTL_KERN; | |||||
mib[1] = KERN_ARND; | |||||
for (nneed = 0, need = obj->needed; need != NULL; need = need->next) | |||||
nneed++; | |||||
if (nneed > 1) { | |||||
needs = xcalloc(nneed, sizeof(Needed_Entry **)); | |||||
for (i = 0, need = obj->needed; i < nneed; i++, need = need->next) | |||||
needs[i] = need; | |||||
for (i=0; i < nneed; i++) { | |||||
do { | |||||
if (sysctl(mib, 2, &j, &sz, NULL, 0)) | |||||
goto err; | |||||
j %= nneed; | |||||
} while (j == i); | |||||
need = needs[i]; | |||||
needs[i] = needs[j]; | |||||
needs[j] = need; | |||||
} | |||||
for (i=0; i < nneed; i++) | |||||
needs[i]->next = i + 1 < nneed ? needs[i + 1] : NULL; | |||||
obj->needed = needs[0]; | |||||
} | |||||
err: | |||||
if (needs != NULL) | |||||
free(needs); | |||||
return; | |||||
} | |||||
#endif | |||||
/* | /* | ||||
* Given a shared object, traverse its list of needed objects, and load | * Given a shared object, traverse its list of needed objects, and load | ||||
* each of them. Returns 0 on success. Generates an error message and | * each of them. Returns 0 on success. Generates an error message and | ||||
* returns -1 on failure. | * returns -1 on failure. | ||||
*/ | */ | ||||
static int | static int | ||||
load_needed_objects(Obj_Entry *first, int flags) | load_needed_objects(Obj_Entry *first, int flags) | ||||
{ | { | ||||
Obj_Entry *obj; | Obj_Entry *obj; | ||||
for (obj = first; obj != NULL; obj = TAILQ_NEXT(obj, next)) { | for (obj = first; obj != NULL; obj = TAILQ_NEXT(obj, next)) { | ||||
if (obj->marker) | if (obj->marker) | ||||
continue; | continue; | ||||
#if defined(SHLIBRANDOM) | |||||
randomize_neededs(obj, flags); | |||||
#endif | |||||
if (process_needed(obj, obj->needed, flags) == -1) | if (process_needed(obj, obj->needed, flags) == -1) | ||||
return (-1); | return (-1); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
load_preload_objects(void) | load_preload_objects(void) | ||||
▲ Show 20 Lines • Show All 3,425 Lines • Show Last 20 Lines |