Changeset 101841 in vbox
- Timestamp:
- Nov 5, 2023 5:53:04 PM (15 months ago)
- Location:
- trunk/src/libs/xpcom18a4
- Files:
-
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/Makefile.kmk
r101839 r101841 192 192 nsprpub/pr/include/prproces.h \ 193 193 nsprpub/pr/include/prshm.h \ 194 nsprpub/pr/include/prshma.h \195 194 nsprpub/pr/include/prsystem.h \ 196 195 nsprpub/pr/include/prthread.h \ … … 509 508 nsprpub/pr/src/md/prosdep.c \ 510 509 nsprpub/pr/src/memory/prshm.c \ 511 nsprpub/pr/src/memory/prshma.c \512 510 nsprpub/pr/src/misc/pratom.c \ 513 511 nsprpub/pr/src/misc/prdtoa.c \ -
trunk/src/libs/xpcom18a4/nsprpub/pr/include/nspr.h
r101794 r101841 61 61 #include "prproces.h" 62 62 #include "prshm.h" 63 #include "prshma.h"64 63 #include "prsystem.h" 65 64 #include "prthread.h" -
trunk/src/libs/xpcom18a4/nsprpub/pr/include/private/primpl.h
r101839 r101841 746 746 #define _PR_MD_DELETE_SHARED_MEMORY _MD_DeleteSharedMemory 747 747 748 extern PRFileMap* _md_OpenAnonFileMap(749 const char *dirName,750 PRSize size,751 PRFileMapProtect prot752 );753 #define _PR_MD_OPEN_ANON_FILE_MAP _md_OpenAnonFileMap754 755 extern PRStatus _md_ExportFileMapAsString(756 PRFileMap *fm,757 PRSize bufSize,758 char *buf759 );760 #define _PR_MD_EXPORT_FILE_MAP_AS_STRING _md_ExportFileMapAsString761 762 extern PRFileMap * _md_ImportFileMapFromString(763 const char *fmstring764 );765 #define _PR_MD_IMPORT_FILE_MAP_FROM_STRING _md_ImportFileMapFromString766 767 748 768 749 -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/md/unix/uxshm.c
r1 r101841 482 482 #endif 483 483 484 485 486 /*487 ** Unix implementation for anonymous memory (file) mapping488 */489 extern PRLogModuleInfo *_pr_shma_lm;490 491 #include <unistd.h>492 493 extern PRFileMap* _md_OpenAnonFileMap(494 const char *dirName,495 PRSize size,496 PRFileMapProtect prot497 )498 {499 PRFileMap *fm = NULL;500 PRFileDesc *fd;501 int osfd;502 PRIntn urc;503 PRIntn mode = 0600;504 char *genName;505 pid_t pid = getpid(); /* for generating filename */506 PRThread *tid = PR_GetCurrentThread(); /* for generating filename */507 int incr; /* for generating filename */508 const int maxTries = 20; /* maximum # attempts at a unique filename */509 PRInt64 size64; /* 64-bit version of 'size' */510 511 /*512 ** generate a filename from input and runtime environment513 ** open the file, unlink the file.514 ** make maxTries number of attempts at uniqueness in the filename515 */516 for ( incr = 0; incr < maxTries ; incr++ ) {517 genName = PR_smprintf( "%s/.NSPR-AFM-%d-%p.%d",518 dirName, (int) pid, tid, incr );519 if ( NULL == genName ) {520 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,521 ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating filename"));522 goto Finished;523 }524 525 /* create the file */526 osfd = open( genName, (O_CREAT | O_EXCL | O_RDWR), mode );527 if ( -1 == osfd ) {528 if ( EEXIST == errno ) {529 PR_smprintf_free( genName );530 continue; /* name exists, try again */531 } else {532 _PR_MD_MAP_OPEN_ERROR( errno );533 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,534 ("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d",535 genName, PR_GetOSError()));536 PR_smprintf_free( genName );537 goto Finished;538 }539 }540 break; /* name generation and open successful, break; */541 } /* end for() */542 543 if ( incr == maxTries ) {544 PR_ASSERT( -1 == osfd );545 PR_ASSERT( EEXIST == errno );546 _PR_MD_MAP_OPEN_ERROR( errno );547 goto Finished;548 }549 550 urc = unlink( genName );551 if ( -1 == urc ) {552 _PR_MD_MAP_UNLINK_ERROR( errno );553 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,554 ("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", errno));555 PR_smprintf_free( genName );556 close( osfd );557 goto Finished;558 }559 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,560 ("_md_OpenAnonFileMap(): unlink(): %s", genName ));561 562 PR_smprintf_free( genName );563 564 fd = PR_ImportFile( osfd );565 if ( NULL == fd ) {566 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,567 ("_md_OpenAnonFileMap(): PR_ImportFile(): failed"));568 goto Finished;569 }570 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,571 ("_md_OpenAnonFileMap(): fd: %p", fd ));572 573 urc = ftruncate( fd->secret->md.osfd, size );574 if ( -1 == urc ) {575 _PR_MD_MAP_DEFAULT_ERROR( errno );576 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,577 ("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", errno));578 PR_Close( fd );579 goto Finished;580 }581 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,582 ("_md_OpenAnonFileMap(): ftruncate(): size: %d", size ));583 584 LL_UI2L(size64, size); /* PRSize (size_t) is unsigned */585 fm = PR_CreateFileMap( fd, size64, prot );586 if ( NULL == fm ) {587 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,588 ("PR_OpenAnonFileMap(): failed"));589 PR_Close( fd );590 goto Finished;591 }592 fm->md.isAnonFM = PR_TRUE; /* set fd close */593 594 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,595 ("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm ));596 597 Finished:598 return(fm);599 } /* end md_OpenAnonFileMap() */600 601 /*602 ** _md_ExportFileMapAsString()603 **604 **605 */606 extern PRStatus _md_ExportFileMapAsString(607 PRFileMap *fm,608 PRSize bufSize,609 char *buf610 )611 {612 PRIntn written;613 PRIntn prot = (PRIntn)fm->prot;614 615 written = PR_snprintf( buf, bufSize, "%ld:%d",616 fm->fd->secret->md.osfd, prot );617 618 return((written == -1)? PR_FAILURE : PR_SUCCESS);619 } /* end _md_ExportFileMapAsString() */620 621 622 extern PRFileMap * _md_ImportFileMapFromString(623 const char *fmstring624 )625 {626 PRStatus rc;627 PRInt32 osfd;628 PRIntn prot; /* really: a PRFileMapProtect */629 PRFileDesc *fd;630 PRFileMap *fm = NULL; /* default return value */631 PRFileInfo64 info;632 633 PR_sscanf( fmstring, "%ld:%d", &osfd, &prot );634 635 /* import the os file descriptor */636 fd = PR_ImportFile( osfd );637 if ( NULL == fd ) {638 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,639 ("_md_ImportFileMapFromString(): PR_ImportFile() failed"));640 goto Finished;641 }642 643 rc = PR_GetOpenFileInfo64( fd, &info );644 if ( PR_FAILURE == rc ) {645 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,646 ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed"));647 goto Finished;648 }649 650 fm = PR_CreateFileMap( fd, info.size, (PRFileMapProtect)prot );651 if ( NULL == fm ) {652 PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,653 ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed"));654 }655 656 Finished:657 return(fm);658 } /* end _md_ImportFileMapFromString() */
Note:
See TracChangeset
for help on using the changeset viewer.