ldt.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/config.h"
  6. #include "linux/slab.h"
  7. #include "asm/uaccess.h"
  8. #include "asm/ptrace.h"
  9. #include "choose-mode.h"
  10. #include "kern.h"
  11. #ifdef CONFIG_MODE_TT
  12. extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
  13. /* XXX this needs copy_to_user and copy_from_user */
  14. int sys_modify_ldt_tt(int func, void __user *ptr, unsigned long bytecount)
  15. {
  16. if (!access_ok(VERIFY_READ, ptr, bytecount))
  17. return -EFAULT;
  18. return modify_ldt(func, ptr, bytecount);
  19. }
  20. #endif
  21. #ifdef CONFIG_MODE_SKAS
  22. extern int userspace_pid[];
  23. #include "skas_ptrace.h"
  24. int sys_modify_ldt_skas(int func, void __user *ptr, unsigned long bytecount)
  25. {
  26. struct ptrace_ldt ldt;
  27. void *buf;
  28. int res, n;
  29. buf = kmalloc(bytecount, GFP_KERNEL);
  30. if(buf == NULL)
  31. return(-ENOMEM);
  32. res = 0;
  33. switch(func){
  34. case 1:
  35. case 0x11:
  36. res = copy_from_user(buf, ptr, bytecount);
  37. break;
  38. }
  39. if(res != 0){
  40. res = -EFAULT;
  41. goto out;
  42. }
  43. ldt = ((struct ptrace_ldt) { .func = func,
  44. .ptr = buf,
  45. .bytecount = bytecount });
  46. #warning Need to look up userspace_pid by cpu
  47. res = ptrace(PTRACE_LDT, userspace_pid[0], 0, (unsigned long) &ldt);
  48. if(res < 0)
  49. goto out;
  50. switch(func){
  51. case 0:
  52. case 2:
  53. n = res;
  54. res = copy_to_user(ptr, buf, n);
  55. if(res != 0)
  56. res = -EFAULT;
  57. else
  58. res = n;
  59. break;
  60. }
  61. out:
  62. kfree(buf);
  63. return(res);
  64. }
  65. #endif
  66. int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
  67. {
  68. return(CHOOSE_MODE_PROC(sys_modify_ldt_tt, sys_modify_ldt_skas, func,
  69. ptr, bytecount));
  70. }
  71. /*
  72. * Overrides for Emacs so that we follow Linus's tabbing style.
  73. * Emacs will notice this stuff at the end of the file and automatically
  74. * adjust the settings for this buffer only. This must remain at the end
  75. * of the file.
  76. * ---------------------------------------------------------------------------
  77. * Local variables:
  78. * c-file-style: "linux"
  79. * End:
  80. */