pagecopy.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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, see
  14. <http://www.gnu.org/licenses/>. */
  15. /* This file defines the macro:
  16. PAGE_COPY_FWD_MAYBE (dstp, srcp, nbytes_left, nbytes)
  17. which is invoked like WORD_COPY_FWD et al. The pointers should be at
  18. least word aligned. This will check if virtual copying by pages can and
  19. should be done and do it if so.
  20. System-specific pagecopy.h files should define these macros and then
  21. #include this file:
  22. PAGE_COPY_THRESHOLD
  23. -- Minimum size for which virtual copying by pages is worthwhile.
  24. PAGE_SIZE
  25. -- Size of a page.
  26. PAGE_COPY_FWD (dstp, srcp, nbytes_left, nbytes)
  27. -- Macro to perform the virtual copy operation.
  28. The pointers will be aligned to PAGE_SIZE bytes.
  29. */
  30. #if defined PAGE_COPY_THRESHOLD && PAGE_COPY_THRESHOLD
  31. #include <assert.h>
  32. #define PAGE_COPY_FWD_MAYBE(dstp, srcp, nbytes_left, nbytes) \
  33. do \
  34. { \
  35. if ((nbytes) >= PAGE_COPY_THRESHOLD && \
  36. PAGE_OFFSET ((dstp) - (srcp)) == 0) \
  37. { \
  38. /* The amount to copy is past the threshold for copying \
  39. pages virtually with kernel VM operations, and the \
  40. source and destination addresses have the same alignment. */ \
  41. size_t nbytes_before = PAGE_OFFSET (-(dstp)); \
  42. if (nbytes_before != 0) \
  43. { \
  44. /* First copy the words before the first page boundary. */ \
  45. WORD_COPY_FWD (dstp, srcp, nbytes_left, nbytes_before); \
  46. assert (nbytes_left == 0); \
  47. nbytes -= nbytes_before; \
  48. } \
  49. PAGE_COPY_FWD (dstp, srcp, nbytes_left, nbytes); \
  50. } \
  51. } while (0)
  52. /* The page size is always a power of two, so we can avoid modulo division. */
  53. #define PAGE_OFFSET(n) ((n) & (PAGE_SIZE - 1))
  54. #else
  55. #define PAGE_COPY_FWD_MAYBE(dstp, srcp, nbytes_left, nbytes) /* nada */
  56. #endif