memcpy.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Optimized memory copy routines.
  3. *
  4. * Copyright (C) 2004 Randolph Chung <tausq@debian.org>
  5. * Copyright (C) 2013-2017 Helge Deller <deller@gmx.de>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. * Portions derived from the GNU C Library
  22. * Copyright (C) 1991, 1997, 2003 Free Software Foundation, Inc.
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/compiler.h>
  27. #include <linux/uaccess.h>
  28. DECLARE_PER_CPU(struct exception_data, exception_data);
  29. #define get_user_space() (segment_eq(get_fs(), KERNEL_DS) ? 0 : mfsp(3))
  30. #define get_kernel_space() (0)
  31. /* Returns 0 for success, otherwise, returns number of bytes not transferred. */
  32. extern unsigned long pa_memcpy(void *dst, const void *src,
  33. unsigned long len);
  34. unsigned long __copy_to_user(void __user *dst, const void *src,
  35. unsigned long len)
  36. {
  37. mtsp(get_kernel_space(), 1);
  38. mtsp(get_user_space(), 2);
  39. return pa_memcpy((void __force *)dst, src, len);
  40. }
  41. EXPORT_SYMBOL(__copy_to_user);
  42. unsigned long __copy_from_user(void *dst, const void __user *src,
  43. unsigned long len)
  44. {
  45. mtsp(get_user_space(), 1);
  46. mtsp(get_kernel_space(), 2);
  47. return pa_memcpy(dst, (void __force *)src, len);
  48. }
  49. EXPORT_SYMBOL(__copy_from_user);
  50. unsigned long copy_in_user(void __user *dst, const void __user *src, unsigned long len)
  51. {
  52. mtsp(get_user_space(), 1);
  53. mtsp(get_user_space(), 2);
  54. return pa_memcpy((void __force *)dst, (void __force *)src, len);
  55. }
  56. void * memcpy(void * dst,const void *src, size_t count)
  57. {
  58. mtsp(get_kernel_space(), 1);
  59. mtsp(get_kernel_space(), 2);
  60. pa_memcpy(dst, src, count);
  61. return dst;
  62. }
  63. EXPORT_SYMBOL(copy_in_user);
  64. EXPORT_SYMBOL(memcpy);
  65. long probe_kernel_read(void *dst, const void *src, size_t size)
  66. {
  67. unsigned long addr = (unsigned long)src;
  68. if (addr < PAGE_SIZE)
  69. return -EFAULT;
  70. /* check for I/O space F_EXTEND(0xfff00000) access as well? */
  71. return __probe_kernel_read(dst, src, size);
  72. }