You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: wolfSSL/src/chapter04.md
+38-4
Original file line number
Diff line number
Diff line change
@@ -551,7 +551,10 @@ By default, wolfSSL assumes that the execution environment provides dynamic memo
551
551
552
552
Using static-buffer-allocation is equivalent in API to using dynamic memory with wolfSSL. This functional equivalency is achieved in wolfSSL by abstracting memory allocation/free into XMALLOC/XFREE function calls. Once static-buffer-allocation is set, wolfSSL will use it from then on to allocate buffers and other structures used internally. Since this feature is set for WOLFSSL_CTX, it will continue to work for the lifetime of the context object.
553
553
554
-
The static-buffer-allocation set in a WOLFSSL_CTX is thread-safe. Even if the same WOLFSSL_CTX is shared by different threads, buffer allocation/free is used under exclusive control inside wolfSSL.
554
+
The static-buffer-allocation set in a WOLFSSL_CTX is thread-safe. Even if the same WOLFSSL_CTX is shared by different threads, buffer allocation/free is used under exclusive control inside wolfSSL. The following is a visual representation of the CTX structure, the arrows indicate passing a pointer to the heap and "..." references all structs and not to the ones listed.
555
+
556
+

557
+
555
558
In comparison to a memory pool functionality offered by an RTOS implementation, memory functionality in an RTOS will commonly suspend a thread (task) if an unused memory block cannot be found when requested until a free block becomes available. wolfSSL’s static memory functionality has no such synchronization capability.
556
559
557
560
### Specifying Static Buffer Use
@@ -582,6 +585,36 @@ user_settings.h
582
585
#define WOLFSSL_NO_MALLOC
583
586
```
584
587
588
+
In addition there are two build configurations. `--enable-staticmemory=small` which is a
589
+
smaller version that has smaller struct sizes and less supporting API's available. The other build
590
+
configuration is `--enable-staticmemory=debug` that enables the ability to set a callback function. This is
591
+
useful in cases where printf() is not available for determining what is being allocated and what
592
+
bucket sizes are being used. Here is what the example client output looks like with example
593
+
callback:
594
+
595
+
```
596
+
./examples/client/client
597
+
...
598
+
...
599
+
...
600
+
Free'ing : 16128
601
+
OUT BUFFER: Alloc'd 6 bytes using bucket size 16992
602
+
Alloc'd 848 bytes using bucket size 1024
603
+
OUT BUFFER: Alloc'd 150 bytes using bucket size 16992
604
+
Alloc'd 13 bytes using bucket size 64
605
+
Alloc'd 12 bytes using bucket size 64
606
+
Alloc'd 848 bytes using bucket size 1024
607
+
IN BUFFER: Alloc'd 40 bytes using bucket size 16992
608
+
Alloc'd 13 bytes using bucket size 64
609
+
Alloc'd 12 bytes using bucket size 64
610
+
Free'ing : 1024
611
+
Free'ing : 512
612
+
613
+
...
614
+
...
615
+
...
616
+
```
617
+
585
618
### Using Static Buffer Allocation
586
619
587
620
This can be helpful for environments without dynamic memory support, or safety-critical applications where dynamic memory use is disallowed.
@@ -727,9 +760,10 @@ For DTLS server
727
760
728
761
|API|description|
729
762
|:---|:---|
730
-
|`wolfSSL_CTX_load_static_memory`|Set buffer for WOLFSSL_CTX as a heap memory.
731
-
|`wolfSSL_CTX_is_static_memory`|Returns whether "Static buffer Allocation" is used. If it is the case, gets usage report.
732
-
|`wolfSSL_is_static_memory`|Returns whether "Static buffer Allocation" is used. If it is the case, gets usage report. |
763
+
|[`wolfSSL_CTX_load_static_memory`](group__Memory.md#function-wolfSSL_CTX_static_memory)| Set buffer for WOLFSSL_CTX as a heap memory. |
764
+
|[`wolfSSL_CTX_is_static_memory`](group__Memory.md#function-wolfSSL_CTX_is_static_memory)| Returns whether "Static buffer Allocation" is used. If it is the case, gets usage report. |
765
+
|[`wolfSSL_is_static_memory`](group__Memory.md#function-wolfSSL_is_static_memory)| Returns whether "Static buffer Allocation" is used. If it is the case, gets usage report. |
766
+
|[`wc_LoadStaticMemory`](group__Memory.md#function-wc_LoadStaticMemory)| Used to set aside static memory for wolfCrypt use. |
733
767
|[`wolfSSL_StaticBufferSz`](group__Memory.md#function-wolfssl_staticbuffersz)| Calculate required buffer size for "Static buffer Allocation" based on the macros defined in /wolfssl/wolfcrypt/memory.h. |
0 commit comments