- Timestamp:
- Nov 6, 2023 2:54:34 PM (16 months ago)
- svn:sync-xref-src-repo-rev:
- 159970
- Location:
- trunk/src/libs/xpcom18a4
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/Makefile.kmk
r101870 r101874 487 487 nsprpub/pr/src/io/prlayer.c \ 488 488 nsprpub/pr/src/io/prlog.c \ 489 nsprpub/pr/src/io/prmmap.c \490 489 nsprpub/pr/src/io/prpolevt.c \ 491 490 nsprpub/pr/src/io/prprf.c \ -
trunk/src/libs/xpcom18a4/nsprpub/pr/include/md/_unixos.h
r101870 r101874 467 467 468 468 extern int _MD_unix_get_nonblocking_connect_error(int osfd); 469 470 /* Memory-mapped files */471 472 struct _MDFileMap {473 PRIntn prot;474 PRIntn flags;475 PRBool isAnonFM; /* when true, PR_CloseFileMap() must close the related fd */476 };477 478 extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);479 #define _MD_CREATE_FILE_MAP _MD_CreateFileMap480 481 #define _MD_GET_MEM_MAP_ALIGNMENT() PR_GetPageSize()482 483 extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,484 PRUint32 len);485 #define _MD_MEM_MAP _MD_MemMap486 487 extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);488 #define _MD_MEM_UNMAP _MD_MemUnmap489 490 extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);491 #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap492 469 493 470 /* -
trunk/src/libs/xpcom18a4/nsprpub/pr/include/prio.h
r101872 r101874 111 111 #define PR_GetPeerName VBoxNsprPR_GetPeerName 112 112 #define PR_GetSocketOption VBoxNsprPR_GetSocketOption 113 #define PR_CreateFileMap VBoxNsprPR_CreateFileMap114 #define PR_GetMemMapAlignment VBoxNsprPR_GetMemMapAlignment115 #define PR_MemMap VBoxNsprPR_MemMap116 #define PR_MemUnmap VBoxNsprPR_MemUnmap117 #define PR_CloseFileMap VBoxNsprPR_CloseFileMap118 113 #define PR_CreatePipe VBoxNsprPR_CreatePipe 119 114 #endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */ … … 1531 1526 1532 1527 /* 1533 *********************************************************************1534 *1535 * Memory-mapped files1536 *1537 *********************************************************************1538 */1539 1540 typedef struct PRFileMap PRFileMap;1541 1542 /*1543 * protection options for read and write accesses of a file mapping1544 */1545 typedef enum PRFileMapProtect {1546 PR_PROT_READONLY, /* read only */1547 PR_PROT_READWRITE, /* readable, and write is shared */1548 PR_PROT_WRITECOPY /* readable, and write is private (copy-on-write) */1549 } PRFileMapProtect;1550 1551 NSPR_API(PRFileMap *) PR_CreateFileMap(1552 PRFileDesc *fd,1553 PRInt64 size,1554 PRFileMapProtect prot);1555 1556 /*1557 * return the alignment (in bytes) of the offset argument to PR_MemMap1558 */1559 NSPR_API(PRInt32) PR_GetMemMapAlignment(void);1560 1561 NSPR_API(void *) PR_MemMap(1562 PRFileMap *fmap,1563 PROffset64 offset, /* must be aligned and sized according to the1564 * return value of PR_GetMemMapAlignment() */1565 PRUint32 len);1566 1567 NSPR_API(PRStatus) PR_MemUnmap(void *addr, PRUint32 len);1568 1569 NSPR_API(PRStatus) PR_CloseFileMap(PRFileMap *fmap);1570 1571 /*1572 1528 ****************************************************************** 1573 1529 * -
trunk/src/libs/xpcom18a4/nsprpub/pr/include/private/primpl.h
r101870 r101874 466 466 }; 467 467 468 struct PRFileMap {469 PRFileDesc *fd;470 PRFileMapProtect prot;471 _MDFileMap md;472 };473 474 468 /************************************************************************/ 475 469 … … 676 670 #define _PR_MD_UNLOCKFILE _MD_UNLOCKFILE 677 671 678 /* Memory-mapped files */679 680 extern PRStatus _PR_MD_CREATE_FILE_MAP(PRFileMap *fmap, PRInt64 size);681 #define _PR_MD_CREATE_FILE_MAP _MD_CREATE_FILE_MAP682 683 extern PRInt32 _PR_MD_GET_MEM_MAP_ALIGNMENT(void);684 #define _PR_MD_GET_MEM_MAP_ALIGNMENT _MD_GET_MEM_MAP_ALIGNMENT685 686 extern void * _PR_MD_MEM_MAP(687 PRFileMap *fmap,688 PROffset64 offset,689 PRUint32 len);690 #define _PR_MD_MEM_MAP _MD_MEM_MAP691 692 extern PRStatus _PR_MD_MEM_UNMAP(void *addr, PRUint32 size);693 #define _PR_MD_MEM_UNMAP _MD_MEM_UNMAP694 695 extern PRStatus _PR_MD_CLOSE_FILE_MAP(PRFileMap *fmap);696 #define _PR_MD_CLOSE_FILE_MAP _MD_CLOSE_FILE_MAP697 698 699 672 /* Interprocess communications (IPC) */ 700 673 -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/md/unix/unix.c
r101839 r101874 748 748 } 749 749 750 #if defined(HAVE_FCNTL_FILE_LOCKING)751 752 PR_IMPLEMENT(PRStatus)753 _MD_LockFile(PRInt32 f)754 {755 PRInt32 rv;756 struct flock arg;757 758 arg.l_type = F_WRLCK;759 arg.l_whence = SEEK_SET;760 arg.l_start = 0;761 arg.l_len = 0; /* until EOF */762 rv = fcntl(f, F_SETLKW, &arg);763 if (rv == 0)764 return PR_SUCCESS;765 _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());766 return PR_FAILURE;767 }768 769 PR_IMPLEMENT(PRStatus)770 _MD_TLockFile(PRInt32 f)771 {772 PRInt32 rv;773 struct flock arg;774 775 arg.l_type = F_WRLCK;776 arg.l_whence = SEEK_SET;777 arg.l_start = 0;778 arg.l_len = 0; /* until EOF */779 rv = fcntl(f, F_SETLK, &arg);780 if (rv == 0)781 return PR_SUCCESS;782 _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());783 return PR_FAILURE;784 }785 786 PR_IMPLEMENT(PRStatus)787 _MD_UnlockFile(PRInt32 f)788 {789 PRInt32 rv;790 struct flock arg;791 792 arg.l_type = F_UNLCK;793 arg.l_whence = SEEK_SET;794 arg.l_start = 0;795 arg.l_len = 0; /* until EOF */796 rv = fcntl(f, F_SETLK, &arg);797 if (rv == 0)798 return PR_SUCCESS;799 _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());800 return PR_FAILURE;801 }802 803 #elif defined(HAVE_BSD_FLOCK)804 805 #include <sys/file.h>806 807 PR_IMPLEMENT(PRStatus)808 _MD_LockFile(PRInt32 f)809 {810 PRInt32 rv;811 rv = flock(f, LOCK_EX);812 if (rv == 0)813 return PR_SUCCESS;814 _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());815 return PR_FAILURE;816 }817 818 PR_IMPLEMENT(PRStatus)819 _MD_TLockFile(PRInt32 f)820 {821 PRInt32 rv;822 rv = flock(f, LOCK_EX|LOCK_NB);823 if (rv == 0)824 return PR_SUCCESS;825 _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());826 return PR_FAILURE;827 }828 829 PR_IMPLEMENT(PRStatus)830 _MD_UnlockFile(PRInt32 f)831 {832 PRInt32 rv;833 rv = flock(f, LOCK_UN);834 if (rv == 0)835 return PR_SUCCESS;836 _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());837 return PR_FAILURE;838 }839 #else840 841 PR_IMPLEMENT(PRStatus)842 _MD_LockFile(PRInt32 f)843 {844 PRInt32 rv;845 rv = lockf(f, F_LOCK, 0);846 if (rv == 0)847 return PR_SUCCESS;848 _PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());849 return PR_FAILURE;850 }851 852 PR_IMPLEMENT(PRStatus)853 _MD_TLockFile(PRInt32 f)854 {855 PRInt32 rv;856 rv = lockf(f, F_TLOCK, 0);857 if (rv == 0)858 return PR_SUCCESS;859 _PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());860 return PR_FAILURE;861 }862 863 PR_IMPLEMENT(PRStatus)864 _MD_UnlockFile(PRInt32 f)865 {866 PRInt32 rv;867 rv = lockf(f, F_ULOCK, 0);868 if (rv == 0)869 return PR_SUCCESS;870 _PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());871 return PR_FAILURE;872 }873 #endif874 875 750 PR_IMPLEMENT(PRStatus) _MD_gethostname(char *name, PRUint32 namelen) 876 751 { … … 883 758 _PR_MD_MAP_GETHOSTNAME_ERROR(_MD_ERRNO()); 884 759 return PR_FAILURE; 885 }886 887 /*888 *******************************************************************889 *890 * Memory-mapped files891 *892 *******************************************************************893 */894 895 PRStatus _MD_CreateFileMap(PRFileMap *fmap, PRInt64 size)896 {897 PRFileInfo info;898 PRUint32 sz;899 900 LL_L2UI(sz, size);901 if (sz) {902 if (PR_GetOpenFileInfo(fmap->fd, &info) == PR_FAILURE) {903 return PR_FAILURE;904 }905 if (sz > info.size) {906 /*907 * Need to extend the file908 */909 if (fmap->prot != PR_PROT_READWRITE) {910 PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, 0);911 return PR_FAILURE;912 }913 if (PR_Seek(fmap->fd, sz - 1, PR_SEEK_SET) == -1) {914 return PR_FAILURE;915 }916 if (PR_Write(fmap->fd, "", 1) != 1) {917 return PR_FAILURE;918 }919 }920 }921 if (fmap->prot == PR_PROT_READONLY) {922 fmap->md.prot = PROT_READ;923 #ifdef OSF1V4_MAP_PRIVATE_BUG924 /*925 * Use MAP_SHARED to work around a bug in OSF1 V4.0D926 * (QAR 70220 in the OSF_QAR database) that results in927 * corrupted data in the memory-mapped region. This928 * bug is fixed in V5.0.929 */930 fmap->md.flags = MAP_SHARED;931 #else932 fmap->md.flags = MAP_PRIVATE;933 #endif934 } else if (fmap->prot == PR_PROT_READWRITE) {935 fmap->md.prot = PROT_READ | PROT_WRITE;936 fmap->md.flags = MAP_SHARED;937 } else {938 PR_ASSERT(fmap->prot == PR_PROT_WRITECOPY);939 fmap->md.prot = PROT_READ | PROT_WRITE;940 fmap->md.flags = MAP_PRIVATE;941 }942 return PR_SUCCESS;943 }944 945 void * _MD_MemMap(946 PRFileMap *fmap,947 PRInt64 offset,948 PRUint32 len)949 {950 PRInt32 off;951 void *addr;952 953 LL_L2I(off, offset);954 if ((addr = mmap(0, len, fmap->md.prot, fmap->md.flags,955 fmap->fd->secret->md.osfd, off)) == (void *) -1) {956 _PR_MD_MAP_MMAP_ERROR(_MD_ERRNO());957 addr = NULL;958 }959 return addr;960 }961 962 PRStatus _MD_MemUnmap(void *addr, PRUint32 len)963 {964 if (munmap(addr, len) == 0) {965 return PR_SUCCESS;966 } else {967 if (errno == EINVAL) {968 PR_SetError(PR_INVALID_ARGUMENT_ERROR, errno);969 } else {970 PR_SetError(PR_UNKNOWN_ERROR, errno);971 }972 return PR_FAILURE;973 }974 }975 976 PRStatus _MD_CloseFileMap(PRFileMap *fmap)977 {978 if ( PR_TRUE == fmap->md.isAnonFM ) {979 PRStatus rc = PR_Close( fmap->fd );980 if ( PR_FAILURE == rc ) {981 PR_LOG( _pr_io_lm, PR_LOG_DEBUG,982 ("_MD_CloseFileMap(): error closing anonymnous file map osfd"));983 return PR_FAILURE;984 }985 }986 PR_DELETE(fmap);987 return PR_SUCCESS;988 760 } 989 761
Note:
See TracChangeset
for help on using the changeset viewer.