File indexing completed on 2025-05-11 08:24:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 #ifdef HAVE_CONFIG_H
0033 #include "config.h"
0034 #endif
0035
0036 #include <errno.h>
0037 #include <stdlib.h>
0038 #include <string.h>
0039 #include <rtems/posix/shmimpl.h>
0040
0041 int _POSIX_Shm_Object_create_from_heap(
0042 POSIX_Shm_Object *shm_obj,
0043 size_t size
0044 )
0045 {
0046 void *p = calloc( 1, size );
0047 if ( p != NULL ) {
0048 shm_obj->handle = p;
0049 shm_obj->size = size;
0050 } else {
0051 errno = EIO;
0052 }
0053 return 0;
0054 }
0055
0056 int _POSIX_Shm_Object_delete_from_heap( POSIX_Shm_Object *shm_obj )
0057 {
0058
0059 memset( shm_obj->handle, 0, shm_obj->size );
0060 free( shm_obj->handle );
0061 shm_obj->handle = NULL;
0062 shm_obj->size = 0;
0063 return 0;
0064 }
0065
0066 int _POSIX_Shm_Object_resize_from_heap(
0067 POSIX_Shm_Object *shm_obj,
0068 size_t size
0069 )
0070 {
0071 void *p;
0072 int err = 0;
0073
0074 if ( size < shm_obj->size ) {
0075
0076 p = (void*)((uintptr_t)shm_obj->handle + (uintptr_t)size);
0077 memset( p, 0, shm_obj->size - size );
0078 }
0079 p = realloc( shm_obj->handle, size );
0080 if ( p != NULL ) {
0081 shm_obj->handle = p;
0082 if ( size > shm_obj->size ) {
0083
0084 memset( p, 0, size - shm_obj->size );
0085 }
0086 shm_obj->size = size;
0087 } else {
0088 err = EIO;
0089 }
0090 return err;
0091 }
0092
0093
0094 int _POSIX_Shm_Object_read_from_heap(
0095 POSIX_Shm_Object *shm_obj,
0096 void *buf,
0097 size_t count
0098 )
0099 {
0100 if ( shm_obj == NULL || shm_obj->handle == NULL )
0101 return 0;
0102
0103 if ( shm_obj->size < count ) {
0104 count = shm_obj->size;
0105 }
0106
0107 memcpy( buf, shm_obj->handle, count );
0108
0109 return count;
0110 }
0111
0112
0113 void * _POSIX_Shm_Object_mmap_from_heap(
0114 POSIX_Shm_Object *shm_obj,
0115 size_t len,
0116 int prot,
0117 off_t off
0118 )
0119 {
0120 if ( shm_obj == NULL || shm_obj->handle == NULL )
0121 return 0;
0122
0123
0124 if ( shm_obj->size < len + off ) {
0125 return NULL;
0126 }
0127
0128 return (char*)shm_obj->handle + off;
0129 }
0130