[PATCH 2/5] posix: shared memory support

Gedare Bloom gedare at rtems.org
Wed Aug 24 15:51:27 UTC 2016


On Tue, Aug 23, 2016 at 9:49 PM, Chris Johns <chrisj at rtems.org> wrote:
> On 18/08/2016 6:02 AM, Gedare Bloom wrote:
>>
>> Add POSIX shared memory manager (Shm).
>> ---
>>  cpukit/posix/Makefile.am                      |   3 +
>>  cpukit/posix/include/rtems/posix/config.h     |   5 +
>>  cpukit/posix/include/rtems/posix/shm.h        |  61 ++++++++
>>  cpukit/posix/include/rtems/posix/shmimpl.h    |  90 ++++++++++++
>>  cpukit/posix/preinstall.am                    |   8 ++
>>  cpukit/posix/src/shm.c                        |  48 +++++++
>>  cpukit/posix/src/shmopen.c                    | 197
>> +++++++++++++++++++++++++-
>>  cpukit/rtems/src/rtemsobjectgetapiclassname.c |   1 +
>>  cpukit/sapi/include/confdefs.h                |  28 ++++
>>  cpukit/score/include/rtems/score/objectimpl.h |   5 +-
>>  cpukit/score/include/rtems/sysinit.h          |   1 +
>>  testsuites/psxtests/psxshm01/system.h         |   2 +-
>>  testsuites/sptests/spsysinit01/init.c         |  17 +++
>>  13 files changed, 459 insertions(+), 7 deletions(-)
>>  create mode 100644 cpukit/posix/include/rtems/posix/shm.h
>>  create mode 100644 cpukit/posix/include/rtems/posix/shmimpl.h
>>  create mode 100644 cpukit/posix/src/shm.c
>>
>> diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
>> index c7620df..5490401 100644
>> --- a/cpukit/posix/Makefile.am
>> +++ b/cpukit/posix/Makefile.am
>> @@ -43,6 +43,8 @@ include_rtems_posix_HEADERS +=
>> include/rtems/posix/psignalimpl.h
>>  include_rtems_posix_HEADERS += include/rtems/posix/pthread.h
>>  include_rtems_posix_HEADERS += include/rtems/posix/pthreadimpl.h
>>  include_rtems_posix_HEADERS += include/rtems/posix/ptimer.h
>> +include_rtems_posix_HEADERS += include/rtems/posix/shm.h
>> +include_rtems_posix_HEADERS += include/rtems/posix/shmimpl.h
>>  include_rtems_posix_HEADERS += include/rtems/posix/semaphore.h
>>  include_rtems_posix_HEADERS += include/rtems/posix/semaphoreimpl.h
>>  include_rtems_posix_HEADERS += include/rtems/posix/threadsup.h
>> @@ -100,6 +102,7 @@ libposix_a_SOURCES += src/munlockall.c
>>  libposix_a_SOURCES += src/munlock.c
>>  libposix_a_SOURCES += src/munmap.c
>>  libposix_a_SOURCES += src/posix_madvise.c
>> +libposix_a_SOURCES += src/shm.c
>>  libposix_a_SOURCES += src/shmopen.c
>>  libposix_a_SOURCES += src/shmunlink.c
>>
>> diff --git a/cpukit/posix/include/rtems/posix/config.h
>> b/cpukit/posix/include/rtems/posix/config.h
>> index 636f1e7..0a1c4e0 100644
>> --- a/cpukit/posix/include/rtems/posix/config.h
>> +++ b/cpukit/posix/include/rtems/posix/config.h
>> @@ -111,6 +111,11 @@ typedef struct {
>>    uint32_t                            maximum_rwlocks;
>>
>>    /**
>> +   * Maximum configured number of POSIX Shared memory objects.
>> +   */
>> +  uint32_t                            maximum_shms;
>> +
>> +  /**
>>     * This field contains the maximum number of POSIX API
>>     * spinlocks which are configured for this application.
>>     */
>> diff --git a/cpukit/posix/include/rtems/posix/shm.h
>> b/cpukit/posix/include/rtems/posix/shm.h
>> new file mode 100644
>> index 0000000..41557b1
>> --- /dev/null
>> +++ b/cpukit/posix/include/rtems/posix/shm.h
>> @@ -0,0 +1,61 @@
>> +/**
>> + * @file
>> + *
>> + * @brief Internal Support for POSIX Shared Memory
>> + */
>> +
>> +/*
>> + * Copyright (c) 2016 Gedare Bloom.
>> + *
>> + * The license and distribution terms for this file may be
>> + * found in the file LICENSE in this distribution or at
>> + * http://www.rtems.org/license/LICENSE.
>> + */
>> +
>> +#ifndef _RTEMS_POSIX_SHM_H
>> +#define _RTEMS_POSIX_SHM_H
>> +
>> +#include <rtems/score/object.h>
>> +#include <rtems/score/threadq.h>
>> +
>> +#ifdef __cplusplus
>> +extern "C" {
>> +#endif
>> +
>> +/**
>> + * @defgroup POSIXShmPrivate POSIX Shared Memory Private Support
>> + *
>> + * @ingroup POSIXAPI
>> + *
>> + * Internal implementation support for POSIX shared memory.
>> + * @{
>> + */
>> +
>> +typedef struct {
>> +   Objects_Control      Object;
>> +   Thread_queue_Control Wait_queue;
>> +
>> +   int                  reference_count;
>> +
>> +   void                *shm_object;
>> +   size_t               shm_object_size;
>> +   void                *( *shm_object_allocate )( size_t size );
>> +   void                 ( *shm_object_free ) ( void *ptr );
>> +
>> +   uid_t                uid;
>> +   gid_t                gid;
>> +   mode_t               mode;
>> +
>> +   time_t               atime;
>> +   time_t               mtime;
>> +   time_t               ctime;
>> +
>> +} POSIX_Shm_Control;
>> +
>> +/** @} */
>> +
>> +#ifdef __cplusplus
>> +}
>> +#endif
>> +
>> +#endif
>> diff --git a/cpukit/posix/include/rtems/posix/shmimpl.h
>> b/cpukit/posix/include/rtems/posix/shmimpl.h
>> new file mode 100644
>> index 0000000..2df4bd3
>> --- /dev/null
>> +++ b/cpukit/posix/include/rtems/posix/shmimpl.h
>> @@ -0,0 +1,90 @@
>> +/**
>> + * @file
>> + *
>> + * @brief Private Support Information for POSIX Shared Memory
>> + *
>> + */
>> +
>> +/*
>> + * Copyright (c) 2016 Gedare Bloom.
>> + *
>> + * The license and distribution terms for this file may be
>> + * found in the file LICENSE in this distribution or at
>> + * http://www.rtems.org/license/LICENSE.
>> + */
>> +
>> +#ifndef _RTEMS_POSIX_SHMIMPL_H
>> +#define _RTEMS_POSIX_SHMIMPL_H
>> +
>> +#include <rtems/posix/posixapi.h>
>> +#include <rtems/posix/shm.h>
>> +#include <rtems/score/objectimpl.h>
>> +
>> +#ifdef __cplusplus
>> +extern "C" {
>> +#endif
>> +
>> +/**
>> + * @ingroup POSIXShmPrivate
>> + * @{
>> + */
>> +
>> +extern Objects_Information _POSIX_Shm_Information;
>> +
>> +RTEMS_INLINE_ROUTINE void _POSIX_Shm_Acquire_critical(
>> +  POSIX_Shm_Control                 *the_shm,
>> +  Thread_queue_Context              *queue_context
>> +)
>> +{
>> +  _Thread_queue_Acquire_critical(
>> +    &the_shm->Wait_queue,
>> +    &queue_context->Lock_context
>> +  );
>> +}
>> +
>> +RTEMS_INLINE_ROUTINE void _POSIX_Shm_Release(
>> +  POSIX_Shm_Control                 *the_shm,
>> +  Thread_queue_Context              *queue_context
>> +)
>> +{
>> +  _Thread_queue_Release( &the_shm->Wait_queue,
>> &queue_context->Lock_context );
>> +}
>> +
>> +RTEMS_INLINE_ROUTINE POSIX_Shm_Control *_POSIX_Shm_Allocate_unprotected(
>> void )
>> +{
>> +  return (POSIX_Shm_Control *)
>> +    _Objects_Allocate_unprotected( &_POSIX_Shm_Information );
>> +}
>> +
>> +/**
>> + * @brief POSIX Shared Memory Free
>> + *
>> + * This routine frees a shm control block.
>> + */
>> +RTEMS_INLINE_ROUTINE void _POSIX_Shm_Free (
>> +  POSIX_Shm_Control *the_shm
>> +)
>> +{
>> +  _Objects_Free( &_POSIX_Shm_Information, &the_shm->Object );
>> +}
>> +
>> +RTEMS_INLINE_ROUTINE POSIX_Shm_Control *_POSIX_Shm_Get_by_name(
>> +  const char                *name,
>> +  size_t                    *name_length_p,
>> +  Objects_Get_by_name_error *error
>> +)
>> +{
>> +  return (POSIX_Shm_Control *) _Objects_Get_by_name(
>> +    &_POSIX_Shm_Information,
>> +    name,
>> +    name_length_p,
>> +    error
>> +  );
>> +}
>> +/** @} */
>> +
>> +#ifdef __cplusplus
>> +}
>> +#endif
>> +
>> +#endif
>> diff --git a/cpukit/posix/preinstall.am b/cpukit/posix/preinstall.am
>> index 1d035e7..5863860 100644
>> --- a/cpukit/posix/preinstall.am
>> +++ b/cpukit/posix/preinstall.am
>> @@ -109,6 +109,14 @@ $(PROJECT_INCLUDE)/rtems/posix/ptimer.h:
>> include/rtems/posix/ptimer.h $(PROJECT_
>>         $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/ptimer.h
>>  PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/ptimer.h
>>
>> +$(PROJECT_INCLUDE)/rtems/posix/shm.h: include/rtems/posix/shm.h
>> $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
>> +       $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/shm.h
>> +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/shm.h
>> +
>> +$(PROJECT_INCLUDE)/rtems/posix/shmimpl.h: include/rtems/posix/shmimpl.h
>> $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
>> +       $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/shmimpl.h
>> +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/shmimpl.h
>> +
>>  $(PROJECT_INCLUDE)/rtems/posix/semaphore.h:
>> include/rtems/posix/semaphore.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
>>         $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/semaphore.h
>>  PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/semaphore.h
>> diff --git a/cpukit/posix/src/shm.c b/cpukit/posix/src/shm.c
>> new file mode 100644
>> index 0000000..7dca6bb
>> --- /dev/null
>> +++ b/cpukit/posix/src/shm.c
>> @@ -0,0 +1,48 @@
>> +/**
>> + * @file
>> + */
>> +
>> +/*
>> + * Copyright (c) 2016 Gedare Bloom.
>> + *
>> + * The license and distribution terms for this file may be
>> + * found in the file LICENSE in this distribution or at
>> + * http://www.rtems.org/license/LICENSE.
>> + */
>> +
>> +#if HAVE_CONFIG_H
>> +#include "config.h"
>> +#endif
>> +
>> +#include <sys/stat.h>
>> +#include <fcntl.h>
>> +
>> +#include <rtems/system.h>
>> +#include <rtems/config.h>
>> +#include <rtems/libio.h>
>> +#include <rtems/sysinit.h>
>> +#include <rtems/posix/shmimpl.h>
>> +
>> +Objects_Information _POSIX_Shm_Information;
>> +
>> +static void _POSIX_Shm_Manager_initialization( void )
>> +{
>> +  _Objects_Initialize_information(
>> +    &_POSIX_Shm_Information,    /* object information table */
>> +    OBJECTS_POSIX_API,          /* object API */
>> +    OBJECTS_POSIX_SHMS,         /* object class */
>> +    Configuration_POSIX_API.maximum_shms,
>> +                                /* maximum objects of this class */
>> +    sizeof( POSIX_Shm_Control ),
>> +                                /* size of this object's control block */
>> +    true,                       /* true if names for this object are
>> strings */
>> +    _POSIX_PATH_MAX,            /* maximum length of each object's name
>> */
>> +    NULL                        /* Proxy extraction support callout */
>> +  );
>> +}
>> +
>> +RTEMS_SYSINIT_ITEM(
>> +  _POSIX_Shm_Manager_initialization,
>> +  RTEMS_SYSINIT_POSIX_SHM,
>> +  RTEMS_SYSINIT_ORDER_MIDDLE
>> +);
>> diff --git a/cpukit/posix/src/shmopen.c b/cpukit/posix/src/shmopen.c
>> index abac3f4..bc4923f 100644
>> --- a/cpukit/posix/src/shmopen.c
>> +++ b/cpukit/posix/src/shmopen.c
>> @@ -16,13 +16,202 @@
>>
>>  #include <sys/mman.h>
>>  #include <errno.h>
>> +#include <unistd.h>
>> +#include <fcntl.h>
>> +#include <sys/stat.h>
>> +
>> +#include <rtems/libio_.h>
>>  #include <rtems/seterr.h>
>>
>> +#include <rtems/posix/shmimpl.h>
>> +#include <rtems/score/wkspace.h>
>> +
>> +static const rtems_filesystem_file_handlers_r shm_handlers;
>> +
>> +static inline void shm_mtime_ctime_update( POSIX_Shm_Control *shm )
>> +{
>> +  struct timeval now;
>> +
>> +  gettimeofday( &now, 0 );
>> +  shm->mtime = now.tv_sec;
>> +  shm->ctime = now.tv_sec;
>> +}
>> +
>> +static int shm_ftruncate( rtems_libio_t *iop, off_t length )
>> +{
>> +  Thread_queue_Context  queue_context;
>> +  POSIX_Shm_Control *shm = (POSIX_Shm_Control *) iop->data1;
>> +
>> +  _POSIX_Shm_Acquire_critical( shm, &queue_context );
>> +
>> +  shm_mtime_ctime_update( shm );
>> +
>> +  _POSIX_Shm_Release( shm, &queue_context );
>> +  return 0;
>> +}
>> +
>> +static inline POSIX_Shm_Control *shm_allocate(
>> +  const char *name_arg,
>> +  size_t name_len,
>> +  int oflag,
>> +  mode_t mode,
>> +  int *error
>> +)
>> +{
>> +  POSIX_Shm_Control *shm;
>> +  char *name;
>> +  struct timeval tv;
>> +
>> +  name = _Workspace_String_duplicate( name_arg, name_len );
>> +  if ( name == NULL ) {
>> +    *error = ENOSPC;
>> +    return NULL;
>> +  }
>> +
>> +  shm = _POSIX_Shm_Allocate_unprotected();
>> +  if ( shm == NULL ) {
>> +    _Workspace_Free( name );
>> +    *error = ENFILE;
>> +    return NULL;
>> +  }
>> +
>> +  gettimeofday( &tv, 0 );
>> +
>> +  shm->reference_count = 1;
>> +  shm->shm_object = NULL;
>> +  shm->shm_object_allocate = _Workspace_Allocate_or_fatal_error;
>> +  shm->shm_object_free = _Workspace_Free;
>> +  shm->shm_object_size = 0;
>> +  shm->mode = mode & ~rtems_filesystem_umask;
>> +  shm->uid = geteuid();
>> +  shm->gid = getegid();
>> +  shm->atime = (time_t) tv.tv_sec;
>> +  shm->mtime = (time_t) tv.tv_sec;
>> +  shm->ctime = (time_t) tv.tv_sec;
>> +
>> +  _Objects_Open_string( &_POSIX_Shm_Information, &shm->Object, name );
>> +
>> +  return shm;
>> +}
>> +
>> +static inline bool shm_access_ok( POSIX_Shm_Control *shm, int oflag )
>> +{
>> +  int flags;
>> +  if ( oflag & O_RDONLY ) {
>> +    flags = RTEMS_FS_PERMS_READ;
>> +  } else {
>> +    flags = RTEMS_FS_PERMS_WRITE;
>> +  }
>> +  return rtems_filesystem_check_access( flags, shm->mode, shm->uid,
>> shm->gid );
>> +}
>> +
>>  int shm_open( const char *name, int oflag, mode_t mode )
>>  {
>> -  (void) name;
>> -  (void) oflag;
>> -  (void) mode;
>> +  int err = 0;
>> +  int fd;
>> +  rtems_libio_t *iop;
>> +  POSIX_Shm_Control *shm;
>> +  size_t len;
>> +  Objects_Get_by_name_error obj_err;
>> +  Thread_queue_Context  queue_context;
>> +
>> +  if ( ( oflag & O_ACCMODE ) != O_RDONLY && ( oflag & O_ACCMODE ) !=
>> O_RDWR ) {
>> +    rtems_set_errno_and_return_minus_one( EACCES );
>> +  }
>> +
>> +  if ( ( oflag & ~( O_RDONLY | O_RDWR | O_CREAT | O_EXCL | O_TRUNC ) ) !=
>> 0 ) {
>> +    rtems_set_errno_and_return_minus_one( EACCES );
>> +  }
>> +
>> +  if ( ( oflag & O_TRUNC ) != 0 && ( oflag & O_ACCMODE ) != O_RDWR ) {
>> +    rtems_set_errno_and_return_minus_one( EACCES );
>> +  }
>>
>> -  rtems_set_errno_and_return_minus_one( EINVAL );
>> +  /* TODO see if the object exists, shms available */
>> +
>> +  _Objects_Allocator_lock();
>> +  shm = _POSIX_Shm_Get_by_name( name, &len, &obj_err );
>> +
>> +  if ( shm == NULL ) {
>> +    switch ( obj_err ) {
>> +      case OBJECTS_GET_BY_NAME_INVALID_NAME:
>> +        err = EINVAL;
>> +        break;
>> +
>> +      case OBJECTS_GET_BY_NAME_NAME_TOO_LONG:
>> +        err = ENAMETOOLONG;
>> +        break;
>> +
>> +      case OBJECTS_GET_BY_NAME_NO_OBJECT:
>> +      default:
>> +        /* Reject any name without a leading slash. */
>> +        if ( name[0] != '/' ) {
>> +          err = EINVAL;
>> +          break;
>> +        }
>> +
>> +        if ( ( oflag & O_CREAT ) != O_CREAT ) {
>> +          err = ENOENT;
>> +          break;
>> +        }
>> +
>> +        shm = shm_allocate(name, len, oflag, mode, &err);
>> +        break;
>> +    }
>> +    _Objects_Allocator_unlock();
>> +    if ( err != 0 ) {
>> +      rtems_set_errno_and_return_minus_one( err );
>> +    }
>> +  } else { /* shm exists */
>> +    _Objects_Allocator_unlock();
>> +    if ( ( oflag & ( O_EXCL | O_CREAT ) ) == ( O_EXCL | O_CREAT ) ) {
>
>
> What happens to the allocated memory when there is an error?
>
>> +      rtems_set_errno_and_return_minus_one( EEXIST );
>> +    }
>> +    if ( !shm_access_ok( shm, oflag ) ) {
>
>
> Same here?
>
It doesn't matter here, because the shm was not allocated during this
call in this code path. I can perhaps refactor some inline helpers to
make the two paths more clear. However...

> Chris
>
>
>> +      rtems_set_errno_and_return_minus_one( EACCES );
>> +    }
>> +    _POSIX_Shm_Acquire_critical( shm, &queue_context );
>> +    ++shm->reference_count;
>> +    _POSIX_Shm_Release( shm, &queue_context );
>> +  }
>> +
>> +  iop = rtems_libio_allocate();
>> +  if ( iop == NULL ) {
>> +    rtems_set_errno_and_return_minus_one( EMFILE );
Here perhaps the shm needs to be freed in case it was allocated. Or
the iop should be allocated earlier and freed in case of an error.

>> +  }
>> +  if ( oflag & O_TRUNC ) {
>> +      shm_ftruncate( iop, 0 );
>> +  }
>> +  fd = rtems_libio_iop_to_descriptor( iop );
>> +  iop->flags |= LIBIO_FLAGS_CLOSE_ON_EXEC;
>> +  if ( oflag & O_RDONLY ) {
>> +    iop->flags |= LIBIO_FLAGS_READ;
>> +  } else {
>> +    iop->flags |= LIBIO_FLAGS_READ_WRITE;
>> +  }
>> +  iop->data0 = fd;
>> +  iop->data1 = shm;
>> +  iop->pathinfo.handlers = &shm_handlers;
>> +  iop->pathinfo.mt_entry = &rtems_filesystem_null_mt_entry;
>> +  rtems_filesystem_location_add_to_mt_entry( &iop->pathinfo );
>> +
>> +  return fd;
>>  }
>> +
>> +static const rtems_filesystem_file_handlers_r shm_handlers = {
>> +  .open_h = rtems_filesystem_default_open,
>> +  .close_h = rtems_filesystem_default_close,
>> +  .read_h = rtems_filesystem_default_read,
>> +  .write_h = rtems_filesystem_default_write,
>> +  .ioctl_h = rtems_filesystem_default_ioctl,
>> +  .lseek_h = rtems_filesystem_default_lseek,
>> +  .fstat_h = rtems_filesystem_default_fstat,
>> +  .ftruncate_h = shm_ftruncate,
>> +  .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
>> +  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
>> +  .fcntl_h = rtems_filesystem_default_fcntl,
>> +  .kqfilter_h = rtems_filesystem_default_kqfilter,
>> +  .poll_h = rtems_filesystem_default_poll,
>> +  .readv_h = rtems_filesystem_default_readv,
>> +  .writev_h = rtems_filesystem_default_writev
>> +};
>> diff --git a/cpukit/rtems/src/rtemsobjectgetapiclassname.c
>> b/cpukit/rtems/src/rtemsobjectgetapiclassname.c
>> index dd92e6c..0923a89 100644
>> --- a/cpukit/rtems/src/rtemsobjectgetapiclassname.c
>> +++ b/cpukit/rtems/src/rtemsobjectgetapiclassname.c
>> @@ -56,6 +56,7 @@ static const rtems_assoc_t
>> rtems_object_api_posix_assoc[] = {
>>    { "Barrier",                 OBJECTS_POSIX_BARRIERS, 0},
>>    { "Spinlock",                OBJECTS_POSIX_SPINLOCKS, 0},
>>    { "RWLock",                  OBJECTS_POSIX_RWLOCKS, 0},
>> +  { "Shared Memory",           OBJECTS_POSIX_SHMS, 0},
>>    { NULL,                      0, 0}
>>  };
>>  #endif
>> diff --git a/cpukit/sapi/include/confdefs.h
>> b/cpukit/sapi/include/confdefs.h
>> index b75839e..385bf62 100644
>> --- a/cpukit/sapi/include/confdefs.h
>> +++ b/cpukit/sapi/include/confdefs.h
>> @@ -2068,6 +2068,10 @@ extern rtems_initialization_tasks_table
>> Initialization_tasks[];
>>        #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS \
>>          rtems_resource_unlimited(CONFIGURE_UNLIMITED_ALLOCATION_SIZE)
>>      #endif
>> +    #if !defined(CONFIGURE_MAXIMUM_POSIX_SHMS)
>> +      #define CONFIGURE_MAXIMUM_POSIX_SHMS \
>> +        rtems_resource_unlimited(CONFIGURE_UNLIMITED_ALLOCATION_SIZE)
>> +    #endif
>>      #if !defined(CONFIGURE_MAXIMUM_POSIX_SPINLOCKS)
>>        #define CONFIGURE_MAXIMUM_POSIX_SPINLOCKS \
>>          rtems_resource_unlimited(CONFIGURE_UNLIMITED_ALLOCATION_SIZE)
>> @@ -2468,6 +2472,7 @@ extern rtems_initialization_tasks_table
>> Initialization_tasks[];
>>    #include <rtems/posix/pthread.h>
>>    #include <rtems/posix/rwlock.h>
>>    #include <rtems/posix/semaphore.h>
>> +  #include <rtems/posix/shm.h>
>>    #include <rtems/posix/spinlock.h>
>>    #include <rtems/posix/threadsup.h>
>>    #include <rtems/posix/timer.h>
>> @@ -2648,6 +2653,23 @@ extern rtems_initialization_tasks_table
>> Initialization_tasks[];
>>    #define CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS(_rwlocks) \
>>      _Configure_Object_RAM(_rwlocks, sizeof(POSIX_RWLock_Control) )
>>
>> +  /**
>> +   * Configure the maximum number of POSIX shared memory objects.
>> +   */
>> +  #if !defined(CONFIGURE_MAXIMUM_POSIX_SHMS)
>> +    #define CONFIGURE_MAXIMUM_POSIX_SHMS 0
>> +  #endif
>> +
>> +  /**
>> +   * This macro is calculated to specify the memory required for
>> +   * POSIX API shared memory.
>> +   *
>> +   * This is an internal parameter.
>> +   */
>> +  #define CONFIGURE_MEMORY_FOR_POSIX_SHMS(_shms) \
>> +    _Configure_Object_RAM(_shms, sizeof(POSIX_Shm_Control) )
>> +
>> +
>>    #ifdef CONFIGURE_POSIX_INIT_THREAD_TABLE
>>
>>      #ifdef CONFIGURE_POSIX_HAS_OWN_INIT_THREAD_TABLE
>> @@ -2875,6 +2897,8 @@ extern rtems_initialization_tasks_table
>> Initialization_tasks[];
>>          CONFIGURE_MAXIMUM_POSIX_SPINLOCKS) + \
>>        CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS( \
>>          CONFIGURE_MAXIMUM_POSIX_RWLOCKS) + \
>> +      CONFIGURE_MEMORY_FOR_POSIX_SHMS( \
>> +        CONFIGURE_MAXIMUM_POSIX_SHMS) + \
>>        CONFIGURE_MEMORY_FOR_POSIX_TIMERS(CONFIGURE_MAXIMUM_POSIX_TIMERS))
>>  #else
>>    /**
>> @@ -3333,6 +3357,7 @@ extern rtems_initialization_tasks_table
>> Initialization_tasks[];
>>        CONFIGURE_MAXIMUM_POSIX_SEMAPHORES,
>>        CONFIGURE_MAXIMUM_POSIX_BARRIERS,
>>        CONFIGURE_MAXIMUM_POSIX_RWLOCKS,
>> +      CONFIGURE_MAXIMUM_POSIX_SHMS,
>>        CONFIGURE_MAXIMUM_POSIX_SPINLOCKS,
>>        CONFIGURE_POSIX_INIT_THREAD_TABLE_SIZE,
>>        CONFIGURE_POSIX_INIT_THREAD_TABLE_NAME
>> @@ -3550,6 +3575,7 @@ extern rtems_initialization_tasks_table
>> Initialization_tasks[];
>>      uint32_t POSIX_BARRIERS;
>>      uint32_t POSIX_SPINLOCKS;
>>      uint32_t POSIX_RWLOCKS;
>> +    uint32_t POSIX_SHMS;
>>  #endif
>>
>>      /* Stack space sizes */
>> @@ -3604,6 +3630,7 @@ extern rtems_initialization_tasks_table
>> Initialization_tasks[];
>>      CONFIGURE_MEMORY_FOR_POSIX_BARRIERS( CONFIGURE_MAXIMUM_POSIX_BARRIERS
>> ),
>>      CONFIGURE_MEMORY_FOR_POSIX_SPINLOCKS(
>> CONFIGURE_MAXIMUM_POSIX_SPINLOCKS ),
>>      CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS( CONFIGURE_MAXIMUM_POSIX_RWLOCKS
>> ),
>> +    CONFIGURE_MEMORY_FOR_POSIX_SHMS( CONFIGURE_MAXIMUM_POSIX_SHMS ),
>>      CONFIGURE_MEMORY_FOR_POSIX_TIMERS( CONFIGURE_MAXIMUM_POSIX_TIMERS ),
>>  #endif
>>
>> @@ -3676,6 +3703,7 @@ extern rtems_initialization_tasks_table
>> Initialization_tasks[];
>>         (CONFIGURE_MAXIMUM_POSIX_BARRIERS != 0) || \
>>         (CONFIGURE_MAXIMUM_POSIX_SPINLOCKS != 0) || \
>>         (CONFIGURE_MAXIMUM_POSIX_RWLOCKS != 0) || \
>> +       (CONFIGURE_MAXIMUM_POSIX_SHMS != 0) || \
>>        defined(CONFIGURE_POSIX_INIT_THREAD_TABLE))
>>    #error "CONFIGURATION ERROR: POSIX API support not configured!!"
>>    #endif
>> diff --git a/cpukit/score/include/rtems/score/objectimpl.h
>> b/cpukit/score/include/rtems/score/objectimpl.h
>> index f5beb3b..13dd291 100644
>> --- a/cpukit/score/include/rtems/score/objectimpl.h
>> +++ b/cpukit/score/include/rtems/score/objectimpl.h
>> @@ -93,11 +93,12 @@ typedef enum {
>>    OBJECTS_POSIX_TIMERS              = 9,
>>    OBJECTS_POSIX_BARRIERS            = 10,
>>    OBJECTS_POSIX_SPINLOCKS           = 11,
>> -  OBJECTS_POSIX_RWLOCKS             = 12
>> +  OBJECTS_POSIX_RWLOCKS             = 12,
>> +  OBJECTS_POSIX_SHMS                = 13
>>  } Objects_POSIX_API;
>>
>>  /** This macro is used to generically specify the last API index. */
>> -#define OBJECTS_POSIX_CLASSES_LAST OBJECTS_POSIX_RWLOCKS
>> +#define OBJECTS_POSIX_CLASSES_LAST OBJECTS_POSIX_SHMS
>>
>>  /*
>>   * For fake objects, which have an object identifier, but no objects
>> diff --git a/cpukit/score/include/rtems/sysinit.h
>> b/cpukit/score/include/rtems/sysinit.h
>> index ad68c45..6a97d78 100644
>> --- a/cpukit/score/include/rtems/sysinit.h
>> +++ b/cpukit/score/include/rtems/sysinit.h
>> @@ -57,6 +57,7 @@ extern "C" {
>>  #define RTEMS_SYSINIT_POSIX_SPINLOCK             000369
>>  #define RTEMS_SYSINIT_POSIX_CLEANUP              00036a
>>  #define RTEMS_SYSINIT_POSIX_KEYS                 00036b
>> +#define RTEMS_SYSINIT_POSIX_SHM                  00036c
>>  #define RTEMS_SYSINIT_IDLE_THREADS               000380
>>  #define RTEMS_SYSINIT_LIBIO                      000400
>>  #define RTEMS_SYSINIT_ROOT_FILESYSTEM            000401
>> diff --git a/testsuites/psxtests/psxshm01/system.h
>> b/testsuites/psxtests/psxshm01/system.h
>> index 9a55a8a..1dde70e 100644
>> --- a/testsuites/psxtests/psxshm01/system.h
>> +++ b/testsuites/psxtests/psxshm01/system.h
>> @@ -21,7 +21,7 @@ void *POSIX_Init(
>>
>>  #define CONFIGURE_MAXIMUM_POSIX_THREADS     1
>>  #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 10
>> -#define CONFIGURE_MAXIMUM_SHMEMS 1
>> +#define CONFIGURE_MAXIMUM_POSIX_SHMS 1
>>
>>  #define CONFIGURE_POSIX_INIT_THREAD_TABLE
>>
>> diff --git a/testsuites/sptests/spsysinit01/init.c
>> b/testsuites/sptests/spsysinit01/init.c
>> index 1ce22d5..3f36842 100644
>> --- a/testsuites/sptests/spsysinit01/init.c
>> +++ b/testsuites/sptests/spsysinit01/init.c
>> @@ -43,6 +43,7 @@
>>  #include <rtems/posix/pthreadimpl.h>
>>  #include <rtems/posix/rwlockimpl.h>
>>  #include <rtems/posix/semaphoreimpl.h>
>> +#include <rtems/posix/shmimpl.h>
>>  #include <rtems/posix/spinlockimpl.h>
>>  #include <rtems/posix/timerimpl.h>
>>  #endif /* RTEMS_POSIX_API */
>> @@ -118,6 +119,8 @@ typedef enum {
>>    POSIX_BARRIER_POST,
>>    POSIX_RWLOCK_PRE,
>>    POSIX_RWLOCK_POST,
>> +  POSIX_SHM_PRE,
>> +  POSIX_SHM_POST,
>>    POSIX_SPINLOCK_PRE,
>>    POSIX_SPINLOCK_POST,
>>    POSIX_CLEANUP_PRE,
>> @@ -527,6 +530,18 @@ LAST(RTEMS_SYSINIT_POSIX_RWLOCK)
>>    next_step(POSIX_RWLOCK_POST);
>>  }
>>
>> +FIRST(RTEMS_SYSINIT_POSIX_SHM)
>> +{
>> +  assert(_POSIX_Shm_Information.maximum == 0);
>> +  next_step(POSIX_SHM_PRE);
>> +}
>> +
>> +LAST(RTEMS_SYSINIT_POSIX_SHM)
>> +{
>> +  assert(_POSIX_Shm_Information.maximum != 0);
>> +  next_step(POSIX_SHM_POST);
>> +}
>> +
>>  FIRST(RTEMS_SYSINIT_POSIX_SPINLOCK)
>>  {
>>    assert(_POSIX_Spinlock_Information.maximum == 0);
>> @@ -767,6 +782,8 @@ static void *POSIX_Init(void *arg)
>>
>>  #define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 1
>>
>> +#define CONFIGURE_MAXIMUM_POSIX_SHMS 1
>> +
>>  #define CONFIGURE_MAXIMUM_POSIX_SPINLOCKS 1
>>
>>  #define CONFIGURE_MAXIMUM_POSIX_TIMERS 1
>>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel



More information about the devel mailing list