elf.c 2.3 KB

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