Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs/shm/shmfs_alloc.c: Allocate zero-initialized memory in flat build #328

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions fs/shm/shmfs_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,48 +51,54 @@ FAR struct shmfs_object_s *shmfs_alloc_object(size_t length)
* chunk in kernel heap
*/

object = fs_heap_zalloc(sizeof(struct shmfs_object_s));
if (object)
size_t hdr_size = sizeof(struct shmfs_object_s);
size_t alloc_size = length;
size_t cachesize = up_get_dcache_linesize();

if (cachesize > 0)
{
size_t cachesize = up_get_dcache_linesize();
if (cachesize > 0)
{
object->paddr = fs_heap_memalign(cachesize,
ALIGN_UP(length, cachesize));
}
else
{
object->paddr = fs_heap_malloc(length);
}
hdr_size = ALIGN_UP(hdr_size, cachesize);
alloc_size = ALIGN_UP(alloc_size, cachesize);
object = fs_heap_memalign(cachesize, hdr_size + alloc_size);
}
else
{
object = fs_heap_malloc(hdr_size + alloc_size);
}

if (object->paddr)
{
allocated = true;
}
if (object)
{
memset(object, 0, hdr_size + alloc_size);
object->paddr = (void *)((uintptr_t)object + hdr_size);
allocated = true;
}

#elif defined(CONFIG_BUILD_PROTECTED)
/* in PROTECTED build, allocate the shm object in kernel heap, and shared
* memory in user heap
*/

size_t alloc_size = length;

object = fs_heap_zalloc(sizeof(struct shmfs_object_s));
if (object)
{
size_t cachesize = up_get_dcache_linesize();

if (cachesize > 0)
{
object->paddr = kumm_memalign(cachesize,
ALIGN_UP(length, cachesize));
alloc_size = ALIGN_UP(alloc_size, cachesize);
object->paddr = kumm_memalign(cachesize, alloc_size);
}
else
{
object->paddr = kumm_malloc(length);
object->paddr = kumm_malloc(alloc_size);
}

if (object->paddr)
{
allocated = true;
memset(object->paddr, 0, alloc_size);
allocated = true;
}
}

Expand Down Expand Up @@ -152,9 +158,7 @@ void shmfs_free_object(FAR struct shmfs_object_s *object)
{
if (object)
{
#if defined(CONFIG_BUILD_FLAT)
fs_heap_free(object->paddr);
#elif defined(CONFIG_BUILD_PROTECTED)
#if defined(CONFIG_BUILD_PROTECTED)
kumm_free(object->paddr);
#elif defined(CONFIG_BUILD_KERNEL)
size_t i;
Expand Down
Loading