uaccess.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301, USA.
  17. */
  18. /*
  19. * Support for user memory access from kernel. This will
  20. * probably be inlined for performance at some point, but
  21. * for ease of debug, and to a lesser degree for code size,
  22. * we implement here as subroutines.
  23. */
  24. #include <linux/types.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/pgtable.h>
  27. /*
  28. * For clear_user(), exploit previously defined copy_to_user function
  29. * and the fact that we've got a handy zero page defined in kernel/head.S
  30. *
  31. * dczero here would be even faster.
  32. */
  33. __kernel_size_t __clear_user_hexagon(void __user *dest, unsigned long count)
  34. {
  35. long uncleared;
  36. while (count > PAGE_SIZE) {
  37. uncleared = __copy_to_user_hexagon(dest, &empty_zero_page,
  38. PAGE_SIZE);
  39. if (uncleared)
  40. return count - (PAGE_SIZE - uncleared);
  41. count -= PAGE_SIZE;
  42. dest += PAGE_SIZE;
  43. }
  44. if (count)
  45. count = __copy_to_user_hexagon(dest, &empty_zero_page, count);
  46. return count;
  47. }
  48. unsigned long clear_user_hexagon(void __user *dest, unsigned long count)
  49. {
  50. if (!access_ok(VERIFY_WRITE, dest, count))
  51. return count;
  52. else
  53. return __clear_user_hexagon(dest, count);
  54. }