From 8ff1b474bc2f1ed17fcb2cce2927a7bfb09e9c7e Mon Sep 17 00:00:00 2001 From: Takashi Kojo Date: Sun, 14 Jun 2020 07:12:13 +0900 Subject: [PATCH 1/3] Tentative: User defined mutex --- user-mutex.c | 27 +++++++++++++++++++++++++++ user_settings.h | 2 ++ wolfcrypt/src/wc_port.c | 7 ++++++- wolfssl/wolfcrypt/wc_port.h | 8 ++++++-- 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 user-mutex.c create mode 100644 user_settings.h diff --git a/user-mutex.c b/user-mutex.c new file mode 100644 index 000000000..fca7da3cc --- /dev/null +++ b/user-mutex.c @@ -0,0 +1,27 @@ +#include + + int wc_InitMutex(wolfSSL_Mutex* m) + { + (void)m; + return 0; + } + + int wc_FreeMutex(wolfSSL_Mutex *m) + { + (void)m; + return 0; + } + + + int wc_LockMutex(wolfSSL_Mutex *m) + { + (void)m; + return 0; + } + + + int wc_UnLockMutex(wolfSSL_Mutex *m) + { + (void)m; + return 0; + } \ No newline at end of file diff --git a/user_settings.h b/user_settings.h new file mode 100644 index 000000000..23554d6e4 --- /dev/null +++ b/user_settings.h @@ -0,0 +1,2 @@ + +typedef int wolfSSL_Mutex; diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 087807b71..5b67c2633 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -647,7 +647,7 @@ int z_fs_close(XFILE file) #endif /* !NO_FILESYSTEM && !WOLFSSL_ZEPHYR */ - +#if !defined(WOLFSSL_USER_MUTEX) wolfSSL_Mutex* wc_InitAndAllocMutex(void) { wolfSSL_Mutex* m = (wolfSSL_Mutex*) XMALLOC(sizeof(wolfSSL_Mutex), NULL, @@ -665,6 +665,7 @@ wolfSSL_Mutex* wc_InitAndAllocMutex(void) return m; } +#endif #ifdef USE_WOLF_STRTOK /* String token (delim) search. If str is null use nextp. */ @@ -1845,6 +1846,10 @@ int wolfSSL_CryptHwMutexUnLock(void) { return 0; } +#elif defined(WOLFSSL_USER_MUTEX) + + /* Use user own mutex */ + #else #warning No mutex handling defined diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 88c7bfe34..cf54e5de1 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -156,8 +156,10 @@ #else #ifndef SINGLE_THREADED - #define WOLFSSL_PTHREADS - #include + #ifndef WOLFSSL_USER_MUTEX + #define WOLFSSL_PTHREADS + #include + #endif #endif #if (defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)) && \ !defined(NO_FILESYSTEM) @@ -238,6 +240,8 @@ typedef struct k_mutex wolfSSL_Mutex; #elif defined(WOLFSSL_TELIT_M2MB) typedef M2MB_OS_MTX_HANDLE wolfSSL_Mutex; + #elif defined(WOLFSSL_USER_MUTEX) + /* typedef User_Mutex wolfSSL_Mutex; */ #else #error Need a mutex type in multithreaded mode #endif /* USE_WINDOWS_API */ From 1253be01423209481929fa6b6b2160de030904b8 Mon Sep 17 00:00:00 2001 From: Takashi Kojo Date: Tue, 23 Jun 2020 17:30:03 +0900 Subject: [PATCH 2/3] Remove user_setting.h and user-mutex.c example files --- user-mutex.c | 27 --------------------------- user_settings.h | 2 -- 2 files changed, 29 deletions(-) delete mode 100644 user-mutex.c delete mode 100644 user_settings.h diff --git a/user-mutex.c b/user-mutex.c deleted file mode 100644 index fca7da3cc..000000000 --- a/user-mutex.c +++ /dev/null @@ -1,27 +0,0 @@ -#include - - int wc_InitMutex(wolfSSL_Mutex* m) - { - (void)m; - return 0; - } - - int wc_FreeMutex(wolfSSL_Mutex *m) - { - (void)m; - return 0; - } - - - int wc_LockMutex(wolfSSL_Mutex *m) - { - (void)m; - return 0; - } - - - int wc_UnLockMutex(wolfSSL_Mutex *m) - { - (void)m; - return 0; - } \ No newline at end of file diff --git a/user_settings.h b/user_settings.h deleted file mode 100644 index 23554d6e4..000000000 --- a/user_settings.h +++ /dev/null @@ -1,2 +0,0 @@ - -typedef int wolfSSL_Mutex; From 55bb95823c4e7bde7e656df3587afcd16b2b44b1 Mon Sep 17 00:00:00 2001 From: Takashi Kojo Date: Wed, 24 Jun 2020 07:31:20 +0900 Subject: [PATCH 3/3] coding template --- wolfcrypt/src/wc_port.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 5b67c2633..3b07e3d84 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -1849,6 +1849,13 @@ int wolfSSL_CryptHwMutexUnLock(void) { #elif defined(WOLFSSL_USER_MUTEX) /* Use user own mutex */ + + /* + int wc_InitMutex(wolfSSL_Mutex* m) { ... } + int wc_FreeMutex(wolfSSL_Mutex *m) { ... } + int wc_LockMutex(wolfSSL_Mutex *m) { ... } + int wc_UnLockMutex(wolfSSL_Mutex *m) { ... } + */ #else #warning No mutex handling defined