From ba77628250ae7158db363fc0d7886ebd43e9cb69 Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Fri, 12 Aug 2016 15:25:10 -0400 Subject: posix: shared memory support Add POSIX shared memory manager (Shm). Includes a hook-based approach for the backing memory storage that defaults to the Workspace, and a test is provided using the heap. A test is also provided for the basic use of mmap'ing a shared memory object. This test currently fails at the mmap stage due to no support for mmap. --- cpukit/posix/src/shmunlink.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'cpukit/posix/src/shmunlink.c') diff --git a/cpukit/posix/src/shmunlink.c b/cpukit/posix/src/shmunlink.c index f5599227b1..ab18450dc7 100644 --- a/cpukit/posix/src/shmunlink.c +++ b/cpukit/posix/src/shmunlink.c @@ -18,9 +18,35 @@ #include #include +#include + int shm_unlink( const char *name ) { - (void) name; + Objects_Get_by_name_error obj_err; + int err = 0; + POSIX_Shm_Control *shm; + + shm = _POSIX_Shm_Get_by_name( name, 0, &obj_err ); + switch ( obj_err ) { + case OBJECTS_GET_BY_NAME_INVALID_NAME: + err = ENOENT; + break; + + case OBJECTS_GET_BY_NAME_NAME_TOO_LONG: + err = ENAMETOOLONG; + break; - rtems_set_errno_and_return_minus_one( ENOENT ); + case OBJECTS_GET_BY_NAME_NO_OBJECT: + default: + _Objects_Close( &_POSIX_Shm_Information, &shm->Object ); + if ( shm->reference_count == 0 ) { + /* TODO: need to make sure this counts mmaps too! */ + /* only remove the shm object if no references exist to it. */ + _POSIX_Shm_Free( shm ); + } + break; + } + if ( err != 0 ) + rtems_set_errno_and_return_minus_one( err ); + return 0; } -- cgit v1.2.3