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

Generic Memory Pools #7418

Merged
merged 8 commits into from
Apr 30, 2024
Merged

Generic Memory Pools #7418

merged 8 commits into from
Apr 30, 2024

Conversation

ejohnstown
Copy link
Contributor

@ejohnstown ejohnstown commented Apr 12, 2024

  1. Add a new API for creating a memory pool, wc_LoadStaticMemory_ex(), updated support functions to work with it. Reimplemented wc_LoadStaticMemory() in terms of the new API.
  2. Changed wolfSSL_CTX_load_static_memory() to use wc_LoadStaticMemory() rather than reimplementing it.

Fixes 17726

Testing

$ autoreconf -ivf
$ ./configure --enable-wolfssh --enable-staticmemory
$ make clean && make
$ ./wolfcrypt/test/test
$ ./examples/server/server &
$ ./examples/client/client

The code should work the same with and without the changes.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

src/ssl.c Outdated Show resolved Hide resolved
1. Modify wolfSSL_CTX_load_static_memory() to use wc_LoadStaticMemory()
   instead of reimplementing it.
2. Initialize the pointers in wc_LoadStaticMemory() to null.
3. Whitespace changes.
1. Add the function wc_LoadStaticMemory_ex(), which is a generic version
   of wc_LoadStaticMemory().
2. Modify wc_LoadStaticMemory() to call wc_LoadStaticMemory_ex() with
   the bucket lists.
3. Rename the function wolfSSL_load_static_memory() as
   wc_partition_static_memory(), make it static, move it higher in the file.
1. Add generic function wolfSSL_StaticBufferSz_ex() where one specifies
   the memory bucket list sizes and distribution.
2. Rewrote wolfSSL_StaticBufferSz() in terms of the new function.
3. Changed the list pointers on wc_LoadStaticMemory_ex() and
   wc_init_memory_heap() to be pointers to const.
1. Add checks for listSz against WOLFMEM_MAX_BUCKETS.
2. Use WOLFMEM_DEF_BUCKETS for the size when using the default memory
   descriptions.
3. Whitespace.
1. Make the function wolfSSL_GetMemStats() public.
@ejohnstown ejohnstown marked this pull request as ready for review April 25, 2024 21:32
Copy link
Contributor

@JacobBarthelmeh JacobBarthelmeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the addition of being able to change the memory bucket sizes at run time and on creation!

billphipps
billphipps previously approved these changes Apr 26, 2024
Copy link
Contributor

@billphipps billphipps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Do we need to add API tests for these now that they are exposed?

wolfcrypt/src/memory.c Show resolved Hide resolved
wolfcrypt/src/memory.c Outdated Show resolved Hide resolved
wolfcrypt/src/memory.c Show resolved Hide resolved
wolfcrypt/src/memory.c Outdated Show resolved Hide resolved
1. Added some extra parameter checking to wc_LoadStaticMemory_ex().
2. Added some extra parameter checking to wc_StaticBufferSz_ex().
3. Rename some parameters and add some logging prints.
4. Some static functions have some parameter checking and they are only
   calling in one spot, remove it.
billphipps
billphipps previously approved these changes Apr 27, 2024
Copy link
Contributor

@billphipps billphipps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good to me. Remember documentation and test updates if you can squeeze them in here.

@ejohnstown
Copy link
Contributor Author

Setting up a heap initializes a mutex, maybe. It isn't cleaned up if needed.

1. Add API test for function `wc_LoadStaticMemory_ex()`.
1. Add API for function `wc_UnloadStaticMemory()` which frees the mutex
   used by the static memory pool.
2. Update the `wc_LoadStaticMemory_ex()` test to free the static memory
   pool's mutex on each successful test case.
@SparkiDev SparkiDev merged commit 4594151 into wolfSSL:master Apr 30, 2024
114 checks passed
@ejohnstown ejohnstown deleted the generic-pool branch May 3, 2024 17:09
jefferyq2 pushed a commit to jefferyq2/wolfssl that referenced this pull request Jun 9, 2024
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.

5 participants