Ticket #6271: 0003-elf-support-for-images-with-a-single-rwx-PT_LOAD-program-header.patch

File 0003-elf-support-for-images-with-a-single-rwx-PT_LOAD-program-header.patch, 2.6 KB (added by lucian, 14 years ago)
  • src/system/kernel/elf.cpp

     
    19651965    size_t reservedSize;
    19661966    status_t status;
    19671967    ssize_t length;
     1968    bool textSectionWritable = false;
     1969    int countExecutableHeaders = 0;
    19681970
    19691971    TRACE(("elf_load_kspace: entry path '%s'\n", path));
    19701972
     
    20662068            B_PAGE_SIZE);
    20672069        if (end > reservedSize)
    20682070            reservedSize = end;
     2071        countExecutableHeaders += programHeaders[i].IsExecutable();
    20692072    }
    20702073
    20712074    // Check whether the segments have an unreasonable amount of unused space
     
    21052108        }
    21062109
    21072110        // we're here, so it must be a PT_LOAD segment
    2108         if (programHeaders[i].IsReadWrite()) {
     2111
     2112        // Usually add-ons have two PT_LOAD headers: one for .data one or .text.
     2113        // x86 and PPC may differ in permission bits for .data's PT_LOAD header
     2114        //   x86 is usually RW, PPC is RWE
     2115
     2116        // Some add-ons may have .text and .data concatenated in a single
     2117        // PT_LOAD RWE header and we must map that to .text.
     2118        if (programHeaders[i].IsReadWrite() && (countExecutableHeaders > 1)) {
    21092119            // this is the writable segment
    21102120            if (image->data_region.size != 0) {
    21112121                // we've already created this segment
     
    21222132            }
    21232133            region = &image->text_region;
    21242134
     2135            // some programs may have .text and .data concatenated in a
     2136            // single PT_LOAD section which is readable/writtable/executable
     2137            textSectionWritable = programHeaders[i].IsReadWrite();
     2138
    21252139            snprintf(regionName, B_OS_NAME_LENGTH, "%s_text", fileName);
    21262140        } else {
    21272141            dprintf("%s: weird program header flags 0x%lx\n", fileName,
     
    21912205        goto error5;
    21922206
    21932207    // We needed to read in the contents of the "text" area, but
    2194     // now we can protect it read-only/execute
     2208    // now we can protect it read-only/execute, unless this is a
     2209    // special image with concatenated .text and .data, when it
     2210    // will also nead write access.
    21952211    set_area_protection(image->text_region.id,
    2196         B_KERNEL_READ_AREA | B_KERNEL_EXECUTE_AREA);
     2212        B_KERNEL_READ_AREA | B_KERNEL_EXECUTE_AREA |
     2213        (textSectionWritable ? B_KERNEL_WRITE_AREA : 0));
    21972214
    21982215    // There might be a hole between the two segments, and we don't need to
    21992216    // reserve this any longer
  • headers/private/system/elf32.h

     
    367367inline bool
    368368Elf32_Phdr::IsExecutable() const
    369369{
    370     return (p_flags & PF_PROTECTION_MASK) == (PF_READ | PF_EXECUTE);
     370    return !!(p_flags & PF_EXECUTE);
    371371}
    372372
    373373