| Russell King | 8ec5366 | 2008-09-07 17:16:54 +0100 | [diff] [blame] | 1 | #include <linux/module.h> | 
|  | 2 | #include <linux/sched.h> | 
|  | 3 | #include <linux/personality.h> | 
|  | 4 | #include <linux/binfmts.h> | 
|  | 5 | #include <linux/elf.h> | 
|  | 6 |  | 
|  | 7 | int elf_check_arch(const struct elf32_hdr *x) | 
|  | 8 | { | 
|  | 9 | unsigned int eflags; | 
|  | 10 |  | 
|  | 11 | /* Make sure it's an ARM executable */ | 
|  | 12 | if (x->e_machine != EM_ARM) | 
|  | 13 | return 0; | 
|  | 14 |  | 
|  | 15 | /* Make sure the entry address is reasonable */ | 
|  | 16 | if (x->e_entry & 1) { | 
|  | 17 | if (!(elf_hwcap & HWCAP_THUMB)) | 
|  | 18 | return 0; | 
|  | 19 | } else if (x->e_entry & 3) | 
|  | 20 | return 0; | 
|  | 21 |  | 
|  | 22 | eflags = x->e_flags; | 
|  | 23 | if ((eflags & EF_ARM_EABI_MASK) == EF_ARM_EABI_UNKNOWN) { | 
| Russell King | d2ed5cb | 2008-11-02 09:16:50 +0000 | [diff] [blame] | 24 | unsigned int flt_fmt; | 
|  | 25 |  | 
| Russell King | 8ec5366 | 2008-09-07 17:16:54 +0100 | [diff] [blame] | 26 | /* APCS26 is only allowed if the CPU supports it */ | 
|  | 27 | if ((eflags & EF_ARM_APCS_26) && !(elf_hwcap & HWCAP_26BIT)) | 
|  | 28 | return 0; | 
|  | 29 |  | 
| Russell King | d2ed5cb | 2008-11-02 09:16:50 +0000 | [diff] [blame] | 30 | flt_fmt = eflags & (EF_ARM_VFP_FLOAT | EF_ARM_SOFT_FLOAT); | 
|  | 31 |  | 
| Russell King | 8ec5366 | 2008-09-07 17:16:54 +0100 | [diff] [blame] | 32 | /* VFP requires the supporting code */ | 
| Russell King | d2ed5cb | 2008-11-02 09:16:50 +0000 | [diff] [blame] | 33 | if (flt_fmt == EF_ARM_VFP_FLOAT && !(elf_hwcap & HWCAP_VFP)) | 
| Russell King | 8ec5366 | 2008-09-07 17:16:54 +0100 | [diff] [blame] | 34 | return 0; | 
|  | 35 | } | 
|  | 36 | return 1; | 
|  | 37 | } | 
|  | 38 | EXPORT_SYMBOL(elf_check_arch); | 
|  | 39 |  | 
|  | 40 | void elf_set_personality(const struct elf32_hdr *x) | 
|  | 41 | { | 
|  | 42 | unsigned int eflags = x->e_flags; | 
|  | 43 | unsigned int personality = PER_LINUX_32BIT; | 
|  | 44 |  | 
|  | 45 | /* | 
|  | 46 | * APCS-26 is only valid for OABI executables | 
|  | 47 | */ | 
|  | 48 | if ((eflags & EF_ARM_EABI_MASK) == EF_ARM_EABI_UNKNOWN) { | 
|  | 49 | if (eflags & EF_ARM_APCS_26) | 
|  | 50 | personality = PER_LINUX; | 
|  | 51 | } | 
|  | 52 |  | 
|  | 53 | set_personality(personality); | 
|  | 54 |  | 
|  | 55 | /* | 
|  | 56 | * Since the FPA coprocessor uses CP1 and CP2, and iWMMXt uses CP0 | 
|  | 57 | * and CP1, we only enable access to the iWMMXt coprocessor if the | 
|  | 58 | * binary is EABI or softfloat (and thus, guaranteed not to use | 
|  | 59 | * FPA instructions.) | 
|  | 60 | */ | 
|  | 61 | if (elf_hwcap & HWCAP_IWMMXT && | 
|  | 62 | eflags & (EF_ARM_EABI_MASK | EF_ARM_SOFT_FLOAT)) { | 
|  | 63 | set_thread_flag(TIF_USING_IWMMXT); | 
|  | 64 | } else { | 
|  | 65 | clear_thread_flag(TIF_USING_IWMMXT); | 
|  | 66 | } | 
|  | 67 | } | 
|  | 68 | EXPORT_SYMBOL(elf_set_personality); | 
|  | 69 |  | 
|  | 70 | /* | 
|  | 71 | * Set READ_IMPLIES_EXEC if: | 
|  | 72 | *  - the binary requires an executable stack | 
|  | 73 | *  - we're running on a CPU which doesn't support NX. | 
|  | 74 | */ | 
|  | 75 | int arm_elf_read_implies_exec(const struct elf32_hdr *x, int executable_stack) | 
|  | 76 | { | 
| Makito SHIOKAWA | 9da616f | 2009-02-19 15:34:59 +0100 | [diff] [blame] | 77 | if (executable_stack != EXSTACK_DISABLE_X) | 
| Russell King | 8ec5366 | 2008-09-07 17:16:54 +0100 | [diff] [blame] | 78 | return 1; | 
| Makito SHIOKAWA | 9da616f | 2009-02-19 15:34:59 +0100 | [diff] [blame] | 79 | if (cpu_architecture() < CPU_ARCH_ARMv6) | 
| Russell King | 8ec5366 | 2008-09-07 17:16:54 +0100 | [diff] [blame] | 80 | return 1; | 
| Russell King | 14f0aa3 | 2009-05-23 11:36:20 +0100 | [diff] [blame] | 81 | #if !defined(CONFIG_AEABI) || defined(CONFIG_OABI_COMPAT) | 
|  | 82 | /* | 
|  | 83 | * If we have support for OABI programs, we can never allow NX | 
|  | 84 | * support - our signal syscall restart mechanism relies upon | 
|  | 85 | * being able to execute code placed on the user stack. | 
|  | 86 | */ | 
|  | 87 | return 1; | 
|  | 88 | #else | 
| Russell King | 8ec5366 | 2008-09-07 17:16:54 +0100 | [diff] [blame] | 89 | return 0; | 
| Russell King | 14f0aa3 | 2009-05-23 11:36:20 +0100 | [diff] [blame] | 90 | #endif | 
| Russell King | 8ec5366 | 2008-09-07 17:16:54 +0100 | [diff] [blame] | 91 | } | 
|  | 92 | EXPORT_SYMBOL(arm_elf_read_implies_exec); |