Example #1
0
/* for the -run option: dynamically load symbol from dll */
void *resolve_sym(struct TCCState *s1, const char *symbol, int type)
{
    char buffer[100];
    int sym_index, dll_index;
    void *addr, **m;
    DLLReference *dllref;

    sym_index = pe_find_import(s1, symbol);
    if (0 == sym_index)
        return NULL;
    dll_index = ((Elf32_Sym *)s1->dynsymtab_section->data + sym_index)->st_value;
    dllref = s1->loaded_dlls[dll_index-1];
    if ( !dllref->handle )
    {
        dllref->handle = LoadLibrary(dllref->name);
    }
    addr = GetProcAddress(dllref->handle, symbol);
    if (NULL == addr)
        addr = GetProcAddress(dllref->handle, get_alt_symbol(buffer, symbol));

    if (addr && STT_OBJECT == type) {
        /* need to return a pointer to the address for data objects */
        m = (void**)tcc_malloc(sizeof addr), *m = addr, addr = m;
#ifdef MEM_DEBUG
        /* yep, we don't free it */
        mem_cur_size -= sizeof (void*);
#endif
    }
    return addr;
}
Example #2
0
File: pe.c Project: HarryR/sanos
static int pe_find_import(TCCState *s1, const char *symbol) {
  char buffer[200];
  const char *s;
  int sym_index, n = 0;
  do {
    s = n ? get_alt_symbol(buffer, symbol) : symbol;
    sym_index = find_elf_sym(s1->dynsymtab_section, s);
  } while (sym_index == 0 && ++n < 2);
  return sym_index;
}
Example #3
0
ST_FN int pe_find_import(TCCState * s1, const char *symbol)
{
    char buffer[200];
    const char *s;
    int sym_index, n = 0;
    do {
        s = n ? get_alt_symbol(buffer, symbol) : symbol;
        sym_index = find_elf_sym(s1->dynsymtab_section, s);
        // printf("find %d %s\n", sym_index, s);
    } while (0 == sym_index && ++n < 2);
    return sym_index;
}