-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
net.mbedtls: enable MBEDTLS_THREADING_C on Windows and macOS #27437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JalonSolov
merged 3 commits into
vlang:master
from
quaesitor-scientiam:mbedtls-threading-windows-macos
Jun 15, 2026
+249
−34
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
8853eed
net.mbedtls: enable MBEDTLS_THREADING_C on Windows and macOS
quaesitor-scientiam b96251d
builder: invalidate thirdparty objects on any module header change
quaesitor-scientiam 81ef524
builder: test thirdparty header invalidation spans the module include…
quaesitor-scientiam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * threading_alt.h - mbedtls_threading_mutex_t for MBEDTLS_THREADING_ALT. | ||
| * | ||
| * V provides this on Windows (which has no pthreads) so that | ||
| * MBEDTLS_THREADING_C can be enabled. The mutex is a Win32 CRITICAL_SECTION; | ||
| * the callbacks that operate on it live in | ||
| * vlib/net/mbedtls/mbedtls_threading.h and are installed once at startup via | ||
| * mbedtls_threading_set_alt() from the net.mbedtls module init(). | ||
| */ | ||
| #ifndef MBEDTLS_THREADING_ALT_H | ||
| #define MBEDTLS_THREADING_ALT_H | ||
|
|
||
| #include <windows.h> | ||
|
|
||
| typedef struct mbedtls_threading_mutex_t { | ||
| CRITICAL_SECTION cs; | ||
| char is_valid; | ||
| } mbedtls_threading_mutex_t; | ||
|
|
||
| #endif /* MBEDTLS_THREADING_ALT_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * mbedtls_threading.h - Win32 mutex callbacks for MBEDTLS_THREADING_ALT. | ||
| * | ||
| * On Windows, mbedtls is built with MBEDTLS_THREADING_C + MBEDTLS_THREADING_ALT | ||
| * (see thirdparty/mbedtls/include/mbedtls/mbedtls_config.h). The library then | ||
| * expects the embedder to supply the four mutex primitives via | ||
| * mbedtls_threading_set_alt(). These wrap a Win32 CRITICAL_SECTION; the matching | ||
| * mbedtls_threading_mutex_t type is defined in | ||
| * thirdparty/mbedtls/include/mbedtls/threading_alt.h. | ||
| * | ||
| * v_mbedtls_threading_setup() is called once from net.mbedtls' init() before any | ||
| * TLS use. On every other platform it is a no-op (pthread threading, or none). | ||
| */ | ||
| #ifndef V_MBEDTLS_THREADING_H | ||
| #define V_MBEDTLS_THREADING_H | ||
|
|
||
| #if defined(_WIN32) && defined(MBEDTLS_THREADING_ALT) | ||
|
|
||
| #include <windows.h> | ||
| #include <mbedtls/threading.h> | ||
| #include <mbedtls/error.h> | ||
|
|
||
| static void v_mbedtls_mutex_init(mbedtls_threading_mutex_t *m) { | ||
| InitializeCriticalSection(&m->cs); | ||
| m->is_valid = 1; | ||
| } | ||
|
|
||
| static void v_mbedtls_mutex_free(mbedtls_threading_mutex_t *m) { | ||
| if (m->is_valid) { | ||
| DeleteCriticalSection(&m->cs); | ||
| m->is_valid = 0; | ||
| } | ||
| } | ||
|
|
||
| static int v_mbedtls_mutex_lock(mbedtls_threading_mutex_t *m) { | ||
| if (!m->is_valid) { | ||
| return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; | ||
| } | ||
| EnterCriticalSection(&m->cs); | ||
| return 0; | ||
| } | ||
|
|
||
| static int v_mbedtls_mutex_unlock(mbedtls_threading_mutex_t *m) { | ||
| if (!m->is_valid) { | ||
| return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; | ||
| } | ||
| LeaveCriticalSection(&m->cs); | ||
| return 0; | ||
| } | ||
|
|
||
| static void v_mbedtls_threading_setup(void) { | ||
| mbedtls_threading_set_alt(v_mbedtls_mutex_init, v_mbedtls_mutex_free, | ||
| v_mbedtls_mutex_lock, v_mbedtls_mutex_unlock); | ||
| } | ||
|
|
||
| #else /* not (Windows + THREADING_ALT) */ | ||
|
|
||
| static void v_mbedtls_threading_setup(void) { } | ||
|
|
||
| #endif | ||
|
|
||
| #endif /* V_MBEDTLS_THREADING_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.