File: | root/firefox-clang/nsprpub/pr/src/md/unix/uxshm.c |
Warning: | line 98, column 5 Value stored to 'rc' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | |
6 | /* |
7 | ** uxshm.c -- Unix Implementations NSPR Named Shared Memory |
8 | ** |
9 | ** |
10 | ** lth. Jul-1999. |
11 | ** |
12 | */ |
13 | #include <string.h> |
14 | #include <prshm.h> |
15 | #include <prerr.h> |
16 | #include <prmem.h> |
17 | #include "primpl.h" |
18 | #include <fcntl.h> |
19 | |
20 | extern PRLogModuleInfo* _pr_shm_lm; |
21 | |
22 | #define NSPR_IPC_SHM_KEY'b' 'b' |
23 | /* |
24 | ** Implementation for System V |
25 | */ |
26 | #if defined PR_HAVE_SYSV_NAMED_SHARED_MEMORY |
27 | # include <sys/ipc.h> |
28 | # include <sys/shm.h> |
29 | # include <sys/types.h> |
30 | # include <sys/stat.h> |
31 | |
32 | # define _MD_OPEN_SHARED_MEMORY_MD_OpenSharedMemory _MD_OpenSharedMemory |
33 | # define _MD_ATTACH_SHARED_MEMORY_MD_AttachSharedMemory _MD_AttachSharedMemory |
34 | # define _MD_DETACH_SHARED_MEMORY_MD_DetachSharedMemory _MD_DetachSharedMemory |
35 | # define _MD_CLOSE_SHARED_MEMORY_MD_CloseSharedMemory _MD_CloseSharedMemory |
36 | # define _MD_DELETE_SHARED_MEMORY_MD_DeleteSharedMemory _MD_DeleteSharedMemory |
37 | |
38 | extern PRSharedMemory* _MD_OpenSharedMemory(const char* name, PRSize size, |
39 | PRIntn flags, PRIntn mode) { |
40 | PRStatus rc = PR_SUCCESS; |
41 | key_t key; |
42 | PRSharedMemory* shm; |
43 | char ipcname[PR_IPC_NAME_SIZE1024]; |
44 | |
45 | rc = _PR_MakeNativeIPCName(name, ipcname, PR_IPC_NAME_SIZE1024, _PRIPCShm); |
46 | if (PR_FAILURE == rc) { |
47 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
48 | PR_LOG(do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s" , name); } } while (0) |
49 | _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) |
50 | ("_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); |
51 | return (NULL((void*)0)); |
52 | } |
53 | |
54 | shm = PR_NEWZAP(PRSharedMemory)((PRSharedMemory*)PR_Calloc(1, sizeof(PRSharedMemory))); |
55 | if (NULL((void*)0) == shm) { |
56 | PR_SetError(PR_OUT_OF_MEMORY_ERROR(-6000L), 0); |
57 | 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) |
58 | ("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); |
59 | return (NULL((void*)0)); |
60 | } |
61 | |
62 | shm->ipcname = (char*)PR_MALLOC(strlen(ipcname) + 1)(PR_Malloc((strlen(ipcname) + 1))); |
63 | if (NULL((void*)0) == shm->ipcname) { |
64 | PR_SetError(PR_OUT_OF_MEMORY_ERROR(-6000L), 0); |
65 | 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) |
66 | ("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); |
67 | PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); }; |
68 | return (NULL((void*)0)); |
69 | } |
70 | |
71 | /* copy args to struct */ |
72 | strcpy(shm->ipcname, ipcname); |
73 | shm->size = size; |
74 | shm->mode = mode; |
75 | shm->flags = flags; |
76 | shm->ident = _PR_SHM_IDENT0xdeadbad; |
77 | |
78 | /* create the file first */ |
79 | if (flags & PR_SHM_CREATE0x1) { |
80 | int osfd = open(shm->ipcname, (O_RDWR02 | O_CREAT0100), shm->mode); |
81 | if (-1 == osfd) { |
82 | _PR_MD_MAP_OPEN_ERROR_MD_unix_map_open_error(errno(*__errno_location ())); |
83 | PR_FREEIF(shm->ipcname)if (shm->ipcname) { PR_Free(shm->ipcname); (shm->ipcname ) = ((void*)0); }; |
84 | PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); }; |
85 | return (NULL((void*)0)); |
86 | } |
87 | if (close(osfd) == -1) { |
88 | _PR_MD_MAP_CLOSE_ERROR_MD_unix_map_close_error(errno(*__errno_location ())); |
89 | PR_FREEIF(shm->ipcname)if (shm->ipcname) { PR_Free(shm->ipcname); (shm->ipcname ) = ((void*)0); }; |
90 | PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); }; |
91 | return (NULL((void*)0)); |
92 | } |
93 | } |
94 | |
95 | /* hash the shm.name to an ID */ |
96 | key = ftok(shm->ipcname, NSPR_IPC_SHM_KEY'b'); |
97 | if (-1 == key) { |
98 | rc = PR_FAILURE; |
Value stored to 'rc' is never read | |
99 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
100 | 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) |
101 | ("_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); |
102 | PR_FREEIF(shm->ipcname)if (shm->ipcname) { PR_Free(shm->ipcname); (shm->ipcname ) = ((void*)0); }; |
103 | PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); }; |
104 | return (NULL((void*)0)); |
105 | } |
106 | |
107 | /* get the shared memory */ |
108 | if (flags & PR_SHM_CREATE0x1) { |
109 | shm->id = shmget(key, shm->size, (shm->mode | IPC_CREAT01000 | IPC_EXCL02000)); |
110 | if (shm->id >= 0) { |
111 | return (shm); |
112 | } |
113 | if ((errno(*__errno_location ()) == EEXIST17) && (flags & PR_SHM_EXCL0x2)) { |
114 | PR_SetError(PR_FILE_EXISTS_ERROR(-5943L), errno(*__errno_location ())); |
115 | 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) |
116 | ("_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) |
117 | errno))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d" , (*__errno_location ())); } } while (0); |
118 | PR_FREEIF(shm->ipcname)if (shm->ipcname) { PR_Free(shm->ipcname); (shm->ipcname ) = ((void*)0); }; |
119 | PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); }; |
120 | return (NULL((void*)0)); |
121 | } |
122 | } |
123 | |
124 | shm->id = shmget(key, shm->size, shm->mode); |
125 | if (-1 == shm->id) { |
126 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
127 | 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) |
128 | ("_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); |
129 | PR_FREEIF(shm->ipcname)if (shm->ipcname) { PR_Free(shm->ipcname); (shm->ipcname ) = ((void*)0); }; |
130 | PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); }; |
131 | return (NULL((void*)0)); |
132 | } |
133 | |
134 | return (shm); |
135 | } /* end _MD_OpenSharedMemory() */ |
136 | |
137 | extern void* _MD_AttachSharedMemory(PRSharedMemory* shm, PRIntn flags) { |
138 | void* addr; |
139 | PRUint32 aFlags = shm->mode; |
140 | |
141 | PR_ASSERT(shm->ident == _PR_SHM_IDENT)((shm->ident == 0xdeadbad)?((void)0):PR_Assert("shm->ident == _PR_SHM_IDENT" ,"/root/firefox-clang/nsprpub/pr/src/md/unix/uxshm.c",141)); |
142 | |
143 | aFlags |= (flags & PR_SHM_READONLY0x01) ? SHM_RDONLY010000 : 0; |
144 | |
145 | addr = shmat(shm->id, NULL((void*)0), aFlags); |
146 | if ((void*)-1 == addr) { |
147 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
148 | 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) |
149 | ("_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) |
150 | 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); |
151 | addr = NULL((void*)0); |
152 | } |
153 | |
154 | return addr; |
155 | } |
156 | |
157 | extern PRStatus _MD_DetachSharedMemory(PRSharedMemory* shm, void* addr) { |
158 | PRStatus rc = PR_SUCCESS; |
159 | PRIntn urc; |
160 | |
161 | PR_ASSERT(shm->ident == _PR_SHM_IDENT)((shm->ident == 0xdeadbad)?((void)0):PR_Assert("shm->ident == _PR_SHM_IDENT" ,"/root/firefox-clang/nsprpub/pr/src/md/unix/uxshm.c",161)); |
162 | |
163 | urc = shmdt(addr); |
164 | if (-1 == urc) { |
165 | rc = PR_FAILURE; |
166 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
167 | PR_LOG(do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm ->ipcname); } } while (0) |
168 | _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) |
169 | ("_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); |
170 | } |
171 | |
172 | return rc; |
173 | } |
174 | |
175 | extern PRStatus _MD_CloseSharedMemory(PRSharedMemory* shm) { |
176 | PR_ASSERT(shm->ident == _PR_SHM_IDENT)((shm->ident == 0xdeadbad)?((void)0):PR_Assert("shm->ident == _PR_SHM_IDENT" ,"/root/firefox-clang/nsprpub/pr/src/md/unix/uxshm.c",176)); |
177 | |
178 | PR_FREEIF(shm->ipcname)if (shm->ipcname) { PR_Free(shm->ipcname); (shm->ipcname ) = ((void*)0); }; |
179 | PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); }; |
180 | |
181 | return PR_SUCCESS; |
182 | } |
183 | |
184 | extern PRStatus _MD_DeleteSharedMemory(const char* name) { |
185 | PRStatus rc = PR_SUCCESS; |
186 | key_t key; |
187 | int id; |
188 | PRIntn urc; |
189 | char ipcname[PR_IPC_NAME_SIZE1024]; |
190 | |
191 | rc = _PR_MakeNativeIPCName(name, ipcname, PR_IPC_NAME_SIZE1024, _PRIPCShm); |
192 | if (PR_FAILURE == rc) { |
193 | PR_SetError(PR_UNKNOWN_ERROR(-5994L), errno(*__errno_location ())); |
194 | PR_LOG(do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s" , name); } } while (0) |
195 | _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) |
196 | ("_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); |
197 | return (PR_FAILURE); |
198 | } |
199 | |
200 | /* create the file first */ |
201 | { |
202 | int osfd = open(ipcname, (O_RDWR02 | O_CREAT0100), 0666); |
203 | if (-1 == osfd) { |
204 | _PR_MD_MAP_OPEN_ERROR_MD_unix_map_open_error(errno(*__errno_location ())); |
205 | return (PR_FAILURE); |
206 | } |
207 | if (close(osfd) == -1) { |
208 | _PR_MD_MAP_CLOSE_ERROR_MD_unix_map_close_error(errno(*__errno_location ())); |
209 | return (PR_FAILURE); |
210 | } |
211 | } |
212 | |
213 | /* hash the shm.name to an ID */ |
214 | key = ftok(ipcname, NSPR_IPC_SHM_KEY'b'); |
215 | if (-1 == key) { |
216 | rc = PR_FAILURE; |
217 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
218 | 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) |
219 | ("_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); |
220 | } |
221 | |
222 | id = shmget(key, 0, 0); |
223 | if (-1 == id) { |
224 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
225 | 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) |
226 | ("_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); |
227 | return (PR_FAILURE); |
228 | } |
229 | |
230 | urc = shmctl(id, IPC_RMID0, NULL((void*)0)); |
231 | if (-1 == urc) { |
232 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
233 | 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) |
234 | ("_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); |
235 | return (PR_FAILURE); |
236 | } |
237 | |
238 | urc = unlink(ipcname); |
239 | if (-1 == urc) { |
240 | _PR_MD_MAP_UNLINK_ERROR_MD_unix_map_unlink_error(errno(*__errno_location ())); |
241 | 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) |
242 | ("_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); |
243 | return (PR_FAILURE); |
244 | } |
245 | |
246 | return rc; |
247 | } /* end _MD_DeleteSharedMemory() */ |
248 | |
249 | /* |
250 | ** Implementation for Posix |
251 | */ |
252 | #elif defined PR_HAVE_POSIX_NAMED_SHARED_MEMORY |
253 | # include <sys/mman.h> |
254 | |
255 | # define _MD_OPEN_SHARED_MEMORY_MD_OpenSharedMemory _MD_OpenSharedMemory |
256 | # define _MD_ATTACH_SHARED_MEMORY_MD_AttachSharedMemory _MD_AttachSharedMemory |
257 | # define _MD_DETACH_SHARED_MEMORY_MD_DetachSharedMemory _MD_DetachSharedMemory |
258 | # define _MD_CLOSE_SHARED_MEMORY_MD_CloseSharedMemory _MD_CloseSharedMemory |
259 | # define _MD_DELETE_SHARED_MEMORY_MD_DeleteSharedMemory _MD_DeleteSharedMemory |
260 | |
261 | struct _MDSharedMemory { |
262 | int handle; |
263 | }; |
264 | |
265 | extern PRSharedMemory* _MD_OpenSharedMemory(const char* name, PRSize size, |
266 | PRIntn flags, PRIntn mode) { |
267 | PRStatus rc = PR_SUCCESS; |
268 | PRInt32 end; |
269 | PRSharedMemory* shm; |
270 | char ipcname[PR_IPC_NAME_SIZE1024]; |
271 | |
272 | rc = _PR_MakeNativeIPCName(name, ipcname, PR_IPC_NAME_SIZE1024, _PRIPCShm); |
273 | if (PR_FAILURE == rc) { |
274 | PR_SetError(PR_UNKNOWN_ERROR(-5994L), errno(*__errno_location ())); |
275 | PR_LOG(do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s" , name); } } while (0) |
276 | _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) |
277 | ("_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); |
278 | return (NULL((void*)0)); |
279 | } |
280 | |
281 | shm = PR_NEWZAP(PRSharedMemory)((PRSharedMemory*)PR_Calloc(1, sizeof(PRSharedMemory))); |
282 | if (NULL((void*)0) == shm) { |
283 | PR_SetError(PR_OUT_OF_MEMORY_ERROR(-6000L), 0); |
284 | 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) |
285 | ("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); |
286 | return (NULL((void*)0)); |
287 | } |
288 | |
289 | shm->ipcname = PR_MALLOC(strlen(ipcname) + 1)(PR_Malloc((strlen(ipcname) + 1))); |
290 | if (NULL((void*)0) == shm->ipcname) { |
291 | PR_SetError(PR_OUT_OF_MEMORY_ERROR(-6000L), 0); |
292 | 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) |
293 | ("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); |
294 | return (NULL((void*)0)); |
295 | } |
296 | |
297 | /* copy args to struct */ |
298 | strcpy(shm->ipcname, ipcname); |
299 | shm->size = size; |
300 | shm->mode = mode; |
301 | shm->flags = flags; |
302 | shm->ident = _PR_SHM_IDENT0xdeadbad; |
303 | |
304 | /* |
305 | ** Create the shared memory |
306 | */ |
307 | if (flags & PR_SHM_CREATE0x1) { |
308 | int oflag = (O_CREAT0100 | O_RDWR02); |
309 | |
310 | if (flags & PR_SHM_EXCL0x2) { |
311 | oflag |= O_EXCL0200; |
312 | } |
313 | shm->id = shm_open(shm->ipcname, oflag, shm->mode); |
314 | } else { |
315 | shm->id = shm_open(shm->ipcname, O_RDWR02, shm->mode); |
316 | } |
317 | |
318 | if (-1 == shm->id) { |
319 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
320 | 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) |
321 | ("_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) |
322 | 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); |
323 | PR_DELETE(shm->ipcname){ PR_Free(shm->ipcname); (shm->ipcname) = ((void*)0); }; |
324 | PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); }; |
325 | return (NULL((void*)0)); |
326 | } |
327 | |
328 | end = ftruncate(shm->id, shm->size); |
329 | if (-1 == end) { |
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(): ftruncate failed, OSError: %d", PR_GetOSError ()); } } while (0) |
332 | ("_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) |
333 | PR_GetOSError()))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d", 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 | return (shm); |
340 | } /* end _MD_OpenSharedMemory() */ |
341 | |
342 | extern void* _MD_AttachSharedMemory(PRSharedMemory* shm, PRIntn flags) { |
343 | void* addr; |
344 | PRIntn prot = (PROT_READ0x1 | PROT_WRITE0x2); |
345 | |
346 | PR_ASSERT(shm->ident == _PR_SHM_IDENT)((shm->ident == 0xdeadbad)?((void)0):PR_Assert("shm->ident == _PR_SHM_IDENT" ,"/root/firefox-clang/nsprpub/pr/src/md/unix/uxshm.c",346)); |
347 | |
348 | if (PR_SHM_READONLY0x01 == flags) { |
349 | prot ^= PROT_WRITE0x2; |
350 | } |
351 | |
352 | addr = mmap((void*)0, shm->size, prot, MAP_SHARED0x01, shm->id, 0); |
353 | if ((void*)-1 == addr) { |
354 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
355 | 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) |
356 | ("_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) |
357 | 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); |
358 | addr = NULL((void*)0); |
359 | } else { |
360 | 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) |
361 | ("_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) |
362 | addr))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm-> ipcname, addr); } } while (0); |
363 | } |
364 | |
365 | return addr; |
366 | } |
367 | |
368 | extern PRStatus _MD_DetachSharedMemory(PRSharedMemory* shm, void* addr) { |
369 | PRStatus rc = PR_SUCCESS; |
370 | PRIntn urc; |
371 | |
372 | PR_ASSERT(shm->ident == _PR_SHM_IDENT)((shm->ident == 0xdeadbad)?((void)0):PR_Assert("shm->ident == _PR_SHM_IDENT" ,"/root/firefox-clang/nsprpub/pr/src/md/unix/uxshm.c",372)); |
373 | |
374 | urc = munmap(addr, shm->size); |
375 | if (-1 == urc) { |
376 | rc = PR_FAILURE; |
377 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
378 | 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) |
379 | ("_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) |
380 | 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); |
381 | } |
382 | return rc; |
383 | } |
384 | |
385 | extern PRStatus _MD_CloseSharedMemory(PRSharedMemory* shm) { |
386 | int urc; |
387 | |
388 | PR_ASSERT(shm->ident == _PR_SHM_IDENT)((shm->ident == 0xdeadbad)?((void)0):PR_Assert("shm->ident == _PR_SHM_IDENT" ,"/root/firefox-clang/nsprpub/pr/src/md/unix/uxshm.c",388)); |
389 | |
390 | urc = close(shm->id); |
391 | if (-1 == urc) { |
392 | _PR_MD_MAP_CLOSE_ERROR_MD_unix_map_close_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_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError ()); } } while (0) |
394 | ("_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) |
395 | PR_GetOSError()))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError ()); } } while (0); |
396 | return (PR_FAILURE); |
397 | } |
398 | PR_DELETE(shm->ipcname){ PR_Free(shm->ipcname); (shm->ipcname) = ((void*)0); }; |
399 | PR_DELETE(shm){ PR_Free(shm); (shm) = ((void*)0); }; |
400 | return PR_SUCCESS; |
401 | } |
402 | |
403 | extern PRStatus _MD_DeleteSharedMemory(const char* name) { |
404 | PRStatus rc = PR_SUCCESS; |
405 | PRUintn urc; |
406 | char ipcname[PR_IPC_NAME_SIZE1024]; |
407 | |
408 | rc = _PR_MakeNativeIPCName(name, ipcname, PR_IPC_NAME_SIZE1024, _PRIPCShm); |
409 | if (PR_FAILURE == rc) { |
410 | PR_SetError(PR_UNKNOWN_ERROR(-5994L), errno(*__errno_location ())); |
411 | PR_LOG(do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s" , name); } } while (0) |
412 | _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) |
413 | ("_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); |
414 | return rc; |
415 | } |
416 | |
417 | urc = shm_unlink(ipcname); |
418 | if (-1 == urc) { |
419 | rc = PR_FAILURE; |
420 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
421 | 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) |
422 | ("_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) |
423 | 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); |
424 | } else { |
425 | 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) |
426 | ("_MD_DeleteSharedMemory(): %s, success", ipcname))do { if (((_pr_shm_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_MD_DeleteSharedMemory(): %s, success", ipcname); } } while (0); |
427 | } |
428 | |
429 | return rc; |
430 | } /* end _MD_DeleteSharedMemory() */ |
431 | #endif |
432 | |
433 | /* |
434 | ** Unix implementation for anonymous memory (file) mapping |
435 | */ |
436 | extern PRLogModuleInfo* _pr_shma_lm; |
437 | |
438 | #include <unistd.h> |
439 | |
440 | extern PRFileMap* _md_OpenAnonFileMap(const char* dirName, PRSize size, |
441 | PRFileMapProtect prot) { |
442 | PRFileMap* fm = NULL((void*)0); |
443 | PRFileDesc* fd; |
444 | int osfd; |
445 | PRIntn urc; |
446 | PRIntn mode = 0600; |
447 | char* genName; |
448 | pid_t pid = getpid(); /* for generating filename */ |
449 | PRThread* tid = PR_GetCurrentThread(); /* for generating filename */ |
450 | int incr; /* for generating filename */ |
451 | const int maxTries = 20; /* maximum # attempts at a unique filename */ |
452 | PRInt64 size64; /* 64-bit version of 'size' */ |
453 | |
454 | /* |
455 | ** generate a filename from input and runtime environment |
456 | ** open the file, unlink the file. |
457 | ** make maxTries number of attempts at uniqueness in the filename |
458 | */ |
459 | for (incr = 0; incr < maxTries; incr++) { |
460 | #define NSPR_AFM_FILENAME"%s/.NSPR-AFM-%d-%p.%d" "%s/.NSPR-AFM-%d-%p.%d" |
461 | genName = PR_smprintf(NSPR_AFM_FILENAME"%s/.NSPR-AFM-%d-%p.%d", dirName, (int)pid, tid, incr); |
462 | if (NULL((void*)0) == genName) { |
463 | 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) |
464 | ("_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) |
465 | "filename"))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating " "filename"); } } while (0); |
466 | goto Finished; |
467 | } |
468 | |
469 | /* create the file */ |
470 | osfd = open(genName, (O_CREAT0100 | O_EXCL0200 | O_RDWR02), mode); |
471 | if (-1 == osfd) { |
472 | if (EEXIST17 == errno(*__errno_location ())) { |
473 | PR_smprintf_free(genName); |
474 | continue; /* name exists, try again */ |
475 | } |
476 | _PR_MD_MAP_OPEN_ERROR_MD_unix_map_open_error(errno(*__errno_location ())); |
477 | 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) |
478 | ("_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) |
479 | 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); |
480 | PR_smprintf_free(genName); |
481 | goto Finished; |
482 | } |
483 | break; /* name generation and open successful, break; */ |
484 | } /* end for() */ |
485 | |
486 | if (incr == maxTries) { |
487 | PR_ASSERT(-1 == osfd)((-1 == osfd)?((void)0):PR_Assert("-1 == osfd","/root/firefox-clang/nsprpub/pr/src/md/unix/uxshm.c" ,487)); |
488 | PR_ASSERT(EEXIST == errno)((17 == (*__errno_location ()))?((void)0):PR_Assert("EEXIST == errno" ,"/root/firefox-clang/nsprpub/pr/src/md/unix/uxshm.c",488)); |
489 | _PR_MD_MAP_OPEN_ERROR_MD_unix_map_open_error(errno(*__errno_location ())); |
490 | goto Finished; |
491 | } |
492 | |
493 | urc = unlink(genName); |
494 | if (-1 == urc) { |
495 | _PR_MD_MAP_UNLINK_ERROR_MD_unix_map_unlink_error(errno(*__errno_location ())); |
496 | 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) |
497 | ("_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); |
498 | PR_smprintf_free(genName); |
499 | close(osfd); |
500 | goto Finished; |
501 | } |
502 | 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) |
503 | ("_md_OpenAnonFileMap(): unlink(): %s", genName))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_md_OpenAnonFileMap(): unlink(): %s", genName); } } while ( 0); |
504 | |
505 | PR_smprintf_free(genName); |
506 | |
507 | fd = PR_ImportFile(osfd); |
508 | if (NULL((void*)0) == fd) { |
509 | 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) |
510 | ("_md_OpenAnonFileMap(): PR_ImportFile(): failed"))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_md_OpenAnonFileMap(): PR_ImportFile(): failed"); } } while (0); |
511 | goto Finished; |
512 | } |
513 | 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); |
514 | |
515 | urc = ftruncate(fd->secret->md.osfd, size); |
516 | if (-1 == urc) { |
517 | _PR_MD_MAP_DEFAULT_ERROR_MD_unix_map_default_error(errno(*__errno_location ())); |
518 | 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) |
519 | ("_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); |
520 | PR_Close(fd); |
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(): ftruncate(): size: %d", size); } } while (0) |
524 | ("_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); |
525 | |
526 | LL_UI2L(size64, size)((size64) = (PRInt64)(size)); /* PRSize (size_t) is unsigned */ |
527 | fm = PR_CreateFileMap(fd, size64, prot); |
528 | if (NULL((void*)0) == fm) { |
529 | 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); |
530 | PR_Close(fd); |
531 | goto Finished; |
532 | } |
533 | fm->md.isAnonFM = PR_TRUE1; /* set fd close */ |
534 | |
535 | 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) |
536 | ("_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); |
537 | |
538 | Finished: |
539 | return (fm); |
540 | } /* end md_OpenAnonFileMap() */ |
541 | |
542 | /* |
543 | ** _md_ExportFileMapAsString() |
544 | ** |
545 | ** |
546 | */ |
547 | extern PRStatus _md_ExportFileMapAsString(PRFileMap* fm, PRSize bufSize, |
548 | char* buf) { |
549 | PRIntn written; |
550 | PRIntn prot = (PRIntn)fm->prot; |
551 | |
552 | written = PR_snprintf(buf, bufSize, "%ld:%d", fm->fd->secret->md.osfd, prot); |
553 | |
554 | return ((written == -1) ? PR_FAILURE : PR_SUCCESS); |
555 | } /* end _md_ExportFileMapAsString() */ |
556 | |
557 | extern PRFileMap* _md_ImportFileMapFromString(const char* fmstring) { |
558 | PRStatus rc; |
559 | PRInt32 osfd; |
560 | PRIntn prot; /* really: a PRFileMapProtect */ |
561 | PRFileDesc* fd; |
562 | PRFileMap* fm = NULL((void*)0); /* default return value */ |
563 | PRFileInfo64 info; |
564 | |
565 | PR_sscanf(fmstring, "%ld:%d", &osfd, &prot); |
566 | |
567 | /* import the os file descriptor */ |
568 | fd = PR_ImportFile(osfd); |
569 | if (NULL((void*)0) == fd) { |
570 | 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) |
571 | ("_md_ImportFileMapFromString(): PR_ImportFile() failed"))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_md_ImportFileMapFromString(): PR_ImportFile() failed"); } } while (0); |
572 | goto Finished; |
573 | } |
574 | |
575 | rc = PR_GetOpenFileInfo64(fd, &info); |
576 | if (PR_FAILURE == rc) { |
577 | 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) |
578 | ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed"))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed" ); } } while (0); |
579 | goto Finished; |
580 | } |
581 | |
582 | fm = PR_CreateFileMap(fd, info.size, (PRFileMapProtect)prot); |
583 | if (NULL((void*)0) == fm) { |
584 | 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) |
585 | ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed"))do { if (((_pr_shma_lm)->level >= (PR_LOG_DEBUG))) { PR_LogPrint ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed") ; } } while (0); |
586 | } |
587 | |
588 | Finished: |
589 | return (fm); |
590 | } /* end _md_ImportFileMapFromString() */ |