elf.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. unsigned int flt_fmt;
  21. /* APCS26 is only allowed if the CPU supports it */
  22. if ((eflags & EF_ARM_APCS_26) && !(elf_hwcap & HWCAP_26BIT))
  23. return 0;
  24. flt_fmt = eflags & (EF_ARM_VFP_FLOAT | EF_ARM_SOFT_FLOAT);
  25. /* VFP requires the supporting code */
  26. if (flt_fmt == EF_ARM_VFP_FLOAT && !(elf_hwcap & HWCAP_VFP))
  27. return 0;
  28. }
  29. return 1;
  30. }
  31. EXPORT_SYMBOL(elf_check_arch);
  32. void elf_set_personality(const struct elf32_hdr *x)
  33. {
  34. unsigned int eflags = x->e_flags;
  35. unsigned int personality = current->personality & ~PER_MASK;
  36. /*
  37. * We only support Linux ELF executables, so always set the
  38. * personality to LINUX.
  39. */
  40. personality |= PER_LINUX;
  41. /*
  42. * APCS-26 is only valid for OABI executables
  43. */
  44. if ((eflags & EF_ARM_EABI_MASK) == EF_ARM_EABI_UNKNOWN &&
  45. (eflags & EF_ARM_APCS_26))
  46. personality &= ~ADDR_LIMIT_32BIT;
  47. else
  48. personality |= ADDR_LIMIT_32BIT;
  49. set_personality(personality);
  50. /*
  51. * Since the FPA coprocessor uses CP1 and CP2, and iWMMXt uses CP0
  52. * and CP1, we only enable access to the iWMMXt coprocessor if the
  53. * binary is EABI or softfloat (and thus, guaranteed not to use
  54. * FPA instructions.)
  55. */
  56. if (elf_hwcap & HWCAP_IWMMXT &&
  57. eflags & (EF_ARM_EABI_MASK | EF_ARM_SOFT_FLOAT)) {
  58. set_thread_flag(TIF_USING_IWMMXT);
  59. } else {
  60. clear_thread_flag(TIF_USING_IWMMXT);
  61. }
  62. }
  63. EXPORT_SYMBOL(elf_set_personality);
  64. /*
  65. * Set READ_IMPLIES_EXEC if:
  66. * - the binary requires an executable stack
  67. * - we're running on a CPU which doesn't support NX.
  68. */
  69. int arm_elf_read_implies_exec(const struct elf32_hdr *x, int executable_stack)
  70. {
  71. if (executable_stack != EXSTACK_DISABLE_X)
  72. return 1;
  73. if (cpu_architecture() < CPU_ARCH_ARMv6)
  74. return 1;
  75. return 0;
  76. }
  77. EXPORT_SYMBOL(arm_elf_read_implies_exec);