security/nss/lib/ssl/sslmutex.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 #ifndef __SSLMUTEX_H_
michael@0 5 #define __SSLMUTEX_H_ 1
michael@0 6
michael@0 7 /* What SSL really wants is portable process-shared unnamed mutexes in
michael@0 8 * shared memory, that have the property that if the process that holds
michael@0 9 * them dies, they are released automatically, and that (unlike fcntl
michael@0 10 * record locking) lock to the thread, not to the process.
michael@0 11 * NSPR doesn't provide that.
michael@0 12 * Windows has mutexes that meet that description, but they're not portable.
michael@0 13 * POSIX mutexes are not automatically released when the holder dies,
michael@0 14 * and other processes/threads cannot release the mutex on behalf of the
michael@0 15 * dead holder.
michael@0 16 * POSIX semaphores can be used to accomplish this on systems that implement
michael@0 17 * process-shared unnamed POSIX semaphores, because a watchdog thread can
michael@0 18 * discover and release semaphores that were held by a dead process.
michael@0 19 * On systems that do not support process-shared POSIX unnamed semaphores,
michael@0 20 * they can be emulated using pipes.
michael@0 21 * The performance cost of doing that is not yet measured.
michael@0 22 *
michael@0 23 * So, this API looks a lot like POSIX pthread mutexes.
michael@0 24 */
michael@0 25
michael@0 26 #include "prtypes.h"
michael@0 27 #include "prlock.h"
michael@0 28
michael@0 29 #if defined(NETBSD)
michael@0 30 #include <sys/param.h> /* for __NetBSD_Version__ */
michael@0 31 #endif
michael@0 32
michael@0 33 #if defined(WIN32)
michael@0 34
michael@0 35 #include <wtypes.h>
michael@0 36
michael@0 37 typedef struct
michael@0 38 {
michael@0 39 PRBool isMultiProcess;
michael@0 40 #ifdef WINNT
michael@0 41 /* on WINNT we need both the PRLock and the Win32 mutex for fibers */
michael@0 42 struct {
michael@0 43 #else
michael@0 44 union {
michael@0 45 #endif
michael@0 46 PRLock* sslLock;
michael@0 47 HANDLE sslMutx;
michael@0 48 } u;
michael@0 49 } sslMutex;
michael@0 50
michael@0 51 typedef int sslPID;
michael@0 52
michael@0 53 #elif defined(LINUX) || defined(AIX) || defined(BEOS) || defined(BSDI) || (defined(NETBSD) && __NetBSD_Version__ < 500000000) || defined(OPENBSD)
michael@0 54
michael@0 55 #include <sys/types.h>
michael@0 56 #include "prtypes.h"
michael@0 57
michael@0 58 typedef struct {
michael@0 59 PRBool isMultiProcess;
michael@0 60 union {
michael@0 61 PRLock* sslLock;
michael@0 62 struct {
michael@0 63 int mPipes[3];
michael@0 64 PRInt32 nWaiters;
michael@0 65 } pipeStr;
michael@0 66 } u;
michael@0 67 } sslMutex;
michael@0 68 typedef pid_t sslPID;
michael@0 69
michael@0 70 #elif defined(XP_UNIX) /* other types of Unix */
michael@0 71
michael@0 72 #include <sys/types.h> /* for pid_t */
michael@0 73 #include <semaphore.h> /* for sem_t, and sem_* functions */
michael@0 74
michael@0 75 typedef struct
michael@0 76 {
michael@0 77 PRBool isMultiProcess;
michael@0 78 union {
michael@0 79 PRLock* sslLock;
michael@0 80 sem_t sem;
michael@0 81 } u;
michael@0 82 } sslMutex;
michael@0 83
michael@0 84 typedef pid_t sslPID;
michael@0 85
michael@0 86 #else
michael@0 87
michael@0 88 /* what platform is this ?? */
michael@0 89
michael@0 90 typedef struct {
michael@0 91 PRBool isMultiProcess;
michael@0 92 union {
michael@0 93 PRLock* sslLock;
michael@0 94 /* include cross-process locking mechanism here */
michael@0 95 } u;
michael@0 96 } sslMutex;
michael@0 97
michael@0 98 typedef int sslPID;
michael@0 99
michael@0 100 #endif
michael@0 101
michael@0 102 #include "seccomon.h"
michael@0 103
michael@0 104 SEC_BEGIN_PROTOS
michael@0 105
michael@0 106 extern SECStatus sslMutex_Init(sslMutex *sem, int shared);
michael@0 107
michael@0 108 /* If processLocal is set to true, then just free resources which are *only* associated
michael@0 109 * with the current process. Leave any shared resources (including the state of
michael@0 110 * shared memory) intact. */
michael@0 111 extern SECStatus sslMutex_Destroy(sslMutex *sem, PRBool processLocal);
michael@0 112
michael@0 113 extern SECStatus sslMutex_Unlock(sslMutex *sem);
michael@0 114
michael@0 115 extern SECStatus sslMutex_Lock(sslMutex *sem);
michael@0 116
michael@0 117 #ifdef WINNT
michael@0 118
michael@0 119 extern SECStatus sslMutex_2LevelInit(sslMutex *sem);
michael@0 120
michael@0 121 #endif
michael@0 122
michael@0 123 SEC_END_PROTOS
michael@0 124
michael@0 125 #endif

mercurial