Bug Summary

File:root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/nspr/pr/./../../../../../nsprpub/pr/src/md/unix/uxshm.c
Warning:line 99, column 9
Value stored to 'rc' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_c_external_nspr_pr1.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/nspr/pr -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/nspr/pr -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D _NSPR_BUILD_ -D LINUX -D HAVE_FCNTL_FILE_LOCKING -D HAVE_POINTER_LOCALTIME_R -D _GNU_SOURCE -D _PR_PTHREADS -I /root/firefox-clang/config/external/nspr/pr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/nspr/pr -I /root/firefox-clang/config/external/nspr -I /root/firefox-clang/nsprpub/pr/include -I /root/firefox-clang/nsprpub/pr/include/private -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c Unified_c_external_nspr_pr1.c
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5/*
6** uxshm.c -- Unix Implementations NSPR Named Shared Memory
7**
8**
9** lth. Jul-1999.
10**
11*/
12#include <string.h>
13#include <prshm.h>
14#include <prerr.h>
15#include <prmem.h>
16#include "primpl.h"
17#include <fcntl.h>
18
19extern PRLogModuleInfo* _pr_shm_lm;
20
21#define NSPR_IPC_SHM_KEY'b' 'b'
22/*
23** Implementation for System V
24*/
25#if defined PR_HAVE_SYSV_NAMED_SHARED_MEMORY
26#include <sys/ipc.h>
27#include <sys/shm.h>
28#include <sys/types.h>
29#include <sys/stat.h>
30
31#define _MD_OPEN_SHARED_MEMORY_MD_OpenSharedMemory _MD_OpenSharedMemory
32#define _MD_ATTACH_SHARED_MEMORY_MD_AttachSharedMemory _MD_AttachSharedMemory
33#define _MD_DETACH_SHARED_MEMORY_MD_DetachSharedMemory _MD_DetachSharedMemory
34#define _MD_CLOSE_SHARED_MEMORY_MD_CloseSharedMemory _MD_CloseSharedMemory
35#define _MD_DELETE_SHARED_MEMORY_MD_DeleteSharedMemory _MD_DeleteSharedMemory
36
37extern PRSharedMemory*
38_MD_OpenSharedMemory(const char* name, PRSize size,
39 PRIntn flags, PRIntn mode)
40{
41 PRStatus rc = PR_SUCCESS;
42 key_t key;
43 PRSharedMemory* shm;
44 char ipcname[PR_IPC_NAME_SIZE1024];
45
46 rc = _PR_MakeNativeIPCName(name, ipcname, PR_IPC_NAME_SIZE1024, _PRIPCShm);
47 if (PR_FAILURE == rc) {
48 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
49 PR_LOG(do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s"
, name); } } while (0)
50 _pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s"
, name); } } while (0)
51 ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s"
, name); } } while (0)
;
52 return (NULL((void*)0));
53 }
54
55 shm = PR_NEWZAP(PRSharedMemory)((PRSharedMemory*)PR_Calloc(1, sizeof(PRSharedMemory)));
56 if (NULL((void*)0) == shm) {
57 PR_SetError(PR_OUT_OF_MEMORY_ERROR(-6000L), 0);
58 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("PR_OpenSharedMemory: New PRSharedMemory out of memory"); }
} while (0)
59 ("PR_OpenSharedMemory: New PRSharedMemory out of memory"))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("PR_OpenSharedMemory: New PRSharedMemory out of memory"); }
} while (0)
;
60 return (NULL((void*)0));
61 }
62
63 shm->ipcname = (char*)PR_MALLOC(strlen(ipcname) + 1)(PR_Malloc((strlen(ipcname) + 1)));
64 if (NULL((void*)0) == shm->ipcname) {
65 PR_SetError(PR_OUT_OF_MEMORY_ERROR(-6000L), 0);
66 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("PR_OpenSharedMemory: New shm->ipcname out of memory"); }
} while (0)
67 ("PR_OpenSharedMemory: New shm->ipcname out of memory"))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("PR_OpenSharedMemory: New shm->ipcname out of memory"); }
} while (0)
;
68 PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); };
69 return (NULL((void*)0));
70 }
71
72 /* copy args to struct */
73 strcpy(shm->ipcname, ipcname);
74 shm->size = size;
75 shm->mode = mode;
76 shm->flags = flags;
77 shm->ident = _PR_SHM_IDENT0xdeadbad;
78
79 /* create the file first */
80 if (flags & PR_SHM_CREATE0x1) {
81 int osfd = open(shm->ipcname, (O_RDWR02 | O_CREAT0100), shm->mode);
82 if (-1 == osfd) {
83 _PR_MD_MAP_OPEN_ERROR_MD_unix_map_open_error(errno(*__errno_location ()));
84 PR_FREEIF(shm->ipcname)if (shm->ipcname) { PR_Free(shm->ipcname); (shm->ipcname
) = ((void*)0); }
;
85 PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); };
86 return (NULL((void*)0));
87 }
88 if (close(osfd) == -1) {
89 _PR_MD_MAP_CLOSE_ERROR_MD_unix_map_close_error(errno(*__errno_location ()));
90 PR_FREEIF(shm->ipcname)if (shm->ipcname) { PR_Free(shm->ipcname); (shm->ipcname
) = ((void*)0); }
;
91 PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); };
92 return (NULL((void*)0));
93 }
94 }
95
96 /* hash the shm.name to an ID */
97 key = ftok(shm->ipcname, NSPR_IPC_SHM_KEY'b');
98 if (-1 == key) {
99 rc = PR_FAILURE;
Value stored to 'rc' is never read
100 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
101 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): ftok() failed on name: %s", shm->
ipcname); } } while (0)
102 ("_MD_OpenSharedMemory(): ftok() failed on name: %s", shm->ipcname))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): ftok() failed on name: %s", shm->
ipcname); } } while (0)
;
103 PR_FREEIF(shm->ipcname)if (shm->ipcname) { PR_Free(shm->ipcname); (shm->ipcname
) = ((void*)0); }
;
104 PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); };
105 return (NULL((void*)0));
106 }
107
108 /* get the shared memory */
109 if (flags & PR_SHM_CREATE0x1) {
110 shm->id = shmget(key, shm->size, (shm->mode | IPC_CREAT01000 | IPC_EXCL02000));
111 if (shm->id >= 0) {
112 return (shm);
113 }
114 if ((errno(*__errno_location ()) == EEXIST17) && (flags & PR_SHM_EXCL0x2)) {
115 PR_SetError(PR_FILE_EXISTS_ERROR(-5943L), errno(*__errno_location ()));
116 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d"
, (*__errno_location ())); } } while (0)
117 ("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d",do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d"
, (*__errno_location ())); } } while (0)
118 errno))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d"
, (*__errno_location ())); } } while (0)
;
119 PR_FREEIF(shm->ipcname)if (shm->ipcname) { PR_Free(shm->ipcname); (shm->ipcname
) = ((void*)0); }
;
120 PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); };
121 return (NULL((void*)0));
122 }
123 }
124
125 shm->id = shmget(key, shm->size, shm->mode);
126 if (-1 == shm->id) {
127 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
128 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): shmget() failed, errno: %d", (*__errno_location
())); } } while (0)
129 ("_MD_OpenSharedMemory(): shmget() failed, errno: %d", errno))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): shmget() failed, errno: %d", (*__errno_location
())); } } while (0)
;
130 PR_FREEIF(shm->ipcname)if (shm->ipcname) { PR_Free(shm->ipcname); (shm->ipcname
) = ((void*)0); }
;
131 PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); };
132 return (NULL((void*)0));
133 }
134
135 return (shm);
136} /* end _MD_OpenSharedMemory() */
137
138extern void*
139_MD_AttachSharedMemory(PRSharedMemory* shm, PRIntn flags)
140{
141 void* addr;
142 PRUint32 aFlags = shm->mode;
143
144 PR_ASSERT(shm->ident == _PR_SHM_IDENT)((shm->ident == 0xdeadbad) ? ((void)0) : PR_Assert("shm->ident == _PR_SHM_IDENT"
, "./../../../../../nsprpub/pr/src/md/unix/uxshm.c", 144))
;
145
146 aFlags |= (flags & PR_SHM_READONLY0x01) ? SHM_RDONLY010000 : 0;
147
148 addr = shmat(shm->id, NULL((void*)0), aFlags);
149 if ((void*)-1 == addr) {
150 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
151 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d"
, shm->ipcname, PR_GetOSError()); } } while (0)
152 ("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d",do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d"
, shm->ipcname, PR_GetOSError()); } } while (0)
153 shm->ipcname, PR_GetOSError()))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d"
, shm->ipcname, PR_GetOSError()); } } while (0)
;
154 addr = NULL((void*)0);
155 }
156
157 return addr;
158}
159
160extern PRStatus
161_MD_DetachSharedMemory(PRSharedMemory* shm, void* addr)
162{
163 PRStatus rc = PR_SUCCESS;
164 PRIntn urc;
165
166 PR_ASSERT(shm->ident == _PR_SHM_IDENT)((shm->ident == 0xdeadbad) ? ((void)0) : PR_Assert("shm->ident == _PR_SHM_IDENT"
, "./../../../../../nsprpub/pr/src/md/unix/uxshm.c", 166))
;
167
168 urc = shmdt(addr);
169 if (-1 == urc) {
170 rc = PR_FAILURE;
171 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
172 PR_LOG(do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm
->ipcname); } } while (0)
173 _pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm
->ipcname); } } while (0)
174 ("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm->ipcname))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm
->ipcname); } } while (0)
;
175 }
176
177 return rc;
178}
179
180extern PRStatus
181_MD_CloseSharedMemory(PRSharedMemory* shm)
182{
183 PR_ASSERT(shm->ident == _PR_SHM_IDENT)((shm->ident == 0xdeadbad) ? ((void)0) : PR_Assert("shm->ident == _PR_SHM_IDENT"
, "./../../../../../nsprpub/pr/src/md/unix/uxshm.c", 183))
;
184
185 PR_FREEIF(shm->ipcname)if (shm->ipcname) { PR_Free(shm->ipcname); (shm->ipcname
) = ((void*)0); }
;
186 PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); };
187
188 return PR_SUCCESS;
189}
190
191extern PRStatus
192_MD_DeleteSharedMemory(const char* name)
193{
194 PRStatus rc = PR_SUCCESS;
195 key_t key;
196 int id;
197 PRIntn urc;
198 char ipcname[PR_IPC_NAME_SIZE1024];
199
200 rc = _PR_MakeNativeIPCName(name, ipcname, PR_IPC_NAME_SIZE1024, _PRIPCShm);
201 if (PR_FAILURE == rc) {
202 PR_SetError(PR_UNKNOWN_ERROR(-5994L), errno(*__errno_location ()));
203 PR_LOG(do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s"
, name); } } while (0)
204 _pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s"
, name); } } while (0)
205 ("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s"
, name); } } while (0)
;
206 return (PR_FAILURE);
207 }
208
209 /* create the file first */
210 {
211 int osfd = open(ipcname, (O_RDWR02 | O_CREAT0100), 0666);
212 if (-1 == osfd) {
213 _PR_MD_MAP_OPEN_ERROR_MD_unix_map_open_error(errno(*__errno_location ()));
214 return (PR_FAILURE);
215 }
216 if (close(osfd) == -1) {
217 _PR_MD_MAP_CLOSE_ERROR_MD_unix_map_close_error(errno(*__errno_location ()));
218 return (PR_FAILURE);
219 }
220 }
221
222 /* hash the shm.name to an ID */
223 key = ftok(ipcname, NSPR_IPC_SHM_KEY'b');
224 if (-1 == key) {
225 rc = PR_FAILURE;
226 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
227 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): ftok() failed on name: %s", ipcname
); } } while (0)
228 ("_MD_DeleteSharedMemory(): ftok() failed on name: %s", ipcname))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): ftok() failed on name: %s", ipcname
); } } while (0)
;
229 }
230
231 id = shmget(key, 0, 0);
232 if (-1 == id) {
233 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
234 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", (*__errno_location
())); } } while (0)
235 ("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", errno))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", (*__errno_location
())); } } while (0)
;
236 return (PR_FAILURE);
237 }
238
239 urc = shmctl(id, IPC_RMID0, NULL((void*)0));
240 if (-1 == urc) {
241 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
242 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname
); } } while (0)
243 ("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname
); } } while (0)
;
244 return (PR_FAILURE);
245 }
246
247 urc = unlink(ipcname);
248 if (-1 == urc) {
249 _PR_MD_MAP_UNLINK_ERROR_MD_unix_map_unlink_error(errno(*__errno_location ()));
250 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname); }
} while (0)
251 ("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname); }
} while (0)
;
252 return (PR_FAILURE);
253 }
254
255 return rc;
256} /* end _MD_DeleteSharedMemory() */
257
258/*
259** Implementation for Posix
260*/
261#elif defined PR_HAVE_POSIX_NAMED_SHARED_MEMORY
262#include <sys/mman.h>
263
264#define _MD_OPEN_SHARED_MEMORY_MD_OpenSharedMemory _MD_OpenSharedMemory
265#define _MD_ATTACH_SHARED_MEMORY_MD_AttachSharedMemory _MD_AttachSharedMemory
266#define _MD_DETACH_SHARED_MEMORY_MD_DetachSharedMemory _MD_DetachSharedMemory
267#define _MD_CLOSE_SHARED_MEMORY_MD_CloseSharedMemory _MD_CloseSharedMemory
268#define _MD_DELETE_SHARED_MEMORY_MD_DeleteSharedMemory _MD_DeleteSharedMemory
269
270struct _MDSharedMemory {
271 int handle;
272};
273
274extern PRSharedMemory*
275_MD_OpenSharedMemory(const char* name, PRSize size,
276 PRIntn flags, PRIntn mode)
277{
278 PRStatus rc = PR_SUCCESS;
279 PRInt32 end;
280 PRSharedMemory* shm;
281 char ipcname[PR_IPC_NAME_SIZE1024];
282
283 rc = _PR_MakeNativeIPCName(name, ipcname, PR_IPC_NAME_SIZE1024, _PRIPCShm);
284 if (PR_FAILURE == rc) {
285 PR_SetError(PR_UNKNOWN_ERROR(-5994L), errno(*__errno_location ()));
286 PR_LOG(do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s"
, name); } } while (0)
287 _pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s"
, name); } } while (0)
288 ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s"
, name); } } while (0)
;
289 return (NULL((void*)0));
290 }
291
292 shm = PR_NEWZAP(PRSharedMemory)((PRSharedMemory*)PR_Calloc(1, sizeof(PRSharedMemory)));
293 if (NULL((void*)0) == shm) {
294 PR_SetError(PR_OUT_OF_MEMORY_ERROR(-6000L), 0);
295 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("PR_OpenSharedMemory: New PRSharedMemory out of memory"); }
} while (0)
296 ("PR_OpenSharedMemory: New PRSharedMemory out of memory"))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("PR_OpenSharedMemory: New PRSharedMemory out of memory"); }
} while (0)
;
297 return (NULL((void*)0));
298 }
299
300 shm->ipcname = PR_MALLOC(strlen(ipcname) + 1)(PR_Malloc((strlen(ipcname) + 1)));
301 if (NULL((void*)0) == shm->ipcname) {
302 PR_SetError(PR_OUT_OF_MEMORY_ERROR(-6000L), 0);
303 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("PR_OpenSharedMemory: New shm->ipcname out of memory"); }
} while (0)
304 ("PR_OpenSharedMemory: New shm->ipcname out of memory"))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("PR_OpenSharedMemory: New shm->ipcname out of memory"); }
} while (0)
;
305 return (NULL((void*)0));
306 }
307
308 /* copy args to struct */
309 strcpy(shm->ipcname, ipcname);
310 shm->size = size;
311 shm->mode = mode;
312 shm->flags = flags;
313 shm->ident = _PR_SHM_IDENT0xdeadbad;
314
315 /*
316 ** Create the shared memory
317 */
318 if (flags & PR_SHM_CREATE0x1) {
319 int oflag = (O_CREAT0100 | O_RDWR02);
320
321 if (flags & PR_SHM_EXCL0x2) {
322 oflag |= O_EXCL0200;
323 }
324 shm->id = shm_open(shm->ipcname, oflag, shm->mode);
325 } else {
326 shm->id = shm_open(shm->ipcname, O_RDWR02, shm->mode);
327 }
328
329 if (-1 == shm->id) {
330 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
331 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d",
shm->ipcname, PR_GetOSError()); } } while (0)
332 ("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d",do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d",
shm->ipcname, PR_GetOSError()); } } while (0)
333 shm->ipcname, PR_GetOSError()))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d",
shm->ipcname, PR_GetOSError()); } } while (0)
;
334 PR_DELETE(shm->ipcname){ PR_Free(shm->ipcname); (shm->ipcname) = ((void*)0); };
335 PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); };
336 return (NULL((void*)0));
337 }
338
339 end = ftruncate(shm->id, shm->size);
340 if (-1 == end) {
341 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
342 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d", PR_GetOSError
()); } } while (0)
343 ("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d",do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d", PR_GetOSError
()); } } while (0)
344 PR_GetOSError()))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d", PR_GetOSError
()); } } while (0)
;
345 PR_DELETE(shm->ipcname){ PR_Free(shm->ipcname); (shm->ipcname) = ((void*)0); };
346 PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); };
347 return (NULL((void*)0));
348 }
349
350 return (shm);
351} /* end _MD_OpenSharedMemory() */
352
353extern void*
354_MD_AttachSharedMemory(PRSharedMemory* shm, PRIntn flags)
355{
356 void* addr;
357 PRIntn prot = (PROT_READ0x1 | PROT_WRITE0x2);
358
359 PR_ASSERT(shm->ident == _PR_SHM_IDENT)((shm->ident == 0xdeadbad) ? ((void)0) : PR_Assert("shm->ident == _PR_SHM_IDENT"
, "./../../../../../nsprpub/pr/src/md/unix/uxshm.c", 359))
;
360
361 if (PR_SHM_READONLY0x01 == flags) {
362 prot ^= PROT_WRITE0x2;
363 }
364
365 addr = mmap((void*)0, shm->size, prot, MAP_SHARED0x01, shm->id, 0);
366 if ((void*)-1 == addr) {
367 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
368 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_AttachSharedMemory(): mmap failed: %s, errno: %d", shm
->ipcname, PR_GetOSError()); } } while (0)
369 ("_MD_AttachSharedMemory(): mmap failed: %s, errno: %d",do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_AttachSharedMemory(): mmap failed: %s, errno: %d", shm
->ipcname, PR_GetOSError()); } } while (0)
370 shm->ipcname, PR_GetOSError()))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_AttachSharedMemory(): mmap failed: %s, errno: %d", shm
->ipcname, PR_GetOSError()); } } while (0)
;
371 addr = NULL((void*)0);
372 } else {
373 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->
ipcname, addr); } } while (0)
374 ("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->ipcname,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->
ipcname, addr); } } while (0)
375 addr))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->
ipcname, addr); } } while (0)
;
376 }
377
378 return addr;
379}
380
381extern PRStatus
382_MD_DetachSharedMemory(PRSharedMemory* shm, void* addr)
383{
384 PRStatus rc = PR_SUCCESS;
385 PRIntn urc;
386
387 PR_ASSERT(shm->ident == _PR_SHM_IDENT)((shm->ident == 0xdeadbad) ? ((void)0) : PR_Assert("shm->ident == _PR_SHM_IDENT"
, "./../../../../../nsprpub/pr/src/md/unix/uxshm.c", 387))
;
388
389 urc = munmap(addr, shm->size);
390 if (-1 == urc) {
391 rc = PR_FAILURE;
392 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
393 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d", shm
->ipcname, PR_GetOSError()); } } while (0)
394 ("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d",do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d", shm
->ipcname, PR_GetOSError()); } } while (0)
395 shm->ipcname, PR_GetOSError()))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d", shm
->ipcname, PR_GetOSError()); } } while (0)
;
396 }
397 return rc;
398}
399
400extern PRStatus
401_MD_CloseSharedMemory(PRSharedMemory* shm)
402{
403 int urc;
404
405 PR_ASSERT(shm->ident == _PR_SHM_IDENT)((shm->ident == 0xdeadbad) ? ((void)0) : PR_Assert("shm->ident == _PR_SHM_IDENT"
, "./../../../../../nsprpub/pr/src/md/unix/uxshm.c", 405))
;
406
407 urc = close(shm->id);
408 if (-1 == urc) {
409 _PR_MD_MAP_CLOSE_ERROR_MD_unix_map_close_error(errno(*__errno_location ()));
410 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError
()); } } while (0)
411 ("_MD_CloseSharedMemory(): close() failed, error: %d",do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError
()); } } while (0)
412 PR_GetOSError()))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError
()); } } while (0)
;
413 return (PR_FAILURE);
414 }
415 PR_DELETE(shm->ipcname){ PR_Free(shm->ipcname); (shm->ipcname) = ((void*)0); };
416 PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); };
417 return PR_SUCCESS;
418}
419
420extern PRStatus
421_MD_DeleteSharedMemory(const char* name)
422{
423 PRStatus rc = PR_SUCCESS;
424 PRUintn urc;
425 char ipcname[PR_IPC_NAME_SIZE1024];
426
427 rc = _PR_MakeNativeIPCName(name, ipcname, PR_IPC_NAME_SIZE1024, _PRIPCShm);
428 if (PR_FAILURE == rc) {
429 PR_SetError(PR_UNKNOWN_ERROR(-5994L), errno(*__errno_location ()));
430 PR_LOG(do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s"
, name); } } while (0)
431 _pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s"
, name); } } while (0)
432 ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s"
, name); } } while (0)
;
433 return rc;
434 }
435
436 urc = shm_unlink(ipcname);
437 if (-1 == urc) {
438 rc = PR_FAILURE;
439 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
440 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): shm_unlink failed: %s, errno: %d"
, ipcname, PR_GetOSError()); } } while (0)
441 ("_MD_DeleteSharedMemory(): shm_unlink failed: %s, errno: %d",do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): shm_unlink failed: %s, errno: %d"
, ipcname, PR_GetOSError()); } } while (0)
442 ipcname, PR_GetOSError()))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): shm_unlink failed: %s, errno: %d"
, ipcname, PR_GetOSError()); } } while (0)
;
443 } else {
444 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): %s, success", ipcname); } } while
(0)
445 ("_MD_DeleteSharedMemory(): %s, success", ipcname))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_MD_DeleteSharedMemory(): %s, success", ipcname); } } while
(0)
;
446 }
447
448 return rc;
449} /* end _MD_DeleteSharedMemory() */
450#endif
451
452/*
453** Unix implementation for anonymous memory (file) mapping
454*/
455extern PRLogModuleInfo* _pr_shma_lm;
456
457#include <unistd.h>
458
459extern PRFileMap*
460_md_OpenAnonFileMap(const char* dirName, PRSize size,
461 PRFileMapProtect prot)
462{
463 PRFileMap* fm = NULL((void*)0);
464 PRFileDesc* fd;
465 int osfd;
466 PRIntn urc;
467 PRIntn mode = 0600;
468 char* genName;
469 pid_t pid = getpid(); /* for generating filename */
470 PRThread* tid = PR_GetCurrentThread(); /* for generating filename */
471 int incr; /* for generating filename */
472 const int maxTries = 20; /* maximum # attempts at a unique filename */
473 PRInt64 size64; /* 64-bit version of 'size' */
474
475 /*
476 ** generate a filename from input and runtime environment
477 ** open the file, unlink the file.
478 ** make maxTries number of attempts at uniqueness in the filename
479 */
480 for (incr = 0; incr < maxTries; incr++) {
481#define NSPR_AFM_FILENAME"%s/.NSPR-AFM-%d-%p.%d" "%s/.NSPR-AFM-%d-%p.%d"
482 genName = PR_smprintf(NSPR_AFM_FILENAME"%s/.NSPR-AFM-%d-%p.%d", dirName, (int)pid, tid, incr);
483 if (NULL((void*)0) == genName) {
484 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG,do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating "
"filename"); } } while (0)
485 ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating "do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating "
"filename"); } } while (0)
486 "filename"))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating "
"filename"); } } while (0)
;
487 goto Finished;
488 }
489
490 /* create the file */
491 osfd = open(genName, (O_CREAT0100 | O_EXCL0200 | O_RDWR02), mode);
492 if (-1 == osfd) {
493 if (EEXIST17 == errno(*__errno_location ())) {
494 PR_smprintf_free(genName);
495 continue; /* name exists, try again */
496 }
497 _PR_MD_MAP_OPEN_ERROR_MD_unix_map_open_error(errno(*__errno_location ()));
498 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG,do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d"
, genName, PR_GetOSError()); } } while (0)
499 ("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d",do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d"
, genName, PR_GetOSError()); } } while (0)
500 genName, PR_GetOSError()))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d"
, genName, PR_GetOSError()); } } while (0)
;
501 PR_smprintf_free(genName);
502 goto Finished;
503 }
504 break; /* name generation and open successful, break; */
505 } /* end for() */
506
507 if (incr == maxTries) {
508 PR_ASSERT(-1 == osfd)((-1 == osfd) ? ((void)0) : PR_Assert("-1 == osfd", "./../../../../../nsprpub/pr/src/md/unix/uxshm.c"
, 508))
;
509 PR_ASSERT(EEXIST == errno)((17 == (*__errno_location ())) ? ((void)0) : PR_Assert("EEXIST == errno"
, "./../../../../../nsprpub/pr/src/md/unix/uxshm.c", 509))
;
510 _PR_MD_MAP_OPEN_ERROR_MD_unix_map_open_error(errno(*__errno_location ()));
511 goto Finished;
512 }
513
514 urc = unlink(genName);
515 if (-1 == urc) {
516 _PR_MD_MAP_UNLINK_ERROR_MD_unix_map_unlink_error(errno(*__errno_location ()));
517 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG,do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", (*__errno_location
())); } } while (0)
518 ("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", errno))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", (*__errno_location
())); } } while (0)
;
519 PR_smprintf_free(genName);
520 close(osfd);
521 goto Finished;
522 }
523 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG,do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): unlink(): %s", genName); } } while (
0)
524 ("_md_OpenAnonFileMap(): unlink(): %s", genName))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): unlink(): %s", genName); } } while (
0)
;
525
526 PR_smprintf_free(genName);
527
528 fd = PR_ImportFile(osfd);
529 if (NULL((void*)0) == fd) {
530 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG,do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): PR_ImportFile(): failed"); } } while
(0)
531 ("_md_OpenAnonFileMap(): PR_ImportFile(): failed"))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): PR_ImportFile(): failed"); } } while
(0)
;
532 goto Finished;
533 }
534 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG, ("_md_OpenAnonFileMap(): fd: %p", fd))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): fd: %p", fd); } } while (0)
;
535
536 urc = ftruncate(fd->secret->md.osfd, size);
537 if (-1 == urc) {
538 _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ()));
539 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG,do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", (
*__errno_location ())); } } while (0)
540 ("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", errno))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", (
*__errno_location ())); } } while (0)
;
541 PR_Close(fd);
542 goto Finished;
543 }
544 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG,do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): ftruncate(): size: %d", size); } } while
(0)
545 ("_md_OpenAnonFileMap(): ftruncate(): size: %d", size))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): ftruncate(): size: %d", size); } } while
(0)
;
546
547 LL_UI2L(size64, size)((size64) = (PRInt64)(size)); /* PRSize (size_t) is unsigned */
548 fm = PR_CreateFileMap(fd, size64, prot);
549 if (NULL((void*)0) == fm) {
550 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG, ("PR_OpenAnonFileMap(): failed"))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("PR_OpenAnonFileMap(): failed"); } } while (0)
;
551 PR_Close(fd);
552 goto Finished;
553 }
554 fm->md.isAnonFM = PR_TRUE1; /* set fd close */
555
556 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG,do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm); }
} while (0)
557 ("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm); }
} while (0)
;
558
559Finished:
560 return (fm);
561} /* end md_OpenAnonFileMap() */
562
563/*
564** _md_ExportFileMapAsString()
565**
566**
567*/
568extern PRStatus
569_md_ExportFileMapAsString(PRFileMap* fm, PRSize bufSize,
570 char* buf)
571{
572 PRIntn written;
573 PRIntn prot = (PRIntn)fm->prot;
574
575 written = PR_snprintf(buf, bufSize, "%ld:%d", fm->fd->secret->md.osfd, prot);
576
577 return ((written == -1) ? PR_FAILURE : PR_SUCCESS);
578} /* end _md_ExportFileMapAsString() */
579
580extern PRFileMap*
581_md_ImportFileMapFromString(const char* fmstring)
582{
583 PRStatus rc;
584 PRInt32 osfd;
585 PRIntn prot; /* really: a PRFileMapProtect */
586 PRFileDesc* fd;
587 PRFileMap* fm = NULL((void*)0); /* default return value */
588 PRFileInfo64 info;
589
590 PR_sscanf(fmstring, "%ld:%d", &osfd, &prot);
591
592 /* import the os file descriptor */
593 fd = PR_ImportFile(osfd);
594 if (NULL((void*)0) == fd) {
595 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG,do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_ImportFileMapFromString(): PR_ImportFile() failed"); }
} while (0)
596 ("_md_ImportFileMapFromString(): PR_ImportFile() failed"))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_ImportFileMapFromString(): PR_ImportFile() failed"); }
} while (0)
;
597 goto Finished;
598 }
599
600 rc = PR_GetOpenFileInfo64(fd, &info);
601 if (PR_FAILURE == rc) {
602 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG,do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed"
); } } while (0)
603 ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed"))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed"
); } } while (0)
;
604 goto Finished;
605 }
606
607 fm = PR_CreateFileMap(fd, info.size, (PRFileMapProtect)prot);
608 if (NULL((void*)0) == fm) {
609 PR_LOG(_pr_shma_lm, PR_LOG_DEBUG,do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_ImportFileMapFromString(): PR_CreateFileMap() failed")
; } } while (0)
610 ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed"))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint
("_md_ImportFileMapFromString(): PR_CreateFileMap() failed")
; } } while (0)
;
611 }
612
613Finished:
614 return (fm);
615} /* end _md_ImportFileMapFromString() */