Skip to content

Pull in some staticmemory features#7595

Merged
dgarske merged 5 commits intowolfSSL:masterfrom
JacobBarthelmeh:static
May 30, 2024
Merged

Pull in some staticmemory features#7595
dgarske merged 5 commits intowolfSSL:masterfrom
JacobBarthelmeh:static

Conversation

@JacobBarthelmeh
Copy link
Copy Markdown
Contributor

@JacobBarthelmeh JacobBarthelmeh commented May 29, 2024

Created during PIC18F effort.

Removes restriction of staticmemory + smallstack builds. Now that there is a global heap hint option.

Adds --enable-staticmemory=small which is a stripped down version of staticmemory (smaller struct sizes and less supporting API available).

Adds --enable-staticmemory=debug which enables setting a debugging callback function. Useful in cases where printf is not available for determining what is being alloc'd and bucket sizes being used. Example client output with example callback is :

./examples/client/client
...
...
...
Free'ing : 16128
OUT BUFFER: Alloc'd 6 bytes using bucket size 16992
Alloc'd 848 bytes using bucket size 1024
OUT BUFFER: Alloc'd 150 bytes using bucket size 16992
Alloc'd 13 bytes using bucket size 64
Alloc'd 12 bytes using bucket size 64
Alloc'd 848 bytes using bucket size 1024
IN BUFFER: Alloc'd 40 bytes using bucket size 16992
Alloc'd 13 bytes using bucket size 64
Alloc'd 12 bytes using bucket size 64
Free'ing : 1024
Free'ing : 512

...
...
...

@JacobBarthelmeh JacobBarthelmeh self-assigned this May 29, 2024
@JacobBarthelmeh
Copy link
Copy Markdown
Contributor Author

current failure is libssh2, which is a known failure

Comment thread wolfssl/wolfcrypt/settings.h
Comment thread wolfssl/wolfcrypt/memory.h Outdated
unsigned int listSz, const unsigned int *sizeList,
const unsigned int *distList, unsigned char* buf, unsigned int sz,
int flag, int max);
#ifdef WOLFSSL_DEBUG_MEMORY_CALLBACK
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please document this build option at the top of memory.c or here in the header.

Comment thread wolfssl/wolfcrypt/memory.h Outdated
typedef struct wc_Memory wc_Memory; /* internal structure for mem bucket */
typedef struct WOLFSSL_HEAP {
wc_Memory* ava[WOLFMEM_MAX_BUCKETS];
#ifndef WOLFSSL_LEAN_STATIC_MEMORY
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please document this new build option WOLFSSL_LEAN_STATIC_MEMORY at the top of memory.c or in the header. Does it reduce code size, change pools? Does it also require use with WOLFSSL_STATIC_MEMORY... etc.

Comment thread configure.ac Outdated
;;
no)
;;
small)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

small | lean

Comment thread wolfcrypt/src/memory.c Outdated
};


#ifdef WOLFSSL_DEBUG_MEMORY_CALLBACK
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can WOLFSSL_DEBUG_MEMORY_CALLBACK be used on its own without static memory?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice if it could:

./configure CFLAGS="-DWOLFSSL_DEBUG_MEMORY_CALLBACK" && make
...
examples/client/client.c:1871:14: error: use of undeclared identifier 'WOLFSSL_DEBUG_MEMORY_ALLOC'
        case WOLFSSL_DEBUG_MEMORY_ALLOC:
             ^
examples/client/client.c:1884:14: error: use of undeclared identifier 'WOLFSSL_DEBUG_MEMORY_FAIL'
        case WOLFSSL_DEBUG_MEMORY_FAIL:
             ^
examples/client/client.c:1888:14: error: use of undeclared identifier 'WOLFSSL_DEBUG_MEMORY_FREE'; did you mean 'WOLFSSL_BIO_MEMORY'?
        case WOLFSSL_DEBUG_MEMORY_FREE:
             ^~~~~~~~~~~~~~~~~~~~~~~~~
             WOLFSSL_BIO_MEMORY
./wolfssl/ssl.h:473:5: note: 'WOLFSSL_BIO_MEMORY' declared here
    WOLFSSL_BIO_MEMORY = 4,
    ^
examples/client/client.c:1892:14: error: use of undeclared identifier 'WOLFSSL_DEBUG_MEMORY_INIT'
        case WOLFSSL_DEBUG_MEMORY_INIT:
             ^
4 errors generated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe combine it with WOLFSSL_DEBUG_MEMORY? Instead of a new macro.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I take that back. The build am using it on does not like _func_ so it would not build with WOLFSSL_DEBUG_MEMORY and WOLFSSL_DEBUG_MEMORY_CALLBACK.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I left it as --enable-staticmemory only for the callback. The reasoning behind that was if using non static memory than users can override XMALLOC/XFREE to achieve close to the same thing at about the same effort as creating a callback function.

Comment thread wolfcrypt/src/memory.c Outdated
static int wc_init_memory_heap(WOLFSSL_HEAP* heap, unsigned int listSz,
const unsigned int* sizeList, const unsigned int* distList)
{
word16 i;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why listSz is unsigned int and this is word16? Can we have those types match?

@JacobBarthelmeh
Copy link
Copy Markdown
Contributor Author

Retest this please Jenkins

@dgarske dgarske self-requested a review May 30, 2024 22:48
@dgarske dgarske merged commit 7fadd4e into wolfSSL:master May 30, 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.

3 participants