Apache HTTPD
apr_buckets_mmap.c
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#include "apr_buckets.h"
18
19#if APR_HAS_MMAP
20
21static apr_status_t mmap_bucket_read(apr_bucket *b, const char **str,
23{
24 apr_bucket_mmap *m = b->data;
26 void *addr;
27
28 if (!m->mmap) {
29 /* the apr_mmap_t was already cleaned up out from under us */
30 return APR_EINVAL;
31 }
32
33 ok = apr_mmap_offset(&addr, m->mmap, b->start);
34 if (ok != APR_SUCCESS) {
35 return ok;
36 }
37 *str = addr;
38 *length = b->length;
39 return APR_SUCCESS;
40}
41
43{
44 /* the apr_mmap_t is about to disappear out from under us, so we
45 * have no choice but to pretend it doesn't exist anymore. the
46 * refcount is now useless because there's nothing to refer to
47 * anymore. so the only valid action on any remaining referrer
48 * is to delete it. no more reads, no more anything. */
50
51 m->mmap = NULL;
52 return APR_SUCCESS;
53}
54
55static void mmap_bucket_destroy(void *data)
56{
58
60 if (m->mmap) {
62 apr_mmap_delete(m->mmap);
63 }
65 }
66}
67
68/*
69 * XXX: are the start and length arguments useful?
70 */
74{
76
77 m = apr_bucket_alloc(sizeof(*m), b->list);
78 m->mmap = mm;
79
82
84 b->type = &apr_bucket_type_mmap;
85
86 return b;
87}
88
89
94{
95 apr_bucket *b = apr_bucket_alloc(sizeof(*b), list);
96
98 b->free = apr_bucket_free;
99 b->list = list;
100 return apr_bucket_mmap_make(b, mm, start, length);
101}
102
104{
105 apr_bucket_mmap *m = b->data;
106 apr_mmap_t *mm = m->mmap;
109
110 if (!mm) {
111 /* the apr_mmap_t was already cleaned up out from under us */
112 return APR_EINVAL;
113 }
114
115 /* shortcut if possible */
116 if (apr_pool_is_ancestor(mm->cntxt, p)) {
117 return APR_SUCCESS;
118 }
119
120 /* duplicate apr_mmap_t into new pool */
121 ok = apr_mmap_dup(&new_mm, mm, p);
122 if (ok != APR_SUCCESS) {
123 return ok;
124 }
125
126 /* decrement refcount on old apr_bucket_mmap */
128
129 /* create new apr_bucket_mmap pointing to new apr_mmap_t */
130 apr_bucket_mmap_make(b, new_mm, b->start, b->length);
131
132 return APR_SUCCESS;
133}
134
136 "MMAP", 5, APR_BUCKET_DATA,
142};
143
144#endif
APR-UTIL Buckets/Bucket Brigades.
APU_DECLARE(void)
Computes SipHash-2-4, producing a 64bit (APR_SIPHASH_DSIZE) hash from a message and a 128bit (APR_SIP...
Definition apr_sha1.c:206
#define APR_EINVAL
Definition apr_errno.h:711
#define APR_BUCKET_INIT(e)
apr_file_t apr_off_t start
apr_read_type_e
Definition apr_buckets.h:57
int apr_off_t * length
apr_size_t size
const apr_array_header_t * list
Definition apr_cstr.h:105
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
apr_sockaddr_t * addr
apr_pool_t * b
Definition apr_pools.h:529
const void * m
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
apr_pool_t * cntxt
Definition apr_mmap.h:64
#define str