Back to index

glibc  2.9
pagecopy.h
Go to the documentation of this file.
00001 /* Macros for copying by pages; used in memcpy, memmove.  Generic macros.
00002    Copyright (C) 1995, 1997 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 /* This file defines the macro:
00021 
00022    PAGE_COPY_FWD_MAYBE (dstp, srcp, nbytes_left, nbytes)
00023 
00024    which is invoked like WORD_COPY_FWD et al.  The pointers should be at
00025    least word aligned.  This will check if virtual copying by pages can and
00026    should be done and do it if so.
00027 
00028    System-specific pagecopy.h files should define these macros and then
00029    #include this file:
00030 
00031    PAGE_COPY_THRESHOLD
00032    -- Minimum size for which virtual copying by pages is worthwhile.
00033 
00034    PAGE_SIZE
00035    -- Size of a page.
00036 
00037    PAGE_COPY_FWD (dstp, srcp, nbytes_left, nbytes)
00038    -- Macro to perform the virtual copy operation.
00039    The pointers will be aligned to PAGE_SIZE bytes.
00040 */
00041 
00042 
00043 #if PAGE_COPY_THRESHOLD
00044 
00045 #include <assert.h>
00046 
00047 #define PAGE_COPY_FWD_MAYBE(dstp, srcp, nbytes_left, nbytes)                \
00048   do                                                                 \
00049     {                                                                \
00050       if ((nbytes) >= PAGE_COPY_THRESHOLD &&                                \
00051          PAGE_OFFSET ((dstp) - (srcp)) == 0)                                \
00052        {                                                             \
00053          /* The amount to copy is past the threshold for copying            \
00054             pages virtually with kernel VM operations, and the              \
00055             source and destination addresses have the same alignment.  */    \
00056          size_t nbytes_before = PAGE_OFFSET (-(dstp));                      \
00057          if (nbytes_before != 0)                                     \
00058            {                                                         \
00059              /* First copy the words before the first page boundary.  */     \
00060              WORD_COPY_FWD (dstp, srcp, nbytes_left, nbytes_before);        \
00061              assert (nbytes_left == 0);                              \
00062              nbytes -= nbytes_before;                                       \
00063            }                                                         \
00064          PAGE_COPY_FWD (dstp, srcp, nbytes_left, nbytes);                   \
00065        }                                                             \
00066     } while (0)
00067 
00068 /* The page size is always a power of two, so we can avoid modulo division.  */
00069 #define PAGE_OFFSET(n)      ((n) & (PAGE_SIZE - 1))
00070 
00071 #else
00072 
00073 #define PAGE_COPY_FWD_MAYBE(dstp, srcp, nbytes_left, nbytes) /* nada */
00074 
00075 #endif