pagecopy.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Macros for copying by pages; used in memcpy, memmove. Generic macros.
  2. Copyright (C) 1995, 1997 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library 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 GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. /* This file defines the macro:
  17. PAGE_COPY_FWD_MAYBE (dstp, srcp, nbytes_left, nbytes)
  18. which is invoked like WORD_COPY_FWD et al. The pointers should be at
  19. least word aligned. This will check if virtual copying by pages can and
  20. should be done and do it if so.
  21. System-specific pagecopy.h files should define these macros and then
  22. #include this file:
  23. PAGE_COPY_THRESHOLD
  24. -- Minimum size for which virtual copying by pages is worthwhile.
  25. PAGE_SIZE
  26. -- Size of a page.
  27. PAGE_COPY_FWD (dstp, srcp, nbytes_left, nbytes)
  28. -- Macro to perform the virtual copy operation.
  29. The pointers will be aligned to PAGE_SIZE bytes.
  30. */
  31. #if PAGE_COPY_THRESHOLD
  32. #include <assert.h>
  33. #define PAGE_COPY_FWD_MAYBE(dstp, srcp, nbytes_left, nbytes) \
  34. do \
  35. { \
  36. if ((nbytes) >= PAGE_COPY_THRESHOLD && \
  37. PAGE_OFFSET ((dstp) - (srcp)) == 0) \
  38. { \
  39. /* The amount to copy is past the threshold for copying \
  40. pages virtually with kernel VM operations, and the \
  41. source and destination addresses have the same alignment. */ \
  42. size_t nbytes_before = PAGE_OFFSET (-(dstp)); \
  43. if (nbytes_before != 0) \
  44. { \
  45. /* First copy the words before the first page boundary. */ \
  46. WORD_COPY_FWD (dstp, srcp, nbytes_left, nbytes_before); \
  47. assert (nbytes_left == 0); \
  48. nbytes -= nbytes_before; \
  49. } \
  50. PAGE_COPY_FWD (dstp, srcp, nbytes_left, nbytes); \
  51. } \
  52. } while (0)
  53. /* The page size is always a power of two, so we can avoid modulo division. */
  54. #define PAGE_OFFSET(n) ((n) & (PAGE_SIZE - 1))
  55. #else
  56. #define PAGE_COPY_FWD_MAYBE(dstp, srcp, nbytes_left, nbytes) /* nada */
  57. #endif