diff options
Diffstat (limited to 'nsprpub/pr/src/md/windows/w32shm.c')
-rw-r--r-- | nsprpub/pr/src/md/windows/w32shm.c | 139 |
1 files changed, 70 insertions, 69 deletions
diff --git a/nsprpub/pr/src/md/windows/w32shm.c b/nsprpub/pr/src/md/windows/w32shm.c index 8e8b1d684..b0d38b9d7 100644 --- a/nsprpub/pr/src/md/windows/w32shm.c +++ b/nsprpub/pr/src/md/windows/w32shm.c @@ -3,7 +3,7 @@ * 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 <private/primpl.h> +#include <private/primpl.h> #include <string.h> #include <prshm.h> #include <prerr.h> @@ -23,15 +23,15 @@ extern PRLogModuleInfo *_pr_shm_lm; */ static DWORD filemapAccessTable[] = { FILE_MAP_ALL_ACCESS & ~FILE_MAP_WRITE, /* read */ - FILE_MAP_ALL_ACCESS & ~FILE_MAP_READ, /* write */ + FILE_MAP_ALL_ACCESS & ~FILE_MAP_READ, /* write */ 0 /* execute */ }; -extern PRSharedMemory * _MD_OpenSharedMemory( - const char *name, - PRSize size, - PRIntn flags, - PRIntn mode +extern PRSharedMemory * _MD_OpenSharedMemory( + const char *name, + PRSize size, + PRIntn flags, + PRIntn mode ) { char ipcname[PR_IPC_NAME_SIZE]; @@ -48,15 +48,15 @@ extern PRSharedMemory * _MD_OpenSharedMemory( if ( PR_FAILURE == rc ) { PR_SetError(PR_UNKNOWN_ERROR, 0 ); - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: name is invalid")); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: name is invalid")); return(NULL); } shm = PR_NEWZAP( PRSharedMemory ); - if ( NULL == shm ) + if ( NULL == shm ) { PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 ); - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory")); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory")); return(NULL); } @@ -64,14 +64,14 @@ extern PRSharedMemory * _MD_OpenSharedMemory( if ( NULL == shm->ipcname ) { PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 ); - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory")); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory")); PR_DELETE(shm); return(NULL); } /* copy args to struct */ strcpy( shm->ipcname, ipcname ); - shm->size = size; + shm->size = size; shm->mode = mode; shm->flags = flags; shm->ident = _PR_SHM_IDENT; @@ -81,7 +81,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory( dwLo = (DWORD) (shm->size & 0xffffffff); if (_PR_NT_MakeSecurityDescriptorACL(mode, filemapAccessTable, - &pSD, &pACL) == PR_SUCCESS) { + &pSD, &pACL) == PR_SUCCESS) { sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = pSD; sa.bInheritHandle = FALSE; @@ -97,48 +97,48 @@ extern PRSharedMemory * _MD_OpenSharedMemory( MultiByteToWideChar(CP_ACP, 0, shm->ipcname, -1, wideIpcName, MAX_PATH); shm->handle = CreateFileMappingW( - (HANDLE)-1 , - lpSA, - flProtect, - dwHi, - dwLo, - wideIpcName); + (HANDLE)-1, + lpSA, + flProtect, + dwHi, + dwLo, + wideIpcName); } #else shm->handle = CreateFileMappingA( - (HANDLE)-1 , - lpSA, - flProtect, - dwHi, - dwLo, - shm->ipcname); + (HANDLE)-1, + lpSA, + flProtect, + dwHi, + dwLo, + shm->ipcname); #endif if (lpSA != NULL) { _PR_NT_FreeSecurityDescriptorACL(pSD, pACL); } if ( NULL == shm->handle ) { - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, - ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s", - shm->ipcname )); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, + ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s", + shm->ipcname )); _PR_MD_MAP_DEFAULT_ERROR( GetLastError()); PR_FREEIF( shm->ipcname ) PR_DELETE( shm ); return(NULL); } else { if (( flags & PR_SHM_EXCL) && ( GetLastError() == ERROR_ALREADY_EXISTS )) { - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, - ( "PR_OpenSharedMemory: Request exclusive & already exists", - shm->ipcname )); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, + ( "PR_OpenSharedMemory: Request exclusive & already exists", + shm->ipcname )); PR_SetError( PR_FILE_EXISTS_ERROR, ERROR_ALREADY_EXISTS ); CloseHandle( shm->handle ); PR_FREEIF( shm->ipcname ) PR_DELETE( shm ); return(NULL); } else { - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, - ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d", - shm->ipcname, shm->handle )); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, + ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d", + shm->ipcname, shm->handle )); return(shm); } } @@ -151,17 +151,17 @@ extern PRSharedMemory * _MD_OpenSharedMemory( #endif if ( NULL == shm->handle ) { _PR_MD_MAP_DEFAULT_ERROR( GetLastError()); - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, - ( "PR_OpenSharedMemory: OpenFileMapping() failed: %s, error: %d", - shm->ipcname, PR_GetOSError())); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, + ( "PR_OpenSharedMemory: OpenFileMapping() failed: %s, error: %d", + shm->ipcname, PR_GetOSError())); PR_FREEIF( shm->ipcname ); PR_DELETE( shm ); return(NULL); } else { - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, - ( "PR_OpenSharedMemory: OpenFileMapping() success: %s, handle: %d", - shm->ipcname, shm->handle )); - return(shm); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, + ( "PR_OpenSharedMemory: OpenFileMapping() success: %s, handle: %d", + shm->ipcname, shm->handle )); + return(shm); } } /* returns from separate paths */ @@ -174,18 +174,19 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags ) PR_ASSERT( shm->ident == _PR_SHM_IDENT ); - if ( PR_SHM_READONLY & flags ) + if ( PR_SHM_READONLY & flags ) { access = FILE_MAP_READ; + } addr = MapViewOfFile( shm->handle, - access, - 0, 0, - shm->size ); + access, + 0, 0, + shm->size ); if ( NULL == addr ) { _PR_MD_MAP_DEFAULT_ERROR( GetLastError()); - PR_LOG( _pr_shm_lm, PR_LOG_ERROR, - ("_MD_AttachSharedMemory: MapViewOfFile() failed. OSerror: %d", PR_GetOSError())); + PR_LOG( _pr_shm_lm, PR_LOG_ERROR, + ("_MD_AttachSharedMemory: MapViewOfFile() failed. OSerror: %d", PR_GetOSError())); } return( addr ); @@ -200,11 +201,11 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr ) PR_ASSERT( shm->ident == _PR_SHM_IDENT ); wrc = UnmapViewOfFile( addr ); - if ( FALSE == wrc ) + if ( FALSE == wrc ) { _PR_MD_MAP_DEFAULT_ERROR( GetLastError()); - PR_LOG( _pr_shm_lm, PR_LOG_ERROR, - ("_MD_DetachSharedMemory: UnmapViewOfFile() failed. OSerror: %d", PR_GetOSError())); + PR_LOG( _pr_shm_lm, PR_LOG_ERROR, + ("_MD_DetachSharedMemory: UnmapViewOfFile() failed. OSerror: %d", PR_GetOSError())); rc = PR_FAILURE; } @@ -223,8 +224,8 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm ) if ( FALSE == wrc ) { _PR_MD_MAP_DEFAULT_ERROR( GetLastError()); - PR_LOG( _pr_shm_lm, PR_LOG_ERROR, - ("_MD_CloseSharedMemory: CloseHandle() failed. OSerror: %d", PR_GetOSError())); + PR_LOG( _pr_shm_lm, PR_LOG_ERROR, + ("_MD_CloseSharedMemory: CloseHandle() failed. OSerror: %d", PR_GetOSError())); rc = PR_FAILURE; } PR_FREEIF( shm->ipcname ); @@ -236,7 +237,7 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm ) extern PRStatus _MD_DeleteSharedMemory( const char *name ) { return( PR_SUCCESS ); -} +} /* @@ -244,7 +245,7 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name ) */ extern PRLogModuleInfo *_pr_shma_lm; -extern PRFileMap* _md_OpenAnonFileMap( +extern PRFileMap* _md_OpenAnonFileMap( const char *dirName, PRSize size, PRFileMapProtect prot @@ -256,7 +257,7 @@ extern PRFileMap* _md_OpenAnonFileMap( fm = PR_CreateFileMap( (PRFileDesc*)-1, size, prot ); if ( NULL == fm ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): PR_CreateFileMap(): failed")); + ("_md_OpenAnonFileMap(): PR_CreateFileMap(): failed")); goto Finished; } @@ -267,12 +268,12 @@ extern PRFileMap* _md_OpenAnonFileMap( ** ERROR_CALL_NOT_IMPLEMENTED on Win95. */ if (DuplicateHandle(GetCurrentProcess(), fm->md.hFileMap, - GetCurrentProcess(), &hFileMap, - 0, TRUE /* inheritable */, - DUPLICATE_SAME_ACCESS) == FALSE) { + GetCurrentProcess(), &hFileMap, + 0, TRUE /* inheritable */, + DUPLICATE_SAME_ACCESS) == FALSE) { PR_SetError( PR_UNKNOWN_ERROR, GetLastError() ); PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): DuplicateHandle(): failed")); + ("_md_OpenAnonFileMap(): DuplicateHandle(): failed")); PR_CloseFileMap( fm ); fm = NULL; goto Finished; @@ -280,7 +281,7 @@ extern PRFileMap* _md_OpenAnonFileMap( CloseHandle(fm->md.hFileMap); fm->md.hFileMap = hFileMap; -Finished: +Finished: return(fm); } /* end md_OpenAnonFileMap() */ @@ -297,12 +298,12 @@ extern PRStatus _md_ExportFileMapAsString( PRIntn written; written = PR_snprintf( buf, (PRUint32) bufSize, "%d:%" PR_PRIdOSFD ":%ld", - (PRIntn)fm->prot, (PROsfd)fm->md.hFileMap, (PRInt32)fm->md.dwAccess ); + (PRIntn)fm->prot, (PROsfd)fm->md.hFileMap, (PRInt32)fm->md.dwAccess ); PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_ExportFileMapAsString(): prot: %x, hFileMap: %x, dwAccess: %x", - fm->prot, fm->md.hFileMap, fm->md.dwAccess )); - + ("_md_ExportFileMapAsString(): prot: %x, hFileMap: %x, dwAccess: %x", + fm->prot, fm->md.hFileMap, fm->md.dwAccess )); + return((written == -1)? PR_FAILURE : PR_SUCCESS); } /* end _md_ExportFileMapAsString() */ @@ -321,12 +322,12 @@ extern PRFileMap * _md_ImportFileMapFromString( PRFileMap *fm = NULL; PR_sscanf( fmstring, "%d:%" PR_SCNdOSFD ":%ld", - &prot, &hFileMap, &dwAccess ); + &prot, &hFileMap, &dwAccess ); fm = PR_NEWZAP(PRFileMap); if ( NULL == fm ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_ImportFileMapFromString(): PR_NEWZAP(): Failed")); + ("_md_ImportFileMapFromString(): PR_NEWZAP(): Failed")); return(fm); } @@ -336,12 +337,12 @@ extern PRFileMap * _md_ImportFileMapFromString( fm->fd = (PRFileDesc*)-1; PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_ImportFileMapFromString(): fm: %p, prot: %d, hFileMap: %8.8x, dwAccess: %8.8x, fd: %x", - fm, prot, fm->md.hFileMap, fm->md.dwAccess, fm->fd)); + ("_md_ImportFileMapFromString(): fm: %p, prot: %d, hFileMap: %8.8x, dwAccess: %8.8x, fd: %x", + fm, prot, fm->md.hFileMap, fm->md.dwAccess, fm->fd)); return(fm); } /* end _md_ImportFileMapFromString() */ #else -Error! Why is PR_HAVE_WIN32_NAMED_SHARED_MEMORY not defined? +Error! Why is PR_HAVE_WIN32_NAMED_SHARED_MEMORY not defined? #endif /* PR_HAVE_WIN32_NAMED_SHARED_MEMORY */ /* --- end w32shm.c --- */ |