|
80 | 80 | /* kvmalloc()/kvfree() and friends added in linux commit a7c3e901, merged for 4.12. |
81 | 81 | * kvrealloc() added in de2860f463, merged for 5.15, backported to 5.10.137. |
82 | 82 | * moved to ultimate home (slab.h) in 8587ca6f34, merged for 5.16. |
83 | | -
|
| 83 | + * |
| 84 | + * however, until 6.11, it took an extra argument, oldsize, that makes it |
| 85 | + * incompatible with traditional libc usage patterns, so we don't try to use it. |
84 | 86 | */ |
85 | | - #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)) || \ |
86 | | - ((LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 137)) && \ |
87 | | - (LINUX_VERSION_CODE < KERNEL_VERSION(5, 11, 90))) |
| 87 | + #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) |
88 | 88 | #define HAVE_KVMALLOC |
89 | 89 | #endif |
| 90 | + #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 11, 0) |
| 91 | + #define HAVE_KVREALLOC |
| 92 | + #endif |
90 | 93 |
|
91 | 94 | /* kernel printf doesn't implement fp. */ |
92 | 95 | #ifndef WOLFSSL_NO_FLOAT_FMT |
|
306 | 309 | #endif |
307 | 310 |
|
308 | 311 | #include <linux/slab.h> |
| 312 | + #include <linux/sched.h> |
309 | 313 |
|
310 | 314 | #ifndef __PIE__ |
311 | 315 | #ifndef SINGLE_THREADED |
|
637 | 641 | typeof(kzalloc_noprof) *kzalloc_noprof; |
638 | 642 | typeof(kvmalloc_node_noprof) *kvmalloc_node_noprof; |
639 | 643 | typeof(kmalloc_trace_noprof) *kmalloc_trace_noprof; |
640 | | - typeof(kvrealloc_noprof) *kvrealloc_noprof; |
| 644 | + #ifdef HAVE_KVREALLOC |
| 645 | + typeof(kvrealloc_noprof) *kvrealloc_noprof; |
| 646 | + #endif |
641 | 647 | #else /* <6.10.0 */ |
642 | 648 | typeof(kmalloc) *kmalloc; |
643 | 649 | typeof(krealloc) *krealloc; |
644 | 650 | #ifdef HAVE_KVMALLOC |
645 | 651 | typeof(kvmalloc_node) *kvmalloc_node; |
| 652 | + #endif |
| 653 | + #ifdef HAVE_KVREALLOC |
646 | 654 | typeof(kvrealloc) *kvrealloc; |
647 | 655 | #endif |
648 | 656 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) |
|
879 | 887 | #define kzalloc(size, flags) kmalloc(size, (flags) | __GFP_ZERO) |
880 | 888 | #ifdef HAVE_KVMALLOC |
881 | 889 | #define kvmalloc_node (wolfssl_linuxkm_get_pie_redirect_table()->kvmalloc_node) |
| 890 | + #endif |
| 891 | + #ifdef HAVE_KVREALLOC |
882 | 892 | #define kvrealloc (wolfssl_linuxkm_get_pie_redirect_table()->kvrealloc) |
883 | 893 | #endif |
884 | 894 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) |
|
1175 | 1185 | #ifdef HAVE_KVMALLOC |
1176 | 1186 | #define malloc(size) kvmalloc_node(WC_LINUXKM_ROUND_UP_P_OF_2(size), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC), NUMA_NO_NODE) |
1177 | 1187 | #define free(ptr) kvfree(ptr) |
1178 | | - #define realloc(ptr, newsize) kvrealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC)) |
| 1188 | + #ifdef HAVE_KVREALLOC |
| 1189 | + #define realloc(ptr, newsize) kvrealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC)) |
| 1190 | + #else |
| 1191 | + #define realloc(ptr, newsize) ((void)(ptr), (void)(newsize), NULL) |
| 1192 | + #endif |
1179 | 1193 | #else |
1180 | 1194 | #define malloc(size) kmalloc(WC_LINUXKM_ROUND_UP_P_OF_2(size), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC)) |
1181 | 1195 | #define free(ptr) kfree(ptr) |
|
1204 | 1218 | #else |
1205 | 1219 | #define XFREE(p, h, t) ({void* _xp; (void)(h); (void)(t); _xp = (p); if(_xp) free(_xp);}) |
1206 | 1220 | #endif |
1207 | | - #define XREALLOC(p, n, h, t) ({(void)(h); (void)(t); realloc(p, n);}) |
| 1221 | + #if defined(HAVE_KVREALLOC) || !defined(HAVE_KVMALLOC) |
| 1222 | + #define XREALLOC(p, n, h, t) ({(void)(h); (void)(t); realloc(p, n);}) |
| 1223 | + #endif |
1208 | 1224 | #endif |
1209 | 1225 |
|
1210 | 1226 | #include <linux/limits.h> |
|
0 commit comments