From 87de70a2984cece87db94f4b445589c4e24e5c77 Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Wed, 15 Mar 2017 14:31:00 -0400 Subject: posix/mman: add mmap support for shm objects Update #2859. --- cpukit/posix/include/rtems/posix/mmanimpl.h | 7 ++++++- cpukit/posix/include/rtems/posix/shm.h | 30 +++++++++++++++++++++++++++++ cpukit/posix/include/rtems/posix/shmimpl.h | 30 +++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) (limited to 'cpukit/posix/include') diff --git a/cpukit/posix/include/rtems/posix/mmanimpl.h b/cpukit/posix/include/rtems/posix/mmanimpl.h index 9743685a57..bb33ac97ed 100644 --- a/cpukit/posix/include/rtems/posix/mmanimpl.h +++ b/cpukit/posix/include/rtems/posix/mmanimpl.h @@ -16,12 +16,15 @@ #ifndef _RTEMS_POSIX_MMANIMPL_H #define _RTEMS_POSIX_MMANIMPL_H -#include +#include +#include /* FIXME: use score chains for proper layering? */ #ifdef __cplusplus extern "C" { #endif +/* FIXME: add Doxygen */ + /** * Every mmap'ed region has a mapping. */ @@ -30,6 +33,8 @@ typedef struct mmap_mappings_s { void* addr; /**< The address of the mapped memory */ size_t len; /**< The length of memory mapped */ int flags; /**< The mapping flags */ + rtems_libio_t *iop; /**< The mapped object's file descriptor pointer */ + bool is_shared_shm; /**< True if MAP_SHARED of shared memory */ } mmap_mapping; extern rtems_chain_control mmap_mappings; diff --git a/cpukit/posix/include/rtems/posix/shm.h b/cpukit/posix/include/rtems/posix/shm.h index dfdd58ed2a..9284b398cf 100644 --- a/cpukit/posix/include/rtems/posix/shm.h +++ b/cpukit/posix/include/rtems/posix/shm.h @@ -91,6 +91,16 @@ struct POSIX_Shm_Object_operations { * Returns the number of bytes read (copied) into @a buf. */ int ( *object_read ) ( POSIX_Shm_Object *shm_obj, void *buf, size_t count ); + + /** + * @brief Maps a shared memory object. + * + * Establishes a memory mapping between the shared memory object and the + * caller. + * + * Returns the mapped address of the object. + */ + void * ( *object_mmap ) ( POSIX_Shm_Object *shm_obj, size_t len, int prot, off_t off); }; /** @@ -143,6 +153,16 @@ extern int _POSIX_Shm_Object_read_from_workspace( size_t count ); +/** + * @brief object_mmap operation for shm objects stored in RTEMS Workspace. + */ +extern void * _POSIX_Shm_Object_mmap_from_workspace( + POSIX_Shm_Object *shm_obj, + size_t len, + int prot, + off_t off +); + /** * @brief object_create operation for shm objects stored in C program heap. */ @@ -173,6 +193,16 @@ extern int _POSIX_Shm_Object_read_from_heap( size_t count ); +/** + * @brief object_mmap operation for shm objects stored in C program heap. + */ +extern void * _POSIX_Shm_Object_mmap_from_heap( + POSIX_Shm_Object *shm_obj, + size_t len, + int prot, + off_t off +); + /** @} */ #ifdef __cplusplus diff --git a/cpukit/posix/include/rtems/posix/shmimpl.h b/cpukit/posix/include/rtems/posix/shmimpl.h index 6d81e5eb27..f16af8123d 100644 --- a/cpukit/posix/include/rtems/posix/shmimpl.h +++ b/cpukit/posix/include/rtems/posix/shmimpl.h @@ -96,6 +96,36 @@ static inline POSIX_Shm_Control* loc_to_shm( return (POSIX_Shm_Control*) loc->node_access; } +static inline int POSIX_Shm_Attempt_delete( + POSIX_Shm_Control* shm +) +{ + Objects_Control *obj; + ISR_lock_Context lock_ctx; + int err; + + err = 0; + + _Objects_Allocator_lock(); + --shm->reference_count; + if ( shm->reference_count == 0 ) { + if ( (*shm->shm_object.ops->object_delete)( &shm->shm_object ) != 0 ) { + err = EIO; + } + } + /* check if the object has been unlinked yet. */ + obj = _Objects_Get( shm->Object.id, &lock_ctx, &_POSIX_Shm_Information ); + if ( obj == NULL ) { + /* if it was unlinked, then it can be freed. */ + _POSIX_Shm_Free( shm ); + } else { + /* it will be freed when it is unlinked. */ + _ISR_lock_ISR_enable( &lock_ctx ); + } + _Objects_Allocator_unlock(); + return err; +} + /** @} */ #ifdef __cplusplus -- cgit v1.2.3