Back to index

glibc  2.9
mman.h
Go to the documentation of this file.
00001 /* Definitions for BSD-style memory management.
00002    Copyright (C) 1994-2000, 2003, 2004, 2005 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 #ifndef       _SYS_MMAN_H
00021 #define       _SYS_MMAN_H   1
00022 
00023 #include <features.h>
00024 #include <bits/types.h>
00025 #define __need_size_t
00026 #include <stddef.h>
00027 
00028 #ifndef __off_t_defined
00029 # ifndef __USE_FILE_OFFSET64
00030 typedef __off_t off_t;
00031 # else
00032 typedef __off64_t off_t;
00033 # endif
00034 # define __off_t_defined
00035 #endif
00036 
00037 #ifndef __mode_t_defined
00038 typedef __mode_t mode_t;
00039 # define __mode_t_defined
00040 #endif
00041 
00042 #include <bits/mman.h>
00043 
00044 /* Return value of `mmap' in case of an error.  */
00045 #define MAP_FAILED   ((void *) -1)
00046 
00047 __BEGIN_DECLS
00048 /* Map addresses starting near ADDR and extending for LEN bytes.  from
00049    OFFSET into the file FD describes according to PROT and FLAGS.  If ADDR
00050    is nonzero, it is the desired mapping address.  If the MAP_FIXED bit is
00051    set in FLAGS, the mapping will be at ADDR exactly (which must be
00052    page-aligned); otherwise the system chooses a convenient nearby address.
00053    The return value is the actual mapping address chosen or MAP_FAILED
00054    for errors (in which case `errno' is set).  A successful `mmap' call
00055    deallocates any previous mapping for the affected region.  */
00056 
00057 #ifndef __USE_FILE_OFFSET64
00058 extern void *mmap (void *__addr, size_t __len, int __prot,
00059                  int __flags, int __fd, __off_t __offset) __THROW;
00060 #else
00061 # ifdef __REDIRECT_NTH
00062 extern void * __REDIRECT_NTH (mmap,
00063                            (void *__addr, size_t __len, int __prot,
00064                             int __flags, int __fd, __off64_t __offset),
00065                            mmap64);
00066 # else
00067 #  define mmap mmap64
00068 # endif
00069 #endif
00070 #ifdef __USE_LARGEFILE64
00071 extern void *mmap64 (void *__addr, size_t __len, int __prot,
00072                    int __flags, int __fd, __off64_t __offset) __THROW;
00073 #endif
00074 
00075 /* Deallocate any mapping for the region starting at ADDR and extending LEN
00076    bytes.  Returns 0 if successful, -1 for errors (and sets errno).  */
00077 extern int munmap (void *__addr, size_t __len) __THROW;
00078 
00079 /* Change the memory protection of the region starting at ADDR and
00080    extending LEN bytes to PROT.  Returns 0 if successful, -1 for errors
00081    (and sets errno).  */
00082 extern int mprotect (void *__addr, size_t __len, int __prot) __THROW;
00083 
00084 /* Synchronize the region starting at ADDR and extending LEN bytes with the
00085    file it maps.  Filesystem operations on a file being mapped are
00086    unpredictable before this is done.  Flags are from the MS_* set.
00087 
00088    This function is a cancellation point and therefore not marked with
00089    __THROW.  */
00090 extern int msync (void *__addr, size_t __len, int __flags);
00091 
00092 #ifdef __USE_BSD
00093 /* Advise the system about particular usage patterns the program follows
00094    for the region starting at ADDR and extending LEN bytes.  */
00095 extern int madvise (void *__addr, size_t __len, int __advice) __THROW;
00096 #endif
00097 #ifdef __USE_XOPEN2K
00098 /* This is the POSIX name for this function.  */
00099 extern int posix_madvise (void *__addr, size_t __len, int __advice) __THROW;
00100 #endif
00101 
00102 /* Guarantee all whole pages mapped by the range [ADDR,ADDR+LEN) to
00103    be memory resident.  */
00104 extern int mlock (__const void *__addr, size_t __len) __THROW;
00105 
00106 /* Unlock whole pages previously mapped by the range [ADDR,ADDR+LEN).  */
00107 extern int munlock (__const void *__addr, size_t __len) __THROW;
00108 
00109 /* Cause all currently mapped pages of the process to be memory resident
00110    until unlocked by a call to the `munlockall', until the process exits,
00111    or until the process calls `execve'.  */
00112 extern int mlockall (int __flags) __THROW;
00113 
00114 /* All currently mapped pages of the process' address space become
00115    unlocked.  */
00116 extern int munlockall (void) __THROW;
00117 
00118 #ifdef __USE_MISC
00119 /* mincore returns the memory residency status of the pages in the
00120    current process's address space specified by [start, start + len).
00121    The status is returned in a vector of bytes.  The least significant
00122    bit of each byte is 1 if the referenced page is in memory, otherwise
00123    it is zero.  */
00124 extern int mincore (void *__start, size_t __len, unsigned char *__vec)
00125      __THROW;
00126 #endif
00127 
00128 #ifdef __USE_GNU
00129 /* Remap pages mapped by the range [ADDR,ADDR+OLD_LEN) to new length
00130    NEW_LEN.  If MREMAP_MAYMOVE is set in FLAGS the returned address
00131    may differ from ADDR.  If MREMAP_FIXED is set in FLAGS the function
00132    takes another paramter which is a fixed address at which the block
00133    resides after a successful call.  */
00134 extern void *mremap (void *__addr, size_t __old_len, size_t __new_len,
00135                    int __flags, ...) __THROW;
00136 
00137 /* Remap arbitrary pages of a shared backing store within an existing
00138    VMA.  */
00139 extern int remap_file_pages (void *__start, size_t __size, int __prot,
00140                           size_t __pgoff, int __flags) __THROW;
00141 #endif
00142 
00143 
00144 /* Open shared memory segment.  */
00145 extern int shm_open (__const char *__name, int __oflag, mode_t __mode);
00146 
00147 /* Remove shared memory segment.  */
00148 extern int shm_unlink (__const char *__name);
00149 
00150 __END_DECLS
00151 
00152 #endif /* sys/mman.h */