1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
22
* @brief APR MMAP routines
26
#include "apr_pools.h"
27
#include "apr_errno.h"
29
#include "apr_file_io.h" /* for apr_file_t */
32
#include <kernel/OS.h>
37
#endif /* __cplusplus */
40
* @defgroup apr_mmap MMAP (Memory Map) Routines
45
/** MMap opened for reading */
46
#define APR_MMAP_READ 1
47
/** MMap opened for writing */
48
#define APR_MMAP_WRITE 2
50
/** @see apr_mmap_t */
51
typedef struct apr_mmap_t apr_mmap_t;
55
* As far as I can tell the only really sane way to store an MMAP is as a
56
* void * and a length. BeOS requires this area_id, but that's just a little
57
* something extra. I am exposing this type, because it doesn't make much
58
* sense to keep it private, and opening it up makes some stuff easier in
61
/** The MMAP structure */
63
/** The pool the mmap structure was allocated out of. */
66
/** An area ID. Only valid on BeOS */
70
/** The handle of the file mapping */
72
/** The start of the real memory page area (mapped view) */
74
/** The physical start, size and offset */
79
/** The start of the memory mapped area */
81
/** The amount of data in the mmap */
83
/** ring of apr_mmap_t's that reference the same
84
* mmap'ed region; acts in place of a reference count */
85
APR_RING_ENTRY(apr_mmap_t) link;
88
#if APR_HAS_MMAP || defined(DOXYGEN)
90
/** @def APR_MMAP_THRESHOLD
91
* Files have to be at least this big before they're mmap()d. This is to deal
92
* with systems where the expense of doing an mmap() and an munmap() outweighs
93
* the benefit for small files. It shouldn't be set lower than 1.
96
# define APR_MMAP_THRESHOLD MMAP_THRESHOLD
99
# define APR_MMAP_THRESHOLD (8*1024)
101
# define APR_MMAP_THRESHOLD 1
103
#endif /* MMAP_THRESHOLD */
105
/** @def APR_MMAP_LIMIT
106
* Maximum size of MMap region
109
# define APR_MMAP_LIMIT MMAP_LIMIT
111
# define APR_MMAP_LIMIT (4*1024*1024)
112
#endif /* MMAP_LIMIT */
114
/** Can this file be MMaped */
115
#define APR_MMAP_CANDIDATE(filelength) \
116
((filelength >= APR_MMAP_THRESHOLD) && (filelength < APR_MMAP_LIMIT))
118
/* Function definitions */
121
* Create a new mmap'ed file out of an existing APR file.
122
* @param newmmap The newly created mmap'ed file.
123
* @param file The file turn into an mmap.
124
* @param offset The offset into the file to start the data pointer at.
125
* @param size The size of the file
126
* @param flag bit-wise or of:
128
* APR_MMAP_READ MMap opened for reading
129
* APR_MMAP_WRITE MMap opened for writing
131
* @param cntxt The pool to use when creating the mmap.
133
APR_DECLARE(apr_status_t) apr_mmap_create(apr_mmap_t **newmmap,
134
apr_file_t *file, apr_off_t offset,
135
apr_size_t size, apr_int32_t flag,
139
* Duplicate the specified MMAP.
140
* @param new_mmap The structure to duplicate into.
141
* @param old_mmap The mmap to duplicate.
142
* @param p The pool to use for new_mmap.
144
APR_DECLARE(apr_status_t) apr_mmap_dup(apr_mmap_t **new_mmap,
145
apr_mmap_t *old_mmap,
150
* @param mm The mmap'ed file.
152
APR_DECLARE(apr_status_t) apr_mmap_delete(apr_mmap_t *mm);
155
* Move the pointer into the mmap'ed file to the specified offset.
156
* @param addr The pointer to the offset specified.
157
* @param mm The mmap'ed file.
158
* @param offset The offset to move to.
160
APR_DECLARE(apr_status_t) apr_mmap_offset(void **addr, apr_mmap_t *mm,
163
#endif /* APR_HAS_MMAP */
171
#endif /* ! APR_MMAP_H */