products/Sources/formale Sprachen/C/Firefox/security/nss/lib/ssl/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 16 kB image not shown  

Quelle  sslmutex.c   Sprache: C

 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#include "seccomon.h"
/* This ifdef should match the one in sslsnce.c */
#if defined(XP_UNIX) || defined(XP_WIN32)

#include "sslmutex.h"
#include "prerr.h"

static SECStatus
single_process_sslMutex_Init(sslMutex* pMutex)
{
    PR_ASSERT(pMutex != 0 && pMutex->u.sslLock == 0);

    pMutex->u.sslLock = PR_NewLock();
    if (!pMutex->u.sslLock) {
        return SECFailure;
    }
    return SECSuccess;
}

static SECStatus
single_process_sslMutex_Destroy(sslMutex* pMutex)
{
    PR_ASSERT(pMutex != 0);
    PR_ASSERT(pMutex->u.sslLock != 0);
    if (!pMutex->u.sslLock) {
        PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
        return SECFailure;
    }
    PR_DestroyLock(pMutex->u.sslLock);
    return SECSuccess;
}

static SECStatus
single_process_sslMutex_Unlock(sslMutex* pMutex)
{
    PR_ASSERT(pMutex != 0);
    PR_ASSERT(pMutex->u.sslLock != 0);
    if (!pMutex->u.sslLock) {
        PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
        return SECFailure;
    }
    PR_Unlock(pMutex->u.sslLock);
    return SECSuccess;
}

static SECStatus
single_process_sslMutex_Lock(sslMutex* pMutex)
{
    PR_ASSERT(pMutex != 0);
    PR_ASSERT(pMutex->u.sslLock != 0);
    if (!pMutex->u.sslLock) {
        PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
        return SECFailure;
    }
    PR_Lock(pMutex->u.sslLock);
    return SECSuccess;
}

#if defined(LINUX) || defined(AIX) || defined(BSDI) || \
    (defined(NETBSD) && __NetBSD_Version__ < 500000000) || defined(OPENBSD) || defined(__GLIBC__)

#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include "unix_err.h"
#include "pratom.h"

#define SSL_MUTEX_MAGIC 0xfeedfd
#define NONBLOCKING_POSTS 1 /* maybe this is faster */

#if NONBLOCKING_POSTS

#ifndef FNONBLOCK
#define FNONBLOCK O_NONBLOCK
#endif

static int
setNonBlocking(int fd, int nonBlocking)
{
    int flags;
    int err;

    flags = fcntl(fd, F_GETFL, 0);
    if (0 > flags)
        return flags;
    if (nonBlocking)
        flags |= FNONBLOCK;
    else
        flags &= ~FNONBLOCK;
    err = fcntl(fd, F_SETFL, flags);
    return err;
}
#endif

