/arch/um/sys-i386/ldt.c

https://bitbucket.org/evzijst/gittest · C · 98 lines · 64 code · 19 blank · 15 comment · 11 complexity · 2a67cd1d52311a4f10404bda888a1a69 MD5 · raw file

  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. res = ptrace(PTRACE_LDT, userspace_pid, 0, (unsigned long) &ldt);
  47. if(res < 0)
  48. goto out;
  49. switch(func){
  50. case 0:
  51. case 2:
  52. n = res;
  53. res = copy_to_user(ptr, buf, n);
  54. if(res != 0)
  55. res = -EFAULT;
  56. else
  57. res = n;
  58. break;
  59. }
  60. out:
  61. kfree(buf);
  62. return(res);
  63. }
  64. #endif
  65. int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
  66. {
  67. return(CHOOSE_MODE_PROC(sys_modify_ldt_tt, sys_modify_ldt_skas, func,
  68. ptr, bytecount));
  69. }
  70. /*
  71. * Overrides for Emacs so that we follow Linus's tabbing style.
  72. * Emacs will notice this stuff at the end of the file and automatically
  73. * adjust the settings for this buffer only. This must remain at the end
  74. * of the file.
  75. * ---------------------------------------------------------------------------
  76. * Local variables:
  77. * c-file-style: "linux"
  78. * End:
  79. */