22 #include "../../include/ecl/ipc/shared_memory_pos.hpp" 24 #ifdef ECL_HAS_POSIX_SHARED_MEMORY 39 void SharedMemoryBase::unlink() {
40 shm_unlink(name.c_str());
43 int SharedMemoryBase::open() {
57 static const int open_flags = O_RDWR;
58 static const int create_flags = O_CREAT|O_RDWR|O_EXCL;
78 static const int permissions = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH;
90 int shm_descriptor = shm_open(name.c_str(),create_flags,permissions);
91 if ( ( shm_descriptor == -1 ) && ( errno == EEXIST ) ) {
93 shm_descriptor = shm_open(name.c_str(),open_flags,permissions);
95 shared_memory_manager =
true;
97 if ( shm_descriptor == -1) {
99 return shm_descriptor;
107 #ifndef ECL_DISABLE_EXCEPTIONS 110 int error_result = errno;
111 switch (error_result) {
113 throw StandardException(LOC,
PermissionsError,
"Opening shared memory failed - permission denied.");
120 case ( EMFILE ) :
case ( ENFILE ) : {
121 throw StandardException(LOC,
OutOfResourcesError,
"Opening shared memory failed - too many file connections already open.");
124 case ( ENOENT ) :
case ( ENAMETOOLONG ) :
case ( EINVAL ) : {
125 throw StandardException(LOC,
InvalidArgError,
"Opening shared memory failed - pathname problem.");
129 throw StandardException(LOC,
NotSupportedError,
"Opening shared memory failed - kernel system functions are not available (remake the kernel).");
134 std::ostringstream ostream;
135 ostream <<
"Posix error " << error_result <<
": " << strerror(error_result) <<
".";
136 return StandardException(loc,
UnknownError, ostream.str());
142 int error_result = errno;
143 switch (error_result) {
145 return StandardException(LOC,
PermissionsError,
"Shared mapping failed - permission problems (see man mmap).");
148 return StandardException(LOC,
MemoryError,
"Shared mapping failed - file locked or too much memory has been locked.");
151 return StandardException(LOC,
InvalidArgError,
"Shared mapping failed - not a valid file descriptor (see man mmap).");
154 return StandardException(LOC,
InvalidArgError,
"Shared mapping failed - start, length or offset were invalid or MAP_PRIVLOCE and MAP_SHARED were either both present or both obso (see man mmap).");
157 return StandardException(LOC,
OutOfResourcesError,
"Shared mapping failed - system limit on the total number of open files has been reached (see man mmap).");
160 return StandardException(LOC,
NotSupportedError,
"Shared mapping failed - underlying filesystem of the specified file doesn't support memory mapping (see man mmap).");
163 return StandardException(LOC,
MemoryError,
"Shared mapping failed - no mem available, or max mappings exceeded (see man mmap).");
166 return StandardException(LOC,
PermissionsError,
"Shared mapping failed - EPERM (see man mmap).");
174 std::ostringstream ostream;
175 ostream <<
"Posix error " << error_result <<
": " << strerror(error_result) <<
".";
176 return StandardException(loc,
UnknownError, ostream.str());
Embedded control libraries.