void do_open( char_data* ch, char* argument ) { thing_data* thing; obj_data* obj; exit_data* door; if( is_confused_pet( ch ) ) return; if( ( thing = one_thing( ch, argument, "open", (thing_array*) &ch->in_room->exits, ch->array, &ch->contents ) ) == NULL ) return; if( ( obj = object( thing ) ) != NULL ) { include_closed = FALSE; open_object( ch, obj ); include_closed = TRUE; return; } if( ( door = exit( thing ) ) != NULL ) { open_door( ch, door ); return; } send( ch, "%s isn't something you can open.\n\r", thing ); }
static XIM _XDynamicOpenIM(XLCd lcd, Display *display, XrmDatabase rdb, char *res_name, char *res_class) { XIM im = (XIM)NULL; char lc_dir[BUFSIZE]; char *lc_name; dynamicOpenProcp im_openIM = (dynamicOpenProcp)NULL; int count; XI18NObjectsList objects_list = xi18n_objects_list; lc_name = lcd->core->name; if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XIM)0; count = lc_count; for (; count-- > 0; objects_list++) { if (objects_list->type != XIM_OBJECT || strcmp(objects_list->locale_name, lc_name)) continue; if (!open_object (objects_list, lc_dir)) continue; im_openIM = (dynamicOpenProcp)fetch_symbol(objects_list, objects_list->open); if (!im_openIM) continue; im = (*im_openIM)(lcd, display, rdb, res_name, res_class); if (im != (XIM)NULL) { break; } close_object (objects_list); } return (XIM)im; }
XLCd _XlcDynamicLoad(const char *lc_name) { XLCd lcd = (XLCd)NULL; dynamicLoadProc lc_loader = (dynamicLoadProc)NULL; int count; XI18NObjectsList objects_list; char lc_dir[BUFSIZE]; if (lc_name == NULL) return (XLCd)NULL; if (_XlcLocaleDirName(lc_dir, BUFSIZE, (char *)lc_name) == (char*)NULL) return (XLCd)NULL; resolve_object(lc_dir, lc_name); objects_list = xi18n_objects_list; count = lc_count; for (; count-- > 0; objects_list++) { if (objects_list->type != XLC_OBJECT || strcmp(objects_list->locale_name, lc_name)) continue; if (!open_object (objects_list, lc_dir)) continue; lc_loader = (dynamicLoadProc)fetch_symbol (objects_list, objects_list->open); if (!lc_loader) continue; lcd = (*lc_loader)(lc_name); if (lcd != (XLCd)NULL) { break; } close_object (objects_list); } return (XLCd)lcd; }
static void * do_actual_load(const char * filename, elf_t * lib, int flags) { (void)flags; if (!lib) { last_error = "could not open library (not found, or other failure)"; return NULL; } size_t lib_size = object_calculate_size(lib); if (lib_size < 4096) { lib_size = 4096; } uintptr_t load_addr = (uintptr_t)malloc(lib_size); object_load(lib, load_addr); object_postload(lib); node_t * item; while (item = list_pop(lib->dependencies)) { elf_t * lib = open_object(item->value); if (!lib) { free((void *)load_addr); last_error = "Failed to load a dependency."; return NULL; } if (!lib->loaded) { do_actual_load(item->value, lib, 0); TRACE_LD("Loaded %s at 0x%x", item->value, lib->base); } } TRACE_LD("Relocating %s", filename); object_relocate(lib); fclose(lib->file); if (lib->ctors) { for (size_t i = 0; i < lib->ctors_size; i += sizeof(uintptr_t)) { TRACE_LD(" 0x%x()", lib->ctors[i]); lib->ctors[i](); } } if (lib->init) { lib->init(); } return (void *)lib; }
int32_t open_system_objects(container_handle_t *ct) { int32_t ret; object_handle_t *obj; ct->base_blk = ct->sb.base_blk; /* open BASE object */ ret = open_object(ct, ct->sb.base_id, ct->sb.base_inode_no, &obj); if (ret < 0) { LOG_ERROR("Open base object failed. ct_name(%s) ret(%d)\n", ct->name, ret); return ret; } ofs_init_sm(&ct->bsm, obj, ct->sb.base_first_free_block, ct->sb.base_free_blocks); /* open SPACE object */ ret = open_object(ct, ct->sb.space_id, ct->sb.space_inode_no, &obj); if (ret < 0) { LOG_ERROR("Open space object failed. ct_name(%s) ret(%d)\n", ct->name, ret); return ret; } ofs_init_sm(&ct->sm, obj, ct->sb.first_free_block, ct->sb.free_blocks); /* open $OBJID object */ ret = open_object(ct, ct->sb.objid_id, ct->sb.objid_inode_no, &obj); if (ret < 0) { LOG_ERROR("Open objid object failed. ct_name(%s) ret(%d)\n", ct->name, ret); return ret; } ct->id_obj = obj; return 0; }
static void * dlopen_ld(const char * filename, int flags) { TRACE_LD("dlopen(%s,0x%x)", filename, flags); elf_t * lib = open_object(filename); if (lib->loaded) { return lib; } void * ret = do_actual_load(filename, lib, flags); TRACE_LD("Loaded %s at 0x%x", filename, lib->base); return ret; }
static Bool _XDynamicRegisterIMInstantiateCallback( XLCd lcd, Display *display, XrmDatabase rdb, char *res_name, char *res_class, XIDProc callback, XPointer client_data) { char lc_dir[BUFSIZE]; char *lc_name; dynamicRegisterCBProcp im_registerIM = (dynamicRegisterCBProcp)NULL; Bool ret_flag = False; int count; XI18NObjectsList objects_list = xi18n_objects_list; #if defined(hpux) int getsyms_cnt, i; struct shl_symbol *symbols; #endif lc_name = lcd->core->name; if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False; count = lc_count; for (; count-- > 0; objects_list++) { if (objects_list->type != XIM_OBJECT || strcmp(objects_list->locale_name, lc_name)) continue; if (!open_object (objects_list, lc_dir)) continue; im_registerIM = (dynamicRegisterCBProcp)fetch_symbol(objects_list, objects_list->im_register); if (!im_registerIM) continue; ret_flag = (*im_registerIM)(lcd, display, rdb, res_name, res_class, callback, client_data); if (ret_flag) break; close_object (objects_list); } return (Bool)ret_flag; }
static XOM _XDynamicOpenOM(XLCd lcd, Display *display, XrmDatabase rdb, _Xconst char *res_name, _Xconst char *res_class) { XOM om = (XOM)NULL; int count; char lc_dir[BUFSIZE]; char *lc_name; dynamicIOpenProcp om_openOM = (dynamicIOpenProcp)NULL; XI18NObjectsList objects_list = xi18n_objects_list; #if defined(hpux) int getsyms_cnt, i; struct shl_symbol *symbols; #endif lc_name = lcd->core->name; if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XOM)0; count = lc_count; for (; count-- > 0; objects_list++) { if (objects_list->type != XOM_OBJECT || strcmp(objects_list->locale_name, lc_name)) continue; if (!open_object (objects_list, lc_dir)) continue; om_openOM = (dynamicIOpenProcp)fetch_symbol(objects_list, objects_list->open); if (!om_openOM) continue; om = (*om_openOM)(lcd, display, rdb, res_name, res_class); if (om != (XOM)NULL) { break; } close_object(objects_list); } return (XOM)om; }
int main(int argc, char * argv[]) { char * file = argv[1]; size_t arg_offset = 1; if (!strcmp(argv[1], "-e")) { arg_offset = 3; file = argv[2]; } char * trace_ld_env = getenv("LD_DEBUG"); if (trace_ld_env && (!strcmp(trace_ld_env,"1") || !strcmp(trace_ld_env,"yes"))) { __trace_ld = 1; } dumb_symbol_table = hashmap_create(10); glob_dat = hashmap_create(10); objects_map = hashmap_create(10); ld_exports_t * ex = ld_builtin_exports; while (ex->name) { hashmap_set(dumb_symbol_table, ex->name, ex->symbol); ex++; } elf_t * main_obj = open_object(file); _main_obj = main_obj; if (!main_obj) { fprintf(stderr, "%s: error: failed to open object '%s'.\n", argv[0], file); return 1; } size_t main_size = object_calculate_size(main_obj); uintptr_t end_addr = object_load(main_obj, 0x0); object_postload(main_obj); object_find_copy_relocations(main_obj); hashmap_t * libs = hashmap_create(10); list_t * ctor_libs = list_create(); list_t * init_libs = list_create(); TRACE_LD("Loading dependencies."); node_t * item; while (item = list_pop(main_obj->dependencies)) { while (end_addr & 0xFFF) { end_addr++; } char * lib_name = item->value; if (!strcmp(lib_name, "libg.so")) goto nope; elf_t * lib = open_object(lib_name); if (!lib) { fprintf(stderr, "Failed to load dependency '%s'.\n", lib_name); return 1; } hashmap_set(libs, lib_name, lib); TRACE_LD("Loading %s at 0x%x", lib_name, end_addr); end_addr = object_load(lib, end_addr); object_postload(lib); TRACE_LD("Relocating %s", lib_name); object_relocate(lib); fclose(lib->file); /* Execute constructors */ if (lib->ctors) { list_insert(ctor_libs, lib); } if (lib->init) { list_insert(init_libs, lib); } nope: free(item); } TRACE_LD("Relocating main object"); object_relocate(main_obj); TRACE_LD("Placing heap at end"); while (end_addr & 0xFFF) { end_addr++; } char * ld_no_ctors = getenv("LD_DISABLE_CTORS"); if (ld_no_ctors && (!strcmp(ld_no_ctors,"1") || !strcmp(ld_no_ctors,"yes"))) { TRACE_LD("skipping ctors because LD_DISABLE_CTORS was set"); } else { foreach(node, ctor_libs) { elf_t * lib = node->value; if (lib->ctors) { TRACE_LD("Executing ctors..."); for (size_t i = 0; i < lib->ctors_size; i += sizeof(uintptr_t)) { TRACE_LD(" 0x%x()", lib->ctors[i]); lib->ctors[i](); } } } }