|
249 | 249 | #define LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT |
250 | 250 | #endif |
251 | 251 |
|
| 252 | + #if (LINUX_VERSION_CODE >= KERNEL_VERSION(7, 1, 0)) && \ |
| 253 | + defined(WC_SYM_RELOC_TABLES) && \ |
| 254 | + !defined(WC_LINUXKM_NO_USE_HEAP_WRAPPERS) && \ |
| 255 | + !defined(WC_LINUXKM_USE_HEAP_WRAPPERS) |
| 256 | + #define WC_LINUXKM_USE_HEAP_WRAPPERS |
| 257 | + #endif |
| 258 | + |
252 | 259 | #ifdef BUILDING_WOLFSSL |
253 | 260 |
|
254 | 261 | #if ((LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0)) || \ |
|
521 | 528 | #include <linux/mm.h> |
522 | 529 | #endif |
523 | 530 |
|
| 531 | + #ifdef WC_LINUXKM_USE_HEAP_WRAPPERS |
| 532 | + WOLFSSL_API void *wc_linuxkm_malloc(size_t size); |
| 533 | + WOLFSSL_API void wc_linuxkm_free(void *ptr); |
| 534 | + WOLFSSL_API void *wc_linuxkm_realloc(void *ptr, size_t newsize); |
| 535 | + WOLFSSL_API size_t wc_linuxkm_malloc_usable_size(void *ptr); |
| 536 | + #endif |
| 537 | + |
524 | 538 | #ifndef WC_CONTAINERIZE_THIS |
525 | 539 | #include <linux/kthread.h> |
526 | 540 | #include <linux/net.h> |
|
973 | 987 |
|
974 | 988 | const unsigned char *_ctype; |
975 | 989 |
|
| 990 | +#ifdef WC_LINUXKM_USE_HEAP_WRAPPERS |
| 991 | + typeof(wc_linuxkm_malloc) *wc_linuxkm_malloc; |
| 992 | + typeof(wc_linuxkm_free) *wc_linuxkm_free; |
| 993 | + typeof(wc_linuxkm_realloc) *wc_linuxkm_realloc; |
| 994 | + typeof(wc_linuxkm_malloc_usable_size) *wc_linuxkm_malloc_usable_size; |
| 995 | +#else /* !WC_LINUXKM_USE_HEAP_WRAPPERS */ |
976 | 996 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 18, 0) |
977 | 997 | typeof(kmalloc_noprof) *kmalloc_noprof; |
978 | 998 | typeof(krealloc_node_align_noprof) *krealloc_node_align_noprof; |
|
1023 | 1043 | #endif |
1024 | 1044 | typeof(kfree) *kfree; |
1025 | 1045 | typeof(ksize) *ksize; |
| 1046 | +#endif /* !WC_LINUXKM_USE_HEAP_WRAPPERS */ |
1026 | 1047 |
|
1027 | 1048 | #ifndef LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT |
1028 | 1049 | typeof(get_random_bytes) *get_random_bytes; |
|
1313 | 1334 |
|
1314 | 1335 | #define _ctype WC_PIE_INDIRECT_SYM(_ctype) |
1315 | 1336 |
|
| 1337 | +#ifdef WC_LINUXKM_USE_HEAP_WRAPPERS |
| 1338 | + /* no native heap call masking -- wc_linuxkm wrapper functions bound |
| 1339 | + * directly to malloc() and friends. |
| 1340 | + */ |
| 1341 | +#else /* !WC_LINUXKM_USE_HEAP_WRAPPERS */ |
1316 | 1342 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 18, 0) |
1317 | 1343 | /* see include/linux/alloc_tag.h and include/linux/slab.h */ |
1318 | 1344 | #define kmalloc_noprof WC_PIE_INDIRECT_SYM(kmalloc_noprof) |
|
1368 | 1394 | #define kvfree WC_PIE_INDIRECT_SYM(kvfree) |
1369 | 1395 | #endif |
1370 | 1396 | #define ksize WC_PIE_INDIRECT_SYM(ksize) |
| 1397 | +#endif /* !WC_LINUXKM_USE_HEAP_WRAPPERS */ |
1371 | 1398 |
|
1372 | 1399 | #ifndef LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT |
1373 | 1400 | #define get_random_bytes WC_PIE_INDIRECT_SYM(get_random_bytes) |
|
1705 | 1732 | #error WOLFSSL_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture. |
1706 | 1733 | #endif /* !CONFIG_X86 */ |
1707 | 1734 | #endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */ |
| 1735 | + #ifdef WC_LINUXKM_USE_HEAP_WRAPPERS |
| 1736 | + WOLFSSL_API extern void *wc_linuxkm_malloc(size_t size); |
| 1737 | + WOLFSSL_API void wc_linuxkm_free(void *ptr); |
| 1738 | + WOLFSSL_API void *wc_linuxkm_realloc(void *ptr, size_t newsize); |
| 1739 | + WOLFSSL_API size_t wc_linuxkm_malloc_usable_size(void *ptr); |
| 1740 | + #endif |
1708 | 1741 | #endif /* !BUILDING_WOLFSSL */ |
1709 | 1742 |
|
1710 | 1743 | /* Copied from wc_port.h */ |
|
1859 | 1892 | ((sizeof(_alloc_sz) * 8UL) - __builtin_clzl(_alloc_sz - 1)); \ |
1860 | 1893 | _alloc_sz; \ |
1861 | 1894 | }) |
| 1895 | + |
| 1896 | + #ifdef WC_LINUXKM_USE_HEAP_WRAPPERS |
| 1897 | + #ifdef WC_CONTAINERIZE_THIS |
| 1898 | + #define malloc(size) WC_PIE_INDIRECT_SYM(wc_linuxkm_malloc)(size) |
| 1899 | + #define free(ptr) WC_PIE_INDIRECT_SYM(wc_linuxkm_free)(ptr) |
| 1900 | + #define realloc(ptr, newsize) WC_PIE_INDIRECT_SYM(wc_linuxkm_realloc)(ptr, newsize) |
| 1901 | + #else |
| 1902 | + #define malloc(size) wc_linuxkm_malloc(size) |
| 1903 | + #define free(ptr) wc_linuxkm_free(ptr) |
| 1904 | + #define realloc(ptr, newsize) wc_linuxkm_realloc(ptr, newsize) |
| 1905 | + #endif |
| 1906 | + #else /* !WC_LINUXKM_USE_HEAP_WRAPPERS */ |
1862 | 1907 | #ifdef USE_KVMALLOC |
1863 | 1908 | #define malloc(size) kvmalloc_node(WC_LINUXKM_ROUND_UP_P_OF_2(size), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC), NUMA_NO_NODE) |
1864 | | - #define free(ptr) kvfree(ptr) |
| 1909 | + #if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 2, 0) |
| 1910 | + #define free(ptr) (preempt_count() == 0 ? kvfree(ptr) : kvfree_atomic(ptr)) |
| 1911 | + #else |
| 1912 | + #define free(ptr) kvfree(ptr) |
| 1913 | + #endif |
1865 | 1914 | #ifdef USE_KVREALLOC |
1866 | 1915 | #define realloc(ptr, newsize) kvrealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC)) |
1867 | 1916 | #else |
|
1872 | 1921 | #define free(ptr) kfree(ptr) |
1873 | 1922 | #define realloc(ptr, newsize) krealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC)) |
1874 | 1923 | #endif |
| 1924 | + #endif /* !WC_LINUXKM_USE_HEAP_WRAPPERS */ |
1875 | 1925 |
|
1876 | 1926 | #ifndef static_assert |
1877 | 1927 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr) |
|
0 commit comments