Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions wolfcrypt/src/wc_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -3966,6 +3966,14 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)

XMEMSET(thread, 0, sizeof(*thread));

thread->tid = (struct k_thread*)XMALLOC(
Z_KERNEL_STACK_SIZE_ADJUST(sizeof(struct k_thread)),
wolfsslThreadHeapHint, DYNAMIC_TYPE_TMP_BUFFER);
if (thread->tid == NULL) {
WOLFSSL_MSG("error: XMALLOC thread->tid failed");
return MEMORY_E;
}

/* TODO: Use the following once k_thread_stack_alloc makes it into a
* release.
* thread->threadStack = k_thread_stack_alloc(WOLFSSL_ZEPHYR_STACK_SZ,
Expand All @@ -3975,14 +3983,18 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
Z_KERNEL_STACK_SIZE_ADJUST(WOLFSSL_ZEPHYR_STACK_SZ),
wolfsslThreadHeapHint, DYNAMIC_TYPE_TMP_BUFFER);
if (thread->threadStack == NULL) {
WOLFSSL_MSG("error: XMALLOC failed");
XFREE(thread->tid, wolfsslThreadHeapHint,
DYNAMIC_TYPE_TMP_BUFFER);
thread->tid = NULL;

WOLFSSL_MSG("error: XMALLOC thread->threadStack failed");
return MEMORY_E;
}

/* k_thread_create does not return any error codes */
/* Casting to k_thread_entry_t should be fine since we just ignore the
* extra arguments being passed in */
k_thread_create(&thread->tid, thread->threadStack,
k_thread_create(thread->tid, thread->threadStack,
WOLFSSL_ZEPHYR_STACK_SZ, (k_thread_entry_t)cb, arg, NULL, NULL,
5, 0, K_NO_WAIT);

Expand All @@ -3994,10 +4006,14 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
int ret = 0;
int err;

err = k_thread_join(&thread.tid, K_FOREVER);
err = k_thread_join(thread.tid, K_FOREVER);
if (err != 0)
ret = MEMORY_E;

XFREE(thread.tid, wolfsslThreadHeapHint,
DYNAMIC_TYPE_TMP_BUFFER);
thread.tid = NULL;

/* TODO: Use the following once k_thread_stack_free makes it into a
* release.
* err = k_thread_stack_free(thread.threadStack);
Expand Down
3 changes: 2 additions & 1 deletion wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,8 @@ typedef struct w64wrapper {
typedef void THREAD_RETURN;
#define WOLFSSL_THREAD_VOID_RETURN
typedef struct {
struct k_thread tid;
/* Zephyr k_thread can be large, > 128 bytes. */
struct k_thread* tid;
k_thread_stack_t* threadStack;
} THREAD_TYPE;
#define WOLFSSL_THREAD
Expand Down