00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef APR_MMAP_H 00018 #define APR_MMAP_H 00019 00020 /** 00021 * @file apr_mmap.h 00022 * @brief APR MMAP routines 00023 */ 00024 00025 #include "apr.h" 00026 #include "apr_pools.h" 00027 #include "apr_errno.h" 00028 #include "apr_ring.h" 00029 #include "apr_file_io.h" /* for apr_file_t */ 00030 00031 #ifdef BEOS 00032 #include <kernel/OS.h> 00033 #endif 00034 00035 #ifdef __cplusplus 00036 extern "C" { 00037 #endif /* __cplusplus */ 00038 00039 /** 00040 * @defgroup apr_mmap MMAP (Memory Map) Routines 00041 * @ingroup APR 00042 * @{ 00043 */ 00044 00045 /** MMap opened for reading */ 00046 #define APR_MMAP_READ 1 00047 /** MMap opened for writing */ 00048 #define APR_MMAP_WRITE 2 00049 00050 /** @see apr_mmap_t */ 00051 typedef struct apr_mmap_t apr_mmap_t; 00052 00053 /** 00054 * @remark 00055 * As far as I can tell the only really sane way to store an MMAP is as a 00056 * void * and a length. BeOS requires this area_id, but that's just a little 00057 * something extra. I am exposing this type, because it doesn't make much 00058 * sense to keep it private, and opening it up makes some stuff easier in 00059 * Apache. 00060 */ 00061 /** The MMAP structure */ 00062 struct apr_mmap_t { 00063 /** The pool the mmap structure was allocated out of. */ 00064 apr_pool_t *cntxt; 00065 #ifdef BEOS 00066 /** An area ID. Only valid on BeOS */ 00067 area_id area; 00068 #endif 00069 #ifdef WIN32 00070 /** The handle of the file mapping */ 00071 HANDLE mhandle; 00072 /** The start of the real memory page area (mapped view) */ 00073 void *mv; 00074 /** The physical start, size and offset */ 00075 apr_off_t pstart; 00076 apr_size_t psize; 00077 apr_off_t poffset; 00078 #endif 00079 /** The start of the memory mapped area */ 00080 void *mm; 00081 /** The amount of data in the mmap */ 00082 apr_size_t size; 00083 /** ring of apr_mmap_t's that reference the same 00084 * mmap'ed region; acts in place of a reference count */ 00085 APR_RING_ENTRY(apr_mmap_t) link; 00086 }; 00087 00088 #if APR_HAS_MMAP || defined(DOXYGEN) 00089 00090 /** @def APR_MMAP_THRESHOLD 00091 * Files have to be at least this big before they're mmap()d. This is to deal 00092 * with systems where the expense of doing an mmap() and an munmap() outweighs 00093 * the benefit for small files. It shouldn't be set lower than 1. 00094 */ 00095 #ifdef MMAP_THRESHOLD 00096 # define APR_MMAP_THRESHOLD MMAP_THRESHOLD 00097 #else 00098 # ifdef SUNOS4 00099 # define APR_MMAP_THRESHOLD (8*1024) 00100 # else 00101 # define APR_MMAP_THRESHOLD 1 00102 # endif /* SUNOS4 */ 00103 #endif /* MMAP_THRESHOLD */ 00104 00105 /** @def APR_MMAP_LIMIT 00106 * Maximum size of MMap region 00107 */ 00108 #ifdef MMAP_LIMIT 00109 # define APR_MMAP_LIMIT MMAP_LIMIT 00110 #else 00111 # define APR_MMAP_LIMIT (4*1024*1024) 00112 #endif /* MMAP_LIMIT */ 00113 00114 /** Can this file be MMaped */ 00115 #define APR_MMAP_CANDIDATE(filelength) \ 00116 ((filelength >= APR_MMAP_THRESHOLD) && (filelength < APR_MMAP_LIMIT)) 00117 00118 /* Function definitions */ 00119 00120 /** 00121 * Create a new mmap'ed file out of an existing APR file. 00122 * @param newmmap The newly created mmap'ed file. 00123 * @param file The file turn into an mmap. 00124 * @param offset The offset into the file to start the data pointer at. 00125 * @param size The size of the file 00126 * @param flag bit-wise or of: 00127 * <PRE> 00128 * APR_MMAP_READ MMap opened for reading 00129 * APR_MMAP_WRITE MMap opened for writing 00130 * </PRE> 00131 * @param cntxt The pool to use when creating the mmap. 00132 */ 00133 APR_DECLARE(apr_status_t) apr_mmap_create(apr_mmap_t **newmmap, 00134 apr_file_t *file, apr_off_t offset, 00135 apr_size_t size, apr_int32_t flag, 00136 apr_pool_t *cntxt); 00137 00138 /** 00139 * Duplicate the specified MMAP. 00140 * @param new_mmap The structure to duplicate into. 00141 * @param old_mmap The mmap to duplicate. 00142 * @param p The pool to use for new_mmap. 00143 */ 00144 APR_DECLARE(apr_status_t) apr_mmap_dup(apr_mmap_t **new_mmap, 00145 apr_mmap_t *old_mmap, 00146 apr_pool_t *p); 00147 00148 /** 00149 * Remove a mmap'ed. 00150 * @param mm The mmap'ed file. 00151 */ 00152 APR_DECLARE(apr_status_t) apr_mmap_delete(apr_mmap_t *mm); 00153 00154 /** 00155 * Move the pointer into the mmap'ed file to the specified offset. 00156 * @param addr The pointer to the offset specified. 00157 * @param mm The mmap'ed file. 00158 * @param offset The offset to move to. 00159 */ 00160 APR_DECLARE(apr_status_t) apr_mmap_offset(void **addr, apr_mmap_t *mm, 00161 apr_off_t offset); 00162 00163 #endif /* APR_HAS_MMAP */ 00164 00165 /** @} */ 00166 00167 #ifdef __cplusplus 00168 } 00169 #endif 00170 00171 #endif /* ! APR_MMAP_H */