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

Pull in some staticmemory features #7595

Merged
merged 5 commits into from
May 30, 2024
Merged

Conversation

JacobBarthelmeh
Copy link
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
Contributor Author

current failure is libssh2, which is a known failure

wolfssl/wolfcrypt/settings.h Show resolved Hide resolved
@@ -246,6 +261,16 @@ WOLFSSL_API int wolfSSL_GetAllocators(wolfSSL_Malloc_cb* mf,
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
Contributor

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.

@@ -214,7 +214,14 @@ WOLFSSL_API int wolfSSL_GetAllocators(wolfSSL_Malloc_cb* mf,
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
Contributor

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.

configure.ac Outdated
;;
no)
;;
small)
Copy link
Contributor

Choose a reason for hiding this comment

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

small | lean

};


#ifdef WOLFSSL_DEBUG_MEMORY_CALLBACK
Copy link
Contributor

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
Contributor

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
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
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
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.

return 1;
}

static int wc_init_memory_heap(WOLFSSL_HEAP* heap, unsigned int listSz,
const unsigned int* sizeList, const unsigned int* distList)
{
word16 i;
Copy link
Contributor

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
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
103 checks passed
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.

3 participants