OLD | NEW |
1 /* ***** BEGIN LICENSE BLOCK ***** | 1 /* ***** BEGIN LICENSE BLOCK ***** |
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
3 * | 3 * |
4 * The contents of this file are subject to the Mozilla Public License Version | 4 * The contents of this file are subject to the Mozilla Public License Version |
5 * 1.1 (the "License"); you may not use this file except in compliance with | 5 * 1.1 (the "License"); you may not use this file except in compliance with |
6 * the License. You may obtain a copy of the License at | 6 * the License. You may obtain a copy of the License at |
7 * http://www.mozilla.org/MPL/ | 7 * http://www.mozilla.org/MPL/ |
8 * | 8 * |
9 * Software distributed under the License is distributed on an "AS IS" basis, | 9 * Software distributed under the License is distributed on an "AS IS" basis, |
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
(...skipping 15 matching lines...) Expand all Loading... |
26 * in which case the provisions of the GPL or the LGPL are applicable instead | 26 * in which case the provisions of the GPL or the LGPL are applicable instead |
27 * of those above. If you wish to allow use of your version of this file only | 27 * of those above. If you wish to allow use of your version of this file only |
28 * under the terms of either the GPL or the LGPL, and not to allow others to | 28 * under the terms of either the GPL or the LGPL, and not to allow others to |
29 * use your version of this file under the terms of the MPL, indicate your | 29 * use your version of this file under the terms of the MPL, indicate your |
30 * decision by deleting the provisions above and replace them with the notice | 30 * decision by deleting the provisions above and replace them with the notice |
31 * and other provisions required by the GPL or the LGPL. If you do not delete | 31 * and other provisions required by the GPL or the LGPL. If you do not delete |
32 * the provisions above, a recipient may use your version of this file under | 32 * the provisions above, a recipient may use your version of this file under |
33 * the terms of any one of the MPL, the GPL or the LGPL. | 33 * the terms of any one of the MPL, the GPL or the LGPL. |
34 * | 34 * |
35 * ***** END LICENSE BLOCK ***** */ | 35 * ***** END LICENSE BLOCK ***** */ |
36 /* $Id: sslmutex.c,v 1.25 2010/04/03 18:27:33 nelson%bolyard.com Exp $ */ | 36 /* $Id: sslmutex.c,v 1.27 2011/10/01 00:11:02 wtc%google.com Exp $ */ |
37 | 37 |
38 #include "seccomon.h" | 38 #include "seccomon.h" |
39 /* This ifdef should match the one in sslsnce.c */ | 39 /* This ifdef should match the one in sslsnce.c */ |
40 #if defined(XP_UNIX) || defined(XP_WIN32) || defined (XP_OS2) || defined(XP_BEOS
) | 40 #if defined(XP_UNIX) || defined(XP_WIN32) || defined (XP_OS2) || defined(XP_BEOS
) |
41 | 41 |
42 #include "sslmutex.h" | 42 #include "sslmutex.h" |
43 #include "prerr.h" | 43 #include "prerr.h" |
44 | 44 |
45 static SECStatus single_process_sslMutex_Init(sslMutex* pMutex) | 45 static SECStatus single_process_sslMutex_Init(sslMutex* pMutex) |
46 { | 46 { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 #endif | 161 #endif |
162 | 162 |
163 loser: | 163 loser: |
164 nss_MD_unix_map_default_error(errno); | 164 nss_MD_unix_map_default_error(errno); |
165 close(pMutex->u.pipeStr.mPipes[0]); | 165 close(pMutex->u.pipeStr.mPipes[0]); |
166 close(pMutex->u.pipeStr.mPipes[1]); | 166 close(pMutex->u.pipeStr.mPipes[1]); |
167 return SECFailure; | 167 return SECFailure; |
168 } | 168 } |
169 | 169 |
170 SECStatus | 170 SECStatus |
171 sslMutex_Destroy(sslMutex *pMutex) | 171 sslMutex_Destroy(sslMutex *pMutex, PRBool processLocal) |
172 { | 172 { |
173 if (PR_FALSE == pMutex->isMultiProcess) { | 173 if (PR_FALSE == pMutex->isMultiProcess) { |
174 return single_process_sslMutex_Destroy(pMutex); | 174 return single_process_sslMutex_Destroy(pMutex); |
175 } | 175 } |
176 if (pMutex->u.pipeStr.mPipes[2] != SSL_MUTEX_MAGIC) { | 176 if (pMutex->u.pipeStr.mPipes[2] != SSL_MUTEX_MAGIC) { |
177 PORT_SetError(PR_INVALID_ARGUMENT_ERROR); | 177 PORT_SetError(PR_INVALID_ARGUMENT_ERROR); |
178 return SECFailure; | 178 return SECFailure; |
179 } | 179 } |
180 close(pMutex->u.pipeStr.mPipes[0]); | 180 close(pMutex->u.pipeStr.mPipes[0]); |
181 close(pMutex->u.pipeStr.mPipes[1]); | 181 close(pMutex->u.pipeStr.mPipes[1]); |
182 | 182 |
| 183 if (processLocal) { |
| 184 return SECSuccess; |
| 185 } |
| 186 |
183 pMutex->u.pipeStr.mPipes[0] = -1; | 187 pMutex->u.pipeStr.mPipes[0] = -1; |
184 pMutex->u.pipeStr.mPipes[1] = -1; | 188 pMutex->u.pipeStr.mPipes[1] = -1; |
185 pMutex->u.pipeStr.mPipes[2] = -1; | 189 pMutex->u.pipeStr.mPipes[2] = -1; |
186 pMutex->u.pipeStr.nWaiters = 0; | 190 pMutex->u.pipeStr.nWaiters = 0; |
187 | 191 |
188 return SECSuccess; | 192 return SECSuccess; |
189 } | 193 } |
190 | 194 |
191 #if defined(LINUX) && defined(i386) | 195 #if defined(LINUX) && defined(i386) |
192 /* No memory barrier needed for this platform */ | 196 /* No memory barrier needed for this platform */ |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 if (hMutex == NULL) { | 406 if (hMutex == NULL) { |
403 hMutex = INVALID_HANDLE_VALUE; | 407 hMutex = INVALID_HANDLE_VALUE; |
404 nss_MD_win32_map_default_error(GetLastError()); | 408 nss_MD_win32_map_default_error(GetLastError()); |
405 return SECFailure; | 409 return SECFailure; |
406 } | 410 } |
407 pMutex->u.sslMutx = hMutex; | 411 pMutex->u.sslMutx = hMutex; |
408 return SECSuccess; | 412 return SECSuccess; |
409 } | 413 } |
410 | 414 |
411 SECStatus | 415 SECStatus |
412 sslMutex_Destroy(sslMutex *pMutex) | 416 sslMutex_Destroy(sslMutex *pMutex, PRBool processLocal) |
413 { | 417 { |
414 HANDLE hMutex; | 418 HANDLE hMutex; |
415 int rv; | 419 int rv; |
416 int retvalue = SECSuccess; | 420 int retvalue = SECSuccess; |
417 | 421 |
418 PR_ASSERT(pMutex != 0); | 422 PR_ASSERT(pMutex != 0); |
419 if (PR_FALSE == pMutex->isMultiProcess) { | 423 if (PR_FALSE == pMutex->isMultiProcess) { |
420 return single_process_sslMutex_Destroy(pMutex); | 424 return single_process_sslMutex_Destroy(pMutex); |
421 } | 425 } |
422 | 426 |
423 /* multi-process mode */ | 427 /* multi-process mode */ |
424 #ifdef WINNT | 428 #ifdef WINNT |
425 /* on NT, get rid of the PRLock used for fibers within a process */ | 429 /* on NT, get rid of the PRLock used for fibers within a process */ |
426 retvalue = sslMutex_2LevelDestroy(pMutex); | 430 retvalue = sslMutex_2LevelDestroy(pMutex); |
427 #endif | 431 #endif |
428 | 432 |
429 PR_ASSERT( pMutex->u.sslMutx != 0 && | 433 PR_ASSERT( pMutex->u.sslMutx != 0 && |
430 pMutex->u.sslMutx != INVALID_HANDLE_VALUE); | 434 pMutex->u.sslMutx != INVALID_HANDLE_VALUE); |
431 if (!pMutex || (hMutex = pMutex->u.sslMutx) == 0 | 435 if (!pMutex || (hMutex = pMutex->u.sslMutx) == 0 |
432 || hMutex == INVALID_HANDLE_VALUE) { | 436 || hMutex == INVALID_HANDLE_VALUE) { |
433 PORT_SetError(PR_INVALID_ARGUMENT_ERROR); | 437 PORT_SetError(PR_INVALID_ARGUMENT_ERROR); |
434 return SECFailure; | 438 return SECFailure; |
435 } | 439 } |
436 | 440 |
437 rv = CloseHandle(hMutex); /* ignore error */ | 441 rv = CloseHandle(hMutex); /* ignore error */ |
438 if (rv) { | 442 if (!processLocal && rv) { |
439 pMutex->u.sslMutx = hMutex = INVALID_HANDLE_VALUE; | 443 pMutex->u.sslMutx = hMutex = INVALID_HANDLE_VALUE; |
440 } else { | 444 } |
| 445 if (!rv) { |
441 nss_MD_win32_map_default_error(GetLastError()); | 446 nss_MD_win32_map_default_error(GetLastError()); |
442 retvalue = SECFailure; | 447 retvalue = SECFailure; |
443 } | 448 } |
444 return retvalue; | 449 return retvalue; |
445 } | 450 } |
446 | 451 |
447 int | 452 int |
448 sslMutex_Unlock(sslMutex *pMutex) | 453 sslMutex_Unlock(sslMutex *pMutex) |
449 { | 454 { |
450 BOOL success = FALSE; | 455 BOOL success = FALSE; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 rv = sem_init(&pMutex->u.sem, shared, 1); | 555 rv = sem_init(&pMutex->u.sem, shared, 1); |
551 } while (rv < 0 && errno == EINTR); | 556 } while (rv < 0 && errno == EINTR); |
552 if (rv < 0) { | 557 if (rv < 0) { |
553 nss_MD_unix_map_default_error(errno); | 558 nss_MD_unix_map_default_error(errno); |
554 return SECFailure; | 559 return SECFailure; |
555 } | 560 } |
556 return SECSuccess; | 561 return SECSuccess; |
557 } | 562 } |
558 | 563 |
559 SECStatus | 564 SECStatus |
560 sslMutex_Destroy(sslMutex *pMutex) | 565 sslMutex_Destroy(sslMutex *pMutex, PRBool processLocal) |
561 { | 566 { |
562 int rv; | 567 int rv; |
563 if (PR_FALSE == pMutex->isMultiProcess) { | 568 if (PR_FALSE == pMutex->isMultiProcess) { |
564 return single_process_sslMutex_Destroy(pMutex); | 569 return single_process_sslMutex_Destroy(pMutex); |
565 } | 570 } |
| 571 |
| 572 /* semaphores are global resources. See SEM_DESTROY(3) man page */ |
| 573 if (processLocal) { |
| 574 return SECSuccess; |
| 575 } |
566 do { | 576 do { |
567 rv = sem_destroy(&pMutex->u.sem); | 577 rv = sem_destroy(&pMutex->u.sem); |
568 } while (rv < 0 && errno == EINTR); | 578 } while (rv < 0 && errno == EINTR); |
569 if (rv < 0) { | 579 if (rv < 0) { |
570 nss_MD_unix_map_default_error(errno); | 580 nss_MD_unix_map_default_error(errno); |
571 return SECFailure; | 581 return SECFailure; |
572 } | 582 } |
573 return SECSuccess; | 583 return SECSuccess; |
574 } | 584 } |
575 | 585 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 pMutex->isMultiProcess = (PRBool)(shared != 0); | 626 pMutex->isMultiProcess = (PRBool)(shared != 0); |
617 if (!shared) { | 627 if (!shared) { |
618 return single_process_sslMutex_Init(pMutex); | 628 return single_process_sslMutex_Init(pMutex); |
619 } | 629 } |
620 PORT_Assert(!("sslMutex_Init not implemented for multi-process applications
!")); | 630 PORT_Assert(!("sslMutex_Init not implemented for multi-process applications
!")); |
621 PORT_SetError(PR_NOT_IMPLEMENTED_ERROR); | 631 PORT_SetError(PR_NOT_IMPLEMENTED_ERROR); |
622 return SECFailure; | 632 return SECFailure; |
623 } | 633 } |
624 | 634 |
625 SECStatus | 635 SECStatus |
626 sslMutex_Destroy(sslMutex *pMutex) | 636 sslMutex_Destroy(sslMutex *pMutex, PRBool processLocal) |
627 { | 637 { |
628 PR_ASSERT(pMutex); | 638 PR_ASSERT(pMutex); |
629 if (PR_FALSE == pMutex->isMultiProcess) { | 639 if (PR_FALSE == pMutex->isMultiProcess) { |
630 return single_process_sslMutex_Destroy(pMutex); | 640 return single_process_sslMutex_Destroy(pMutex); |
631 } | 641 } |
632 PORT_Assert(!("sslMutex_Destroy not implemented for multi-process applicatio
ns !")); | 642 PORT_Assert(!("sslMutex_Destroy not implemented for multi-process applicatio
ns !")); |
633 PORT_SetError(PR_NOT_IMPLEMENTED_ERROR); | 643 PORT_SetError(PR_NOT_IMPLEMENTED_ERROR); |
634 return SECFailure; | 644 return SECFailure; |
635 } | 645 } |
636 | 646 |
(...skipping 17 matching lines...) Expand all Loading... |
654 return single_process_sslMutex_Lock(pMutex); | 664 return single_process_sslMutex_Lock(pMutex); |
655 } | 665 } |
656 PORT_Assert(!("sslMutex_Lock not implemented for multi-process applications
!")); | 666 PORT_Assert(!("sslMutex_Lock not implemented for multi-process applications
!")); |
657 PORT_SetError(PR_NOT_IMPLEMENTED_ERROR); | 667 PORT_SetError(PR_NOT_IMPLEMENTED_ERROR); |
658 return SECFailure; | 668 return SECFailure; |
659 } | 669 } |
660 | 670 |
661 #endif | 671 #endif |
662 | 672 |
663 #endif | 673 #endif |
OLD | NEW |