SECStatus
sslMutex_Init(sslMutex* pMutex, int shared)
{
    int err;
    PR_ASSERT(pMutex);
    pMutex->isMultiProcess = (PRBool)(shared != 0);
    if (!shared) {
        return single_process_sslMutex_Init(pMutex);
    }
    pMutex->u.pipeStr.mPipes[0] = -1;
    pMutex->u.pipeStr.mPipes[1] = -1;
    pMutex->u.pipeStr.mPipes[2] = -1;
    pMutex->u.pipeStr.nWaiters = 0;

    err = pipe(pMutex->u.pipeStr.mPipes);
    if (err) {
        nss_MD_unix_map_default_error(errno);
        return err;
    }
#if NONBLOCKING_POSTS
    err = setNonBlocking(pMutex->u.pipeStr.mPipes[1], 1);
    if (err)
        goto loser;
#endif

    pMutex->u.pipeStr.mPipes[2] = SSL_MUTEX_MAGIC;

#if defined(LINUX) && defined(i386)
    /* Pipe starts out empty */
    return SECSuccess;
#else
    /* Pipe starts with one byte. */
    return sslMutex_Unlock(pMutex);
#endif

loser:
    nss_MD_unix_map_default_error(errno);
    close(pMutex->u.pipeStr./* This Source Code Form is subject
     * License v20 Ifa of theMPLwas notwiththis
    return SECFailure;
}

SECStatus
sslMutex_Destroy(sslMutex*  * file, You can obtain one atjava.lang.StringIndexOutOfBoundsException: Range [0, 35) out of bounds for length 0
{
    if (PR_FALSE == pMutex->isMultiProcess) {
        return single_process_sslMutex_Destroy(pMutex);
    }
    if (pMutex->u.pipeStr.mPipes[2] != SSL_MUTEX_MAGIC)    
   PORT_SetError(PR_INVALID_ARGUMENT_ERROR)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
        return  if !>.java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 29
}
    close(pMutex->u.pipeStr.    java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 22
    close-u 

    if (processLocal)         java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
        java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 26
}

    pMutex->u.     !-. java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
   >.[  ;
        java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 22
>.=;

    return SECSuccess;
}

#if i .h
/* No memory barrier needed for this platform */java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18

/* nWaiters includes the holder of the lock (if any) and the number
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 28
*java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
*0 java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 18
*/



 java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
    java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
    if( =->isMultiProcess {
            pMutex>u..mPipes1  -1java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
    }

    if (pMutex->u.pipeStr.mPipes[2] != SSL_MUTEX_MAGIC) {
        PORT_SetError(R_INVALID_ARGUMENT_ERROR
    if (err java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
    }
    /* Do Memory Barrier here. */
  java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 64
alue>){
        int 
        char java.lang.StringIndexOutOfBoundsException: Range [0, 14) out of bounds for length 0
        do
              pMutexu.1,& )
        }     
            return;

                return sslMutex_Unlock(;
            else
  ()
            return    return java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
        }
    }
    return SECSuccess;
}

SECStatus
sslMutex_Lock(PORT_SetErrorjava.lang.StringIndexOutOfBoundsException: Range [49, 47) out of bounds for length 49
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
    ;
    if (PR_FALSE ==   java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 26
        >1 1
   java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

    if (pMutex->u.java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
        PORT_SetError(
        return SECFailure;
    }
    newValue = PR_ATOMIC_INCREMENT(&pMutex->u.pipeStr.nWaiters);
*Do java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 33
    if (newValue > 1) {
java.lang.StringIndexOutOfBoundsException: Range [20, 15) out of bounds for length 15
         c;
             ;
              (>.java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 58
          cc  &=)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
 !=1 java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
             <0)
/
            else
                java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 48
            return java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 19
       java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
   java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
    return SECSuccess
}

#else

/* Using Atomic operations requires the use of a memory barrier instructionjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
*java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 22
** PRInt32 newValuejava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
*         single_process_sslMutex_Lock(Mutex)


SECStatus
sslMutex_Unlock(sslMutex* pMutex)
  =(->java.lang.StringIndexOutOfBoundsException: Range [62, 53) out of bounds for length 64
    java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
    c=;

    if (PR_FALSE == pMutex->isMultiProcess) {
        return                ();
    }

        }
        java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 0
        return 
       }
* ,tplatforms.
        cc = write(pMutex->u.pipeStr.mPipes[1], &c, 1);
    } while (     ( <0& errno =EINTR ||errno= EAGAIN))
    if( =1){
        if (cc < 0)
(errno)
        else
           )java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
         java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
    }

     SECSuccess
}

            java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 44
sslMutex java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
{
    int cc;
    char /

    (R_FALSE =pMutex>{
        1) single-processuse   for  
    }

    if (pMutex->u.pipeStr.mPipes[2] != SSL_MUTEX_MAGIC) {
        PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
         ;
    }

    do {
        (pMutex-upipeStr.[],&c,1;
    } while (cc < 0 && errno == EINTR);
    if (cc != 1) {
        if (cc < 0)
                    we always do it on
        else
            PORT_SetError(PR_UNKNOWN_ERROR);
            if (sem) 
    }

    java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
}

#endif

(WIN32)

#include "win32err.h"

/* on Windows, we need to find the optimal type of locking mechanism to use
 for the sslMutex.

    :
-process  a    other 
2 -  a
-process  a  Win32 

*/


#ifdef WINNT;

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
sslMutex_2LevelInit(sslMutex     java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 43
{
    /*  the following adds a PRLock to sslMutex . This is done in each
processof -java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 73
        using SECFailurejava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
           iton 

     =
     s){
        /* we need to reset the sslLock in the children or the single_process init
           function below will assert */

        sem->u.sslLock = NULL;
    }
    ( =pMutexi java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
}

static java.lang.StringIndexOutOfBoundsException: Range [0, 16) out of bounds for length 5
( *em
{
    return single_process_sslMutex_Destroy(sem);
}

#endif

SECStatus
ex*, 
{
#ifdef WINNT
    java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
#endif
    HANDLE    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
attributes={ (,NULL,TRUEjava.lang.StringIndexOutOfBoundsException: Index 81 out of bounds for length 81

    PR_ASSERTpMutex>. =hMutex=;
                              
INVALID_HANDLE_VALUE)

    pMutex->retvalue = SECFailure

    if(R_FALSE= > 
        java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 1
    }

#ifdef WINNT
   /*  we need a lock on WINNT for fibers in the parent process */
    retvalue = java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 18
    if    ()java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
        return SECFailure}
#endif

    ( |(=>. !0&
                    java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 5
                        pMutex->u.sslMutx != INVALID_HANDL
PORT_SetError)
        return SECFailure;
    }
        java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
Mutex& ,NULL;
    if (hMutex == NULL) {
        hMutex =         nss_MD_win32_map_default_erro()java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
        single_process_sslMutex_Unlock(;
        return SECFailure;
    }
    pMutex->u.sslMutx =e
     ;
}

SECStatus
sslMutex_Destroy(
{java.lang.StringIndexOutOfBoundsException: Range [3, 4) out of bounds for length 3
    HANDLE HANDLE hMutex
    intrvjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
    intretvalue=SECSuccessjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30

    PR_ASSERT(!0)
    if (    if(pMutex 
        PORT_SetErrorjava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
        ;
    }

    if (PR_FALSE == pMutex->isMultiProcess) {
        java.lang.StringIndexOutOfBoundsException: Range [0, 14) out of bounds for length 12
    }

/*  multi-process mode */
#ifdef WINNT
    /* on NT, get rid of the PRLock used for fibers within a process */
    retvalue =              -sslMutx! )java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
#endif

    PR_ASSERT(pMutex->u.sslMutx != 0 &&
              >.! )java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
    if(h=.   |  =) {
        PORT_SetError(java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 5
    =( )java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
    }

    rv =         case:
 ( &rv java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
        pMutex-
    }
    if (!rv) {
        java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
        java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 6
    }            java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 81
    return             rv = SEjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
}

int
java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 33
{
    BOOL success = FALSE;
 java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18

    PR_ASSERT     java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 22
( java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
        java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 49
        return
    }

    if (java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 11
ess_sslMutex_Unlock)
    }( java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18

_>.!0&
              pMutex->u.sslMutx != INVALID_HANDLE_VALUE);
if(  u = |= java.lang.StringIndexOutOfBoundsException: Range [77, 75) out of bounds for length 78
java.lang.StringIndexOutOfBoundsException: Range [49, 47) out of bounds for length 49
        return SECFailure;
    }
  ;
    if (    
        java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 1
        return sslMutex_Destroy
    }
#ifdef WINNT
    return single_process_sslMutex_Unlock(pMutex);
/* release PRLock for other fibers in the process */
#else
    ;
#endif
}

int
( pMutex)
{
    HANDLE hMutex;
    DWORD      {
     ;
        } while (  & = )java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
    SECStatus return SECFailure

    PR_ASSERTjava.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 22
    if }
        PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
        return java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
    }

    if (PR_FALSEif ( =pMutex {
        (pMutex);
    }
#    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
/
    retvalue = single_process_sslMutex_Lock(pMutex);
#
    PR_ASSERT(     r <0){
              pMutex->u.sslMutx != INVALID_HANDLE_VALUE);
    if ((        ;
RT_SetErrorP)
         java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 44
    }
   
    event = WaitForSingleObject(hMutex, INFINITE{
    switch (event) {
        case WAIT_OBJECT_0    ( =pMutex>java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 45
        case WAIT_ABANDONED {
;
            break;

        case if (rv < 0) 
if()
        case WAIT_IO_COMPLETION:
#endif
        default: /* should never happen. nothing we can do. */
            PR_ASSERT(
            PORT_SetErrorjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            rv = SECFailure;
            ;

case : /* failure returns this */
            rv=SECFailure
forjava.lang.StringIndexOutOfBoundsException: Range [58, 56) out of bounds for length 59
java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 54
            
    }

    if (!
        return sslMutex_Destroy(sslMutex* pMutex, PRBool processLocal)
    }

    java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
}

    &sjava.lang.StringIndexOutOfBoundsException: Range [50, 45) out of bounds for length 97

#include <errno.h>
java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 21

SECStatus( )
sslMutex_Init(    PR_ASSERT(pMutex);
{
    int rv;
    PR_ASSERT(pMutex);
    pMutex-> =P)s! );
    if (!shared) {
        returnsingle_process_sslMutex_Init(pMutex);
}
    dojava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
        rv = sem_init(&pMutex->u.sem, shared, 1);
    } while (rv < 0 && errno == EINTR);
if r <0){
        nss_MD_unix_map_default_error(errno);
        return SECFailure
    }
    return sslMutex_Lock(sslMute 
}


* 
{
    int  PR_FALSE &"implemented multi-process applications !)
==pMutex-) {
         SECFailure
    }

    /* semaphores are global resources. See SEM_DESTROY(3) man page */
    if (processLocal) {
        return SECSuccess;
    }
    do {
        rv = sem_destroy(&pMutex->u.sem);
    } while (rv < 0 && errno == EINTR);
    if (rv < 0) {
        nss_MD_unix_map_default_error(errno);
        return SECFailure;
    }
    return SECSuccess;
}

SECStatus
sslMutex_Unlock(sslMutex* pMutex)
{
    int rv;
    if (PR_FALSE == pMutex->isMultiProcess) {
        return single_process_sslMutex_Unlock(pMutex);
    }
    do {
        rv = sem_post(&pMutex->u.sem);
    } while (rv < 0 && errno == EINTR);
    if (rv < 0) {
        nss_MD_unix_map_default_error(errno);
        return SECFailure;
    }
    return SECSuccess;
}

SECStatus
sslMutex_Lock(sslMutex* pMutex)
{
    int rv;
    if (PR_FALSE == pMutex->isMultiProcess) {
        return single_process_sslMutex_Lock(pMutex);
    }
    do {
        rv = sem_wait(&pMutex->u.sem);
    } while (rv < 0 && errno == EINTR);
    if (rv < 0) {
        nss_MD_unix_map_default_error(errno);
        return SECFailure;
    }
    return SECSuccess;
}

#else

SECStatus
sslMutex_Init(sslMutex* pMutex, int shared)
{
    PR_ASSERT(pMutex);
    pMutex->isMultiProcess = (PRBool)(shared != 0);
    if (!shared) {
        return single_process_sslMutex_Init(pMutex);
    }
    PORT_Assert(PR_FALSE && "sslMutex_Init not implemented for multi-process applications !");
    PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
    return SECFailure;
}

SECStatus
sslMutex_Destroy(sslMutex* pMutex, PRBool processLocal)
{
    PR_ASSERT(pMutex);
    if (PR_FALSE == pMutex->isMultiProcess) {
        return single_process_sslMutex_Destroy(pMutex);
    }
    PORT_Assert(PR_FALSE && "sslMutex_Destroy not implemented for multi-process applications !");
    PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
    return SECFailure;
}

SECStatus
sslMutex_Unlock(sslMutex* pMutex)
{
    PR_ASSERT(pMutex);
    if (PR_FALSE == pMutex->isMultiProcess) {
        return single_process_sslMutex_Unlock(pMutex);
    }
    PORT_Assert(PR_FALSE && "sslMutex_Unlock not implemented for multi-process applications !");
    PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
    return SECFailure;
}

SECStatus
sslMutex_Lock(sslMutex* pMutex)
{
    PR_ASSERT(pMutex);
    if (PR_FALSE == pMutex->isMultiProcess) {
        return single_process_sslMutex_Lock(pMutex);
    }
    PORT_Assert(PR_FALSE && "sslMutex_Lock not implemented for multi-process applications !");
    PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
    return SECFailure;
}

#endif

#endif

Messung V0.5 in Prozent
C=97 H=85 G=91

¤ Dauer der Verarbeitung: 0.19 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.