int main(int argc, char ** argv) { int fd = 0; int max_size = 4 * 1024; char newline = '\n'; char * buffer = malloc(max_size * sizeof(char)); int current_size = read_line(fd, buffer, max_size); int pos = find_symbol(newline, buffer, current_size); while (pos != -1) { while (pos != -1) { // process all data process_line(buffer, pos); int line_size = pos + 1; memmove(buffer, buffer + line_size, current_size - line_size); current_size = current_size - line_size; pos = find_symbol(newline, buffer, current_size); } // read new data if (eof) { break; } int r = read_line(fd, buffer + current_size, max_size - current_size); current_size = current_size + r; pos = find_symbol(newline, buffer, current_size); } free(buffer); }
static void find_vold() { char buf[2048], *ptr = NULL; int i = 0, fd; pid_t found = 0; FILE *f = NULL; vold.found = 0; if ((f = fopen("/proc/net/netlink", "r")) == NULL) die("[-] fopen"); for (;!feof(f);) { memset(buf, 0, sizeof(buf)); if (!fgets(buf, sizeof(buf), f)) break; if ((ptr = strtok(buf, "\t ")) == NULL) break; if ((ptr = strtok(NULL, "\t ")) == NULL) break; if ((ptr = strtok(NULL, "\t ")) == NULL) break; if (!*ptr) break; i = atoi(ptr); if (i <= 1) continue; sprintf(buf, "/proc/%d/cmdline", i); if ((fd = open(buf, O_RDONLY)) < 0) continue; memset(buf, 0, sizeof(buf)); read(fd, buf, sizeof(buf) - 1); close(fd); if (strstr(buf, "/system/bin/vold")) { found = i; break; } } fclose(f); if (!found) return; vold.pid = found; vold.found = 1; /* If already called no need to look for the mappings again as * they wont change */ if (vold.system) return; ptr = find_symbol("system"); vold.system = (uint32_t)ptr; printf("[+] Found system: %p strcmp: %p\n", ptr, find_symbol("strcmp")); return; }
void *resolve_service_symbol(const char *name) { if(strncmp(name, "__", 2) != 0) return NULL; name += 2; if(strncmp(name, "syscall_", 8) == 0) return find_symbol(syscalls, name + 8); if(strncmp(name, "eh_", 3) == 0) return find_symbol(eh, name + 3); return find_symbol(compiler_rt, name); }
jvm_agent_t *Jagent_create(struct ps_prochandle *P, int vers) { jvm_agent_t* J; int err; if (vers != JVM_DB_VERSION) { errno = ENOTSUP; return NULL; } J = (jvm_agent_t*)calloc(sizeof(struct jvm_agent), 1); debug = getenv("LIBJVMDB_DEBUG") != NULL; if (debug) debug = 3; if (debug) { fprintf(stderr, "Jagent_create: debug=%d\n", debug); #ifdef X86_COMPILER2 fprintf(stderr, "Jagent_create: R_SP=%d, R_FP=%d, POINTER_SIZE=%d\n", R_SP, R_FP, POINTER_SIZE); #endif /* X86_COMPILER2 */ } J->P = P; // Initialize the initial previous frame J->prev_fr.fp = 0; J->prev_fr.pc = 0; J->prev_fr.sp = 0; J->prev_fr.sender_sp = 0; err = find_symbol(J, "__1cHnmethodG__vtbl_", &J->nmethod_vtbl); CHECK_FAIL(err); err = find_symbol(J, "__1cKBufferBlobG__vtbl_", &J->BufferBlob_vtbl); if (err != PS_OK) J->BufferBlob_vtbl = 0; err = find_symbol(J, "__1cICodeBlobG__vtbl_", &J->CodeBlob_vtbl); CHECK_FAIL(err); err = find_symbol(J, "__1cLRuntimeStubG__vtbl_", &J->RuntimeStub_vtbl); CHECK_FAIL(err); err = find_symbol(J, "__1cNMethodG__vtbl_", &J->Method_vtbl); CHECK_FAIL(err); err = parse_vmstructs(J); CHECK_FAIL(err); err = read_volatiles(J); CHECK_FAIL(err); return J; fail: Jagent_destroy(J); return NULL; }
static Bool check_ifdef_condition(char *name) { Symbol *symbol; symbol = find_symbol(name, CURRENTMODULE->local_symtab); if (symbol != NULL && (symbol->is_defined || (symbol->scope == SCOPE_EXTERN || symbol->scope == SCOPE_GLOBAL))) return TRUE; symbol = find_symbol(name, global_symtab); if (symbol != NULL && (symbol->is_defined || (symbol->scope == SCOPE_EXTERN || symbol->scope == SCOPE_GLOBAL))) return TRUE; return FALSE; }
// GCC-LD do not produce ____div0_from_arm in -r mode and because this division work bad // We add to the end of .text and replace __div0 for specific places with this value. int add_div0_arm() { struct elf32_sym* s; int rv; int symidx; s = find_symbol("__div0"); symidx = last_found_symidx; if ( !s) return ELFFLT_OK; if (s->st_shndx != text.number) { PRINTERR(stderr,"__div0 should be .text symbol\n"); return ELFFLT_UNHANDLED_RELOC; } /* if ( (text.size - s->st_value) != 3 ) { PRINTERR(stderr,"Warning! At %s __div0 is not on the end of .text. Doesn't check such case\n", filename_elf); } */ // Prepare reloc used in added func struct elf32_rela rela; rela.r_info = symidx <<8; rela.r_info |= R_ARM_ABS32; rela.r_offset = text.size+8; rela.r_addend = 0; // Append new func to the end of .text offs_div0_from_arm = text.size; memcpy( flat_buf+text.flat_offset+offs_div0_from_arm, div0_arm, sizeof(div0_arm) ); text.size+=sizeof(div0_arm); // Apply reloc rv = apply_realloc( &text, &rela, &text, s, -1); // Detect allowed to patch points s = find_symbol(".divsi3_skip_div0_test"); if ( s && s->st_shndx == text.number ) { offs_divsi3_skip_div0_test = text.flat_offset + s->st_value + 0x114; } s = find_symbol("__aeabi_uidiv"); if ( s && s->st_shndx == text.number ) { offs__aeabi_uidiv = text.flat_offset + s->st_value + 0xec; } return rv; }
int find_symbol_in_elfhs(Elf32_Sym *in_symbol, Elf32_Sym **out_symbol, task_register_cons **out_symbol_trc, task_register_cons *app_trc, Elf32_Ehdr *sys_elfh, task_register_tree *other_trcs) { Elf32_Sym *final_symbol = NULL; task_register_cons *final_symbol_trc = NULL; Elf32_Shdr *strtab_sect = find_section(".dynstr", app_trc->elfh); char *symbol_name = get_shstr(app_trc->elfh, strtab_sect, in_symbol->st_name); INFO_MSG("Relocating symbol %s\n", symbol_name); if (in_symbol->st_shndx == SHN_UNDEF) { /* * Find the symbol elsewhere. */ if (other_trcs) { task_register_cons *trcp; TASK_ACQUIRE_TR_LOCK(); RB_FOREACH(trcp, task_register_tree_t, other_trcs) { if (trcp == app_trc) continue; DEBUG_MSG("looking for symbol \"%s\" in \"%s\"\n", symbol_name, trcp->name); final_symbol = find_symbol(symbol_name, trcp->elfh); if (final_symbol == NULL) continue; if (final_symbol->st_shndx == SHN_UNDEF) final_symbol = NULL; if (final_symbol != NULL) { final_symbol_trc = trcp; break; } } TASK_RELEASE_TR_LOCK(); } if (final_symbol == NULL) { final_symbol = find_symbol(symbol_name, sys_elfh); /* * If the symbol is found in the system elfh, * let the symbol trc be NULL. */ final_symbol_trc = NULL; } } else {
void analyze_image_haiku_version_and_abi(int fd, image_t* image, elf_ehdr& eheader, int32 sheaderSize, char* buffer, size_t bufferSize) { // Haiku API version elf_sym* symbol = find_symbol(image, SymbolLookupInfo(B_SHARED_OBJECT_HAIKU_VERSION_VARIABLE_NAME, B_SYMBOL_TYPE_DATA, true)); if (symbol != NULL && symbol->st_shndx != SHN_UNDEF && symbol->st_value > 0 && symbol->st_size >= sizeof(uint32)) { image->api_version = *(uint32*)(symbol->st_value + image->regions[0].delta); } else image->api_version = 0; // Haiku ABI symbol = find_symbol(image, SymbolLookupInfo(B_SHARED_OBJECT_HAIKU_ABI_VARIABLE_NAME, B_SYMBOL_TYPE_DATA)); if (symbol != NULL && symbol->st_shndx != SHN_UNDEF && symbol->st_value > 0 && symbol->Type() == STT_OBJECT && symbol->st_size >= sizeof(uint32)) { image->abi = *(uint32*)(symbol->st_value + image->regions[0].delta); } else image->abi = 0; if (image->abi == 0) { // No ABI version in the shared object, i.e. it has been built before // that was introduced in Haiku. We have to try and analyze the gcc // version. if (!analyze_object_gcc_version(fd, image, eheader, sheaderSize, buffer, bufferSize)) { FATAL("%s: Failed to get gcc version.\n", image->path); // not really fatal, actually // assume ancient BeOS image->abi = B_HAIKU_ABI_GCC_2_ANCIENT; } } // guess the API version, if we couldn't figure it out yet if (image->api_version == 0) { image->api_version = image->abi > B_HAIKU_ABI_GCC_2_BEOS ? HAIKU_VERSION_PRE_GLUE_CODE : B_HAIKU_VERSION_BEOS; } }
/* return the level a *variable* has been declared at * or -1 if undeclared */ int level(char *name, data_type_t data_type, YYLTYPE loc) { symbol *s; int i; for ( i = FUNCTION_LEVEL; i <= GLOBAL_LEVEL; i++ ) { s = find_symbol(i, name); if ( s ) { /* function used as var */ if ( s->type == FUNCTION ) { fprintf(stderr, " Function `%s' used as a variable:"" decl: line %d(this file?), use: line %d\n", s->name, s->loc.first_line, loc.first_line); return -1; } if ( s->u.var.data_type != data_type ) { fprintf(stderr, " Type mismatch: variable `%s':"" decl[%s]: line %d(this file?), use[%s]: line %d\n", s->name, data_type_names[s->u.var.data_type], s->loc.first_line, data_type_names[data_type], loc.first_line); return -1; } return i; } } fprintf(stderr, " Undeclared variable: `%s': line %d\n", name, loc.first_line); return -1; }
/* * create a symbol table entry unless one already exists */ void create_symbol( int type, unsigned char value, char *buffer, int length) { TUPLE *tuple; /* * first search for same identifier string */ tuple = find_symbol( data.level, buffer, length); /* * update symbol type entry or make new symbol table entry */ if( tuple) { if( 0 < type) tuple->token = type; if( 0 < value) tuple->value = value; return; } tuple = new_tuple( type, value, get_address( 1), 0, buffer, length); tuple->level = data.level; /* * attach it to the head of the symbol table list (LIFO) */ tuple->next = data.symbol_table; data.symbol_table = tuple; return; }
int apply_relocation(struct LKM_Module *lkm_mod, int sect_num) { int i=0; uint64_t sym_val; struct Secthdr *to_rel_sect, *secthdr = &lkm_mod->sect_hdr[sect_num]; struct Elf64_Rela *rela = (void *)((char *)lkm_mod->tmp_buf + secthdr->sh_offset); size_t size = secthdr->sh_size / sizeof(*rela); void *rel = (void *)((char *)lkm_mod->tmp_buf + lkm_mod->sect_hdr[secthdr->sh_info].sh_offset); struct Symhdr *symhdr = (void *)((char *)lkm_mod->tmp_buf + lkm_mod->sect_hdr[secthdr->sh_link].sh_offset); //secthdr->sh_link will give section header index of symbol table. sh_offset will give me offset of symbol table. Add it to base of file to get the actual address of symbol table. to_rel_sect = &lkm_mod->sect_hdr[secthdr->sh_info]; uint64_t to_rel_size = to_rel_sect->sh_size; struct Elf64_Rela *ptr_rela = rela; while(i < size){ if(ELF64_R_TYPE(ptr_rela->r_info) == R_X86_64_64){ sym_val = find_symbol(lkm_mod, to_rel_sect, symhdr, ptr_rela); if(sym_val == 0){ cprintf("Unable to find symbol value..\n"); return -1; } *((uint64_t *)((char *)rel + ptr_rela->r_offset)) = sym_val; } i++; ptr_rela++; } return 0; }
static value_object eval_function(char* name, expr_list* args) { expr_list* head = args; value_list* arg_vals = NULL; while (head != NULL) { value_object v = eval_aux(head->expression); arg_vals = append_value(arg_vals, v); head = head->next; } fpl_function fun; symbol_def* symbol = find_symbol(name); if (symbol == NULL) { fprintf(stderr, "Error: function `%s' does not exist\n", name); return make_null(); } if (symbol->type != SYM_FUNCTION) { fprintf(stderr, "Error: `%s' is not a function\n", name); return make_null(); } value_object val = (symbol->function)(arg_vals); return val; }
void process_extern() { SYM *sym; NextToken(); if (token != tk_id) printf("Expecting an identifier.\r\n"); else { sym = find_symbol(lastid); if (pass == 3) { if (sym) { } else { sym = new_symbol(lastid); } if (sym) { sym->defined = 0; sym->value = 0; sym->segment = segment; sym->scope = 'P'; sym->isExtern = 1; } } else if (pass > 3) { } } }
/* TODO: obey static to declare a function to the file level */ symbol *define_function(char *name, YYLTYPE loc, data_type_t return_type, symbol* param_list) { symbol *s; MALLOC(s, symbol, 1); s->type = FUNCTION; s->loc = loc; strcpy(s->name, name); //s->u.func.arity = size; s->u.func.return_type = return_type; s->u.func.defined = TRUE; s->u.func.plist = param_list; print_fn_signature(s); if ( check_duplicate(GLOBAL_LEVEL, s) ) { /* if a prototype exists, replace it by the definition */ symbol *sym; if ( (sym = find_symbol(GLOBAL_LEVEL, s->name)) ) { delete_symbol(GLOBAL_LEVEL, sym); } add_symbol(GLOBAL_LEVEL, s); // add all params as vars to the current function symtable for ( sym = param_list; sym; sym = sym->u.param.next ) if ( !declare_symbol(VARIABLE, sym->name, sym->loc, FUNCTION_LEVEL, sym->u.param.data_type, sym->u.param.size) ) return NULL; return s; } else { nberrs++; printf("errrrrr\n"); return NULL; } }
static int verify_export_symbols(struct module *mod) { unsigned int i; struct module *owner; const struct kernel_symbol *s; struct { const struct kernel_symbol *sym; unsigned int num; } arr[] = { { mod->syms, mod->num_syms},}; for (i = 0; i < ARRAY_SIZE(arr); i++) { for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { if (find_symbol(s->name, &owner, NULL, 0)) { kprintf("verify_export_symbols: " "%s: exports duplicate symbol %s" " (owned by %s)\n", mod->name, s->name, module_name(owner)); return -1; } } } return 0; }
obj_t symbol_name(obj_t symbol) { CHECK_OBJ(symbol); CHECK(is_symbol(symbol), "must be symbol", symbol); obj_t name = fixvec1_get_ptr(symbol, 0); if (is_uninitialized(name)) { size_t max_len = 12; ssize_t name_len; wchar_t name_buf[max_len]; while (true) { name_len = swprintf(name_buf, max_len, L"g%04d", ++gen_name_counter); assert(0 <= name_len && name_len < max_len); name = make_string_from_chars(name_buf, name_len); if (!is_null(find_symbol(name))) continue; /* with lock */ { /* verify symbol still absent */ fixvec1_set_ptr(symbol, 0, name); all_symbols_list = make_pair(symbol, all_symbols_list); } break; } } return name; }
SYM *new_symbol(char *name) { SYM *p; SYM ts; if (p = find_symbol(name)) { printf("Symbol already in table.\r\n"); return p; } if (numsym > 65525) { printf("Too many symbols.\r\n"); return (SYM *)NULL; } if (pass > 5) { printf("%s: added\r\n", name); } ts.name = nmTable.AddName(name); // strncpy(syms[numsym].name, name, sizeof(syms[numsym].name)/sizeof(char)-1); // syms[numsym].name[199] = '\0'; ts.value = 0x8000000000000000LL | numsym; ts.defined = 0; ts.segment = segment; ts.scope = ' '; ts.isExtern = 0; p = insert_symbol(&ts); numsym++; return p; }
/* resolve the imports for a Win32 module */ int resolve_imports( void ) { int i, j; if (nb_undef_symbols == -1) return 0; /* no symbol file specified */ add_extra_undef_symbols(); remove_ignored_symbols(); for (i = 0; i < nb_imports; i++) { struct import *imp = dll_imports[i]; for (j = 0; j < nb_undef_symbols; j++) { const char *res = find_symbol( undef_symbols[j], imp->exports, imp->nb_exports ); if (res) { add_import_func( imp, res ); free( undef_symbols[j] ); undef_symbols[j] = NULL; } } /* remove all the holes in the undef symbols list */ if (!remove_symbol_holes()) warn_unused( imp ); } return 1; }
/* * create a symbol table entry unless one already exists */ void create_symbol( int type, unsigned char value, char *buffer, int length) { CLIPS *clips; /* * first search for same identifier string */ clips = find_symbol( data.level, buffer, length); /* * update symbol type entry or make new symbol table entry */ if( clips) { if( 0 < type) clips->token = type; if( 0 < value) clips->value = value; return; } clips = al_clips( type, value, get_address(), 0, buffer, length); clips->level = data.level; /* * attach it to the head of the symbol table list (LIFO) */ clips->next = data.symbol_table; data.symbol_table = clips; return; }
int read_line(int fd, char * buffer, int max_size) { if (max_size == 0) { return 0; } char newline = '\n'; int pos = -1; int from = 0; while (pos == -1) { int r = read(fd, buffer + from, max_size - from); if (r == 0) { eof = 1; if (buffer[from - 1] != newline) { buffer[from] = newline; from = from + 1; } return from; } pos = find_symbol(newline, buffer + from, r); from = from + r; if (from == max_size && pos == -1) { write(1, "buffer is full", 14); _exit(1); } } return from; }
static void add_reloc(Elf *elf) { char name[100]; for (int i = 0; i < LIST_LEN(elf->sections); i++) { Section *sect = LIST_REF(elf->sections, i); if (LIST_LEN(sect->rels) == 0) continue; String *b = make_string(); for (int j = 0; j < LIST_LEN(sect->rels); j++) { Reloc *rel = LIST_REF(sect->rels, j); o8(b, rel->off); if (rel->sym) { o8(b, ELF64_R_INFO(find_symbol(elf, rel->sym)->index, rel->type)); } else { o8(b, ELF64_R_INFO(rel->section->symindex, rel->type)); } o8(b, rel->addend); } strcpy(name, ".rela"); strcpy(name + 5, sect->name); Section *relsec = make_section(name, SHT_RELA); relsec->link = elf->symtabnum; relsec->info = i + 1; relsec->body = b; relsec->entsize = 24; relsec->align = 4; add_section(elf, relsec); } }
void initialize_intrinsic() { int i; SYMBOL sp; intrinsic_entry *ep; for (i = 0, ep = &intrinsic_table[0]; INTR_OP((ep = &intrinsic_table[i])) != INTR_END; i++){ if ((ep->langSpec & langSpecSet) == 0) { continue; } if (!(isValidString(INTR_NAME(ep)))) { continue; } if (INTR_HAS_KIND_ARG(ep)) { if (((INTR_OP(ep) != INTR_MINLOC) && (INTR_OP(ep) != INTR_MAXLOC)) && INTR_RETURN_TYPE_SAME_AS(ep) != -1) { fatal("%: Invalid intrinsic initialization.", __func__); } } sp = find_symbol((char *)INTR_NAME(ep)); SYM_TYPE(sp) = S_INTR; SYM_VAL(sp) = i; } }
/* Make sure argument is OK */ static int check_arg(node_ptr arg, int wantbool) { if (!arg) { yyerror("Null node encountered"); return 0; } if (arg->type == N_VAR) { node_ptr qval = find_symbol(arg->sval); if (!qval) { yyserror("Variable '%s' not found", arg->sval); return 0; } if (wantbool != qval->isbool) { if (wantbool) yyserror("Variable '%s' not Boolean", arg->sval); else yyserror("Variable '%s' not integer", arg->sval); return 0; } return 1; } if (arg->type == N_NUM) { if (wantbool && strcmp(arg->sval,"0") != 0 && strcmp(arg->sval,"1") != 0) { yyserror("Value '%s' not Boolean", arg->sval); return 0; } return 1; } if (wantbool && !arg->isbool) yyserror("Non Boolean argument '%s'", show_expr(arg)); if (!wantbool && arg->isbool) yyserror("Non integer argument '%s'", show_expr(arg)); return (wantbool == arg->isbool); }
/*---------------------------------------------------------------------------*/ static uint32_t find_symbol_inflat(const char *symbol, struct relevant_section *have_to_be_sect) { struct elf32_sym* s; struct relevant_section *sect; s = find_symbol(symbol); if ( !s ) { if ( FLAG_WARNSYMBOL ) PRINTERR(stderr, "Warning: not found '%s' symbol\n", symbol); return 0; } sect = find_section(s->st_shndx); if ( sect==0 ) { if ( FLAG_WARNSYMBOL ) PRINTERR(stderr, "Warning: unknown section of '%s' symbol\n",symbol); return 0; } if ( have_to_be_sect && have_to_be_sect->number != sect->number ) { if ( FLAG_WARNSYMBOL ) PRINTERR(stderr, "Warning: wrong section of '%s' symbol - %s while required %s\n", symbol, sect->name, have_to_be_sect->name ); return 0; } return sect->flat_offset + s->st_value; }
void process_definition(char *tok, struct program *prog){ struct symbol *s; // previously declared if( (s = find_symbol(tok, prog->tbl)) ){ // do stuff } // new term else{ s = (struct symbol *) malloc(sizeof(struct symbol)); if(!s){ print_memory_error(prog); return; } memset(s, 0, sizeof(struct symbol)); s->iden = (char *) malloc(strlen(tok)); strncpy(s->iden, tok, strlen(tok)); } struct Term *t = (struct Term *) malloc(sizeof(struct Term)); if(!t){ print_memory_error(prog); return; } strncpy(t->term, tok, strlen(tok)); }
int main (int argc, char *argv[]) { int pid; struct link_map *map; char sym_name[256]; unsigned long sym_addr; unsigned long new_addr, old_addr, rel_addr; pid = atoi (argv[1]); ptrace_attach (pid); map = get_linkmap (pid); sym_addr = find_symbol (pid, map, "_dl_open"); printf ("found _dl_open at addr %p\n", sym_addr); call_dl_open (pid, sym_addr, "/home/joker/JustForFun/Injectso/passwd/so.so"); /* 找到我们的新函数newread的地址 */ strcpy (sym_name, "newread"); /* intercept */ sym_addr = find_symbol (pid, map, sym_name); printf ("%s addr\t %p\n", sym_name, sym_addr); /* 找到read的RELOCATION地址 */ strcpy (sym_name, "read"); rel_addr = find_sym_in_rel (pid, sym_name); printf ("%s rel addr\t %p\n", sym_name, rel_addr); /* 找到用于保存read地址的指针 */ strcpy (sym_name, "oldread"); old_addr = find_symbol (pid, map, sym_name); printf ("%s addr\t %p\n", sym_name, old_addr); /* 函数重定向 */ puts ("intercept..."); /* intercept */ ptrace_read (pid, rel_addr, &new_addr, sizeof (new_addr)); ptrace_write (pid, old_addr, &new_addr, sizeof (new_addr)); ptrace_write (pid, rel_addr, &sym_addr, sizeof (sym_addr)); puts ("injectso ok"); /* 脱离进程 */ ptrace_detach (pid); exit (0); }
void function_and_parameter_check(char * name, int param_count) { symtabEntry * func_sym = find_symbol(name, NULL); if (func_sym == NULL) { printf("Error: There is no function named '%s'!\n", name); } else if (func_sym->parameter != param_count) { printf("Error: '%s' expected %i parameters, but got %i!\n", name, func_sym->parameter, param_count); } }
image_id preload_image(char const* path) { if (path == NULL) return B_BAD_VALUE; KTRACE("rld: preload_image(\"%s\")", path); image_t *image = NULL; status_t status = load_image(path, B_LIBRARY_IMAGE, NULL, NULL, &image); if (status < B_OK) { KTRACE("rld: preload_image(\"%s\") failed to load container: %s", path, strerror(status)); return status; } if (image->find_undefined_symbol == NULL) image->find_undefined_symbol = find_undefined_symbol_global; status = load_dependencies(image); if (status < B_OK) goto err; set_image_flags_recursively(image, RTLD_GLOBAL); status = relocate_dependencies(image); if (status < B_OK) goto err; status = add_preloaded_image(image); if (status < B_OK) goto err; inject_runtime_loader_api(image); remap_images(); init_dependencies(image, true); // if the image contains an add-on, register it runtime_loader_add_on* addOnStruct; if (find_symbol(image, SymbolLookupInfo("__gRuntimeLoaderAddOn", B_SYMBOL_TYPE_DATA), (void**)&addOnStruct) == B_OK) { add_add_on(image, addOnStruct); } KTRACE("rld: preload_image(\"%s\") done: id: %" B_PRId32, path, image->id); return image->id; err: KTRACE("rld: preload_image(\"%s\") failed: %s", path, strerror(status)); dequeue_loaded_image(image); delete_image(image); return status; }
///Function to find a vector symbol definition inline vector_expr_node* find_local_symbol(const char* sym_name, bool assert_on_fail = true) const{ vector_expr_node* vec_expr = find_symbol(sym_name); if( assert_on_fail && !vec_expr ){ fprintf(stderr,"ERROR : Unknown Symbol %s\n",sym_name); fflush(stderr); exit(1); } return vec_expr; }
void update_and_append_scope(symtabEntry * scope, char * name, symtabEntryType type, int parameter_count) { int i; symtabEntry * existing = find_symbol(name, 0); if (existing != NULL) { if (parameter_count != existing->parameter) { puts("Parameter count not matched.\n"); } else { for (i = 0; i < parameter_count; ++i) { symtabEntry * param1 = find_parameter_symbol(scope, i + 1, scope); symtabEntry * param2 = find_parameter_symbol(existing, i + 1, theSymboltable); if (param1 == NULL) { puts("Could not find the parameter in the current scope"); } else if (param2 == NULL) { puts("Could not find the parameter in the existing symbol table"); } else if (param1->type != param2->type) { puts("Parameters of prototype do not match actual function definition in `__test__`\n"); } } } for (i = 0; i < existing->parameter; ++i) { delete_symbol(find_parameter_symbol(existing, i + 1, theSymboltable)); } delete_symbol(find_symbol(name, 0)); } scope->name = strdup(name); if (strcmp(scope->name, "main") == 0) { scope->type = PROG; } else if (type == NOP) { scope->type = PROC; } else { scope->type = FUNC; scope->internType = type; } scope->parameter = parameter_count; append_to_symbol_table(scope); }