Apache Portable Runtime
Loading...
Searching...
No Matches
apr_mmap.h
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#ifndef APR_MMAP_H
18#define APR_MMAP_H
19
20/**
21 * @file apr_mmap.h
22 * @brief APR MMAP routines
23 */
24
25#include "apr.h"
26#include "apr_pools.h"
27#include "apr_errno.h"
28#include "apr_ring.h"
29#include "apr_file_io.h" /* for apr_file_t */
30
31#ifdef BEOS
32#include <kernel/OS.h>
33#endif
34
35#ifdef __cplusplus
36extern "C" {
37#endif /* __cplusplus */
38
39/**
40 * @defgroup apr_mmap MMAP (Memory Map) Routines
41 * @ingroup APR
42 * @{
43 */
44
45/** MMap opened for reading */
46#define APR_MMAP_READ 1
47/** MMap opened for writing */
48#define APR_MMAP_WRITE 2
49
50/** @see apr_mmap_t */
51typedef struct apr_mmap_t apr_mmap_t;
52
53/**
54 * @remark
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
59 * Apache.
60 */
61/** The MMAP structure */
62struct apr_mmap_t {
63 /** The pool the mmap structure was allocated out of. */
65#if defined(BEOS)
66 /** An area ID. Only valid on BeOS */
67 area_id area;
68#elif defined(WIN32)
69 /** The handle of the file mapping */
70 HANDLE mhandle;
71 /** The start of the real memory page area (mapped view) */
72 void *mv;
73#else
74 apr_off_t poffset;
75#endif
76 /** The start of the memory mapped area */
77 void *mm;
78 /** The amount of data in the mmap */
79 apr_size_t size;
80 /** ring of apr_mmap_t's that reference the same
81 * mmap'ed region; acts in place of a reference count */
83};
84
85#if APR_HAS_MMAP || defined(DOXYGEN)
86
87/** @def APR_MMAP_THRESHOLD
88 * Files have to be at least this big before they're mmap()d. This is to deal
89 * with systems where the expense of doing an mmap() and an munmap() outweighs
90 * the benefit for small files. It shouldn't be set lower than 1.
91 */
92#ifdef MMAP_THRESHOLD
93# define APR_MMAP_THRESHOLD MMAP_THRESHOLD
94#else
95# ifdef SUNOS4
96# define APR_MMAP_THRESHOLD (8*1024)
97# else
98# define APR_MMAP_THRESHOLD 1
99# endif /* SUNOS4 */
100#endif /* MMAP_THRESHOLD */
101
102/** @def APR_MMAP_LIMIT
103 * Maximum size of MMap region
104 */
105#ifdef MMAP_LIMIT
106# define APR_MMAP_LIMIT MMAP_LIMIT
107#else
108# define APR_MMAP_LIMIT (4*1024*1024)
109#endif /* MMAP_LIMIT */
110
111/** Can this file be MMaped */
112#define APR_MMAP_CANDIDATE(filelength) \
113 ((filelength >= APR_MMAP_THRESHOLD) && (filelength < APR_MMAP_LIMIT))
114
115/* Function definitions */
116
117/**
118 * Create a new mmap'ed file out of an existing APR file.
119 * @param newmmap The newly created mmap'ed file.
120 * @param file The file to turn into an mmap.
121 * @param offset The offset into the file to start the data pointer at.
122 * @param size The size of the file
123 * @param flag bit-wise or of:
124 * <PRE>
125 * APR_MMAP_READ MMap opened for reading
126 * APR_MMAP_WRITE MMap opened for writing
127 * </PRE>
128 * @param cntxt The pool to use when creating the mmap.
129 */
131 apr_file_t *file, apr_off_t offset,
132 apr_size_t size, apr_int32_t flag,
133 apr_pool_t *cntxt);
134
135/**
136 * Duplicate the specified MMAP.
137 * @param new_mmap The structure to duplicate into.
138 * @param old_mmap The mmap to duplicate.
139 * @param p The pool to use for new_mmap.
140 */
142 apr_mmap_t *old_mmap,
143 apr_pool_t *p);
144
145/**
146 * Remove a mmap'ed.
147 * @param mm The mmap'ed file.
148 */
150
151/**
152 * Move the pointer into the mmap'ed file to the specified offset.
153 * @param addr The pointer to the offset specified.
154 * @param mm The mmap'ed file.
155 * @param offset The offset to move to.
156 */
158 apr_off_t offset);
159
160#endif /* APR_HAS_MMAP */
161
162/** @} */
163
164#ifdef __cplusplus
165}
166#endif
167
168#endif /* ! APR_MMAP_H */
APR Platform Definitions.
APR Error Codes.
APR File I/O Handling.
APR memory allocation.
APR Rings.
int apr_status_t
Definition apr_errno.h:44
struct apr_file_t apr_file_t
Definition apr_file_io.h:195
apr_status_t apr_mmap_delete(apr_mmap_t *mm)
apr_status_t apr_mmap_offset(void **addr, apr_mmap_t *mm, apr_off_t offset)
apr_status_t apr_mmap_dup(apr_mmap_t **new_mmap, apr_mmap_t *old_mmap, apr_pool_t *p)
apr_status_t apr_mmap_create(apr_mmap_t **newmmap, apr_file_t *file, apr_off_t offset, apr_size_t size, apr_int32_t flag, apr_pool_t *cntxt)
#define APR_DECLARE(type)
Definition apr.h:523
struct apr_pool_t apr_pool_t
Definition apr_pools.h:60
Definition apr_mmap.h:62
apr_size_t size
Definition apr_mmap.h:79
apr_pool_t * cntxt
Definition apr_mmap.h:64
void * mm
Definition apr_mmap.h:77
APR_RING_ENTRY(apr_mmap_t) link