1
1

Protection plus begining of shared memory on windows.

This commit was SVN r8464.
Этот коммит содержится в:
George Bosilca 2005-12-12 20:24:07 +00:00
родитель 7d8d516a4a
Коммит 94c109081b

Просмотреть файл

@ -21,14 +21,21 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif /* HAVE_FCNTL_H */
#ifdef HAVE_TIME_H
#include <time.h>
#endif /* HAVE_TIME_H */
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#include <sys/errno.h>
#endif /* HAVE_SYS_STAT_H */
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
@ -52,7 +59,7 @@ OBJ_CLASS_INSTANCE(
*/
mca_common_sm_mmap_t *mca_common_sm_mmap = NULL;
#if !defined(__WINDOWS__)
static int mca_common_sm_mmap_open(char* path)
{
int fd = -1;
@ -74,14 +81,14 @@ static int mca_common_sm_mmap_open(char* path)
}
return fd;
}
#endif /* !defined(__WINDOWS__) */
mca_common_sm_mmap_t* mca_common_sm_mmap_init(size_t size, char *file_name,
size_t size_ctl_structure, size_t data_seg_alignment)
{
int fd,return_code=OMPI_SUCCESS;
int fd, return_code = OMPI_SUCCESS;
bool file_previously_opened;
mca_common_sm_file_header_t* seg;
mca_common_sm_mmap_t* map;
@ -89,6 +96,7 @@ mca_common_sm_mmap_t* mca_common_sm_mmap_init(size_t size, char *file_name,
unsigned char *addr = NULL;
size_t tmp,mem_offset;
#if !defined(__WINDOWS__)
/* input parameter error checks */
if( (size < sizeof(mca_common_sm_file_header_t) ) ||
( file_name == NULL ) ||
@ -102,7 +110,7 @@ mca_common_sm_mmap_t* mca_common_sm_mmap_init(size_t size, char *file_name,
setup in this function is complete because the initial perms
are 000 (an fchmod() is executed below, enabling the other
processes to get in) */
fd=mca_common_sm_mmap_open(file_name);
fd = mca_common_sm_mmap_open(file_name);
if( -1 == fd ) {
opal_output(0, "mca_common_sm_mmap_init: mca_common_sm_mmap_open failed \n");
return NULL;
@ -140,6 +148,30 @@ mca_common_sm_mmap_t* mca_common_sm_mmap_init(size_t size, char *file_name,
close(fd);
return NULL;
}
#else
HANDLE hMapObject;
LPVOID lpvMem = NULL;
hMapObject = CreateFileMapping( INVALID_HANDLE_VALUE, /* use paging file */
NULL, /* no security attributes */
PAGE_READWRITE, /* read/write access */
0, /* size: high 32-bits */
size, /* size: low 32-bits */
file_name); /* name of map object */
if( NULL != hMapObject ) {
/* Get a pointer to the file-mapped shared memory. */
lpvMem = MapViewOfFile( hMapObject, /* object to map view of */
FILE_MAP_WRITE, /* read/write access */
0, /* high offset: map from */
0, /* low offset: beginning */
0); /* default: map entire file */
if( NULL == lpvMem ) {
CloseHandle(hMapObject);
}
}
if( NULL == lpvMem )
return NULL;
#endif /* !defined(__WINDOWS) */
/* set up the map object */
map = OBJ_NEW(mca_common_sm_mmap_t);