Skip to content

Conversation

@roadelou
Copy link

@roadelou roadelou commented Mar 7, 2021

Reason for the Pull Request

See issue #15, malloc and free are declared in the stdlib header of the pulp-runtime but are not actually implemented as of commit 252cecb.

Changes introduced by the Pull Request

This pull request introduces 3 main changes in the codebase:

  1. In alloc_pool.h, two functions were added: pos_alloc_user_data and pos_free_user_data. These functions are used to hide from the user the location where the data is allocated, which may change with the hardware (as was the case in pulp-rt, see rt_alloc). That way, the pos_alloc_t structs are only visible within alloc_pool.c and not exposed to the end user.

  2. In alloc_pool.c, I added the implementations for pos_alloc_user_data and pos_free_user_data. The preferred locations to put the data are the same as in rt_alloc.

  3. In io.c, I added the implementation for malloc and free. The implementation is similar to that used in the io.c of pulp-rt in that the size of the allocated chunk is stored before the pointer given to the user.

Additional Notes

I tried to keep the same style as the rest of the codebase so that the code would blend in well, and I also reused names from pulp-rt.

I haven't thoroughly tested the code yet, but I should be able to during the week. I can post a small update then if the PR hasn't been merged yet.

Finally, the internal pos_alloc in alloc.c uses int for the size, while malloc stores it as a uint32_t. I kept that from the original codebase to avoid introducing many changes at once, but it might cause bugs in edge cases where a size >2GB is allocated at once.

roadelou added 3 commits March 7, 2021 10:56
The `pos_alloc_user_data` and `pos_free_user_data` are meant to hide
hardware-related considreations from the user, providing a single
low-level interface to allocate memory.
`malloc` and `free` are simple wrapper around `pos_alloc_user_data`
and `pos_free_user_data`. They hide the size of the allocated chunk
from the user at the beginning of the allocated pointer.
@roadelou roadelou mentioned this pull request Mar 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant