Ticket #8520: runtimeloader_archcheck_2.diff

File runtimeloader_archcheck_2.diff, 2.1 KB (added by kallisti5, 12 years ago)

patch v2, not at all tested :)

  • headers/os/support/Errors.h

    diff --git a/headers/os/support/Errors.h b/headers/os/support/Errors.h
    index 48f5699..19a0032 100644
    a b  
    7474
    7575#define B_DEBUGGER_ALREADY_INSTALLED    (B_OS_ERROR_BASE + 0x400)
    7676
     77#define B_BAD_IMAGE_ARCHITECTURE    (B_OS_ERROR_BASE + 0x410)
     78#define B_BAD_IMAGE_PLATFORM        (B_OS_ERROR_BASE + 0x411)
     79
    7780/* Application Kit Errors */
    7881#define B_BAD_REPLY                         (B_APP_ERROR_BASE + 0)
    7982#define B_DUPLICATE_REPLY                   (B_APP_ERROR_BASE + 1)
  • src/system/runtime_loader/runtime_loader.cpp

    diff --git a/src/system/runtime_loader/runtime_loader.cpp b/src/system/runtime_loader/runtime_loader.cpp
    index bbc9c45..37de472 100644
    a b search_executable_in_path_list(const char *name, const char *pathList,  
    215215}
    216216
    217217
     218static status_t
     219test_architecture(uint16 elfMachine)
     220{
     221    char name[128];
     222    switch (elfMachine) {
     223        case EM_386:
     224        case EM_486:
     225            name = "x86";
     226            #if defined(__i386__)
     227            return B_OK;
     228            #endif
     229            // TODO: Multilib check for i386 on x86_64?
     230            break;
     231        case EM_X86_64:
     232            name = "x86_64";
     233            #if defined(__x86_64__)
     234            return B_OK;
     235            #endif
     236            break;
     237        case EM_PPC:
     238        case EM_PPC64:
     239            name = "PowerPC";
     240            #if defined(__powerpc__)
     241            return B_OK;
     242            #endif
     243            break;
     244        case EM_ARM:
     245            name = "ARM";
     246            #if defined(__arm__)
     247            return B_OK;
     248            #endif
     249            break;
     250        case EM_MIPS:
     251            name = "MIPS";
     252            #if defined(__mips__)
     253            return B_OK;
     254            #endif
     255            break;
     256        default:
     257            name = "Unknown";
     258    }
     259    TRACE("runtime_loader: %s not correct architecture\n", name);
     260    return B_BAD_IMAGE_ARCHITECTURE;
     261}
     262
     263
    218264int
    219265open_executable(char *name, image_type type, const char *rpath,
    220266    const char *programPath, const char *compatibilitySubDir)
    test_executable(const char *name, char *invoker)  
    349395        }
    350396    } else if (status == B_OK) {
    351397        struct Elf32_Ehdr *elfHeader = (struct Elf32_Ehdr *)buffer;
     398
     399        status = test_architecture(elfHeader->e_machine);
     400
    352401        if (elfHeader->e_entry == 0) {
    353402            // we don't like to open shared libraries
    354403            status = B_NOT_AN_EXECUTABLE;