1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/ssl/sslmutex.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,125 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 +#ifndef __SSLMUTEX_H_ 1.8 +#define __SSLMUTEX_H_ 1 1.9 + 1.10 +/* What SSL really wants is portable process-shared unnamed mutexes in 1.11 + * shared memory, that have the property that if the process that holds 1.12 + * them dies, they are released automatically, and that (unlike fcntl 1.13 + * record locking) lock to the thread, not to the process. 1.14 + * NSPR doesn't provide that. 1.15 + * Windows has mutexes that meet that description, but they're not portable. 1.16 + * POSIX mutexes are not automatically released when the holder dies, 1.17 + * and other processes/threads cannot release the mutex on behalf of the 1.18 + * dead holder. 1.19 + * POSIX semaphores can be used to accomplish this on systems that implement 1.20 + * process-shared unnamed POSIX semaphores, because a watchdog thread can 1.21 + * discover and release semaphores that were held by a dead process. 1.22 + * On systems that do not support process-shared POSIX unnamed semaphores, 1.23 + * they can be emulated using pipes. 1.24 + * The performance cost of doing that is not yet measured. 1.25 + * 1.26 + * So, this API looks a lot like POSIX pthread mutexes. 1.27 + */ 1.28 + 1.29 +#include "prtypes.h" 1.30 +#include "prlock.h" 1.31 + 1.32 +#if defined(NETBSD) 1.33 +#include <sys/param.h> /* for __NetBSD_Version__ */ 1.34 +#endif 1.35 + 1.36 +#if defined(WIN32) 1.37 + 1.38 +#include <wtypes.h> 1.39 + 1.40 +typedef struct 1.41 +{ 1.42 + PRBool isMultiProcess; 1.43 +#ifdef WINNT 1.44 + /* on WINNT we need both the PRLock and the Win32 mutex for fibers */ 1.45 + struct { 1.46 +#else 1.47 + union { 1.48 +#endif 1.49 + PRLock* sslLock; 1.50 + HANDLE sslMutx; 1.51 + } u; 1.52 +} sslMutex; 1.53 + 1.54 +typedef int sslPID; 1.55 + 1.56 +#elif defined(LINUX) || defined(AIX) || defined(BEOS) || defined(BSDI) || (defined(NETBSD) && __NetBSD_Version__ < 500000000) || defined(OPENBSD) 1.57 + 1.58 +#include <sys/types.h> 1.59 +#include "prtypes.h" 1.60 + 1.61 +typedef struct { 1.62 + PRBool isMultiProcess; 1.63 + union { 1.64 + PRLock* sslLock; 1.65 + struct { 1.66 + int mPipes[3]; 1.67 + PRInt32 nWaiters; 1.68 + } pipeStr; 1.69 + } u; 1.70 +} sslMutex; 1.71 +typedef pid_t sslPID; 1.72 + 1.73 +#elif defined(XP_UNIX) /* other types of Unix */ 1.74 + 1.75 +#include <sys/types.h> /* for pid_t */ 1.76 +#include <semaphore.h> /* for sem_t, and sem_* functions */ 1.77 + 1.78 +typedef struct 1.79 +{ 1.80 + PRBool isMultiProcess; 1.81 + union { 1.82 + PRLock* sslLock; 1.83 + sem_t sem; 1.84 + } u; 1.85 +} sslMutex; 1.86 + 1.87 +typedef pid_t sslPID; 1.88 + 1.89 +#else 1.90 + 1.91 +/* what platform is this ?? */ 1.92 + 1.93 +typedef struct { 1.94 + PRBool isMultiProcess; 1.95 + union { 1.96 + PRLock* sslLock; 1.97 + /* include cross-process locking mechanism here */ 1.98 + } u; 1.99 +} sslMutex; 1.100 + 1.101 +typedef int sslPID; 1.102 + 1.103 +#endif 1.104 + 1.105 +#include "seccomon.h" 1.106 + 1.107 +SEC_BEGIN_PROTOS 1.108 + 1.109 +extern SECStatus sslMutex_Init(sslMutex *sem, int shared); 1.110 + 1.111 +/* If processLocal is set to true, then just free resources which are *only* associated 1.112 + * with the current process. Leave any shared resources (including the state of 1.113 + * shared memory) intact. */ 1.114 +extern SECStatus sslMutex_Destroy(sslMutex *sem, PRBool processLocal); 1.115 + 1.116 +extern SECStatus sslMutex_Unlock(sslMutex *sem); 1.117 + 1.118 +extern SECStatus sslMutex_Lock(sslMutex *sem); 1.119 + 1.120 +#ifdef WINNT 1.121 + 1.122 +extern SECStatus sslMutex_2LevelInit(sslMutex *sem); 1.123 + 1.124 +#endif 1.125 + 1.126 +SEC_END_PROTOS 1.127 + 1.128 +#endif