Beispiel #1
0
static void command_get_children_cache_client(void * x) {
    CommandGetChildrenArgs * args = (CommandGetChildrenArgs *)x;
    Channel * c = cache_channel();
    int err = 0;
    Symbol * sym = NULL;
    Symbol ** list = NULL;
    int cnt = 0;

    if (id2symbol(args->id, &sym) < 0) err = errno;
    if (err == 0 && get_symbol_children(sym, &list, &cnt) < 0) err = errno;

    cache_exit();

    write_stringz(&c->out, "R");
    write_stringz(&c->out, args->token);
    write_errno(&c->out, err);

    if (err == 0) {
        int i;
        write_stream(&c->out, '[');
        for (i = 0; i < cnt; i++) {
            if (i > 0) write_stream(&c->out, ',');
            json_write_string(&c->out, symbol2id(list[i]));
        }
        write_stream(&c->out, ']');
        write_stream(&c->out, 0);
    }
    else {
        write_stringz(&c->out, "null");
    }

    write_stream(&c->out, MARKER_EOM);
}
static void command_get_children(char * token, Channel * c) {
    int err = 0;
    char id[256];
    Symbol sym;
    Symbol * list = NULL;
    int cnt = 0;

    json_read_string(&c->inp, id, sizeof(id));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);

    if (id2symbol(id, &sym) < 0) err = errno;
    if (err == 0 && get_symbol_children(&sym, &list, &cnt) < 0) err = errno;

    write_stringz(&c->out, "R");
    write_stringz(&c->out, token);
    write_errno(&c->out, err);

    if (err == 0) {
        int i;
        write_stream(&c->out, '[');
        for (i = 0; i < cnt; i++) {
            if (i > 0) write_stream(&c->out, ',');
            json_write_string(&c->out, symbol2id(list + i));
        }
        write_stream(&c->out, ']');
        write_stream(&c->out, 0);
    }
    else {
        write_stringz(&c->out, "null");
    }

    write_stream(&c->out, MARKER_EOM);
    loc_free(list);
}
Beispiel #3
0
static ContextAddress find_module(Context * ctx, ELF_File * exe_file, ELF_File * module,
                                  ContextAddress r_map, ContextAddress r_brk) {
#if ENABLE_Symbols
    Symbol * sym = NULL;
    int i = 0, n = 0;
    Symbol ** children = NULL;
    ContextAddress link = r_map;
    Symbol * sym_l_addr = NULL;
    Symbol * sym_l_next = NULL;
    Symbol * sym_l_tls_modid = NULL;
    if (find_symbol_by_name(ctx, STACK_NO_FRAME, r_brk, "link_map", &sym) < 0)
        str_exception(errno, "Cannot find loader symbol: link_map");
    if (get_symbol_children(sym, &children, &n) < 0) exception(errno);
    for (i = 0; i < n; i++) {
        char * name = NULL;
        if (get_symbol_name(children[i], &name) < 0) exception(errno);
        if (name == NULL) continue;
        if (strcmp(name, "l_map_start") == 0) sym_l_addr = children[i];
        else if (strcmp(name, "l_next") == 0) sym_l_next = children[i];
        else if (strcmp(name, "l_tls_modid") == 0) sym_l_tls_modid = children[i];
    }
    if (sym_l_addr == NULL || sym_l_next == NULL || sym_l_tls_modid == NULL)
        str_exception(ERR_OTHER, "Invalid 'link_map' fields");
    while (link != 0) {
        ContextAddress l_tls_modid = 0;
        read_field(ctx, sym_l_tls_modid, link, &l_tls_modid);
        if (l_tls_modid != 0) {
            ContextAddress l_addr = 0;
            ELF_File * link_file = NULL;
            read_field(ctx, sym_l_addr, link, &l_addr);
            elf_map_to_link_time_address(ctx, l_addr, 0, &link_file, NULL);
            if (link_file != NULL) {
                if (link_file == module) return l_tls_modid;
                if (get_dwarf_file(link_file) == module) return l_tls_modid;
            }
        }
        read_field(ctx, sym_l_next, link, &link);
    }
#endif
    return 0;
}