@@ -101,48 +101,72 @@ WOLFSSL_API int wolfSSL_GetAllocators(wolfSSL_Malloc_cb* mf,
101101 #ifndef WOLFSSL_STATIC_ALIGN
102102 #define WOLFSSL_STATIC_ALIGN 16
103103 #endif
104+ /* WOLFMEM_BUCKETS - list of the sizes of buckets in the pool
105+ * WOLFMEM_DIST - list of quantities of buffers in the buckets
106+ * WOLFMEM_DEF_BUCKETS - number of values in WOLFMEM_BUCKETS and WOLFMEM_DIST
107+ * WOLFMEM_MAX_BUCKETS - size of the arrays used to store the buckets and
108+ * dists in the memory pool; defaults to WOLFMEM_DEF_BUCKETS
109+ *
110+ * The following defines provide a reasonable set of buckets in the memory
111+ * pool for running wolfSSL on a Linux box. The bucket and dist lists below
112+ * have nine items each, so WOLFMEM_DEF_BUCKETS is set to 9.
113+ *
114+ * If WOLFMEM_DEF_BUCKETS is less then WOLFMEM_MAX_BUCKETS, the unused values
115+ * are set to zero and ignored. If WOLFMEM_MAX_BUCKETS is less than
116+ * WOLFMEM_DEF_BUCKETS, not all the buckets will be created in the pool.
117+ */
118+ #ifndef WOLFMEM_DEF_BUCKETS
119+ #define WOLFMEM_DEF_BUCKETS 9 /* number of default memory blocks */
120+ #endif
121+
104122 #ifndef WOLFMEM_MAX_BUCKETS
105- #define WOLFMEM_MAX_BUCKETS 9
123+ #define WOLFMEM_MAX_BUCKETS WOLFMEM_DEF_BUCKETS
124+ #endif
125+
126+ #if WOLFMEM_MAX_BUCKETS < WOLFMEM_DEF_BUCKETS
127+ #warning "ignoring excess buckets, MAX_BUCKETS less than DEF_BUCKETS"
106128 #endif
107- #define WOLFMEM_DEF_BUCKETS 9 /* number of default memory blocks */
129+
108130 #ifndef WOLFMEM_IO_SZ
109131 #define WOLFMEM_IO_SZ 16992 /* 16 byte aligned */
110132 #endif
133+
134+ #ifndef LARGEST_MEM_BUCKET
135+ #ifndef SESSION_CERTS
136+ #define LARGEST_MEM_BUCKET 16128
137+ #elif defined(OPENSSL_EXTRA )
138+ #ifdef WOLFSSL_TLS13
139+ #define LARGEST_MEM_BUCKET 30400
140+ #else
141+ #define LARGEST_MEM_BUCKET 25600
142+ #endif
143+ #elif defined(WOLFSSL_CERT_EXT )
144+ /* certificate extensions requires 24k for the SSL struct */
145+ #define LARGEST_MEM_BUCKET 24576
146+ #else
147+ /* increase 23k for object member of WOLFSSL_X509_NAME_ENTRY */
148+ #define LARGEST_MEM_BUCKET 23440
149+ #endif
150+ #endif
151+
111152 #ifndef WOLFMEM_BUCKETS
112153 #ifndef SESSION_CERTS
113154 /* default size of chunks of memory to separate into */
114- #ifndef LARGEST_MEM_BUCKET
115- #define LARGEST_MEM_BUCKET 16128
116- #endif
117155 #define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3456,4544,\
118156 LARGEST_MEM_BUCKET
119- #elif defined (OPENSSL_EXTRA )
157+ #elif defined(OPENSSL_EXTRA )
120158 /* extra storage in structs for multiple attributes and order */
121- #ifndef LARGEST_MEM_BUCKET
122- #ifdef WOLFSSL_TLS13
123- #define LARGEST_MEM_BUCKET 30400
124- #else
125- #define LARGEST_MEM_BUCKET 25600
126- #endif
127- #endif
128159 #define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3360,4480,\
129160 LARGEST_MEM_BUCKET
130- #elif defined (WOLFSSL_CERT_EXT )
131- /* certificate extensions requires 24k for the SSL struct */
132- #ifndef LARGEST_MEM_BUCKET
133- #define LARGEST_MEM_BUCKET 24576
134- #endif
161+ #elif defined(WOLFSSL_CERT_EXT )
135162 #define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3456,4544,\
136163 LARGEST_MEM_BUCKET
137164 #else
138- /* increase 23k for object member of WOLFSSL_X509_NAME_ENTRY */
139- #ifndef LARGEST_MEM_BUCKET
140- #define LARGEST_MEM_BUCKET 23440
141- #endif
142165 #define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3456,4544,\
143166 LARGEST_MEM_BUCKET
144167 #endif
145168 #endif
169+
146170 #ifndef WOLFMEM_DIST
147171 #ifndef WOLFSSL_STATIC_MEMORY_SMALL
148172 #define WOLFMEM_DIST 49,10,6,14,5,6,9,1,1
0 commit comments