From c6bb1c33bcf70d1398073c96a4fac4f9b031b9ab Mon Sep 17 00:00:00 2001 From: Kevin Kirspel Date: Thu, 29 Jun 2017 10:36:43 -0400 Subject: posix/mmap: Add support for file handler and MAP_ANON Added a mmap file handler to struct _rtems_filesystem_file_handlers_r. Updated each file handler object to support the default mmap handler. Updated mmap() to call the mmap handler for MAP_SHARED. Added a mmap file handler for shm Added support for MAP_ANON in mmap(). Updates #2859 --- cpukit/posix/src/shmopen.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'cpukit/posix/src/shmopen.c') diff --git a/cpukit/posix/src/shmopen.c b/cpukit/posix/src/shmopen.c index fa1027e30c..e729f9bd4e 100644 --- a/cpukit/posix/src/shmopen.c +++ b/cpukit/posix/src/shmopen.c @@ -106,6 +106,35 @@ static int shm_close( rtems_libio_t *iop ) return 0; } +static int shm_mmap( + rtems_libio_t *iop, + void** addr, + size_t len, + int prot, + off_t off +) +{ + POSIX_Shm_Control *shm = iop_to_shm( iop ); + + _Objects_Allocator_lock(); + + *addr = (*shm->shm_object.ops->object_mmap)( &shm->shm_object, len, prot, off); + if ( *addr != NULL ) { + /* Keep a reference in the shared memory to prevent its removal. */ + ++shm->reference_count; + + /* Update atime */ + _POSIX_Shm_Update_atime(shm); + } else { + _Objects_Allocator_unlock(); + rtems_set_errno_and_return_minus_one( ENOMEM ); + } + + _Objects_Allocator_unlock(); + + return 0; +} + static inline POSIX_Shm_Control *shm_allocate( const char *name_arg, size_t name_len, @@ -275,6 +304,7 @@ static const rtems_filesystem_file_handlers_r shm_handlers = { .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync, .fcntl_h = rtems_filesystem_default_fcntl, .kqfilter_h = rtems_filesystem_default_kqfilter, + .mmap_h = shm_mmap, .poll_h = rtems_filesystem_default_poll, .readv_h = rtems_filesystem_default_readv, .writev_h = rtems_filesystem_default_writev -- cgit v1.2.3