~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/shmem/os2/shm.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
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
 
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 "apr_portable.h"
 
23
 
 
24
struct apr_shm_t {
 
25
    apr_pool_t *pool;
 
26
    void *memblock;
 
27
};
 
28
 
 
29
APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
 
30
                                         apr_size_t reqsize,
 
31
                                         const char *filename,
 
32
                                         apr_pool_t *pool)
 
33
{
 
34
    int rc;
 
35
    apr_shm_t *newm = (apr_shm_t *)apr_palloc(pool, sizeof(apr_shm_t));
 
36
    char *name = NULL;
 
37
    ULONG flags = PAG_COMMIT|PAG_READ|PAG_WRITE;
 
38
 
 
39
    newm->pool = pool;
 
40
 
 
41
    if (filename) {
 
42
        name = apr_pstrcat(pool, "\\SHAREMEM\\", filename, NULL);
 
43
    }
 
44
 
 
45
    if (name == NULL) {
 
46
        flags |= OBJ_GETTABLE;
 
47
    }
 
48
 
 
49
    rc = DosAllocSharedMem(&(newm->memblock), name, reqsize, flags);
 
50
 
 
51
    if (rc) {
 
52
        return APR_OS2_STATUS(rc);
 
53
    }
 
54
 
 
55
    *m = newm;
 
56
    return APR_SUCCESS;
 
57
}
 
58
 
 
59
APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m)
 
60
{
 
61
    DosFreeMem(m->memblock);
 
62
    return APR_SUCCESS;
 
63
}
 
64
 
 
65
APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename,
 
66
                                         apr_pool_t *pool)
 
67
{
 
68
    return APR_ENOTIMPL;
 
69
}
 
70
 
 
71
APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
 
72
                                         const char *filename,
 
73
                                         apr_pool_t *pool)
 
74
{
 
75
    int rc;
 
76
    apr_shm_t *newm = (apr_shm_t *)apr_palloc(pool, sizeof(apr_shm_t));
 
77
    char *name = NULL;
 
78
    ULONG flags = PAG_READ|PAG_WRITE;
 
79
 
 
80
    newm->pool = pool;
 
81
    name = apr_pstrcat(pool, "\\SHAREMEM\\", filename, NULL);
 
82
 
 
83
    rc = DosGetNamedSharedMem(&(newm->memblock), name, flags);
 
84
 
 
85
    if (rc) {
 
86
        return APR_FROM_OS_ERROR(rc);
 
87
    }
 
88
 
 
89
    *m = newm;
 
90
    return APR_SUCCESS;
 
91
}
 
92
 
 
93
APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m)
 
94
{
 
95
    int rc = 0;
 
96
 
 
97
    if (m->memblock) {
 
98
        rc = DosFreeMem(m->memblock);
 
99
    }
 
100
 
 
101
    return APR_FROM_OS_ERROR(rc);
 
102
}
 
103
 
 
104
APR_DECLARE(void *) apr_shm_baseaddr_get(const apr_shm_t *m)
 
105
{
 
106
    return m->memblock;
 
107
}
 
108
 
 
109
APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m)
 
110
{
 
111
    ULONG flags, size = 0x1000000;
 
112
    DosQueryMem(m->memblock, &size, &flags);
 
113
    return size;
 
114
}
 
115
 
 
116
APR_POOL_IMPLEMENT_ACCESSOR(shm)
 
117
 
 
118
APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm,
 
119
                                         apr_shm_t *shm)
 
120
{
 
121
    *osshm = shm->memblock;
 
122
    return APR_SUCCESS;
 
123
}
 
124
 
 
125
APR_DECLARE(apr_status_t) apr_os_shm_put(apr_shm_t **m,
 
126
                                         apr_os_shm_t *osshm,
 
127
                                         apr_pool_t *pool)
 
128
{
 
129
    int rc;
 
130
    apr_shm_t *newm = (apr_shm_t *)apr_palloc(pool, sizeof(apr_shm_t));
 
131
    ULONG flags = PAG_COMMIT|PAG_READ|PAG_WRITE;
 
132
 
 
133
    newm->pool = pool;
 
134
 
 
135
    rc = DosGetSharedMem(&(newm->memblock), flags);
 
136
 
 
137
    if (rc) {
 
138
        return APR_FROM_OS_ERROR(rc);
 
139
    }
 
140
 
 
141
    *m = newm;
 
142
    return APR_SUCCESS;
 
143
}    
 
144