Mercurial > hg > nginx
annotate src/os/win32/ngx_shmem.c @ 8122:106328a70f4e
Added warning about redefinition of listen socket protocol options.
The "listen" directive in the http module can be used multiple times
in different server blocks. Originally, it was supposed to be specified
once with various socket options, and without any parameters in virtual
server blocks. For example:
server { listen 80 backlog=1024; server_name foo; ... }
server { listen 80; server_name bar; ... }
server { listen 80; server_name bazz; ... }
The address part of the syntax ("address[:port]" / "port" / "unix:path")
uniquely identifies the listening socket, and therefore is enough for
name-based virtual servers (to let nginx know that the virtual server
accepts requests on the listening socket in question).
To ensure that listening options do not conflict between virtual servers,
they were allowed only once. For example, the following configuration
will be rejected ("duplicate listen options for 0.0.0.0:80 in ..."):
server { listen 80 backlog=1024; server_name foo; ... }
server { listen 80 backlog=512; server_name bar; ... }
At some point it was, however, noticed, that it is sometimes convenient
to repeat some options for clarity. In nginx 0.8.51 the "ssl" parameter
was allowed to be specified multiple times, e.g.:
server { listen 443 ssl backlog=1024; server_name foo; ... }
server { listen 443 ssl; server_name bar; ... }
server { listen 443 ssl; server_name bazz; ... }
This approach makes configuration more readable, since SSL sockets are
immediately visible in the configuration. If this is not needed, just the
address can still be used.
Later, additional protocol-specific options similar to "ssl" were
introduced, notably "http2" and "proxy_protocol". With these options,
one can write:
server { listen 443 ssl backlog=1024; server_name foo; ... }
server { listen 443 http2; server_name bar; ... }
server { listen 443 proxy_protocol; server_name bazz; ... }
The resulting socket will use ssl, http2, and proxy_protocol, but this
is not really obvious from the configuration.
To emphasize such misleading configurations are discouraged, nginx now
warns as long as the "listen" directive is used with options different
from the options previously used if this is potentially confusing.
In particular, the following configurations are allowed:
server { listen 8401 ssl backlog=1024; server_name foo; }
server { listen 8401 ssl; server_name bar; }
server { listen 8401 ssl; server_name bazz; }
server { listen 8402 ssl http2 backlog=1024; server_name foo; }
server { listen 8402 ssl; server_name bar; }
server { listen 8402 ssl; server_name bazz; }
server { listen 8403 ssl; server_name bar; }
server { listen 8403 ssl; server_name bazz; }
server { listen 8403 ssl http2; server_name foo; }
server { listen 8404 ssl http2 backlog=1024; server_name foo; }
server { listen 8404 http2; server_name bar; }
server { listen 8404 http2; server_name bazz; }
server { listen 8405 ssl http2 backlog=1024; server_name foo; }
server { listen 8405 ssl http2; server_name bar; }
server { listen 8405 ssl http2; server_name bazz; }
server { listen 8406 ssl; server_name foo; }
server { listen 8406; server_name bar; }
server { listen 8406; server_name bazz; }
And the following configurations will generate warnings:
server { listen 8501 ssl http2 backlog=1024; server_name foo; }
server { listen 8501 http2; server_name bar; }
server { listen 8501 ssl; server_name bazz; }
server { listen 8502 backlog=1024; server_name foo; }
server { listen 8502 ssl; server_name bar; }
server { listen 8503 ssl; server_name foo; }
server { listen 8503 http2; server_name bar; }
server { listen 8504 ssl; server_name foo; }
server { listen 8504 http2; server_name bar; }
server { listen 8504 proxy_protocol; server_name bazz; }
server { listen 8505 ssl http2 proxy_protocol; server_name foo; }
server { listen 8505 ssl http2; server_name bar; }
server { listen 8505 ssl; server_name bazz; }
server { listen 8506 ssl http2; server_name foo; }
server { listen 8506 ssl; server_name bar; }
server { listen 8506; server_name bazz; }
server { listen 8507 ssl; server_name bar; }
server { listen 8507; server_name bazz; }
server { listen 8507 ssl http2; server_name foo; }
server { listen 8508 ssl; server_name bar; }
server { listen 8508; server_name bazz; }
server { listen 8508 ssl backlog=1024; server_name foo; }
server { listen 8509; server_name bazz; }
server { listen 8509 ssl; server_name bar; }
server { listen 8509 ssl backlog=1024; server_name foo; }
The basic idea is that at most two sets of protocol options are allowed:
the main one (with socket options, if any), and a shorter one, with options
being a subset of the main options, repeated for clarity. As long as the
shorter set of protocol options is used, all listen directives except the
main one should use it.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 28 Jan 2023 01:29:45 +0300 |
parents | af7eba90645d |
children |
rev | line source |
---|---|
605 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
605 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 | |
11 | |
6133
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
12 /* |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
13 * Base addresses selected by system for shared memory mappings are likely |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
14 * to be different on Windows Vista and later versions due to address space |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
15 * layout randomization. This is however incompatible with storing absolute |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
16 * addresses within the shared memory. |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
17 * |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
18 * To make it possible to store absolute addresses we create mappings |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
19 * at the same address in all processes by starting mappings at predefined |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
20 * addresses. The addresses were selected somewhat randomly in order to |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
21 * minimize the probability that some other library doing something similar |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
22 * conflicts with us. The addresses are from the following typically free |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
23 * blocks: |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
24 * |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
25 * - 0x10000000 .. 0x70000000 (about 1.5 GB in total) on 32-bit platforms |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
26 * - 0x000000007fff0000 .. 0x000007f68e8b0000 (about 8 TB) on 64-bit platforms |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
27 * |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
28 * Additionally, we allow to change the mapping address once it was detected |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
29 * to be different from one originally used. This is needed to support |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
30 * reconfiguration. |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
31 */ |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
32 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
33 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
34 #ifdef _WIN64 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
35 #define NGX_SHMEM_BASE 0x0000047047e00000 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
36 #else |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
37 #define NGX_SHMEM_BASE 0x2efe0000 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
38 #endif |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
39 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
40 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
41 ngx_uint_t ngx_allocation_granularity; |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
42 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
43 |
605 | 44 ngx_int_t |
45 ngx_shm_alloc(ngx_shm_t *shm) | |
46 { | |
6133
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
47 u_char *name; |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
48 uint64_t size; |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
49 static u_char *base = (u_char *) NGX_SHMEM_BASE; |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
50 |
4570
b3d4e9c66e24
Win32: fixed memory allocation for shmem name (ticket #134).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
51 name = ngx_alloc(shm->name.len + 2 + NGX_INT32_LEN, shm->log); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
52 if (name == NULL) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
53 return NGX_ERROR; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
54 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
55 |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
56 (void) ngx_sprintf(name, "%V_%s%Z", &shm->name, ngx_unique); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
57 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
58 ngx_set_errno(0); |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
59 |
2903
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
60 size = shm->size; |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
61 |
605 | 62 shm->handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, |
2903
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
63 (u_long) (size >> 32), |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
64 (u_long) (size & 0xffffffff), |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
65 (char *) name); |
605 | 66 |
67 if (shm->handle == NULL) { | |
68 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
2716
d5896f6608e8
move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
605
diff
changeset
|
69 "CreateFileMapping(%uz, %s) failed", |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
70 shm->size, name); |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
71 ngx_free(name); |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
72 |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
73 return NGX_ERROR; |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
74 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
75 |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
76 ngx_free(name); |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
77 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
78 if (ngx_errno == ERROR_ALREADY_EXISTS) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
79 shm->exists = 1; |
605 | 80 } |
81 | |
6133
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
82 shm->addr = MapViewOfFileEx(shm->handle, FILE_MAP_WRITE, 0, 0, 0, base); |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
83 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
84 if (shm->addr != NULL) { |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
85 base += ngx_align(size, ngx_allocation_granularity); |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
86 return NGX_OK; |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
87 } |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
88 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
89 ngx_log_debug3(NGX_LOG_DEBUG_CORE, shm->log, ngx_errno, |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
90 "MapViewOfFileEx(%uz, %p) of file mapping \"%V\" failed, " |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
91 "retry without a base address", |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
92 shm->size, base, &shm->name); |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
93 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
94 /* |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
95 * Order of shared memory zones may be different in the master process |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
96 * and worker processes after reconfiguration. As a result, the above |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
97 * may fail due to a conflict with a previously created mapping remapped |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
98 * to a different address. Additionally, there may be a conflict with |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
99 * some other uses of the memory. In this case we retry without a base |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
100 * address to let the system assign the address itself. |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
101 */ |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
102 |
605 | 103 shm->addr = MapViewOfFile(shm->handle, FILE_MAP_WRITE, 0, 0, 0); |
104 | |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
105 if (shm->addr != NULL) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
106 return NGX_OK; |
605 | 107 } |
108 | |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
109 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
110 "MapViewOfFile(%uz) of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
111 shm->size, &shm->name); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
112 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
113 if (CloseHandle(shm->handle) == 0) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
114 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
115 "CloseHandle() of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
116 &shm->name); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
117 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
118 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
119 return NGX_ERROR; |
605 | 120 } |
121 | |
122 | |
6133
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
123 ngx_int_t |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
124 ngx_shm_remap(ngx_shm_t *shm, u_char *addr) |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
125 { |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
126 if (UnmapViewOfFile(shm->addr) == 0) { |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
127 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
128 "UnmapViewOfFile(%p) of file mapping \"%V\" failed", |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
129 shm->addr, &shm->name); |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
130 return NGX_ERROR; |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
131 } |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
132 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
133 shm->addr = MapViewOfFileEx(shm->handle, FILE_MAP_WRITE, 0, 0, 0, addr); |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
134 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
135 if (shm->addr != NULL) { |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
136 return NGX_OK; |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
137 } |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
138 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
139 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
140 "MapViewOfFileEx(%uz, %p) of file mapping \"%V\" failed", |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
141 shm->size, addr, &shm->name); |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
142 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
143 return NGX_ERROR; |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
144 } |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
145 |
af7eba90645d
Win32: shared memory base addresses and remapping.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4570
diff
changeset
|
146 |
605 | 147 void |
148 ngx_shm_free(ngx_shm_t *shm) | |
149 { | |
150 if (UnmapViewOfFile(shm->addr) == 0) { | |
151 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
152 "UnmapViewOfFile(%p) of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
153 shm->addr, &shm->name); |
605 | 154 } |
155 | |
156 if (CloseHandle(shm->handle) == 0) { | |
157 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
158 "CloseHandle() of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
159 &shm->name); |
605 | 160 } |
161 } |