Skip to content

Rework platform_buffer_create() to take platform_heap_id hid as arg. Fix (minor) latent bug in this routine. #507

Closed

Description

@gapisback

platform_buffer_create() currently takes platform_heap_handle UNUSED_PARAM(heap_handle) as the arg to specify the "heap"-handle from which a new mmap()-ed buffer will be created.

Currently, in Splinter, heap_id is NULL, and we fall-back to using malloc(). The heap is used to allocte buffer_handle *bh structure.

Right now, things work ok. In a future dev effort, we are looking to support alternate memory handles, say, a shared-memory segment from which stuff like bh can be allocated. The platform_buffer_create() uses platform_get_heap_id() to access the heap-ID to allocate from (and that's anyway NULL right now).

This issue is being raised to make couple of small changes:

  1. Change the interface of platform_buffer_create() to take heap_id as its argument. In future, this will make it easier to drop-in support for other sources of heap-memory given by the heap-ID.
  2. There is a minor bug in the current code. This function could access a NULL bh if ever TYPED_MALLOC() were to fail. This code chunk will seg-fault:
 60 platform_buffer_create(size_t               length,
 61                        platform_heap_handle UNUSED_PARAM(heap_handle),
 62                        platform_module_id   UNUSED_PARAM(module_id))
 63 {
 64    buffer_handle *bh = TYPED_MALLOC(platform_get_heap_id(), bh);
 65
 66    if (bh != NULL) {
[...]
 91    bh->length = length;
 92    return bh;

Activity

  1. self-assigned this
    on Dec 21, 2022
  2. added
    code-cleanupMinor corrections, improvements, code-cleanup; not necessarily a bug per se.
    on Dec 21, 2022
  3. added a commit that references this issue on Dec 22, 2022
  4. added a commit that references this issue on Dec 25, 2022
  5. added 5 commits that reference this issue on Jan 6, 2023
  6. added a commit that references this issue on Jan 11, 2023
  7. added a commit that references this issue on Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

code-cleanupMinor corrections, improvements, code-cleanup; not necessarily a bug per se.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions