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.
17
#include "apr_general.h"
19
#include "apr_errno.h"
21
#include "apr_strings.h"
24
#include <kernel/OS.h>
25
#include "apr_portable.h"
36
APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
44
char shname[B_OS_NAME_LENGTH];
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... */
48
pagesize = ((reqsize + B_PAGE_SIZE - 1) / B_PAGE_SIZE) * B_PAGE_SIZE;
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++);
57
newid = create_area(filename ? filename : shname,
58
(void*)&addr, B_ANY_ADDRESS,
59
pagesize, B_LAZY_LOCK, B_READ_AREA|B_WRITE_AREA);
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;
74
APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m)
82
APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename,
85
area_id deleteme = find_area(filename);
87
if (deleteme == B_NAME_NOT_FOUND)
90
delete_area(deleteme);
94
APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
101
area_id deleteme = find_area(filename);
103
if (deleteme == B_NAME_NOT_FOUND)
106
new_m = (apr_shm_t*)apr_palloc(pool, sizeof(apr_shm_t*));
111
get_area_info(deleteme, &ai);
112
get_thread_info(find_thread(NULL), &ti);
114
if (ti.team != ai.team) {
117
narea = clone_area(ai.name, &(ai.address), B_CLONE_ADDRESS,
118
B_READ_AREA|B_WRITE_AREA, ai.area);
123
get_area_info(narea, &ai);
125
new_m->memblock = ai.address;
126
new_m->ptr = (void*)ai.address;
127
new_m->avail = ai.size;
128
new_m->reqsize = ai.size;
136
APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m)
142
APR_DECLARE(void *) apr_shm_baseaddr_get(const apr_shm_t *m)
147
APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m)
152
APR_POOL_IMPLEMENT_ACCESSOR(shm)
154
APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm,
160
APR_DECLARE(apr_status_t) apr_os_shm_put(apr_shm_t **m,