Apache HTTPD
shm.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_general.h"
18#include "apr_shm.h"
19#include "apr_errno.h"
20#include "apr_lib.h"
21#include "apr_strings.h"
22#include <stdio.h>
23#include <stdlib.h>
24#include <kernel/OS.h>
25#include "apr_portable.h"
26
27struct apr_shm_t {
29 void *memblock;
30 void *ptr;
34};
35
38 const char *filename,
40{
43 char *addr;
45
46 (*m) = (apr_shm_t *)apr_pcalloc(p, sizeof(apr_shm_t));
47 /* we MUST allocate in pages, so calculate how big an area we need... */
49
50 if (!filename) {
51 int num = 0;
52 snprintf(shname, B_OS_NAME_LENGTH, "apr_shmem_%ld", find_thread(NULL));
53 while (find_area(shname) >= 0)
54 snprintf(shname, B_OS_NAME_LENGTH, "apr_shmem_%ld_%d",
55 find_thread(NULL), num++);
56 }
58 (void*)&addr, B_ANY_ADDRESS,
60
61 if (newid < 0)
62 return errno;
63
64 (*m)->pool = p;
65 (*m)->aid = newid;
66 (*m)->memblock = addr;
67 (*m)->ptr = (void*)addr;
68 (*m)->avail = pagesize; /* record how big an area we actually created... */
69 (*m)->reqsize = reqsize;
70
71 return APR_SUCCESS;
72}
73
76 const char *filename,
79{
81}
82
84{
85 delete_area(m->aid);
86 m->avail = 0;
87 m->memblock = NULL;
88 return APR_SUCCESS;
89}
90
93{
95
97 return APR_EINVAL;
98
100 return APR_SUCCESS;
101}
102
104{
105 if (m->filename) {
106 return apr_shm_remove(m->filename, m->pool);
107 }
108 else {
109 return APR_ENOTIMPL;
110 }
111}
112
114 const char *filename,
116{
121
123 return APR_EINVAL;
124
125 new_m = (apr_shm_t*)apr_palloc(pool, sizeof(apr_shm_t*));
126 if (new_m == NULL)
127 return APR_ENOMEM;
128 new_m->pool = pool;
129
132
133 if (ti.team != ai.team) {
135
136 narea = clone_area(ai.name, &(ai.address), B_CLONE_ADDRESS,
138
139 if (narea < B_OK)
140 return narea;
141
143 new_m->aid = narea;
144 new_m->memblock = ai.address;
145 new_m->ptr = (void*)ai.address;
146 new_m->avail = ai.size;
147 new_m->reqsize = ai.size;
148 }
149
150 (*m) = new_m;
151
152 return APR_SUCCESS;
153}
154
156 const char *filename,
159{
160 return apr_shm_attach(m, filename, pool);
161}
162
164{
165 delete_area(m->aid);
166 return APR_SUCCESS;
167}
168
170{
171 return m->memblock;
172}
173
175{
176 return m->reqsize;
177}
178
180
182
184 apr_shm_t *shm)
185{
186 return APR_ENOTIMPL;
187}
188
192{
193 return APR_ENOTIMPL;
194}
195
APR Error Codes.
APR Miscellaneous library routines.
APR general purpose library routines.
APR Portability Routines.
APR Shared Memory Routines.
APR Strings library.
#define APR_ENOMEM
Definition apr_errno.h:683
#define APR_ENOTIMPL
Definition apr_errno.h:476
#define APR_EINVAL
Definition apr_errno.h:711
const char apr_ssize_t int flags
Definition apr_encode.h:168
const void apr_status_t(*) apr_status_t(* APR_DECLARE)(void) apr_pool_pre_cleanup_register(apr_pool_t *p
Definition apr_pools.h:646
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
apr_sockaddr_t * addr
#define APR_PERMS_SET_ENOTIMPL(type)
apr_interval_time_t apr_int32_t * num
Definition apr_poll.h:273
#define APR_POOL_IMPLEMENT_ACCESSOR(type)
Definition apr_pools.h:91
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
void * apr_os_shm_t
apr_os_shm_t * osshm
apr_shm_t * shm
apr_size_t const char * filename
Definition apr_shm.h:72
apr_size_t reqsize
Definition apr_shm.h:71
const void * m
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
void * memblock
Definition shm.c:29
area_id aid
Definition shm.c:33
void * ptr
Definition shm.c:30
apr_pool_t * pool
apr_size_t avail
Definition shm.c:32
apr_size_t reqsize
apr_size_t size
Definition shm.c:34