From 8ff1b474bc2f1ed17fcb2cce2927a7bfb09e9c7e Mon Sep 17 00:00:00 2001 From: Takashi Kojo Date: Sun, 14 Jun 2020 07:12:13 +0900 Subject: [PATCH] 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 */