Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
uxshm.c File Reference
#include <string.h>
#include <prshm.h>
#include <prerr.h>
#include <prmem.h>
#include "primpl.h"
#include <fcntl.h>
#include <unistd.h>

Go to the source code of this file.

Defines

#define NSPR_IPC_SHM_KEY   'b'

Functions

PRFileMap_md_OpenAnonFileMap (const char *dirName, PRSize size, PRFileMapProtect prot)
PRStatus _md_ExportFileMapAsString (PRFileMap *fm, PRSize bufSize, char *buf)
PRFileMap_md_ImportFileMapFromString (const char *fmstring)

Variables

PRLogModuleInfo_pr_shm_lm
PRLogModuleInfo_pr_shma_lm

Define Documentation

Definition at line 55 of file uxshm.c.


Function Documentation

PRStatus _md_ExportFileMapAsString ( PRFileMap fm,
PRSize  bufSize,
char *  buf 
)

Definition at line 606 of file uxshm.c.

{
    PRIntn  written;
    PRIntn  prot = (PRIntn)fm->prot;
    
    written = PR_snprintf( buf, bufSize, "%ld:%d",
        fm->fd->secret->md.osfd, prot );
        
    return((written == -1)? PR_FAILURE : PR_SUCCESS);
} /* end _md_ExportFileMapAsString() */

Here is the call graph for this function:

Definition at line 622 of file uxshm.c.

{
    PRStatus    rc;
    PRInt32     osfd;
    PRIntn      prot; /* really: a PRFileMapProtect */
    PRFileDesc  *fd;
    PRFileMap   *fm = NULL; /* default return value */
    PRFileInfo64 info;

    PR_sscanf( fmstring, "%ld:%d", &osfd, &prot );

    /* import the os file descriptor */
    fd = PR_ImportFile( osfd );
    if ( NULL == fd ) {
        PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
            ("_md_ImportFileMapFromString(): PR_ImportFile() failed"));
        goto Finished;
    }

    rc = PR_GetOpenFileInfo64( fd, &info );
    if ( PR_FAILURE == rc )  {
        PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
            ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed"));    
        goto Finished;
    }

    fm = PR_CreateFileMap( fd, info.size, (PRFileMapProtect)prot );
    if ( NULL == fm ) {
        PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
            ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed"));    
    }

Finished:
    return(fm);
} /* end _md_ImportFileMapFromString() */

Here is the call graph for this function:

PRFileMap* _md_OpenAnonFileMap ( const char *  dirName,
PRSize  size,
PRFileMapProtect  prot 
)

Definition at line 493 of file uxshm.c.

{
    PRFileMap   *fm = NULL;
    PRFileDesc  *fd;
    int         osfd;
    PRIntn      urc;
    PRIntn      mode = 0600;
    char        *genName;
    pid_t       pid = getpid(); /* for generating filename */
    PRThread    *tid = PR_GetCurrentThread(); /* for generating filename */
    int         incr; /* for generating filename */
    const int   maxTries = 20; /* maximum # attempts at a unique filename */
    PRInt64     size64; /* 64-bit version of 'size' */

    /*
    ** generate a filename from input and runtime environment
    ** open the file, unlink the file.
    ** make maxTries number of attempts at uniqueness in the filename
    */
    for ( incr = 0; incr < maxTries ; incr++ ) {
        genName = PR_smprintf( "%s/.NSPR-AFM-%d-%p.%d", 
            dirName, (int) pid, tid, incr );
        if ( NULL == genName ) {
            PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
                ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating filename"));
            goto Finished;
        }
        
        /* create the file */
        osfd = open( genName, (O_CREAT | O_EXCL | O_RDWR), mode );
        if ( -1 == osfd ) {
            if ( EEXIST == errno )  {
                PR_smprintf_free( genName );
                continue; /* name exists, try again */
            } else {
                _PR_MD_MAP_OPEN_ERROR( errno );
                PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
                    ("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d", 
                        genName, PR_GetOSError()));
                PR_smprintf_free( genName );
                goto Finished;
            }
        }
        break; /* name generation and open successful, break; */
    } /* end for() */

    if ( incr == maxTries ) {
        PR_ASSERT( -1 == osfd );
        PR_ASSERT( EEXIST == errno );
        _PR_MD_MAP_OPEN_ERROR( errno );
        goto Finished;
    }

    urc = unlink( genName );
    if ( -1 == urc ) {
        _PR_MD_MAP_UNLINK_ERROR( errno );
        PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
            ("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", errno));
        PR_smprintf_free( genName );
        close( osfd );
        goto Finished;        
    }
    PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
        ("_md_OpenAnonFileMap(): unlink(): %s", genName ));

    PR_smprintf_free( genName );

    fd = PR_ImportFile( osfd );
    if ( NULL == fd ) {
        PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
            ("_md_OpenAnonFileMap(): PR_ImportFile(): failed"));
        goto Finished;        
    }
    PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
        ("_md_OpenAnonFileMap(): fd: %p", fd ));

    urc = ftruncate( fd->secret->md.osfd, size );
    if ( -1 == urc ) {
        _PR_MD_MAP_DEFAULT_ERROR( errno );
        PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
            ("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", errno));
        PR_Close( fd );
        goto Finished;        
    }
    PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
        ("_md_OpenAnonFileMap(): ftruncate(): size: %d", size ));

    LL_UI2L(size64, size);  /* PRSize (size_t) is unsigned */
    fm = PR_CreateFileMap( fd, size64, prot );
    if ( NULL == fm )  {
        PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
            ("PR_OpenAnonFileMap(): failed"));
        PR_Close( fd );
        goto Finished;        
    }
    fm->md.isAnonFM = PR_TRUE; /* set fd close */

    PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
        ("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm ));

Finished:    
    return(fm);
} /* end md_OpenAnonFileMap() */

Here is the call graph for this function:


Variable Documentation

Definition at line 51 of file prinit.c.

Definition at line 52 of file prinit.c.