Mercurial > hg > nginx-quic
annotate src/os/win32/ngx_shmem.c @ 4448:539355d9e675 stable-1.0
Merge of r4404:
Fixed sched_setaffinity(2) to correctly pass size.
Second argument (cpusetsize) is size in bytes, not in bits. Previously
used constant 32 resulted in reading of uninitialized memory and caused
EINVAL to be returned on some Linux kernels.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 05 Feb 2012 19:25:24 +0000 |
parents | 474a9daf8c80 |
children | d620f497c50f |
rev | line source |
---|---|
605 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 | |
10 | |
11 ngx_int_t | |
12 ngx_shm_alloc(ngx_shm_t *shm) | |
13 { | |
2903
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
14 u_char *name; |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
15 uint64_t size; |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
16 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
17 name = ngx_alloc(shm->name.len + 2 + sizeof(NGX_INT32_LEN), shm->log); |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
18 if (name == NULL) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
19 return NGX_ERROR; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
20 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
21 |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
22 (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
|
23 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
24 ngx_set_errno(0); |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
25 |
2903
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
26 size = shm->size; |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
27 |
605 | 28 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
|
29 (u_long) (size >> 32), |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
30 (u_long) (size & 0xffffffff), |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
31 (char *) name); |
605 | 32 |
33 if (shm->handle == NULL) { | |
34 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
|
35 "CreateFileMapping(%uz, %s) failed", |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
36 shm->size, name); |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
37 ngx_free(name); |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
38 |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
39 return NGX_ERROR; |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
40 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
41 |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
42 ngx_free(name); |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
43 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
44 if (ngx_errno == ERROR_ALREADY_EXISTS) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
45 shm->exists = 1; |
605 | 46 } |
47 | |
48 shm->addr = MapViewOfFile(shm->handle, FILE_MAP_WRITE, 0, 0, 0); | |
49 | |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
50 if (shm->addr != NULL) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
51 return NGX_OK; |
605 | 52 } |
53 | |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
54 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
|
55 "MapViewOfFile(%uz) of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
56 shm->size, &shm->name); |
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 if (CloseHandle(shm->handle) == 0) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
59 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
|
60 "CloseHandle() of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
61 &shm->name); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
62 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
63 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
64 return NGX_ERROR; |
605 | 65 } |
66 | |
67 | |
68 void | |
69 ngx_shm_free(ngx_shm_t *shm) | |
70 { | |
71 if (UnmapViewOfFile(shm->addr) == 0) { | |
72 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
|
73 "UnmapViewOfFile(%p) of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
74 shm->addr, &shm->name); |
605 | 75 } |
76 | |
77 if (CloseHandle(shm->handle) == 0) { | |
78 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
|
79 "CloseHandle() of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
80 &shm->name); |
605 | 81 } |
82 } |