-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes for Windows 64-bit builds #1427
base: development
Are you sure you want to change the base?
Conversation
Hi, and thanks for the contribution! To accept the contribution and any future contribution we will need a Contributor’s Licence Agreement (CLA) signed by yourself or by whoever has the authority to do so if this is a contribution from a company. For personal contributions, you can create an mbed account and accept an online agreement with a click through here, or you can find an agreement to sign and return to us, here, if the contribution is from a company or you prefer not to create an mbed account. Thanks for your understanding. Now - about the code. Looking through your PR, I can see you've made quite a few changes to the library to make it work better with Windows, and there are changes to change Mbed TLS is fundamentally a cross-platform library, and we want it to work as well on Windows as Linux as Android as a baremetal board. However, it is fundamentally a UTF-8 library, and at the moment we only support UTF-8. For accessing the filesystem I can see that's a problem in Windows. The way we try to address platform dependencies is through the platform code, which can be replaced and substituted for code that suits the platform of your choice. So for those who can't use Equally, the way to address issues of I don't think #1029 which does similar things in a different way, will suit your needs because it still has |
Hi, and thanks for the reply
The idea was to change as little as possible, as in the third commit, which failed only because macro names did not conform to local standards.
UTF-16LE is the native character format in Windows. UTF-8 would require encoding and decoding between PS. I revisited Windows-specific parts in |
Macros for function names might be better in lower case FIx in mbedtls_x509_crt_parse_file function
#define MBEDTLS_TCHAR TCHAR | ||
#define MBEDTLS_FOPEN _tfopen | ||
#else | ||
#define MBEDTLS__T(x) x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is MBEDTLS__T
supposed to mean? and MBEDTLS_TCHAR
? Please use names that are meaningful on their own. Most Mbed TLS developers aren't familiar with the Windows APIs. Also, please document when to use those macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a tough job to comment on Windows-specific changes without knowing the platform.
What is MBEDTLS__T supposed to mean? and MBEDTLS_TCHAR?
Here is a short article covering the basics: https://msdn.microsoft.com/en-us/library/dybsewaf.aspx
Please use names that are meaningful on their own.
That might be redirected to Microsoft.
In the fist commit I tried to use original macro names defined in Windows, but had to comply to local standards and to add prefixes.
when to use those macros.
In short, do not use it in non-Windows code, because after macro expansion this code should be the same as it was before the requested changes were applied. That is why TCHAR
becomes simply char and _T()
is a no-op in non-Windows environment.
#else | ||
#define MBEDTLS__T(x) x | ||
#define MBEDTLS_TCHAR char | ||
#define MBEDTLS_FOPEN fopen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but code in this PR is already working, and #1029 is still in development, and Windows-specific part of it probably was never tested.
library/x509_crt.c
Outdated
return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); | ||
|
||
hFind = FindFirstFileW( szDir, &file_data ); | ||
hFind = FindFirstFile( szDir, &file_data ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before trying to reconcile, it would be nice to get a compilable code in #1029.
I left a comment there, awaiting for changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1029 also adds an abstraction for that.
The Windows-specific part of the mbedtls_x509_crt_parse_path
function does not use any abstractions. It could be verified using cross-repository compare that this part of code has no differences with the current development
branch.
Even more, there might be no gain in enforcing Unix-style abstraction here.
Sorry, I am getting curious. |
Hi @irwir I can confirm that the Mbed clickthrough CLA has been accepted. Unfortunately, it's not integrated with Github, so the job of checkin a PR contributor against the mbed system is a manual step. |
@Patater - Please provide a design review. |
@@ -72,6 +72,9 @@ | |||
#include <sys/types.h> | |||
#include <sys/stat.h> | |||
#include <dirent.h> | |||
#define mbedtls_strlen strlen | |||
#else | |||
#define mbedtls_strlen _tcslen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to cause undefined reference to '_tcslen'
when building with MinGW-w64 (v5.0.2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue should have been resolved: 973661f.
ssl_server.exe
was built with portable istallation of MinGW, and connection tested in Firefox.
library/x509_crt.c
Outdated
memcpy( filename, path, len ); | ||
filename[len++] = '\\'; | ||
memset( filename, 0, sizeof(filename) ); | ||
_tcsncpy( filename, path, len ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to cause undefined reference to '_tcsncpy'
when building with MinGW-w64 (v5.0.2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for testing.
Could you suggest how to define these _tcslen
and _tcslen
in MinGW-w64?
In Visual Studio for Unicode builds it is
#define _tcslen wcslen
and
#define _tcsncpy wcsncpy
In ANSI builds
#define _tcslen strlen
and
#define _tcsncpy strncpy
Edit.
Found in MinGW repository, file string.h
:
size_t __cdecl wcslen(const wchar_t *_Str);
wchar_t *wcsncpy(wchar_t * __restrict__ _Dest,const wchar_t * __restrict__ _Source,size_t _Count) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
Perhaps adding preprocessor definitions would be sufficient to build successfully in MinGW-w64?
Does this PR have any better future than staying in historically-reviewed category? |
Description
Sockets in the current code are assumed to be signed integers, while in Windows sockets are unsigned long or unsigned long long depending on configuration.
Macros and minor code changes were made for better compatibility with Visual Studio.
Also Unicode file names are better handled as wide character strings.
The goal was to try to change Windows-specific parts of the code, but leave common or non-Windows code intact.
Status
READY
Requires Backporting
NO
Which branch?
development
Additional comments
The code was tested in VS 2013/2015/2017, both 32- and 64-bit.
VS 2010 projects will need testing.