uaccess_user.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk)
  3. * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
  4. * Licensed under the GPL
  5. */
  6. #include <setjmp.h>
  7. #include <string.h>
  8. /* These are here rather than tt/uaccess.c because skas mode needs them in
  9. * order to do SIGBUS recovery when a tmpfs mount runs out of room.
  10. */
  11. unsigned long __do_user_copy(void *to, const void *from, int n,
  12. void **fault_addr, void **fault_catcher,
  13. void (*op)(void *to, const void *from,
  14. int n), int *faulted_out)
  15. {
  16. unsigned long *faddrp = (unsigned long *) fault_addr, ret;
  17. sigjmp_buf jbuf;
  18. *fault_catcher = &jbuf;
  19. if(sigsetjmp(jbuf, 1) == 0){
  20. (*op)(to, from, n);
  21. ret = 0;
  22. *faulted_out = 0;
  23. }
  24. else {
  25. ret = *faddrp;
  26. *faulted_out = 1;
  27. }
  28. *fault_addr = NULL;
  29. *fault_catcher = NULL;
  30. return ret;
  31. }
  32. void __do_copy(void *to, const void *from, int n)
  33. {
  34. memcpy(to, from, n);
  35. }
  36. int __do_copy_to_user(void *to, const void *from, int n,
  37. void **fault_addr, void **fault_catcher)
  38. {
  39. unsigned long fault;
  40. int faulted;
  41. fault = __do_user_copy(to, from, n, fault_addr, fault_catcher,
  42. __do_copy, &faulted);
  43. if(!faulted) return(0);
  44. else return(n - (fault - (unsigned long) to));
  45. }
  46. /*
  47. * Overrides for Emacs so that we follow Linus's tabbing style.
  48. * Emacs will notice this stuff at the end of the file and automatically
  49. * adjust the settings for this buffer only. This must remain at the end
  50. * of the file.
  51. * ---------------------------------------------------------------------------
  52. * Local variables:
  53. * c-file-style: "linux"
  54. * End:
  55. */