elf.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. int elf_check_arch(const struct elf32_hdr *x)
  7. {
  8. unsigned int eflags;
  9. /* Make sure it's an ARM executable */
  10. if (x->e_machine != EM_ARM)
  11. return 0;
  12. /* Make sure the entry address is reasonable */
  13. if (x->e_entry & 1) {
  14. if (!(elf_hwcap & HWCAP_THUMB))
  15. return 0;
  16. } else if (x->e_entry & 3)
  17. return 0;
  18. eflags = x->e_flags;
  19. if ((eflags & EF_ARM_EABI_MASK) == EF_ARM_EABI_UNKNOWN) {
  20. /* APCS26 is only allowed if the CPU supports it */
  21. if ((eflags & EF_ARM_APCS_26) && !(elf_hwcap & HWCAP_26BIT))
  22. return 0;
  23. /* VFP requires the supporting code */
  24. if ((eflags & EF_ARM_VFP_FLOAT) && !(elf_hwcap & HWCAP_VFP))
  25. return 0;
  26. }
  27. return 1;
  28. }
  29. EXPORT_SYMBOL(elf_check_arch);
  30. void elf_set_personality(const struct elf32_hdr *x)
  31. {
  32. unsigned int eflags = x->e_flags;
  33. unsigned int personality = PER_LINUX_32BIT;
  34. /*
  35. * APCS-26 is only valid for OABI executables
  36. */
  37. if ((eflags & EF_ARM_EABI_MASK) == EF_ARM_EABI_UNKNOWN) {
  38. if (eflags & EF_ARM_APCS_26)
  39. personality = PER_LINUX;
  40. }
  41. set_personality(personality);
  42. /*
  43. * Since the FPA coprocessor uses CP1 and CP2, and iWMMXt uses CP0
  44. * and CP1, we only enable access to the iWMMXt coprocessor if the
  45. * binary is EABI or softfloat (and thus, guaranteed not to use
  46. * FPA instructions.)
  47. */
  48. if (elf_hwcap & HWCAP_IWMMXT &&
  49. eflags & (EF_ARM_EABI_MASK | EF_ARM_SOFT_FLOAT)) {
  50. set_thread_flag(TIF_USING_IWMMXT);
  51. } else {
  52. clear_thread_flag(TIF_USING_IWMMXT);
  53. }
  54. }
  55. EXPORT_SYMBOL(elf_set_personality);
  56. /*
  57. * Set READ_IMPLIES_EXEC if:
  58. * - the binary requires an executable stack
  59. * - we're running on a CPU which doesn't support NX.
  60. */
  61. int arm_elf_read_implies_exec(const struct elf32_hdr *x, int executable_stack)
  62. {
  63. if (executable_stack != EXSTACK_ENABLE_X)
  64. return 1;
  65. if (cpu_architecture() <= CPU_ARCH_ARMv6)
  66. return 1;
  67. return 0;
  68. }
  69. EXPORT_SYMBOL(arm_elf_read_implies_exec);