syscall32.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright 2002,2003 Andi Kleen, SuSE Labs */
  2. /* vsyscall handling for 32bit processes. Map a stub page into it
  3. on demand because 32bit cannot reach the kernel's fixmaps */
  4. #include <linux/mm.h>
  5. #include <linux/string.h>
  6. #include <linux/kernel.h>
  7. #include <linux/gfp.h>
  8. #include <linux/init.h>
  9. #include <linux/stringify.h>
  10. #include <linux/security.h>
  11. #include <asm/proto.h>
  12. #include <asm/tlbflush.h>
  13. #include <asm/ia32_unistd.h>
  14. #include <asm/vsyscall32.h>
  15. extern unsigned char syscall32_syscall[], syscall32_syscall_end[];
  16. extern unsigned char syscall32_sysenter[], syscall32_sysenter_end[];
  17. extern int sysctl_vsyscall32;
  18. static struct page *syscall32_pages[1];
  19. static int use_sysenter = -1;
  20. struct linux_binprm;
  21. /* Setup a VMA at program startup for the vsyscall page */
  22. int syscall32_setup_pages(struct linux_binprm *bprm, int exstack)
  23. {
  24. struct mm_struct *mm = current->mm;
  25. int ret;
  26. down_write(&mm->mmap_sem);
  27. /*
  28. * MAYWRITE to allow gdb to COW and set breakpoints
  29. *
  30. * Make sure the vDSO gets into every core dump.
  31. * Dumping its contents makes post-mortem fully interpretable later
  32. * without matching up the same kernel and hardware config to see
  33. * what PC values meant.
  34. */
  35. /* Could randomize here */
  36. ret = install_special_mapping(mm, VSYSCALL32_BASE, PAGE_SIZE,
  37. VM_READ|VM_EXEC|
  38. VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
  39. VM_ALWAYSDUMP,
  40. syscall32_pages);
  41. up_write(&mm->mmap_sem);
  42. return ret;
  43. }
  44. static int __init init_syscall32(void)
  45. {
  46. char *syscall32_page = (void *)get_zeroed_page(GFP_KERNEL);
  47. if (!syscall32_page)
  48. panic("Cannot allocate syscall32 page");
  49. syscall32_pages[0] = virt_to_page(syscall32_page);
  50. if (use_sysenter > 0) {
  51. memcpy(syscall32_page, syscall32_sysenter,
  52. syscall32_sysenter_end - syscall32_sysenter);
  53. } else {
  54. memcpy(syscall32_page, syscall32_syscall,
  55. syscall32_syscall_end - syscall32_syscall);
  56. }
  57. return 0;
  58. }
  59. __initcall(init_syscall32);
  60. /* May not be __init: called during resume */
  61. void syscall32_cpu_init(void)
  62. {
  63. if (use_sysenter < 0)
  64. use_sysenter = (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL);
  65. /* Load these always in case some future AMD CPU supports
  66. SYSENTER from compat mode too. */
  67. checking_wrmsrl(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
  68. checking_wrmsrl(MSR_IA32_SYSENTER_ESP, 0ULL);
  69. checking_wrmsrl(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
  70. wrmsrl(MSR_CSTAR, ia32_cstar_target);
  71. }