- Timestamp:
- Jun 22, 2021, 9:00:19 PM (3 years ago)
- Location:
- azure_iot_hub_f767zi/trunk/wolfssl-4.7.0
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/wolfssl/wolfcrypt/wc_port.h
r457 r464 55 55 #endif 56 56 57 #ifdef WOLFSSL_LINUXKM 58 #ifdef HAVE_CONFIG_H 59 #ifndef PACKAGE_NAME 60 #error wc_port.h included before config.h 61 #endif 62 /* config.h is autogenerated without gating, and is subject to repeat 63 * inclusions, so gate it out here to keep autodetection masking 64 * intact: 65 */ 66 #undef HAVE_CONFIG_H 67 #endif 68 69 #ifdef BUILDING_WOLFSSL 70 71 _Pragma("GCC diagnostic push"); 72 73 /* we include all the needed kernel headers with these masked out. else 74 * there are profuse warnings. 75 */ 76 _Pragma("GCC diagnostic ignored \"-Wunused-parameter\""); 77 _Pragma("GCC diagnostic ignored \"-Wpointer-arith\""); 78 _Pragma("GCC diagnostic ignored \"-Wshadow\""); 79 _Pragma("GCC diagnostic ignored \"-Wnested-externs\""); 80 _Pragma("GCC diagnostic ignored \"-Wredundant-decls\""); 81 _Pragma("GCC diagnostic ignored \"-Wsign-compare\""); 82 _Pragma("GCC diagnostic ignored \"-Wpointer-sign\""); 83 _Pragma("GCC diagnostic ignored \"-Wbad-function-cast\""); 84 _Pragma("GCC diagnostic ignored \"-Wdiscarded-qualifiers\""); 85 86 #include <linux/kconfig.h> 87 #include <linux/kernel.h> 88 #include <linux/version.h> 89 #include <linux/ctype.h> 90 #include <linux/init.h> 91 #include <linux/module.h> 92 #include <linux/mm.h> 93 #ifndef SINGLE_THREADED 94 #include <linux/kthread.h> 95 #endif 96 #include <linux/net.h> 97 #include <linux/slab.h> 98 #if defined(WOLFSSL_AESNI) || defined(USE_INTEL_SPEEDUP) 99 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) 100 #include <asm/i387.h> 101 #else 102 #include <asm/simd.h> 103 #endif 104 #ifndef SAVE_VECTOR_REGISTERS 105 #define SAVE_VECTOR_REGISTERS() kernel_fpu_begin() 106 #endif 107 #ifndef RESTORE_VECTOR_REGISTERS 108 #define RESTORE_VECTOR_REGISTERS() kernel_fpu_end() 109 #endif 110 #elif defined(WOLFSSL_ARMASM) 111 #include <asm/fpsimd.h> 112 #ifndef SAVE_VECTOR_REGISTERS 113 #define SAVE_VECTOR_REGISTERS() ({ preempt_disable(); fpsimd_preserve_current_state(); }) 114 #endif 115 #ifndef RESTORE_VECTOR_REGISTERS 116 #define RESTORE_VECTOR_REGISTERS() ({ fpsimd_restore_current_state(); preempt_enable(); }) 117 #endif 118 #else 119 #ifndef SAVE_VECTOR_REGISTERS 120 #define SAVE_VECTOR_REGISTERS() ({}) 121 #endif 122 #ifndef RESTORE_VECTOR_REGISTERS 123 #define RESTORE_VECTOR_REGISTERS() ({}) 124 #endif 125 #endif 126 127 _Pragma("GCC diagnostic pop"); 128 129 /* Linux headers define these using C expressions, but we need 130 * them to be evaluable by the preprocessor, for use in sp_int.h. 131 */ 132 _Static_assert(sizeof(ULONG_MAX) == 8, "WOLFSSL_LINUXKM supported only on targets with 64 bit long words."); 133 #undef UCHAR_MAX 134 #define UCHAR_MAX 255 135 #undef USHRT_MAX 136 #define USHRT_MAX 65535 137 #undef UINT_MAX 138 #define UINT_MAX 4294967295U 139 #undef ULONG_MAX 140 #define ULONG_MAX 18446744073709551615UL 141 #undef ULLONG_MAX 142 #define ULLONG_MAX ULONG_MAX 143 #undef INT_MAX 144 #define INT_MAX 2147483647 145 #undef LONG_MAX 146 #define LONG_MAX 9223372036854775807L 147 #undef LLONG_MAX 148 #define LLONG_MAX LONG_MAX 149 150 /* remove this multifariously conflicting macro, picked up from 151 * Linux arch/<arch>/include/asm/current.h. 152 */ 153 #undef current 154 155 /* prevent gcc's mm_malloc.h from being included, since it unconditionally 156 * includes stdlib.h, which is kernel-incompatible. 157 */ 158 #define _MM_MALLOC_H_INCLUDED 159 160 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) 161 /* kvmalloc()/kvfree() and friends added in linux commit a7c3e901 */ 162 #define malloc(x) kvmalloc(x, GFP_KERNEL) 163 #define free(x) kvfree(x) 164 void *lkm_realloc(void *ptr, size_t newsize); 165 #define realloc(x, y) lkm_realloc(x, y) 166 #else 167 #define malloc(x) kmalloc(x, GFP_KERNEL) 168 #define free(x) kfree(x) 169 #define realloc(x,y) krealloc(x, y, GFP_KERNEL) 170 #endif 171 172 /* min() and max() in linux/kernel.h over-aggressively type-check, producing 173 * myriad spurious -Werrors throughout the codebase. 174 */ 175 #undef min 176 #undef max 177 178 /* work around namespace conflict between wolfssl/internal.h (enum HandShakeType) 179 * and linux/key.h (extern int()). 180 */ 181 #define key_update wc_key_update 182 183 #define lkm_printf(format, args...) printk(KERN_INFO "wolfssl: %s(): " format, __func__, ## args) 184 #define printf(...) lkm_printf(__VA_ARGS__) 185 186 #endif /* BUILDING_WOLFSSL */ 187 188 /* needed to suppress inclusion of stdio.h in wolfssl/wolfcrypt/types.h */ 189 #define XSNPRINTF snprintf 190 191 /* the rigmarole around kstrtol() here is to accommodate its warn-unused-result attribute. */ 192 #define XATOI(s) ({ \ 193 long _xatoi_res = 0; \ 194 int _xatoi_ret = kstrtol(s, 10, &_xatoi_res); \ 195 if (_xatoi_ret != 0) { \ 196 _xatoi_res = 0; \ 197 } \ 198 (int)_xatoi_res; \ 199 }) 200 201 #else /* ! WOLFSSL_LINUXKM */ 202 203 #ifndef SAVE_VECTOR_REGISTERS 204 #define SAVE_VECTOR_REGISTERS() do{}while(0) 205 #endif 206 #ifndef RESTORE_VECTOR_REGISTERS 207 #define RESTORE_VECTOR_REGISTERS() do{}while(0) 208 #endif 209 210 #endif /* WOLFSSL_LINUXKM */ 57 211 58 212 /* THREADING/MUTEX SECTION */ … … 84 238 /* do nothing, just don't pick Unix */ 85 239 #elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS) 240 /* do nothing */ 241 #elif defined(RTTHREAD) 86 242 /* do nothing */ 87 243 #elif defined(EBSNET) … … 157 313 #else 158 314 #ifndef SINGLE_THREADED 159 #define WOLFSSL_PTHREADS 160 #include <pthread.h> 315 #ifndef WOLFSSL_USER_MUTEX 316 #if defined(WOLFSSL_LINUXKM) 317 #define WOLFSSL_KTHREADS 318 #else 319 #define WOLFSSL_PTHREADS 320 #include <pthread.h> 321 #endif 322 #endif 161 323 #endif 162 324 #if (defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)) && \ 163 325 !defined(NO_FILESYSTEM) 164 #include <unistd.h> /* for close of BIO */ 326 #ifdef FUSION_RTOS 327 #include <fclunistd.h> 328 #else 329 #include <unistd.h> /* for close of BIO */ 330 #endif 165 331 #endif 166 332 #endif … … 184 350 #include "semphr.h" 185 351 typedef SemaphoreHandle_t wolfSSL_Mutex; 352 #elif defined (RTTHREAD) 353 #include "rtthread.h" 354 typedef rt_mutex_t wolfSSL_Mutex; 186 355 #elif defined(WOLFSSL_SAFERTOS) 187 356 typedef struct wolfSSL_Mutex { … … 193 362 #elif defined(WOLFSSL_PTHREADS) 194 363 typedef pthread_mutex_t wolfSSL_Mutex; 364 #elif defined(WOLFSSL_KTHREADS) 365 typedef struct mutex wolfSSL_Mutex; 195 366 #elif defined(THREADX) 196 367 typedef TX_MUTEX wolfSSL_Mutex; … … 239 410 #elif defined(WOLFSSL_TELIT_M2MB) 240 411 typedef M2MB_OS_MTX_HANDLE wolfSSL_Mutex; 412 #elif defined(WOLFSSL_USER_MUTEX) 413 /* typedef User_Mutex wolfSSL_Mutex; */ 414 #elif defined(WOLFSSL_LINUXKM) 415 typedef struct mutex wolfSSL_Mutex; 241 416 #else 242 417 #error Need a mutex type in multithreaded mode … … 246 421 /* Enable crypt HW mutex for Freescale MMCAU, PIC32MZ or STM32 */ 247 422 #if defined(FREESCALE_MMCAU) || defined(WOLFSSL_MICROCHIP_PIC32MZ) || \ 248 defined(STM32_CRYPTO) 423 defined(STM32_CRYPTO) || defined(STM32_HASH) || defined(STM32_RNG) 249 424 #ifndef WOLFSSL_CRYPT_HW_MUTEX 250 425 #define WOLFSSL_CRYPT_HW_MUTEX 1 … … 289 464 WOLFSSL_API int wolfCrypt_Cleanup(void); 290 465 466 #ifdef WOLFSSL_TRACK_MEMORY_VERBOSE 467 WOLFSSL_API long wolfCrypt_heap_peakAllocs_checkpoint(void); 468 WOLFSSL_API long wolfCrypt_heap_peakBytes_checkpoint(void); 469 #endif 470 291 471 292 472 /* FILESYSTEM SECTION */ … … 312 492 #define XBADFILE -1 313 493 #define XFGETS(b,s,f) -2 /* Not ported yet */ 494 314 495 #elif defined(LSR_FS) 315 496 #include <fs.h> … … 324 505 #define XSEEK_END 0 325 506 #define XBADFILE NULL 326 #define XFGETS(b,s,f) -2 /* Not ported yet */ 507 #define XFGETS(b,s,f) -2 /* Not ported yet */ 508 327 509 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) 328 510 #define XFILE MQX_FILE_PTR … … 337 519 #define XBADFILE NULL 338 520 #define XFGETS fgets 521 339 522 #elif defined(WOLFSSL_DEOS) 340 523 #define NO_FILESYSTEM 341 524 #warning "TODO - DDC-I Certifiable Fast File System for Deos is not integrated" 342 / /#define XFILE bfd *525 /* #define XFILE bfd * */ 343 526 344 527 #elif defined(MICRIUM) … … 355 538 #define XBADFILE NULL 356 539 #define XFGETS(b,s,f) -2 /* Not ported yet */ 540 357 541 #elif defined(WOLFSSL_NUCLEUS_1_2) 358 542 #include "fal/inc/fal.h" … … 367 551 #define XSEEK_END PSEEK_END 368 552 #define XBADFILE NULL 553 369 554 #elif defined(WOLFSSL_APACHE_MYNEWT) 370 555 #include <fs/fs.h> … … 381 566 #define XBADFILE NULL 382 567 #define XFGETS(b,s,f) -2 /* Not ported yet */ 568 383 569 #elif defined(WOLFSSL_ZEPHYR) 384 570 #include <fs.h> … … 415 601 #define XFGETS(b,s,f) -2 /* Not ported yet */ 416 602 603 #elif defined (WOLFSSL_XILINX) 604 #include "xsdps.h" 605 #include "ff.h" 606 607 /* workaround to declare variable and provide type */ 608 #define XFILE FIL curFile; FIL* 609 #define XFOPEN(NAME, MODE) ({ FRESULT res; res = f_open(&curFile, (NAME), (FA_OPEN_ALWAYS | FA_WRITE | FA_READ)); (res == FR_OK) ? &curFile : NULL; }) 610 #define XFSEEK(F, O, W) f_lseek((F), (O)) 611 #define XFTELL(F) f_tell((F)) 612 #define XREWIND(F) f_rewind((F)) 613 #define XFREAD(BUF, SZ, AMT, F) ({ FRESULT res; UINT br; res = f_read((F), (BUF), (SZ)*(AMT), &br); (void)br; res; }) 614 #define XFWRITE(BUF, SZ, AMT, F) ({ FRESULT res; UINT written; res = f_write((F), (BUF), (SZ)*(AMT), &written); (void)written; res; }) 615 #define XFCLOSE(F) f_close((F)) 616 #define XSEEK_END 0 617 #define XBADFILE NULL 618 #define XFGETS(b,s,f) f_gets((b), (s), (f)) 619 620 #elif defined(FUSION_RTOS) 621 #include <fclstdio.h> 622 #include <fclunistd.h> 623 #include <fcldirent.h> 624 #include <sys/fclstat.h> 625 #include <fclstring.h> 626 #include <fcl_os.h> 627 #define XFILE FCL_FILE* 628 #define XFOPEN FCL_FOPEN 629 #define XFSEEK FCL_FSEEK 630 #define XFTELL FCL_FTELL 631 #define XREWIND FCL_REWIND 632 #define XFREAD FCL_FREAD 633 #define XFWRITE FCL_FWRITE 634 #define XFCLOSE FCL_FCLOSE 635 #define XSEEK_END SEEK_END 636 #define XBADFILE NULL 637 #define XFGETS FCL_FGETS 638 #define XFPUTS FCL_FPUTS 639 #define XFPRINTF FCL_FPRINTF 640 #define XVFPRINTF FCL_VFPRINTF 641 #define XVSNPRINTF FCL_VSNPRINTF 642 #define XSNPRINTF FCL_SNPRINTF 643 #define XSPRINTF FCL_SPRINTF 644 #define DIR FCL_DIR 645 #define stat FCL_STAT 646 #define opendir FCL_OPENDIR 647 #define closedir FCL_CLOSEDIR 648 #define readdir FCL_READDIR 649 #define dirent fclDirent 650 #define strncasecmp FCL_STRNCASECMP 651 652 /* FUSION SPECIFIC ERROR CODE */ 653 #define FUSION_IO_SEND_E 63 654 417 655 #elif defined(WOLFSSL_USER_FILESYSTEM) 418 656 /* To be defined in user_settings.h */ … … 427 665 #define XFOPEN fopen 428 666 #endif 667 #define XFDOPEN fdopen 429 668 #define XFSEEK fseek 430 669 #define XFTELL ftell … … 436 675 #define XBADFILE NULL 437 676 #define XFGETS fgets 677 #define XFPRINTF fprintf 438 678 439 679 #if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR)\ … … 442 682 #include <unistd.h> 443 683 #include <sys/stat.h> 444 #endif 684 #define XWRITE write 685 #define XREAD read 686 #define XCLOSE close 687 #endif 688 #endif 689 690 /* Defaults, user may over-ride with user_settings.h or in a porting section 691 * above 692 */ 693 #ifndef XVFPRINTF 694 #define XVFPRINTF vfprintf 695 #endif 696 #ifndef XVSNPRINTF 697 #define XVSNPRINTF vsnprintf 698 #endif 699 #ifndef XFPUTS 700 #define XFPUTS fputs 701 #endif 702 #ifndef XSPRINTF 703 #define XSPRINTF sprintf 445 704 #endif 446 705 … … 451 710 #define MAX_PATH 256 452 711 #endif 712 713 WOLFSSL_LOCAL int wc_FileLoad(const char* fname, unsigned char** buf, 714 size_t* bufLen, void* heap); 453 715 454 716 #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_NUCLEUS) && \ … … 529 791 530 792 #elif defined(WOLFSSL_XILINX) 531 #define USER_TIME 793 #ifndef XTIME 794 #define XTIME(t1) xilinx_time((t1)) 795 #endif 532 796 #include <time.h> 533 797 … … 554 818 #elif defined(MICROCHIP_TCPIP_V5) || defined(MICROCHIP_TCPIP) 555 819 #include <time.h> 820 extern time_t pic32_time(time_t* timer); 556 821 #define XTIME(t1) pic32_time((t1)) 557 822 #define XGMTIME(c, t) gmtime((c)) … … 638 903 #define USE_WOLF_TM 639 904 905 906 #elif defined(WOLFSSL_LINUXKM) 907 #ifdef BUILDING_WOLFSSL 908 909 /* includes are all above, with incompatible warnings masked out. */ 910 #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 5, 0) 911 typedef __kernel_time_t time_t; 912 #else 913 typedef __kernel_time64_t time_t; 914 #endif 915 extern time_t time(time_t * timer); 916 #define XTIME time 917 #define WOLFSSL_GMTIME 918 #define XGMTIME(c, t) gmtime(c) 919 #define NO_TIMEVAL 1 920 921 #endif /* BUILDING_WOLFSSL */ 922 640 923 #else 641 924 /* default */ … … 675 958 #endif 676 959 #if !defined(XGMTIME) && !defined(TIME_OVERRIDES) 677 #if defined(WOLFSSL_GMTIME) || !defined(HAVE_GMTIME_R) || defined(WOLF_C99) 678 #define XGMTIME(c, t) gmtime((c)) 679 #else 960 /* Always use gmtime_r if available. */ 961 #if defined(HAVE_GMTIME_R) 680 962 #define XGMTIME(c, t) gmtime_r((c), (t)) 681 963 #define NEED_TMP_TIME 964 #else 965 #define XGMTIME(c, t) gmtime((c)) 682 966 #endif 683 967 #endif 684 968 #if !defined(XVALIDATE_DATE) && !defined(HAVE_VALIDATE_DATE) 685 969 #define USE_WOLF_VALIDDATE 686 #define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))970 #define XVALIDATE_DATE(d, f, t) wc_ValidateDate((d), (f), (t)) 687 971 #endif 688 972 … … 743 1027 744 1028 #ifndef FILE_BUFFER_SIZE 745 #define FILE_BUFFER_SIZE 1024 /* default static file buffer size for input, 1029 #define FILE_BUFFER_SIZE 1024 /* default static file buffer size for input, \ 746 1030 will use dynamic buffer if not big enough */ 747 1031 #endif
Note:
See TracChangeset
for help on using the changeset viewer.