Ejemplo n.º 1
0
SgAsmElfSection *
SgAsmElfSection::init_from_segment_table(SgAsmElfSegmentTableEntry *shdr, bool mmap_only)
{
    if (!mmap_only) {
        /* Purpose */
        set_purpose(SP_HEADER);

        /* File mapping */
        set_offset(shdr->get_offset());
        set_size(shdr->get_filesz());
        set_file_alignment(shdr->get_align());
        grab_content();
    
        /* Name */
        char name[128];
        switch (shdr->get_type()) {
            case SgAsmElfSegmentTableEntry::PT_LOAD:         strcpy(name, "LOAD");        break;
            case SgAsmElfSegmentTableEntry::PT_DYNAMIC:      strcpy(name, "DYNAMIC");     break;
            case SgAsmElfSegmentTableEntry::PT_INTERP:       strcpy(name, "INTERP");      break;
            case SgAsmElfSegmentTableEntry::PT_NOTE:         strcpy(name, "NOTE");        break;
            case SgAsmElfSegmentTableEntry::PT_SHLIB:        strcpy(name, "SHLIB");       break;
            case SgAsmElfSegmentTableEntry::PT_PHDR:         strcpy(name, "PHDR");        break;
            case SgAsmElfSegmentTableEntry::PT_TLS:          strcpy(name, "TLS");         break;
            case SgAsmElfSegmentTableEntry::PT_GNU_EH_FRAME: strcpy(name, "EH_FRAME");    break;
            case SgAsmElfSegmentTableEntry::PT_GNU_STACK:    strcpy(name, "GNU_STACK");   break;
            case SgAsmElfSegmentTableEntry::PT_GNU_RELRO:    strcpy(name, "GNU_RELRO");   break;
            case SgAsmElfSegmentTableEntry::PT_PAX_FLAGS:    strcpy(name, "PAX_FLAGS");   break;
            case SgAsmElfSegmentTableEntry::PT_SUNWBSS:      strcpy(name, "SUNWBSS");     break;
            case SgAsmElfSegmentTableEntry::PT_SUNWSTACK:    strcpy(name, "SUNWSTACK");   break;
            default:                                         sprintf(name, "PT_0x%08x", shdr->get_type()); break;
        }
        sprintf(name+strlen(name), "#%" PRIuPTR "", shdr->get_index());
        set_name(new SgAsmBasicString(name));
    }
    
    /* Memory mapping */
    set_mapped_preferred_rva(shdr->get_vaddr());
    set_mapped_actual_va(0); /*will be assigned by Loader*/
    set_mapped_size(shdr->get_memsz());
    set_mapped_alignment(shdr->get_align());
    set_mapped_rperm(shdr->get_flags() & SgAsmElfSegmentTableEntry::PF_RPERM ? true : false);
    set_mapped_wperm(shdr->get_flags() & SgAsmElfSegmentTableEntry::PF_WPERM ? true : false);
    set_mapped_xperm(shdr->get_flags() & SgAsmElfSegmentTableEntry::PF_XPERM ? true : false);

    /* Add segment table entry to section */
    set_segment_entry(shdr);
    shdr->set_parent(this);

    return this;
}
Ejemplo n.º 2
0
Archivo: dag.hpp Proyecto: baharev/asol
dag<T>::dag(const char* file_name) {

    std::stringstream in;

    grab_content(file_name, in);

    skip_text(in, "problem name", false);

    skip_text(in, "number of primitives");
    in >> num_of_prims;

    skip_text(in, "number of variables");
    in >> num_of_vars;

    skip_text(in, "number of constraints");
    in >> num_of_cons;

    skip_text(in, "number of nonzeros");
    in >> num_of_nzeros;

    skip_text(in, "number of numeric constants");
    in >> num_of_nums;

    // FIXME Error checking >=0

    //--------------------------------------------------------------------------

    Node = new node<T>*[num_of_prims];

    for (int i=0; i<num_of_prims; ++i)
        Node[i] = 0;

    var = new T[num_of_vars];
    tmp = new T[num_of_prims];
    num = new T[num_of_nums];

    // FIXME Defined variables are unused
    //dfv = new int[n_dfvs];

    con = new T*[num_of_cons];
    constraint_buffer = new T[num_of_cons];

    //--------------------------------------------------------------------------

    skip_text(in, "numeric constant values");

    for (int i=0; i<num_of_nums; ++i) {
        double value;
        in >> value;
        num[i] = T(value);
    }

    //--------------------------------------------------------------------------

    skip_text(in, "constraint indices in primitives");

    for (int i=0; i<num_of_cons; ++i) {
        int index;
        in >> index;
        check_index(index, num_of_prims);
        con[i] = tmp + index;
    }

    //--------------------------------------------------------------------------

    skip_text(in, "primitives");

    for (int i=0; i<num_of_prims; ++i) {

        int arity;
        in >> arity;

        std::string op;
        in >> op;

        int index;
        in >> index;

        if (index != i)
            error("unexpected error");

        if (arity == 1) {
            T* arg = get_arg(in, i);
            add_unary_primitive(op, i, arg);
        }
        else if (arity == 2) {
            T* arg1 = get_arg(in, i);
            T* arg2 = get_arg(in, i);
            add_binary_primitive(op, i, arg1, arg2);
        }
        else {
            error("incorrect arity");
        }
    }

    //--------------------------------------------------------------------------

    // FIXME Make it optional!

    skip_text(in, "initial point");

    for (int i=0; i<num_of_vars; ++i) {
        double value;
        in >> value;
        var[i] = T(value);
    }

    //--------------------------------------------------------------------------

    skip_text(in, "EOF");
}
Ejemplo n.º 3
0
SgAsmElfSection *
SgAsmElfSection::init_from_section_table(SgAsmElfSectionTableEntry *shdr, SgAsmElfStringSection *strsec, int id)
{
    ROSE_ASSERT(shdr);
    ROSE_ASSERT(strsec);
    ROSE_ASSERT(id>=0);

    /* Purpose */
    switch (shdr->get_sh_type()) {
      case SgAsmElfSectionTableEntry::SHT_PROGBITS:
        set_purpose(SP_PROGRAM);
        break;
      case SgAsmElfSectionTableEntry::SHT_STRTAB:
        set_purpose(SP_HEADER);
        break;
      case SgAsmElfSectionTableEntry::SHT_DYNSYM:
      case SgAsmElfSectionTableEntry::SHT_SYMTAB:
        set_purpose(SP_SYMTAB);
        break;
      default:
        set_purpose(SP_OTHER);
        break;
    }

    /* File mapping */
    set_offset(shdr->get_sh_offset());
    if (SgAsmElfSectionTableEntry::SHT_NULL==shdr->get_sh_type() ||
        SgAsmElfSectionTableEntry::SHT_NOBITS==shdr->get_sh_type()) {
        set_size(0);
    } else {
        set_size(shdr->get_sh_size());
    }
    set_file_alignment(shdr->get_sh_addralign());
    grab_content();

    /* Memory mapping */
    if (shdr->get_sh_addr() > 0) {
        set_mapped_preferred_rva(shdr->get_sh_addr());
        set_mapped_actual_va(0); /*will be assigned by Loader*/
        set_mapped_size(shdr->get_sh_size());
        set_mapped_rperm(true);
        set_mapped_wperm((shdr->get_sh_flags() & 0x01) == 0x01);
        set_mapped_xperm((shdr->get_sh_flags() & 0x04) == 0x04);
        set_mapped_alignment(shdr->get_sh_addralign());
    } else {
        set_mapped_preferred_rva(0);
        set_mapped_actual_va(0); /*will be assigned by Loader*/
        set_mapped_size(0);
        set_mapped_rperm(false);
        set_mapped_wperm(false);
        set_mapped_xperm(false);
        set_mapped_alignment(shdr->get_sh_addralign());
    }

    /* Name. This has to be near the end because possibly strsec==this, in which case we have to call set_size() to extend the
     * section to be large enough before we can try to look up the name. */
    set_id(id);
    set_name(new SgAsmStoredString(strsec->get_strtab(), shdr->get_sh_name()));

    /* Add section table entry to section */
    set_section_entry(shdr);
    shdr->set_parent(this);

    return this;
}